You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by ritesh_ks <re...@gmail.com> on 2007/04/02 18:03:54 UTC

ClassCastException while using same custom jar in 2 service units

Hello,

Environment: ServiceMix 3.0.1
JRE: 1.5.0.9
App Server: JBoss 4.0.4GA

I have a custom exception class that I plan on using in 2 different service
units. First service unit catches an exception and throws my custom
exception. The second service unit (a JSR) takes the custom exception from
the message exchange and processes it.

I have added the custom jar (which has Exception class) as a dependancy and
included it in the library in xbean and servicemix files of two service
units. Both service units are part of the same service assembly.

At run-time, in the JSR, I see a ClassCastException while casting the
exception (received via exchange.getError) as my custom exception. I have
pasted the exception log below.

However, If I do not package the jar (containing the exception class) in the
service units but instead install them in the JBoss deploy directory, then
it works.

I have another custom class that I use to set as a property on the message
in one service unit and retreive from another service unit that works. I am
typecasting there also.

However in this case of custom exception it does not work. How can I package
the same Jar in two service units in one service assembly without getting
this error?

I do not want to put the jar in jboss deploy because then it becomes an
external deployment outside of my service unit.

Thanks and Regards,
Ritesh

==========================================================================
2007-04-02 11:28:52,744 DEBUG
[org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow] Called Flow send
2007-04-02 11:28:52,744 DEBUG
[org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue]
org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue$1@1571dff dequeued
exchange: InOut[
  id: ID:rsamanpure-1693-1175527707400-7:0
  status: Error
  role: consumer
  endpoint: ExampleService
  in: <?xml version="1.0" encoding="UTF-8"?><echoHello
xmlns="http://servicemix.apache.org/replaceMe"><echoHello>testing
echo</echoHello></echoHello>
  error: com.mycompany.servicemix.samples.CustomException: This is a custom
Exception
]
2007-04-02 11:28:52,744 DEBUG
[org.apache.servicemix.jbi.messaging.DeliveryChannelImpl] Processing inbound
exchange: InOut[
  id: ID:rsamanpure-1693-1175527707400-7:0
  status: Error
  role: consumer
  endpoint: ExampleService
  in: <?xml version="1.0" encoding="UTF-8"?><echoHello
xmlns="http://servicemix.apache.org/replaceMe"><echoHello>testing
echo</echoHello></echoHello>
  error: com.mycompany.servicemix.samples.CustomException: This is a custom
Exception
]
2007-04-02 11:28:52,744 DEBUG
[org.apache.servicemix.jbi.messaging.DeliveryChannelImpl] Notifying exchange
ID:rsamanpure-1693-1175527707400-7:0(1c57a92) in
DeliveryChannel{servicemix-jsr181} from processInboundSynchronousExchange
2007-04-02 11:28:52,744 DEBUG
[org.apache.servicemix.jbi.messaging.DeliveryChannelImpl] Notified:
ID:rsamanpure-1693-1175527707400-7:0(1c57a92) in
DeliveryChannel{servicemix-jsr181} from sendSync
2007-04-02 11:28:52,744 ERROR
[org.codehaus.xfire.handler.DefaultFaultHandler] Fault occurred!
java.lang.ClassCastException:
com.mycompany.servicemix.samples.CustomException
	at
com.mycompany.errorMsg.service.ExampleServiceImpl.sayHello(ExampleServiceImpl.java:74)
	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:585)
	at
org.codehaus.xfire.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:54)
	at
org.codehaus.xfire.service.binding.ServiceInvocationHandler.sendMessage(ServiceInvocationHandler.java:271)
	at
org.codehaus.xfire.service.binding.ServiceInvocationHandler$1.run(ServiceInvocationHandler.java:84)
	at
org.codehaus.xfire.service.binding.ServiceInvocationHandler.execute(ServiceInvocationHandler.java:132)
	at
org.codehaus.xfire.service.binding.ServiceInvocationHandler.invoke(ServiceInvocationHandler.java:107)
	at
org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
	at
org.codehaus.xfire.transport.DefaultEndpoint.onReceive(DefaultEndpoint.java:64)
	at
org.codehaus.xfire.transport.AbstractChannel.receive(AbstractChannel.java:38)
	at
org.apache.servicemix.jsr181.Jsr181ExchangeProcessor.doProcess(Jsr181ExchangeProcessor.java:113)
	at
org.apache.servicemix.jsr181.Jsr181ExchangeProcessor.process(Jsr181ExchangeProcessor.java:68)
	at
org.apache.servicemix.common.AsyncBaseLifeCycle.processExchange(AsyncBaseLifeCycle.java:410)
	at
org.apache.servicemix.common.BaseLifeCycle.onMessageExchange(BaseLifeCycle.java:43)
	at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:624)
	at
