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.
Here is the class:
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;
}
}
If comment out those two contexts, no error when calling tryMe Restful.
When using thwo two contexts, calling tryMe restful, will throw following errors:
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
here is the weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<wls:weblogic-version>12.1.3</wls:weblogic-version>
<wls:context-root>demoRest</wls:context-root>
<wls:container-descriptor>
<wls:prefer-web-inf-classes>false</wls:prefer-web-inf-classes>
<wls:prefer-application-packages>
<!-- slf4j -->
<wls:package-name>org.slf4j</wls:package-name>
<!-- jersey-bundle-*.jar -->
<wls:package-name>com.sun.jersey.*</wls:package-name>
<wls:package-name>com.sun.research.ws.wadl.*</wls:package-name>
<wls:package-name>com.sun.ws.rs.ext.*</wls:package-name>
<!-- Jackson-*.jar -->
<wls:package-name>org.codehaus.jackson.*</wls:package-name>
<!-- jsr311*.jar -->
<wls:package-name>javax.ws.rs.*</wls:package-name>
<!-- javassist -->
<wls:package-name>javassist.*</wls:package-name>
<!-- aop repackaged -->
<wls:package-name>org.aopalliance.*</wls:package-name>
<wls:package-name>com.sun.jersey.*</wls:package-name>
<wls:package-name>org.glassfish.jersey.*</wls:package-name>
<wls:package-name>jersey.repackaged.org.objectweb.asm.*</wls:package-name>
<wls:package-name>org.objectweb.asm.*</wls:package-name>
<wls:package-name>com.sun.ws.rs.ext.*</wls:package-name>
<wls:package-name>javax.ws.rs.*</wls:package-name>
<wls:package-name>com.sun.research.ws.wadl.*</wls:package-name>
<wls:package-name>jersey.repackaged.*</wls:package-name>
<!-- hk2 -->
<wls:package-name>org.glassfish.hk2.*</wls:package-name>
<wls:package-name>org.jvnet.hk2.internal.*</wls:package-name>
<wls:package-name>org.jvnet.hk2.*</wls:package-name>
<wls:package-name>org.jvnet.tiger_types.*</wls:package-name>
<!-- jpa2.1 hibernate -->
<wls:package-name>javax.persistence.*</wls:package-name>
<wls:package-name>org.hibernate.*</wls:package-name>
<wls:package-name>org.hibernate.validator.*</wls:package-name>
<wls:package-name>javax.validation.*</wls:package-name>
<!-- commons io <wls:package-name>org.apache.commons.io.*</wls:package-name> -->
</wls:prefer-application-packages>
<wls:prefer-application-resources>
<wls:resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</wls:resource-name>
<wls:resource-name>META-INF/services/javax.ws.rs.ext.RuntimeDelegate</wls:resource-name>
<!-- jersey -->
<wls:resource-name>META-INF/services/org.glassfish.jersey.*</wls:resource-name>
<wls:resource-name>org.glassfish.jersey.*</wls:resource-name>
<wls:resource-name>jersey.repackaged.*</wls:resource-name>
<!-- hk2 -->
<wls:resource-name>META-INF/services/org.glassfish.hk2.*</wls:resource-name>
<!-- slf4j -->
<wls:resource-name>org.slf4j</wls:resource-name>
<!-- jersey-bundle-*.jar -->
<wls:resource-name>com.sun.jersey.*</wls:resource-name>
<wls:resource-name>com.sun.research.ws.wadl.*</wls:resource-name>
<wls:resource-name>com.sun.ws.rs.ext.*</wls:resource-name>
<!-- Jackson-*.jar -->
<wls:resource-name>org.codehaus.jackson.*</wls:resource-name>
<!-- jsr311*.jar -->
<wls:resource-name>javax.ws.rs.*</wls:resource-name>
<!-- jpa2.1 hibernate -->
<wls:resource-name>javax.persistence.*</wls:resource-name>
<wls:resource-name>org.hibernate.*</wls:resource-name>
<wls:resource-name>org.hibernate.validator.*</wls:resource-name>
<wls:resource-name>javax.validation.*</wls:resource-name>
<!-- commons io -->
<wls:resource-name>org.apache.commons.io.*</wls:resource-name>
</wls:prefer-application-resources>
</wls:container-descriptor>
check duplicate topic, you can use static access if you absolutely have to
HttpServletRequest request=
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With