users@jersey.java.net

Re: [Jersey] Re: NPE On Jersey 1.1.5 Final, ResourceClass.java

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 25 Jan 2010 11:30:44 +0100

On Jan 25, 2010, at 11:24 AM, Erdinc Yilmazel wrote:

> Thank you Paul. I created an issue for this: https://jersey.dev.java.net/issues/show_bug.cgi?id=467
>

Thanks,
Paul.

> Erdinc
>
> On Mon, Jan 25, 2010 at 9:26 AM, Paul Sandoz <Paul.Sandoz_at_sun.com>
> wrote:
> Hi Erdinc,
>
> I do not think this is a GAE issue.
>
> I think the problem is the following:
>
>> @Inject
>> SessionHandler sessionHandler;
>
> Are you using Jersey's @Inject or Guice's @Inject in the above? the
> stack trace indicates the former.
>
> There is an ordering issue when Jersey;s @Inject is utilized. The
> fix looks simple. Could you log an issue?
>
> A workaround is to inject ResourceContext:
>
> @Context ResourceContext rc;
>
> an do:
>
> SessionHandler sessionHandler = rc.get(SessionHandler.class);
>
> Or uses Guice's @Inject if that is what you really intended.
>
> Paul.
>
> On Jan 22, 2010, at 6:58 PM, Erdinc Yilmazel wrote:
>
>> Ok, I think I narrowed the problem and I am a bit closer to
>> solution. I am using a class which extends
>> com.sun.jersey.spi.container.servlet.ServletContainer as a servlet
>> filter to make Guice integration possible, (Using modified code
>> from jersey-guice package). In the same class I am also registering
>> a ResourceFilterFactory and an InjectableProvider.
>>
>> I am doing this by the following code in the void
>> configure(WebConfig wc, ResourceConfig rc, WebApplication wa) method:
>>
>> @Override
>> protected void configure(WebConfig wc, ResourceConfig rc,
>> WebApplication wa) {
>> super.configure(wc, rc, wa);
>> rc.getSingletons().add(new LoginResourceFilterFactory());
>> rc.getSingletons().add(new SessionDataProvider());
>> }
>>
>>
>> This was working fine in previous versions of Jersey, but now It is
>> causing a NullPointerException that is described in my previous
>> email. When I don't override the method above, everything works
>> fine including guice integration. The ResourceFilterFactory that is
>> causing the problem is something like this:
>>
>>
>> import com.sun.jersey.api.model.AbstractMethod;
>> import com.sun.jersey.spi.container.ResourceFilter;
>> import com.sun.jersey.spi.container.ResourceFilterFactory;
>> import com.sun.jersey.spi.inject.Inject;
>> import javax.ws.rs.ext.Provider;
>> import java.util.ArrayList;
>> import java.util.List;
>>
>> @Provider
>> public class LoginResourceFilterFactory implements
>> ResourceFilterFactory {
>> @Inject
>> SessionHandler sessionHandler;
>>
>> @Override
>> public List<ResourceFilter> create(AbstractMethod am) {
>> LoginRequired lr = am.getAnnotation(LoginRequired.class);
>> if (lr == null) {
>> lr = am.getResource().getAnnotation(LoginRequired.class);
>> if (lr == null) {
>> return null;
>> }
>> }
>> final LoginResourceFilter filter =
>> LoginResourceFilter.instance(sessionHandler, lr.value());
>>
>> return new ArrayList<ResourceFilter>() {{
>> add(filter);
>> }};
>> }
>> }
>>
>>
>> Erdinc
>>
>>
>> On Fri, Jan 22, 2010 at 3:52 PM, Erdinc Yilmazel
>> <erdinc_at_yilmazel.com> wrote:
>> Hi,
>>
>> I'm trying to use Jersey 1.1.5 Final along with the Google Guice
>> integration. I am getting a NullPointerException on
>> ResourceClass.java..
>>
>>
>> WARNING: failed GuiceFilter
>> java.lang.NullPointerException
>> at
>> com
>> .sun
>> .jersey
>> .server.impl.model.ResourceClass.processOptions(ResourceClass.java:
>> 374)
>> at
>> com
>> .sun
>> .jersey
>> .server.impl.model.ResourceClass.processMethods(ResourceClass.java:
>> 323)
>> at
>> com
>> .sun
>> .jersey.server.impl.model.ResourceClass.<init>(ResourceClass.java:
>> 133)
>> at
>> com
>> .sun
>> .jersey
>> .server
>> .impl
>> .application
>> .WebApplicationImpl.newResourceClass(WebApplicationImpl.java:554)
>> at
>> com
>> .sun
>> .jersey
>> .server
>> .impl
>> .application
>> .WebApplicationImpl.getResourceClass(WebApplicationImpl.java:459)
>> at
>> com
>> .sun
>> .jersey
>> .server
>> .impl
>> .application
>> .WebApplicationImpl.getResourceClass(WebApplicationImpl.java:481)
>> at com.sun.jersey.server.impl.application.WebApplicationImpl
>> $9.getInjectable(WebApplicationImpl.java:709)
>> at com.sun.jersey.server.impl.application.WebApplicationImpl
>> $9.getInjectable(WebApplicationImpl.java:705)
>> at
>> com
>> .sun
>> .jersey
>> .core
>> .spi
>> .factory
>> .InjectableProviderFactory
>> .getInjectable(InjectableProviderFactory.java:202)
>> at
>> com
>> .sun
>> .jersey
>> .core
>> .spi
>> .factory
>> .InjectableProviderFactory
>> .getInjectable(InjectableProviderFactory.java:216)
>> at
>> com
>> .sun
>> .jersey
>> .core.spi.component.ComponentInjector.inject(ComponentInjector.java:
>> 89)
>> at
>> com
>> .sun
>> .jersey
>> .core
>> .spi
>> .component
>> .ProviderFactory.injectOnProviderInstance(ProviderFactory.java:240)
>> at
>> com
>> .sun
>> .jersey
>> .core
>> .spi
>> .component
>> .ProviderFactory.injectOnProviderInstances(ProviderFactory.java:228)
>> at
>> com
>> .sun
>> .jersey
>> .server
>> .impl
>> .application.WebApplicationImpl.initiate(WebApplicationImpl.java:907)
>>
>>
>> The problem is at this method, where this.wadlFactory is null.
>>
>> private void processOptions(ResourceMethodMap methodMap,
>> AbstractResource resource, PathPattern p) {
>> List<ResourceMethod> l = methodMap.get("OPTIONS");
>> if (l != null) {
>> return;
>> }
>>
>> ResourceMethod optionsMethod =
>> this.wadlFactory.createWadlOptionsMethod(methodMap, resource, p);
>> if (optionsMethod == null)
>> optionsMethod = new ResourceHttpOptionsMethod(methodMap);
>> methodMap.put(optionsMethod);
>> }
>>
>> Any thoughts? I am currently trying to deploy my application
>> locally using the Google Appengine Dev Server. Could it be
>> something about appengine restrictions?
>>
>> Erdinc
>>
>
>