Skip to content
Browse files

initial implementation (no jackson yet)

  • Loading branch information...
0 parents commit d989d400d0332f53ffd12277226aaa368e5866ea @sunnygleason committed Jul 17, 2010
7 .gitignore
@@ -0,0 +1,7 @@
+*.DS_Store*
+bin
+target
+.classpath
+.project
+.settings
+test-output
90 pom.xml
@@ -0,0 +1,90 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.g414.j4</groupId>
+ <artifactId>j4-minimal</artifactId>
+ <version>0.1.0</version>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>maven2-repository.dev.java.net</id>
+ <name>Java.net Repository for Maven</name>
+ <url>http://download.java.net/maven/2/</url>
+ <layout>default</layout>
+ </pluginRepository>
+ <pluginRepository>
+ <id>maven-repository.dev.java.net</id>
+ <name>Java.net Maven 1 Repository (legacy)</name>
+ <url>http://download.java.net/maven/1</url>
+ <layout>legacy</layout>
+ </pluginRepository>
+ </pluginRepositories>
+
+ <repositories>
+ <repository>
+ <id>m1.dev.java.net</id>
+ <url>http://download.java.net/maven/1</url>
+ <layout>legacy</layout>
+ </repository>
+ <repository>
+ <id>m2.dev.java.net</id>
+ <url>http://download.java.net/maven/2</url>
+ <layout>default</layout>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>6.1.24</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>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-server</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey.contribs</groupId>
+ <artifactId>jersey-guice</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>5.11</version>
+ <classifier>jdk15</classifier>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludedGroups>slow</excludedGroups>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
+
22 src/main/java/com/g414/j4/minimal/EmptyServlet.java
@@ -0,0 +1,22 @@
+package com.g414.j4.minimal;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * An Empty, "do nothing servlet" to add to the context. Otherwise, the filters
+ * will never kick in.
+ */
+public class EmptyServlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ throw new IllegalStateException("unable to service request");
+ }
+}
23 src/main/java/com/g414/j4/minimal/Main.java
@@ -0,0 +1,23 @@
+package com.g414.j4.minimal;
+
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.servlet.Context;
+
+import com.google.inject.servlet.GuiceFilter;
+
+/**
+ * Starts an embedded Jetty server.
+ */
+public class Main {
+ public static void main(String[] args) throws Exception {
+ Server server = new Server(8080);
+ Context root = new Context(server, "/", Context.SESSIONS);
+
+ root.addEventListener(new SampleConfig());
+ root.addFilter(GuiceFilter.class, "/*", 0);
+
+ root.addServlet(EmptyServlet.class, "/*");
+
+ server.start();
+ }
+}
26 src/main/java/com/g414/j4/minimal/SampleConfig.java
@@ -0,0 +1,26 @@
+package com.g414.j4.minimal;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.servlet.GuiceServletContextListener;
+import com.google.inject.servlet.ServletModule;
+import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
+
+/**
+ * Example Guice Server configuration. Creates an Injector, and binds it to
+ * whatever Modules we want. In this case, we use an anonymous Module, but other
+ * modules are welcome as well.
+ */
+public class SampleConfig extends GuiceServletContextListener {
+ @Override
+ protected Injector getInjector() {
+ return Guice.createInjector(new ServletModule() {
+ @Override
+ protected void configureServlets() {
+ bind(SampleResource.class);
+
+ serve("*").with(GuiceContainer.class);
+ }
+ });
+ }
+}
21 src/main/java/com/g414/j4/minimal/SampleResource.java
@@ -0,0 +1,21 @@
+package com.g414.j4.minimal;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+/**
+ * The Jersey Resource itself. Note that this class is a POJO - it does not need
+ * to know anything about Guice. Although, if we wanted to Inject members using
+ * Guice, we could!
+ */
+@Path("/sample")
+public class SampleResource {
+ @GET
+ @Produces("text/plain")
+ @Path("{who}")
+ public String sayGreeting(@PathParam("who") String name) {
+ return "Greetings, " + name + "!";
+ }
+}

0 comments on commit d989d40

Please sign in to comment.
Something went wrong with that request. Please try again.