Sebastian Sdorra avatar Sebastian Sdorra committed 2cf4cf0

using google guice instead of weld

Comments (0)

Files changed (9)

   </modules>
 
   <repositories>
+
     <repository>
       <id>java.net2</id>
       <name>Repository hosting the jee6 artifacts</name>
       <url>http://download.java.net/maven/2</url>
     </repository>
+
+  <repository>
+    <id>guice-maven</id>
+    <name>guice maven</name>
+    <url>http://guiceyfruit.googlecode.com/svn/repo/releases</url>
+  </repository>
+
+
   </repositories>
 
   <dependencies>

scm-webapp/pom.xml

   <dependencies>
 
     <dependency>
-      <groupId>javax</groupId>
-      <artifactId>javaee-web-api</artifactId>
-      <version>6.0</version>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+      <version>2.5</version>
       <scope>provided</scope>
     </dependency>
 
     <dependency>
       <groupId>com.sun.jersey</groupId>
       <artifactId>jersey-core</artifactId>
-      <version>1.1.0-ea</version>
-      <scope>provided</scope>
+      <version>${jersey.version}</version>
     </dependency>
 
     <dependency>
       <groupId>com.sun.jersey</groupId>
       <artifactId>jersey-json</artifactId>
-      <version>1.1.0-ea</version>
-      <scope>provided</scope>
+      <version>${jersey.version}</version>
     </dependency>
 
     <dependency>
       <groupId>com.sun.jersey</groupId>
       <artifactId>jersey-bundle</artifactId>
