users@jersey.java.net

Re: [Jersey] Jersey provider-detection fails under Tomcat?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 06 Jan 2009 17:01:01 +0100

Ah, sorry, false alarm!!, this class loading is giving me a real
headache.

If one does:

   - Class.forName(name, true, loader) then initialization of the
class will occur when obtaining the class

if one does:

   - Class.forName(name, false, loader) then initialization will occur
when the class is instantiated.

The loading of the classes via META-INF/services uses the former,
which means it fails early and the classes are ignored and the never
get passed to an IoC provider factory for instantiation.

Thus what is happening is because the @Provider is on the the
multipart readers/writers they are getting registered via class
scanning that loads the Class without initialization and thus
initialization is deferred when the class is instantiated by the Guice
component provider.

Paul.

On Jan 6, 2009, at 4:39 PM, Gili wrote:

>
> As far as I know, GuiceComponentProviderFactory will have
> Guice inject if:
>
> 1) There is a default constructor, or
> 2) There is at most one constructor annotated with @Inject and all
> constructor arguments can also be injected by Guice (recursive
> algorithm)
>
> If #2 fails because the dependencies cannot be injected even
> though the
> constructor is marked with @Inject then the
> GuiceComponentProviderFactory will throw an exception instead of
> returning null.
>
> In conclusion: GuiceComponentProviderFactory should not be
> affected by
> the existence of @Provider as far as I know. I will run an actual test
> on my end to double check and report back here.
>
> Gili
>
> Paul Sandoz (via Nabble) wrote:
>
> > After some further investigation I realized that my evaluation is
> > wrong. Only when instantiating does a NoClassDefFoundError
> regardless
> > of the difference in class loading (which is in the process of being
> > fixed).
> >
> > I notice that your GuiceComponentProviderFactory is instantiating
> the
> > provider class. The registered IoC component provider factory will
> be
> > asked to instantiate components registered in both cases (@Provider
> > and META-INF/services) and if the provider factory returns null
> Jersey
> > instantiates. For some reasons your provider factory is
> instantiating
> > for the case of a class annotated with @Provider but not otherwise,
> > does your code have some logic to check annotations on the classes
> it
> > instantiates?
> >
> > Paul.
> >
> > On Dec 24, 2008, at 3:10 AM, Gili wrote:
> >
> > >
> > > Here is what I found out:
> > >
> > > - The MultiPart provider fails to initialize because Javamail is
> > > missing.
> > > Glassfish bundles this dependency, whereas Tomcat does not.
> > > - If the MessageBodyReader omits @Provider then no error message
> > > shows up.
> > > The binding fails silently, causing Jersey to issue a confusing
> error
> > > message about the MessageBodyReader being missing when in fact
> it is
> > > not.
> > > - If the MessageBodyReader is annotated using @Provider the
> following
> > > exception shows up when the webapp is initialized:
> > >
> > > SEVERE: Exception starting filter warpServletFilter
> > > java.lang.NoClassDefFoundError: javax/mail/MessagingException
> > > at java.lang.Class.getDeclaredConstructors0(Native Method)
> > > at
> java.lang.Class.privateGetDeclaredConstructors(Class.java:
> > > 2389)
> > > at java.lang.Class.getDeclaredConstructors(Class.java:
> 1836)
> > > at
> > > com
> > > .google
> > > .inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:
> 192)
> > > at
> > > com
> >
> > .google.inject.ConstructorInjector.<init>(ConstructorInjector.java:
> 45)
> > > at com.google.inject.InjectorImpl
> $5.create(InjectorImpl.java:
> > > 728)
> > > at com.google.inject.InjectorImpl
> $5.create(InjectorImpl.java:
> > > 724)
> > > at
> > > com.google.inject.internal.FailableCache
> $1.create(FailableCache.java:
> > > 32)
> > > at
> > >
> com.google.inject.internal.ReferenceCache.create(ReferenceCache.java:
> > > 54)
> > > at
> > > com
> > > .google
> > > .inject
> > > .internal
> >
> > .AbstractReferenceCache.internalCreate(AbstractReferenceCache.java:
> 59)
> > > at
> > > com
> > > .google
> > > .inject
> >
> > .internal.AbstractReferenceCache.get(AbstractReferenceCache.java:
> 116)
> > > at
> > >
> com.google.inject.internal.ReferenceCache.get(ReferenceCache.java:28)
> > > at
> > > com.google.inject.internal.FailableCache.get(FailableCache.java:
> 43)
> > > at
> > > com.google.inject.InjectorImpl
> > > $LateBoundConstructor.bind(InjectorImpl.java:431)
> > > at
> > >
> com.google.inject.ClassBindingImpl.initialize(ClassBindingImpl.java:
> > > 46)
> > > at
> > >
> com.google.inject.InjectorImpl.initializeBinding(InjectorImpl.java:
> > > 320)
> > > at
> > > com
> > > .google
> > > .inject.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:
> 615)
> > > at
> > > com
> > > .google
> > > .inject
> >
> > .InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:
> 558)
> > > at
> > > com
> >
> > .google.inject.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:
> > > 168)
> > > at
> > >
> com.google.inject.InjectorImpl.getBindingOrThrow(InjectorImpl.java:
> > > 128)
> > > at
> > > com.google.inject.InjectorImpl.getBinding(InjectorImpl.java:105)
> > > at
> > > com.google.inject.InjectorImpl.getBinding(InjectorImpl.java:60)
> > > at
> > > com
> > > .sun
> > > .jersey
> > > .spi
> > > .guice
> > > .container
> > > .GuiceComponentProviderFactory
> > > .getComponentProvider(GuiceComponentProviderFactory.java:98)
> > > at
> > > com
> > > .sun
> > > .jersey
> > > .spi
> > > .guice
> > > .container
> > > .GuiceComponentProviderFactory
> > > .getComponentProvider(GuiceComponentProviderFactory.java:87)
> > > at
> > > com
> > > .sun
> > > .jersey
> > > .core
> > > .spi
> > > .component
> > > .ioc
> >
> > .IoCProviderFactory._getComponentProvider(IoCProviderFactory.java:
> 68)
> > > at
> > > com
> > > .sun
> > > .jersey
> > > .core
> > > .spi
> >
> >
> .component.ProviderFactory.getComponentProvider(ProviderFactory.java:
> > > 126)
> > > at
> > > com
> > > .sun
> > > .jersey
> > > .core
> >
> > .spi.component.ProviderServices.getComponent(ProviderServices.java:
> > > 163)
> > > at
> > > com
> > > .sun
> > > .jersey
> > > .core
> > > .spi
> > > .component
> > > .ProviderServices.getProvidersAndServices(ProviderServices.java:
> 119)
> > > at
> > > com
> > > .sun
> > > .jersey
> > > .core
> > > .spi
> >
> > .factory.MessageBodyFactory.getProviderMap(MessageBodyFactory.java:
> > > 136)
> > > at
> > > com
> > > .sun
> > > .jersey
> > > .core
> >
> > .spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:
> > > 110)
> > > at
> > > com
> > > .sun
> > > .jersey
> >
> > .core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:
> 105)
> > > at
> > > com
> > > .sun
> > > .jersey
> > > .server
> > > .impl
> >
> > .application.WebApplicationImpl.initiate(WebApplicationImpl.java:
> 462)
> > > at
> > > com
> > > .sun
> > > .jersey
> >
> >
> .spi.guice.container.servlet.GuiceServlet.initiate(GuiceServlet.java:
> > > 47)
> > > at
> > > com
> > > .sun
> > > .jersey
> >
> > .spi.container.servlet.ServletContainer.load(ServletContainer.java:
> > > 540)
> > > at
> > > com
> > > .sun
> > > .jersey
> >
> > .spi.container.servlet.ServletContainer.init(ServletContainer.java:
> > > 207)
> > > at
> > > com
> >
> >
> .wideplay.warp.servlet.ServletDefinition.init(ServletDefinition.java:
> > > 50)
> > > at
> > > com
> > > .wideplay
> > > .warp
> >
> > .servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:31)
> > > at
> > > com
> > > .wideplay
> > > .warp
> > > .servlet
> > > .ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:
> 38)
> > > at
> com.wideplay.warp.servlet.WebFilter.init(WebFilter.java:70)
> > > at
> > > org
> > > .apache
> > > .catalina
> >
> >
> .core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:
> > > 275)
> > > at
> > > org
> > > .apache
> > > .catalina
> > > .core
> >
> > .ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:
> > > 397)
> > > at
> > > org
> > > .apache
> > > .catalina
> >
> > .core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:
> 108)
> > > at
> > > org
> > > .apache
> > > .catalina.core.StandardContext.filterStart(StandardContext.java:
> 3709)
> > > at
> > >
> org.apache.catalina.core.StandardContext.start(StandardContext.java:
> > > 4363)
> > > at
> > > org
> > > .apache
> >
> > .catalina.core.ContainerBase.addChildInternal(ContainerBase.java:
> 791)
> > > at
> > >
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:
> > > 771)
> > > at
> > >
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
> > > at
> > > org
> >
> >
> .apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:
> > > 627)
> > > at
> > >
> org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:511)
> > > at
> > > org.apache.catalina.startup.HostConfig.check(HostConfig.java:
> 1231)
> > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
> > > at
> > > sun
> > > .reflect
> > > .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
> 39)
> > > at
> > > sun
> > > .reflect
> > > .DelegatingMethodAccessorImpl
> > > .invoke(DelegatingMethodAccessorImpl.java:25)
> > > at java.lang.reflect.Method.invoke(Method.java:597)
> > > at
> > > org
> > > .apache
> > > .tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:
> 297)
> > > at
> > > com
> > > .sun
> > > .jmx
> > > .interceptor
> > > .DefaultMBeanServerInterceptor
> > > .invoke(DefaultMBeanServerInterceptor.java:836)
> > > at
> > >
> com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
> > > at
> > >
> org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:
> > > 1471)
> > > at
> > > org
> >
> > .apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:
> > > 824)
> > > at
> > >
> org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:
> > > 350)
> > > at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
> > > at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> > > at
> > > org
> > > .apache
> > > .catalina
> > > .core
> >
> >
> .ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
> > > 290)
> > > at
> > > org
> > > .apache
> > > .catalina
> >
> > .core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
> 206)
> > > at
> > > org
> > > .apache
> >
> >
> .catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
> > > 233)
> > > at
> > > org
> > > .apache
> >
> >
> .catalina.core.StandardContextValve.invoke(StandardContextValve.java:
> > > 191)
> > > at
> > > org
> > > .apache
> > > .catalina
> > > .authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:
> 525)
> > > at
> > > org
> > > .apache
> > > .catalina.core.StandardHostValve.invoke(StandardHostValve.java:
> 128)
> > > at
> > > org
> > > .apache
> > > .catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
> 102)
> > > at
> > > org
> > > .apache
> >
> > .catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
> > > 109)
> > > at
> > > org
> >
> > .apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
> > > 286)
> > > at
> > > org
> >
> > .apache.coyote.http11.Http11Processor.process(Http11Processor.java:
> > > 845)
> > > at
> > > org.apache.coyote.http11.Http11Protocol
> > > $Http11ConnectionHandler.process(Http11Protocol.java:583)
> > > at
> > > org.apache.tomcat.util.net.JIoEndpoint
> $Worker.run(JIoEndpoint.java:
> > > 447)
> > > at java.lang.Thread.run(Thread.java:619)
> > > Caused by: java.lang.ClassNotFoundException:
> > > javax.mail.MessagingException
> > > at
> > > org
> > > .apache
> >
> > .catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:
> > > 1387)
> > > at
> > > org
> > > .apache
> >
> > .catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:
> > > 1233)
> > > at
> java.lang.ClassLoader.loadClassInternal(ClassLoader.java:
> > > 320)
> > > ... 75 more
> > >
> > > I filed two bug reports:
> > > https://jersey.dev.java.net/issues/show_bug.cgi?id=171
> > > https://jersey.dev.java.net/issues/show_bug.cgi?id=172
> > >
> > > Gili
> > >
> > >
> > > Gili wrote:
> > >>
> > >> It's taking me forever to debug this, but in the process of
> > >> troubleshooting I noticed that MultiPartReader isn't annotated
> with
> > >> @Provider as required according to MessageBodyReader's
> > >> specification. The
> > >> Javadoc reads "To add a MessageBodyReader implementation,
> annotate
> > >> the
> > >> implementation class with @Provider". Could this be it? It still
> > >> doesn't
> > >> explain why this works under Glassfish without the annotation.
> > >>
> > >> Gili
> > >>
> > >>
> > >> Gili wrote:
> > >>>
> > >>> I took my existing webapp, moved from Glassfish v2 to Tomcat
> and
> > >>> all of a
> > >>> sudden I get:
> > >>>
> > >>> SEVERE: A message body reader for Java type, class
> > >>> com.sun.jersey.multipart.MultiPart, and MIME media type,
> multipart/
> > >>> mixed,
> > >>> was not found
> > >>>
> > >>> I'm guessing that Jersey provider scanning is failing under
> Tomcat
> > >>> for
> > >>> some reason...? Paul, Craig can you guys confirm this?
> > >>>
> > >>> Thanks,
> > >>> Gili
> > >>>
> > >>
> > >>
> > >
> > > --
> > > View this message in context:
> > http://n2.nabble.com/Jersey-provider-detection-fails-under-Tomcat--tp1688690p1696750.html
> > > Sent from the Jersey mailing list archive at Nabble.com.
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@...
> > <http://n2.nabble.com/user/SendEmail.jtp?type=node&node=2117985&i=0>
> > > For additional commands, e-mail: users-help@...
> > <http://n2.nabble.com/user/SendEmail.jtp?type=node&node=2117985&i=1>
> > >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@...
> > <http://n2.nabble.com/user/SendEmail.jtp?type=node&node=2117985&i=2>
> > For additional commands, e-mail: users-help@...
> > <http://n2.nabble.com/user/SendEmail.jtp?type=node&node=2117985&i=3>
> >
> >
> >
> >
> ------------------------------------------------------------------------
> > This email is a reply to your post @
> > http://n2.nabble.com/Jersey-provider-detection-fails-under-Tomcat--tp1688690p2117985.html
> > You can reply by email or by visting the link above.
> >
>
> View this message in context: Re: [Jersey] Jersey provider-detection
> fails under Tomcat?
> Sent from the Jersey mailing list archive at Nabble.com.