title: inject context HttpServletRequest cause "interface org.glassfish.hk2.api.ProxyCtl is not visible from class loader" (jersey 2.21, weblogic 12.1.3)
body: <p>I am using jersey 2.21 on weblogic 12c (12.1.3) to provide Rest. The Rest class is working fine without injecting context HTTPServeletRequest/HTTPServletResponse. But once inject the context, it throws "interface org.glassfish.hk2.api.ProxyCtl is not visible from class loader" error, when calling the service. </p>
  
  <p>Here is the class:</p>
  
  <pre><code>import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.QueryParam;
  import javax.ws.rs.core.Context;
  import javax.ws.rs.core.MediaType;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.stereotype.Component;
  
  @Component
  @Path("test")
  public class TestResource {
  Logger logger = LoggerFactory.getLogger(TestResource.class);
  
  
  @Context HttpServletResponse resp; 
  @Context HttpServletRequest request; 
  
  
  /**
   * Test site connectivity. Return parameter txt's content in reply
   * @param content
   * @return 
   */
  @GET
  @Path("/tryMe")
  @Produces(MediaType.TEXT_PLAIN)
  public String echoTest(@QueryParam("txt") String content) { 
      System.out.println("Try me reach.");
      System.out.println("from client: "+request.getRemoteAddr()); 
  
  
      return content;
  }
  
  }
  </code></pre>
  
  <p>If comment out those two contexts, no error when calling tryMe Restful.<br/> 
  When using thwo two contexts, calling tryMe restful, will throw following errors:<br/></p>
  
  <pre><code>Root cause of ServletException.
          A MultiException has 2 exceptions.  They are:
          1. java.lang.IllegalArgumentException: interface org.glassfish.hk2.api.ProxyCtl is not visible from class loader
          2. java.lang.IllegalArgumentException: While attempting to create a Proxy for javax.servlet.http.HttpServletRequest in scope org.glassfish.jersey.process.internal.RequestScoped an error occured while creating the proxy
  
              at org.jvnet.hk2.internal.ProxyUtilities.generateProxy(ProxyUtilities.java:225)
              at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2044)
              at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114)
              at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88)
              at org.glassfish.jersey.internal.inject.ContextInjectionResolver.resolve(ContextInjectionResolver.java:126)
              Truncated. see log file for complete stacktrace
          Caused By: java.lang.IllegalArgumentException: interface org.glassfish.hk2.api.ProxyCtl is not visible from class loader
              at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:581)
              at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:557)
              at java.lang.reflect.WeakCache$Factory.get(WeakCache.java:230)
              at java.lang.reflect.WeakCache.get(WeakCache.java:127)
              at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:419)
              Truncated. see log file for complete stacktrace
  </code></pre>
  
  <p>here is the weblogic.xml<br/></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;wls:weblogic-web-app
  xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
  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 http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd"&gt;
  &lt;wls:weblogic-version&gt;12.1.3&lt;/wls:weblogic-version&gt;
  &lt;wls:context-root&gt;demoRest&lt;/wls:context-root&gt;
  &lt;wls:container-descriptor&gt;
      &lt;wls:prefer-web-inf-classes&gt;false&lt;/wls:prefer-web-inf-classes&gt;
      &lt;wls:prefer-application-packages&gt;
          &lt;!-- slf4j --&gt;
          &lt;wls:package-name&gt;org.slf4j&lt;/wls:package-name&gt;
  
          &lt;!-- jersey-bundle-*.jar --&gt;
          &lt;wls:package-name&gt;com.sun.jersey.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;com.sun.research.ws.wadl.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;com.sun.ws.rs.ext.*&lt;/wls:package-name&gt;
  
          &lt;!-- Jackson-*.jar --&gt;
          &lt;wls:package-name&gt;org.codehaus.jackson.*&lt;/wls:package-name&gt;
  
          &lt;!-- jsr311*.jar --&gt;
          &lt;wls:package-name&gt;javax.ws.rs.*&lt;/wls:package-name&gt;
  
          &lt;!-- javassist --&gt;
          &lt;wls:package-name&gt;javassist.*&lt;/wls:package-name&gt;
          &lt;!-- aop repackaged --&gt;
          &lt;wls:package-name&gt;org.aopalliance.*&lt;/wls:package-name&gt;
  
  
          &lt;wls:package-name&gt;com.sun.jersey.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;org.glassfish.jersey.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;jersey.repackaged.org.objectweb.asm.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;org.objectweb.asm.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;com.sun.ws.rs.ext.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;javax.ws.rs.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;com.sun.research.ws.wadl.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;jersey.repackaged.*&lt;/wls:package-name&gt;
  
          &lt;!-- hk2 --&gt;
          &lt;wls:package-name&gt;org.glassfish.hk2.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;org.jvnet.hk2.internal.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;org.jvnet.hk2.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;org.jvnet.tiger_types.*&lt;/wls:package-name&gt;
  
  
          &lt;!-- jpa2.1 hibernate --&gt;
          &lt;wls:package-name&gt;javax.persistence.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;org.hibernate.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;org.hibernate.validator.*&lt;/wls:package-name&gt;
          &lt;wls:package-name&gt;javax.validation.*&lt;/wls:package-name&gt;
  
          &lt;!-- commons io &lt;wls:package-name&gt;org.apache.commons.io.*&lt;/wls:package-name&gt; --&gt;
      &lt;/wls:prefer-application-packages&gt;
  
  
      &lt;wls:prefer-application-resources&gt;
          &lt;wls:resource-name&gt;META-INF/services/javax.servlet.ServletContainerInitializer&lt;/wls:resource-name&gt;
          &lt;wls:resource-name&gt;META-INF/services/javax.ws.rs.ext.RuntimeDelegate&lt;/wls:resource-name&gt;
  
          &lt;!-- jersey --&gt;
          &lt;wls:resource-name&gt;META-INF/services/org.glassfish.jersey.*&lt;/wls:resource-name&gt;
          &lt;wls:resource-name&gt;org.glassfish.jersey.*&lt;/wls:resource-name&gt;
          &lt;wls:resource-name&gt;jersey.repackaged.*&lt;/wls:resource-name&gt;
  
          &lt;!-- hk2 --&gt;
          &lt;wls:resource-name&gt;META-INF/services/org.glassfish.hk2.*&lt;/wls:resource-name&gt;
  
          &lt;!-- slf4j --&gt;
          &lt;wls:resource-name&gt;org.slf4j&lt;/wls:resource-name&gt;
  
          &lt;!-- jersey-bundle-*.jar --&gt;
          &lt;wls:resource-name&gt;com.sun.jersey.*&lt;/wls:resource-name&gt;
          &lt;wls:resource-name&gt;com.sun.research.ws.wadl.*&lt;/wls:resource-name&gt;
          &lt;wls:resource-name&gt;com.sun.ws.rs.ext.*&lt;/wls:resource-name&gt;
  
          &lt;!-- Jackson-*.jar --&gt;
          &lt;wls:resource-name&gt;org.codehaus.jackson.*&lt;/wls:resource-name&gt;
  
          &lt;!-- jsr311*.jar --&gt;
          &lt;wls:resource-name&gt;javax.ws.rs.*&lt;/wls:resource-name&gt;
  
          &lt;!-- jpa2.1 hibernate --&gt;
          &lt;wls:resource-name&gt;javax.persistence.*&lt;/wls:resource-name&gt;
          &lt;wls:resource-name&gt;org.hibernate.*&lt;/wls:resource-name&gt;
          &lt;wls:resource-name&gt;org.hibernate.validator.*&lt;/wls:resource-name&gt;
          &lt;wls:resource-name&gt;javax.validation.*&lt;/wls:resource-name&gt;
  
          &lt;!-- commons io --&gt;
          &lt;wls:resource-name&gt;org.apache.commons.io.*&lt;/wls:resource-name&gt;
      &lt;/wls:prefer-application-resources&gt;
  &lt;/wls:container-descriptor&gt;
  </code></pre>
  
  <p></p>