-      <version>1.1.0-ea</version>
-      <scope>provided</scope>
+      <version>${jersey.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>com.sun.jersey.contribs</groupId>
+      <artifactId>jersey-guice</artifactId>
+      <version>${jersey.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>com.google.inject</groupId>
+      <artifactId>guice</artifactId>
+      <version>2.0</version>
+    </dependency>
+
+    <dependency>
+      <groupId>com.google.inject.extensions</groupId>
+      <artifactId>guice-servlet</artifactId>
+      <version>2.0</version>
     </dependency>
 
   </dependencies>
 
   <build>
+
     <plugins>
 
       <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-war-plugin</artifactId>
-        <version>2.1-beta-1</version>
-        <configuration>
-          <failOnMissingWebXml>false</failOnMissingWebXml>
-        </configuration>
+        <groupId>org.mortbay.jetty</groupId>
+        <artifactId>maven-jetty-plugin</artifactId>
+        <version>6.1.25</version>
       </plugin>
 
     </plugins>
 
     <finalName>scm-webapp</finalName>
+  </build>
 
-  </build>
+  <properties>
+    <jersey.version>1.4-ea06</jersey.version>
+  </properties>
 
   <profiles>
 

scm-webapp/src/main/java/sonia/scm/ContextListener.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+
+
+package sonia.scm;
+
+//~--- non-JDK imports --------------------------------------------------------
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.servlet.GuiceServletContextListener;
+import com.google.inject.servlet.ServletModule;
+
+import sonia.scm.api.rest.UriExtensionsConfig;
+import sonia.scm.security.Authenticator;
+import sonia.scm.security.DemoAuthenticator;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import com.sun.jersey.api.core.PackagesResourceConfig;
+import com.sun.jersey.api.core.ResourceConfig;
+import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
+import com.sun.jersey.spi.container.servlet.ServletContainer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * @author Sebastian Sdorra
+ */
+public class ContextListener extends GuiceServletContextListener
+{
+
+  /** Field description */
+  public static final String REST_MAPPING = "/api/rest/*";
+
+  /** Field description */
+  public static final String REST_PACKAGE = "sonia.scm.api.rest";
+
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  @Override
+  protected Injector getInjector()
+  {
+    return Guice.createInjector(new ServletModule()
+    {
+      @Override
+      protected void configureServlets()
+      {
+        bind(Authenticator.class).to(DemoAuthenticator.class);
+
+        Map<String, String> params = new HashMap<String, String>();
+
+        /*
+         * params.put("com.sun.jersey.spi.container.ContainerRequestFilters",
+         *          "com.sun.jersey.api.container.filter.LoggingFilter");
+         * params.put("com.sun.jersey.spi.container.ContainerResponseFilters",
+         *          "com.sun.jersey.api.container.filter.LoggingFilter");
+         * params.put("com.sun.jersey.config.feature.Trace", "true");
+         * params.put("com.sun.jersey.config.feature.TracePerRequest", "true");
+         */
+        params.put(ResourceConfig.FEATURE_REDIRECT, Boolean.TRUE.toString());
+        params.put(ServletContainer.RESOURCE_CONFIG_CLASS,
+                   UriExtensionsConfig.class.getName());
+        params.put(PackagesResourceConfig.PROPERTY_PACKAGES, REST_PACKAGE);
+        serve(REST_MAPPING).with(GuiceContainer.class, params);
+      }
+    });
+  }
+}

scm-webapp/src/main/java/sonia/scm/api/rest/resources/AuthenticationResource.java

 
 //~--- non-JDK imports --------------------------------------------------------
 
+import com.google.inject.Inject;
+
 import sonia.scm.SCMContext;
 import sonia.scm.ScmState;
 import sonia.scm.User;
 
 //~--- JDK imports ------------------------------------------------------------
 
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
 import javax.servlet.http.HttpServletRequest;
 
 import javax.ws.rs.FormParam;
  *
  * @author Sebastian Sdorra
  */
-@Singleton
 @Path("authentication")
 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
 public class AuthenticationResource

scm-webapp/src/main/java/sonia/scm/api/rest/resources/GroupResource.java

 import java.util.Collection;
 import java.util.LinkedHashMap;
 
-import javax.inject.Singleton;
-
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
  *
  * @author Sebastian Sdorra
  */
-@Singleton
 @Path("groups")
 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
 public class GroupResource extends AbstractResource<Group>

scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java

 import java.util.HashMap;
 import java.util.LinkedHashMap;
 
-import javax.inject.Singleton;
 
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
  *
  * @author Sebastian Sdorra
  */
-@Singleton
 @Path("repositories")
 @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
 public class RepositoryResource extends AbstractResource<Repository>

scm-webapp/src/main/java/sonia/scm/security/SecurityFilter.java

 
 //~--- non-JDK imports --------------------------------------------------------
 
+import com.google.inject.Inject;
 import sonia.scm.User;
 
 //~--- JDK imports ------------------------------------------------------------
 
 import java.security.Principal;
 
-import javax.inject.Inject;
 
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
-import javax.servlet.annotation.WebFilter;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequestWrapper;
 import javax.servlet.http.HttpServletResponse;
  *
  * @author Sebastian Sdorra
  */
-@WebFilter(urlPatterns = "/api/rest/*")
 public class SecurityFilter implements Filter
 {
 

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

-<?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>

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

 <?xml version="1.0" encoding="UTF-8"?>
-<web-app 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/web-app_3_0.xsd"
-	 version="3.0">
+<web-app version="2.5" 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/web-app_2_5.xsd">
 
-  <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>
+  <listener>
+    <listener-class>sonia.scm.ContextListener</listener-class>
+  </listener>
 
-  <servlet-mapping>
-    <servlet-name>Jersey Web Application</servlet-name>
-    <url-pattern>/api/rest/*</url-pattern>
-  </servlet-mapping>
+  <filter>
+    <filter-name>guiceFilter</filter-name>
+    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
+  </filter>
+
+  <filter-mapping>
+    <filter-name>guiceFilter</filter-name>
+    <url-pattern>/*</url-pattern>
+  </filter-mapping>
 
   <welcome-file-list>
     <welcome-file>index.html</welcome-file>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.