title: Grizzly and ServletContainerContext
body: <p>I'm trying to get hold of some injected context (for example Session or HttpServletRequest) in a Servlet I've written, running on Grizzly, but nothing I do seems to work. The whole process seems to stall rather prematurely with the following error:</p>
  
  <pre><code>SEVERE: Missing dependency for field: javax.servlet.http.HttpServletRequest com.test.server.LolCat.hsr
  </code></pre>
  
  <p>The server is dead simple, it consists of two files, the static entry point (Main.java):</p>
  
  <pre><code>package com.test.server;
  
  import java.io.IOException;
  import java.net.URI;
  import javax.ws.rs.core.UriBuilder;
  
  import org.glassfish.grizzly.http.server.HttpServer;
  import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory;
  import com.sun.jersey.api.core.ClassNamesResourceConfig;
  import com.sun.jersey.api.core.ResourceConfig;
  
  public class Main {
  
      private static URI getBaseURI() {
          return UriBuilder.fromUri("http://localhost/").port(8080).build();
      }
  
      public static final URI BASE_URI = getBaseURI();
  
      public static void main(String[] args) throws IOException {
          ResourceConfig rc = new ClassNamesResourceConfig(LolCat.class);
          HttpServer httpServer = GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
          System.in.read();
          httpServer.stop();
      }
  }
  </code></pre>
  
  <p>and the serlvet (LolCat.java):</p>
  
  <pre><code>package com.test.server;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.core.Context;
  
  @Path(value = "/lol")
  public class LolCat {
  
      @Context HttpServletRequest hsr;
  
      @GET
      @Path(value="/cat")
      public String list() {
          return "meow";
      }
  
  }
  </code></pre>
  
  <p>Specifically, it's the @Context-line in the above source file that is the source and solution to all my problems. I need it, and according to everything I've read about Jersey and Servlets it should work, but alas it does not. I've also tried using GrizzlyWebContainerFactory instead of the GrizzlyServerFactory, but to no avail.</p>
  
  <p>For reference, the project is compiled with the following dependencies:</p>
  
  <ul>
  <li>org.glassfish.grizzly:grizzly-framework:jar:2.2.21</li>
  <li>org.glassfish.grizzly:grizzly-http:jar:2.2.21</li>
  <li>org.glassfish.grizzly:grizzly-http-servlet:jar:2.2.21</li>
  <li>org.glassfish.grizzly:grizzly-http-server:jar:2.2.21</li>
  <li>com.sun.jersey:jersey-server:jar:1.17</li>
  <li>com.sun.jersey:jersey-servlet:jar:1.17</li>
  <li>com.sun.jersey:jersey-core:jar:1.17</li>
  <li>javax.servlet:javax.servlet-api:jar:2.5.0</li>
  <li>com.sun.jersey:jersey-grizzly2:jar:1.17</li>
  <li>com.sun.jersey:jersey-grizzly2-servlet:jar:1.17</li>
  <li>asm:asm:jar:3.3.1</li>
  </ul>