users@jersey.java.net

Re: [Jersey] ClassCastException from ProviderServices

From: Imran M Yousuf <imyousuf_at_smartitengineering.com>
Date: Mon, 25 Oct 2010 17:08:21 +0600

Hi Paul,

I wanted to say "embedded jetty" :). And yes the I was loading jersey
from 2 class loaders, I guessed it, tried loading the war-classes as
direct dependency and thus avoiding the exception. Thanks for the
confirmation. Is there any workaround for 2 classloaders loading same
version of jersey for such cases?

Regards,

Imran

On Mon, Oct 25, 2010 at 4:53 PM, Paul Sandoz <Paul.Sandoz_at_oracle.com> wrote:
> Hi Imran,
>
> What do you mean by "embedded jersey"? what HTTP container are you using?
>
> This type of problem can occur when two separate class loaders are utilized
> to load the same or different versions of Jersey.
>
> For example, Jersey is initialized using an application specific class
> loader, but some of the classes obtained from META-INF/services files are
> loaded and instantiated using a system specific class loader. This results
> in the same service interface, I say, being loaded twice, for each class
> loader, and thus the service instance cannot be cast to I that was loaded
> from the application specific class loader.
>
> It is hard to tell further why this is happening without more details on
> your environment.
>
> Paul.
>
> On Oct 24, 2010, at 9:13 AM, Imran M Yousuf wrote:
>
>> Hi,
>>
>> I am getting the following exception trying to load an application via
>> embedded jersey. Any idea what might cause it? Jersey version is 1.3
>>
>> java.lang.ClassCastException
>>        at java.lang.Class.cast(Class.java:2990)
>>        at
>> com.sun.jersey.core.spi.component.ProviderServices.getProvidersAndServices(ProviderServices.java:204)
>>        at
>> com.sun.jersey.core.spi.factory.InjectableProviderFactory.configure(InjectableProviderFactory.java:103)
>>        at
>> com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:860)
>>        at
>> com.sun.jersey.server.impl.application.WebApplicationImpl.access$600(WebApplicationImpl.java:153)
>>        at
>> com.sun.jersey.server.impl.application.WebApplicationImpl$11.f(WebApplicationImpl.java:652)
>>        at
>> com.sun.jersey.server.impl.application.WebApplicationImpl$11.f(WebApplicationImpl.java:649)
>>        at
>> com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:177)
>>        at
>> com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:649)
>>        at
>> com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:644)
>>        at
>> com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:428)
>>        at
>> com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:277)
>>        at
>> com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:573)
>>        at
>> com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:211)
>>        at
>> com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:332)
>>        at
>> com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:671)
>>        at
>> org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:74)
>>
>> Is there a way to disable lookup for providers by default?
>>
>> Regards,
>>
>> --
>> Imran M Yousuf
>> Twitter: @imyousuf - http://twitter.com/imyousuf
>> Blog: http://imyousuf-tech.blogs.smartitengineering.com/
>> Mobile: +880-1711402557
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>



-- 
Imran M Yousuf
Entrepreneur & CEO
Smart IT Engineering Ltd.
25/5B, Block F, Haji Chinu Miah Road Bylane
Joint Quarter, Mohammadpur
Dhaka - 1207, Bangladesh
Email: imran_at_smartitengineering.com
Twitter: @imyousuf - http://twitter.com/imyousuf
Blog: http://imyousuf-tech.blogs.smartitengineering.com/
Mobile: +880-1711402557