org.apache.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:170)
	at
org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.java:177)
	at
org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue$1.run(SedaQueue.java:227)
	at
org.apache.geronimo.connector.work.WorkerContext.run(WorkerContext.java:291)
	at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown
Source)
	at java.lang.Thread.run(Thread.java:595)
==========================================================================
Custom Jar source:  http://www.nabble.com/file/7615/ExceptionClass.zip
ExceptionClass.zip 
Compiled jar of the custom exception: 
http://www.nabble.com/file/7616/mycompanyTest-1.0.jar mycompanyTest-1.0.jar 
Test document to run against the example: 
http://www.nabble.com/file/7618/testDocument.xml testDocument.xml 
Source Code of the example:  http://www.nabble.com/file/7617/errorMsg.zip
errorMsg.zip  
-- 
View this message in context: http://www.nabble.com/ClassCastException-while-using-same-custom-jar-in-2-service-units-tf3506609s12049.html#a9793635
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: ClassCastException while using same custom jar in 2 service units

Posted by Guillaume Nodet <gn...@gmail.com>.
You need to put the jar in the classpath for the web app then.
The easiest way to do that is to put it in the WEB-INF/lib folder
inside the app, which is not related to ServiceMix in anyway.
But if you do that, your classes should be available to all the classloaders
that ServiceMix will create.
Note that the <library/> stuff only works with trunk.

On 5/18/07, vinodhc <vc...@sterlingtesting.com> wrote:
>
>
> Guillaume,
> Ritesh is a colleague of mine.
>
> I wanted to point out here that we are trying to do this in Servicemix
> that
> is deployed under JBoss using servicemix-web.war. Will this shared library
> patch still work?
>
> The reason I ask is because I believe the standalone version of Servicemix
> 3.1 has a new Classloader that requires our jars to be specified in a
> configuration file - servicemix.conf.
>
> This configuration file is not available to the servicemix version
> deployed
> under JBoss. So where does the classloader search for these shared
> libraries?
> Can you please guide us in implementing this shared library functionality
> with Servicemix under JBoss.
>
>
> Ritesh Samanpure wrote:
> >
> > Thanks for the reply Guillaume.
> >
> > I am able to include and load the jar along with the shared library. Now
> > as per your note, I would set the classpath in my Service Unit using
> > <library>xx</library>
> >
> > I have used it as <library>.</library> which makes this relative to the
> > current SU. How can I now point it to look for a jar in the shared
> > libraries ?
> >
> > Thanks,
> > Ritesh
> >
> >
> > gnodet wrote:
> >>
> >> There are different solutions to solve this problem:
> >>   * put the needed classes in the container classloader (in
> lib/optional
> >> for
> >> example),
> >>   * serialize the object somehow (using xml ?)
> >>   * use the new ability to reference Shared Libraries from Service
> Units
> >> (SM-918)
> >>     by adding a <library>xx</library> tag to the <classpath/> element
> in
> >> your xbean.xml file.
> >>
> >> On 4/12/07, Ritesh Samanpure <ri...@gmail.com> wrote:
> >>>
> >>>
> >>> Hello Ppl,
> >>>
> >>> Sorry to bump the post back to the top but we are stuck with the
> issue.
> >>> Would really appreciate it if someone has faced this very same issue
> and
> >>> resolved it.
> >>>
> >>> Thanks
> >>> --
> >>> View this message in context:
> >>>
> http://www.nabble.com/ClassCastException-while-using-same-custom-jar-in-2-service-units-tf3506609s12049.html#a9949542
> >>>
> >>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
> >>>
> >>>
> >>
> >>
> >> --
> >> Cheers,
> >> Guillaume Nodet
> >> ------------------------
> >> LogicBlaze
> >> Principal Engineer, IONA
> >> Blog: http://gnodet.blogspot.com/
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/ClassCastException-while-using-same-custom-jar-in-2-service-units-tf3506609s12049.html#a10673318
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Principal Engineer, IONA
Blog: http://gnodet.blogspot.com/

Re: ClassCastException while using same custom jar in 2 service units

Posted by vinodhc <vc...@sterlingtesting.com>.
Guillaume,
Ritesh is a colleague of mine.

I wanted to point out here that we are trying to do this in Servicemix that
is deployed under JBoss using servicemix-web.war. Will this shared library
patch still work?

The reason I ask is because I believe the standalone version of Servicemix
3.1 has a new Classloader that requires our jars to be specified in a
configuration file - servicemix.conf. 

This configuration file is not available to the servicemix version deployed
under JBoss. So where does the classloader search for these shared
libraries?
Can you please guide us in implementing this shared library functionality
with Servicemix under JBoss.


