title: Jersey 2.4 on Glassfish 4.0.1: How to inject context HttpServletRequest into ContainerRequestFilter?
body: <p>Jersey 2.4 is able to inject HttpServletRequest: <a href="https://java.net/jira/browse/JERSEY-1960" rel="nofollow">https://java.net/jira/browse/JERSEY-1960</a></p>
  
  <p>Glassfish 4.0.1 is bundled with Jersey 2.4: <a href="http://dlc.sun.com.edgesuite.net/glassfish/4.0.1/nightly/latest-glassfish.zip" rel="nofollow">http://dlc.sun.com.edgesuite.net/glassfish/4.0.1/nightly/latest-glassfish.zip</a></p>
  
  <p>Opened bug at Glassfish:
  <a href="https://java.net/jira/browse/GLASSFISH-20885" rel="nofollow">https://java.net/jira/browse/GLASSFISH-20885</a></p>
  
  <pre><code>@Provider
  @Priority(Priorities.AUTHENTICATION)
  public class AuthRequestFilter implements ContainerRequestFilter {
      @Context
      HttpServletRequest webRequest;
  
      @Override
      public void filter(ContainerRequestContext requestContext) throws IOException {
          HttpSession session = webRequest.getSession();
          String user = (String)session.getAttribute("USER_ID");
      }
  }
  </code></pre>
  
  <p>Glassfish 4.0.1 can not deploy this filter with the following exception:</p>
  
  <pre><code>    at org.glassfish.jersey.internal.Errors$2.call(Errors.java:289)
      at org.glassfish.jersey.internal.Errors$2.call(Errors.java:286)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:286)
      at org.glassfish.jersey.server.ApplicationHandler.&lt;init&gt;(ApplicationHandler.java:284)
      at org.glassfish.jersey.servlet.WebComponent.&lt;init&gt;(WebComponent.java:302)
      at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167)
      at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349)
      at javax.servlet.GenericServlet.init(GenericServlet.java:244)
      at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1382)
      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5704)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:5946)
      at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
      at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2286)
      at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1932)
      at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139)
      at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
  java.lang.IllegalArgumentException: While attempting to create a Proxy for javax.servlet.http.HttpServletRequest in proxiable scope org.glassfish.jersey.process.internal.RequestScoped an error occured while creating the proxy
      at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2309)
      at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:98)
      at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:87)
      at org.glassfish.jersey.internal.inject.ContextInjectionResolver.resolve(ContextInjectionResolver.java:104)
      at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:803)
      at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:832)
      at org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider$CdiFactory$2.getInstance(CdiComponentProvider.java:203)
      at org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider$CdiFactory.provide(CdiComponentProvider.java:149)
      at org.jvnet.hk2.internal.FactoryCreator.create(FactoryCreator.java:96)
      at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:456)
      at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:69)
      at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2350)
      at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:98)
      at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:87)
      at org.glassfish.jersey.internal.inject.Providers.getAllRankedProviders(Providers.java:235)
      at org.glassfish.jersey.server.ApplicationHandler.getProcessingProviders(ApplicationHandler.java:617)
      at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:410)
      at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:162)
      at org.glassfish.jersey.server.ApplicationHandler$3.run(ApplicationHandler.java:287)
      at org.glassfish.jersey.internal.Errors$2.call(Errors.java:289)
      at org.glassfish.jersey.internal.Errors$2.call(Errors.java:286)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:286)
      at org.glassfish.jersey.server.ApplicationHandler.&lt;init&gt;(ApplicationHandler.java:284)
      at org.glassfish.jersey.servlet.WebComponent.&lt;init&gt;(WebComponent.java:302)
      at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167)
      at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349)
      at javax.servlet.GenericServlet.init(GenericServlet.java:244)
      at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1382)
      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5704)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:5946)
      at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
      at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2286)
      at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1932)
      at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139)
      at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
      at org.glassfish.jersey.internal.Errors$2.call(Errors.java:289)
      at org.glassfish.jersey.internal.Errors$2.call(Errors.java:286)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:286)
      at org.glassfish.jersey.server.ApplicationHandler.&lt;init&gt;(ApplicationHandler.java:284)
      at org.glassfish.jersey.servlet.WebComponent.&lt;init&gt;(WebComponent.java:302)
      at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167)
      at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349)
      at javax.servlet.GenericServlet.init(GenericServlet.java:244)
      at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1382)
      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5704)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:5946)
      at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
      at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2286)
      at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1932)
      at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139)
      at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
      Startup of context  failed due to previous errors]]
  
  [glassfish 4.0] [SEVERE] [AS-WEB-CORE-00108] [javax.enterprise.web.core] [tid: _ThreadID=50 _ThreadName=admin-listener(4)] [timeMillis: 1383814486801] [levelValue: 1000] [[
    ContainerBase.addChild: start:
  org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: interface org.glassfish.hk2.api.ProxyCtl is not visible from class loader
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:5954)
      at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
      at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2286)
      at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1932)
      at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139)
      at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
      at org.glassfish.jersey.internal.Errors$2.call(Errors.java:289)
      at org.glassfish.jersey.internal.Errors$2.call(Errors.java:286)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:286)
      at org.glassfish.jersey.server.ApplicationHandler.&lt;init&gt;(ApplicationHandler.java:284)
      at org.glassfish.jersey.servlet.WebComponent.&lt;init&gt;(WebComponent.java:302)
      at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167)
      at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349)
      at javax.servlet.GenericServlet.init(GenericServlet.java:244)
      at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1382)
      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5704)
      ... 50 more
      ]]
  </code></pre>