On Apr 21, 2010, at 5:08 PM, James Russo wrote:
> 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?
Yes. Method parameters, for methods that Jersey invokes, are
independent of the scope of the class. Setter methods and fields are
not. But in this case Jersey will inject a thread local proxy for
HttpServletRequest so you can use it with singleton-scoped classes.
IIRC if your beans are managed by Spring then by default they are
singletons.
> 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.
>
OK.
Paul.
> -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
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: dev-help_at_jersey.dev.java.net
>