dev@jersey.java.net

Re: [Jersey] null pointer exception on resource class access HttpServletRequest?

From: James Russo <jr_at_halo3.net>
Date: Wed, 21 Apr 2010 11:08:42 -0400

Paul,

        Let me see if I can break it down into something I can send you. This started happening when I went to add spring @Transaction support to one of my resource methods. I've since backed all that back out and still happening. It's going to be something simple I am overlooking...

Just so I understand. I should be able to @Scope("singleton") if I use HttpServletRequest as a parameter to my method using @Context? If I would like to have req be a class variable then, I'll need @Scope("request").

I'll keep digging and see what I can figure out.

-jr
        
On Apr 21, 2010, at 10:46 AM, Paul Sandoz wrote:

> Hi James,
>
> First time i have seen that type of error. Not sure why it occurs. It is rather fundamental and implies that Jersey's context is set up with a null request and I do not see how that can happen (see the code at the end of the email).
>
> Can you send me your project (email me directly if disclosure is an issue) as i think it will be a lot easier to work out what might be the problem.
>
> Also sending a server log would be most helpful.
>
> Paul.
>
> public void handleRequest(ContainerRequest request, ContainerResponseWriter responseWriter)
> throws IOException {
> final ContainerResponse response = new ContainerResponse(
> this,
> request,
> responseWriter);
> handleRequest(request, response);
> }
>
> public void handleRequest(ContainerRequest request, ContainerResponse response) throws IOException {
> final WebApplicationContext localContext = new
> WebApplicationContext(this, request, response);
>
> context.set(localContext);
> try {
> _handleRequest(localContext, request, response);
> } finally {
> PerRequestFactory.destroy(localContext);
> closeableFactory.close(localContext);
> context.set(null);
> }
> }
>
>
> On Apr 21, 2010, at 4:29 PM, James Russo wrote:
>
>> Hello Everyone,
>>
>> I am getting a null pointer exception while trying to use jersey and spring. I think it has something to do with the resource class being "singleton" scoped. I am using: 1.1.5.1
>>
>> java.lang.NullPointerException
>> at com.sun.jersey.server.impl.application.WebApplicationContext.getProperties(WebApplicationContext.java:114)
>> at com.sun.jersey.server.impl.resource.PerRequestFactory.destroy(PerRequestFactory.java:75)
>> at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:943)
>>
>> I have the RequestContextListener in my web.xml..
>>
>> I have my resource class with @Scope("singleton") and then I have some resource methods which the following as a parameter:
>>
>> @Context HttpServletRequest req
>>
>> So, I would think that the class can be singleton since the request is coming via a method parameter. I need the request object to get at some header values. I have tried changing to @Scope("request"), but it has the same result.
>>
>> Anyone point me in the right direction here before I waste all day on this?
>>
>> thanks,
>>
>> -jr
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: dev-help_at_jersey.dev.java.net
>