users@jersey.java.net

Re: [Jersey] ExceptionMapper and constructor injection of _at_Context UriInfo ?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 23 Jul 2009 20:58:39 +0200

On Jul 23, 2009, at 3:12 PM, Morten wrote:

> --- Den tors 23/7/09 skrev Paul Sandoz <Paul.Sandoz_at_Sun.COM>:
>>> Unfortunately, jersey gives an error that the class
>> can't be instantiated (assumingly because it does not
>> support injection of the provider).
>>
>> Any more information on the error? stack trace?
>
> Sorry for leaving this out. Here is the stack trace:
>
> SEVERE: The provider class, class
> com.test.ws.controller.CustomExceptionMapper, could not be
> instantiated. Processing will continue but the class will not be
> utilized
> java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
> at
> sun
> .reflect
> .NativeConstructorAccessorImpl
> .newInstance(NativeConstructorAccessorImpl.java:39)
> at
> sun
> .reflect
> .DelegatingConstructorAccessorImpl
> .newInstance(DelegatingConstructorAccessorImpl.java:27)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
> at
> com
> .sun
> .jersey
> .core
> .spi
> .component
> .ComponentConstructor._getInstance(ComponentConstructor.java:160)
> at
> com
> .sun
> .jersey
> .core
> .spi
> .component
> .ComponentConstructor.getInstance(ComponentConstructor.java:140)
> at
> com
> .sun
> .jersey
> .core
> .spi
> .component
> .ProviderFactory.__getComponentProvider(ProviderFactory.java:159)
> at
> com
> .sun
> .jersey
> .core
> .spi
> .component
> .ProviderFactory._getComponentProvider(ProviderFactory.java:152)
> at
> com
> .sun
> .jersey
> .core
> .spi.component.ioc.IoCProviderFactory.wrap(IoCProviderFactory.java:
> 106)
> at
> com
> .sun
> .jersey
> .core
> .spi
> .component
> .ioc
> .IoCProviderFactory._getComponentProvider(IoCProviderFactory.java:87)
> at
> com
> .sun
> .jersey
> .core
> .spi
> .component.ProviderFactory.getComponentProvider(ProviderFactory.java:
> 146)
> at
> com
> .sun
> .jersey
> .core
> .spi.component.ProviderServices.getComponent(ProviderServices.java:
> 185)
> at
> com
> .sun
> .jersey
> .core
> .spi.component.ProviderServices.getProviders(ProviderServices.java:95)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .ExceptionMapperFactory.<init>(ExceptionMapperFactory.java:67)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application.WebApplicationImpl.initiate(WebApplicationImpl.java:570)
> at
> com
> .sun
> .jersey
> .api
> .container.ContainerFactory.createContainer(ContainerFactory.java:168)
>
>
>> Many of the internal providers supplied by Jersey use
>> constructor injection. I did a quick test and it works for
>> me e.g. i modified the helloworld sample [1] resource class
>> to be:
>
> Hmm. Stange. Are you using another sw cfg then I am (I am using
> newest releases 1.1.1-ea with Sun's HTTPServer on JDK1.6_0_13 on Mac
> OS 10.5 )
>

I think the issue is as Craig says your constructor code is throwing
an exception. For example, such an exception can occur if you try to
access the UriInfo in the constructor (what is injected is a thread
local proxy which is valid when used in the scope of a request).


> P.S. Thanks for your prompt replies to my mails on this mailing
> list. Great support!
>

No problem. Thanks!

Paul.