I have a bit of a problem with understanding why @Context
dependency injection returns collection of $Proxy(random number) instances instead of HttpServletRequest or HttpServletResponse.
I am using Glassfish 3.1.2.2 with it's version of Jersey(Jersey: 1.11.1) and my app is built as EAR application.
I have simple @Remote interface where I annotate my methods and REST services work without any problems, but the moment I try to access HttpServletRequest information it just causes problems.
I have annotated private fields in my session bean:
@Context
private HttpServletRequest request;
@Context
private HttpServletResponse response;
And also created method signature to include @Context as set of parameters:
@POST
@Path("authenticate")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public Response authenticate(@FormParam("username") String username, @FormParam("password") String password, @Context HttpServletRequest request, @Context HttpServletResponse response);
When I try and debug the method just after an entry I can see that global request and response objects are null where local method instances are of $ProxyXXX type.
The problem is I can't access (or I'm not sure how) these objects. According to tutorials on the web they should be available to me, but the moment I try to access these, this is being thrown:
WARNING: StandardWrapperValve[RestDataService]: PWC1406: Servlet.service() for servlet RestDataService threw exception
java.lang.IllegalStateException: No thread local value in scope for proxy of class $Proxy245
at com.sun.jersey.server.impl.ThreadLocalInvoker.invoke(ThreadLocalInvoker.java:93)
at $Proxy245.getContextPath(Unknown Source)
This is how I am trying to call these (in this example I simply call getContextPath)
@Override
public Response authenticate(String username, String password, HttpServletRequest request, HttpServletResponse response) {
System.out.println("just a test: " + request.getContextPath());
What am I missing here? Has anyone experienced similar problem?
Greg