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:55:59 +0200

On Jul 23, 2009, at 7:43 PM, Craig McClanahan wrote:

> 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)
>>
>>
>>
> FWIW, I've seen this type of thing when the constructor of my class
> itself threw an exception (like an NPE or something). It might be
> worth looking for something like that.
>

Yes, notice the InvocationTargetException which is thrown when a Java
method/constructor is invoked using reflection:

   InvocationTargetException is a checked exception that wraps an
exception thrown by an invoked method or
   constructor.

I guess InvocationTargetException.printStackTrace() does not print the
target exception. I should improve the logging.

Paul.