Ritesh Samanpure wrote:
> 
> Thanks for the reply Guillaume.
> 
> I am able to include and load the jar along with the shared library. Now
> as per your note, I would set the classpath in my Service Unit using
> <library>xx</library>
> 
> I have used it as <library>.</library> which makes this relative to the
> current SU. How can I now point it to look for a jar in the shared
> libraries ? 
> 
> Thanks,
> Ritesh
> 
> 
> gnodet wrote:
>> 
>> There are different solutions to solve this problem:
>>   * put the needed classes in the container classloader (in lib/optional
>> for
>> example),
>>   * serialize the object somehow (using xml ?)
>>   * use the new ability to reference Shared Libraries from Service Units
>> (SM-918)
>>     by adding a <library>xx</library> tag to the <classpath/> element in
>> your xbean.xml file.
>> 
>> On 4/12/07, Ritesh Samanpure <ri...@gmail.com> wrote:
>>>
>>>
>>> Hello Ppl,
>>>
>>> Sorry to bump the post back to the top but we are stuck with the issue.
>>> Would really appreciate it if someone has faced this very same issue and
>>> resolved it.
>>>
>>> Thanks
>>> --
>>> View this message in context:
>>> http://www.nabble.com/ClassCastException-while-using-same-custom-jar-in-2-service-units-tf3506609s12049.html#a9949542
>>>
>>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>>
>>>
>> 
>> 
>> -- 
>> Cheers,
>> Guillaume Nodet
>> ------------------------
>> LogicBlaze
>> Principal Engineer, IONA
>> Blog: http://gnodet.blogspot.com/
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/ClassCastException-while-using-same-custom-jar-in-2-service-units-tf3506609s12049.html#a10673318
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: ClassCastException while using same custom jar in 2 service units

Posted by Ritesh Samanpure <ri...@gmail.com>.
Thanks for the reply Guillaume.

I am able to include and load the jar along with the shared library. Now as
per your note, I would set the classpath in my Service Unit using
<library>xx</library>

I have used it as <library>.</library> which makes this relative to the
current SU. How can I now point it to look for a jar in the shared libraries
? 

Thanks,
Ritesh


gnodet wrote:
> 
> There are different solutions to solve this problem:
>   * put the needed classes in the container classloader (in lib/optional
> for
> example),
>   * serialize the object somehow (using xml ?)
>   * use the new ability to reference Shared Libraries from Service Units
> (SM-918)
>     by adding a <library>xx</library> tag to the <classpath/> element in
> your xbean.xml file.
> 
> On 4/12/07, Ritesh Samanpure <ri...@gmail.com> wrote:
>>
>>
>> Hello Ppl,
>>
>> Sorry to bump the post back to the top but we are stuck with the issue.
>> Would really appreciate it if someone has faced this very same issue and
>> resolved it.
>>
>> Thanks
>> --
>> View this message in context:
>> http://www.nabble.com/ClassCastException-while-using-same-custom-jar-in-2-service-units-tf3506609s12049.html#a9949542
>>
>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> LogicBlaze
> Principal Engineer, IONA
> Blog: http://gnodet.blogspot.com/
> 
> 

-- 
View this message in context: http://www.nabble.com/ClassCastException-while-using-same-custom-jar-in-2-service-units-tf3506609s12049.html#a10414516
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: ClassCastException while using same custom jar in 2 service units

Posted by Guillaume Nodet <gn...@gmail.com>.
There are different solutions to solve this problem:
  * put the needed classes in the container classloader (in lib/optional for
example),
  * serialize the object somehow (using xml ?)
  * use the new ability to reference Shared Libraries from Service Units
(SM-918)
    by adding a <library>xx</library> tag to the <classpath/> element in
your xbean.xml file.

On 4/12/07, Ritesh Samanpure <ri...@gmail.com> wrote:
>
>
> Hello Ppl,
>
> Sorry to bump the post back to the top but we are stuck with the issue.
> Would really appreciate it if someone has faced this very same issue and
> resolved it.
>
> Thanks
> --
> View this message in context: http://www.nabble.com/ClassCastException-while-using-same-custom-jar-in-2-service-units-tf3506609s12049.html#a9949542
>
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
LogicBlaze
Principal Engineer, IONA
Blog: http://gnodet.blogspot.com/

Re: ClassCastException while using same custom jar in 2 service units

Posted by Ritesh Samanpure <ri...@gmail.com>.
Hello Ppl,

Sorry to bump the post back to the top but we are stuck with the issue.
Would really appreciate it if someone has faced this very same issue and
resolved it.

Thanks
-- 
View this message in context: http://www.nabble.com/ClassCastException-while-using-same-custom-jar-in-2-service-units-tf3506609s12049.html#a9949542
Sent from the ServiceMix - User mailing list archive at Nabble.com.