1. Sebastian Sdorra
  2. scm-manager

Commits

Sebastian Sdorra  committed dc99e64

added jersey for rest api

  • Participants
  • Parent commits 4ddf42e
  • Branches default

Comments (0)

Files changed (8)

File scm-webapp/pom.xml

View file
       <scope>test</scope>
     </dependency>
 
+
+    <dependency>
+      <groupId>com.sun.jersey</groupId>
+      <artifactId>jersey-core</artifactId>
+      <version>1.1.0-ea</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>com.sun.jersey</groupId>
+      <artifactId>jersey-json</artifactId>
+      <version>1.1.0-ea</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>com.sun.jersey</groupId>
+      <artifactId>jersey-bundle</artifactId>
+      <version>1.1.0-ea</version>
+      <scope>provided</scope>
+    </dependency>
+
   </dependencies>
 
   <build>

File scm-webapp/src/main/java/sonia/scm/Group.java

View file
 import java.util.Iterator;
 import java.util.List;
 
+import javax.xml.bind.annotation.XmlRootElement;
+
 /**
  *
  * @author Sebastian Sdorra
  */
+@XmlRootElement
 public class Group implements Serializable
 {
 

File scm-webapp/src/main/java/sonia/scm/api/rest/JsonJaxbContextResolver.java

View file
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+
+
+package sonia.scm.api.rest;
+
+//~--- non-JDK imports --------------------------------------------------------
+
+import sonia.scm.Group;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import com.sun.jersey.api.json.JSONConfiguration;
+import com.sun.jersey.api.json.JSONJAXBContext;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.Provider;
+
+import javax.xml.bind.JAXBContext;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+@Provider
+public class JsonJaxbContextResolver implements ContextResolver<JAXBContext>
+{
+
+  /**
+   * Constructs ...
+   *
+   *
+   * @throws Exception
+   */
+  public JsonJaxbContextResolver() throws Exception
+  {
+    this.context = new JSONJAXBContext(
+        JSONConfiguration.mapped().rootUnwrapping(true).arrays(
+          "members").build(), types.toArray(new Class[0]));
+  }
+
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @param objectType
+   *
+   * @return
+   */
+  @Override
+  public JAXBContext getContext(Class<?> objectType)
+  {
+    return (types.contains(objectType))
+           ? context
+           : null;
+  }
+
+  //~--- fields ---------------------------------------------------------------
+
+  /** Field description */
+  private JAXBContext context;
+
+  /** Field description */
+  private List<Class> types = Arrays.asList(new Class[] { Group.class });
+}

File scm-webapp/src/main/java/sonia/scm/api/rest/UriExtensionsConfig.java

View file
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+
+
+package sonia.scm.api.rest;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import com.sun.jersey.api.core.PackagesResourceConfig;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+public class UriExtensionsConfig extends PackagesResourceConfig
+{
+
+  /**
+   * Constructs ...
+   *
+   */
+  public UriExtensionsConfig()
+  {
+    super();
+  }
+
+  /**
+   * Constructs ...
+   *
+   *
+   * @param props
+   */
+  public UriExtensionsConfig(Map<String, Object> props)
+  {
+    super(props);
+  }
+
+  /**
+   * Constructs ...
+   *
+   *
+   * @param paths
+   */
+  public UriExtensionsConfig(String[] paths)
+  {
+    super(paths);
+  }
+
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  @Override
+  public Map<String, MediaType> getMediaTypeMappings()
+  {
+    if (mediaTypeMap == null)
+    {
+      mediaTypeMap = new HashMap<String, MediaType>();
+      mediaTypeMap.put("json", MediaType.APPLICATION_JSON_TYPE);
+      mediaTypeMap.put("xml", MediaType.APPLICATION_XML_TYPE);
+    }
+
+    return mediaTypeMap;
+  }
+
+  //~--- fields ---------------------------------------------------------------
+
+  /** Field description */
+  private Map<String, MediaType> mediaTypeMap;
+}

File scm-webapp/src/main/webapp/WEB-INF/beans.xml

View file
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+    Document   : beans.xml
+    Created on : September 3, 2010, 2:32 PM
+    Author     : sdorra
+    Description:
+        Purpose of the document follows.
+-->
+
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+
+  <!--
+  <alternatives>
+    <class></class>
+  </alternatives>
+  -->
+
+</beans>

File scm-webapp/src/main/webapp/WEB-INF/web.xml

View file
 	 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 	 version="3.0">
 
-    <session-config>
-        <session-timeout>
+  <servlet>
+    <servlet-name>Jersey Web Application</servlet-name>
+    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+    <init-param>
+      <param-name>com.sun.jersey.config.feature.Redirect</param-name>
+      <param-value>true</param-value>
+    </init-param>
+    <init-param>
+      <param-name>com.sun.jersey.config.feature.ImplicitViewables</param-name>
+      <param-value>true</param-value>
+    </init-param>
+    <init-param>
+      <param-name>com.sun.jersey.config.property.packages</param-name>
+      <param-value>sonia.scm.api.rest</param-value>
+    </init-param>
+    <init-param>
+      <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
+      <param-value>sonia.scm.api.rest.UriExtensionsConfig</param-value>
+    </init-param>
+    <load-on-startup>1</load-on-startup>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>Jersey Web Application</servlet-name>
+    <url-pattern>/api/rest/*</url-pattern>
+  </servlet-mapping>
+
+  <welcome-file-list>
+    <welcome-file>index.html</welcome-file>
+  </welcome-file-list>
+
+  <session-config>
+    <session-timeout>
             30
-        </session-timeout>
-    </session-config>
-    
+    </session-timeout>
+  </session-config>
+
 </web-app>

File scm-webapp/src/main/webapp/index.html

View file
+<!--
+To change this template, choose Tools | Templates
+and open the template in the editor.
+-->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+  <head>
+    <title></title>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+  </head>
+  <body>
+    TODO write content
+  </body>
+</html>

File scm-webapp/src/main/webapp/index.jsp

-<%@page contentType="text/html" pageEncoding="UTF-8"%>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
-   "http://www.w3.org/TR/html4/loose.dtd">
-
-<html>
-    <head>
-        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-        <title>JSP Page</title>
-    </head>
-    <body>
-        <h1>Hello World!</h1>
-    </body>
-</html>