You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Tanvi <ta...@gmail.com> on 2012/12/11 11:23:33 UTC

Class cast exception while sending message from JBI to other using NMR

Hi,

I am trying to have communication between 2 JBIs via NMR in service mix 4
assembly. I am able to pass various standard java parameters e.g. String,
int etc. But facing problem during sending collection object of custom data
type.

I am sending a list of VO from a JBI and trying to read the same List as
incoming message in the next JBI.
e.g. List<TransitVO> transitList - is sent from source and same is to be
read at destination.

I could print the class of the object received from NMR as 'ArrayList' and I
am able to read the list size properly i.e. list is not NULL at destination. 
A simple for loop used for iterating through this list is giving me a class
cast exception.

                for (TransitVO transitVO : transitList) {
                	LOGGER.debug("******* Bank No :: " +
transitVO.getBankNo());
                }

A ClassCastException of kind, com.test.vo.TransitVO can not be cast to
com.test.vo.TransitVO is thrown Both data types in exception are same.
A Similar kind of issue found at below link :
https://issues.apache.org/jira/browse/SMXCOMP-397
Tried the solution suggested. It did not work. 

Please help.

Regards,
Tanvi.





--
View this message in context: http://servicemix.396122.n5.nabble.com/Class-cast-exception-while-sending-message-from-JBI-to-other-using-NMR-tp5715233.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Class cast exception while sending message from JBI to other using NMR

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

This is a good question. No, currently SA can't tell the difference if symbolic names are same.

A work around, if you build those bundles, you actually can specify the symbolic name yourself, to make different version bundles use different symbolic name.
-------------
Freeman(Yue) Fang

Red Hat, Inc. 
FuseSource is now part of Red Hat
Web: http://fusesource.com | http://www.redhat.com/
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: @Freeman小屋

On 2012-12-12, at 下午3:17, Tanvi wrote:

> Hey Freeman,
> 
> Thanks for quick help:)
> 
> As per your suggestion, all shared JARs should not be added in SA/SUs but
> should be deployed as separate bundles and classpath entries to be added in
> SA/SUs.
> 
> Consider a case, 
> My DAO, Delegate, Util projects are used by multiple SAs. One SA needs to
> use version 1.0 of all, other needs version 2.0 of all.
> As Symbolic name in MANIFEST.MF file does not contain version, it would
> remain same though version is different. Classpath entry in 2 of the SAs
> will remain same as it refers only symbolic name and doesnot have version in
> it. 
> 
> How will each SA identify bundles of its own required versions if symbolic
> name mentioned in both is same?
> 
> Regards,
> Tanvi
> 
> 
> 
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/Class-cast-exception-while-sending-message-from-JBI-to-other-using-NMR-tp5715233p5715242.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Class cast exception while sending message from JBI to other using NMR

Posted by Tanvi <ta...@gmail.com>.
Hey Freeman,

Thanks for quick help:)

As per your suggestion, all shared JARs should not be added in SA/SUs but
should be deployed as separate bundles and classpath entries to be added in
SA/SUs.

Consider a case, 
My DAO, Delegate, Util projects are used by multiple SAs. One SA needs to
use version 1.0 of all, other needs version 2.0 of all.
As Symbolic name in MANIFEST.MF file does not contain version, it would
remain same though version is different. Classpath entry in 2 of the SAs
will remain same as it refers only symbolic name and doesnot have version in
it. 

How will each SA identify bundles of its own required versions if symbolic
name mentioned in both is same?

Regards,
Tanvi



--
View this message in context: http://servicemix.396122.n5.nabble.com/Class-cast-exception-while-sending-message-from-JBI-to-other-using-NMR-tp5715233p5715242.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Class cast exception while sending message from JBI to other using NMR

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

My comment inline
-------------
Freeman(Yue) Fang

Red Hat, Inc. 
FuseSource is now part of Red Hat
Web: http://fusesource.com | http://www.redhat.com/
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: @Freeman小屋

On 2012-12-12, at 下午2:03, Tanvi wrote:

> Hi Freeman,
> 
> Thanks for your reply :)
> 
> I have an independent project (JAR) of VOs which is added as a dependency in
> POM of each of SU. Since each SU has set of JBIs, which use this VO JAR, VO
> project is a part of each of zip built for an SU.
> 
> As per your suggestion, I performed below steps:
> 1. Changed VO packaging from JAR to bundle
> 2. Installed VO bundle independently in SMX-4
> 3. Added symbolic name of VO bundle in classpath of each of SU.
> 
> with this I could remove the class cast exception. :)
> 
> My next query is, similar to this VO jar, I have some of the other projects
> like DAO layer, Delegate layer, UTIL layer which are shared across SUs i.e.
> each SU pom.xml has dependency of these projects. 
> 
> - I did not get any such classloader problem for other JARs, what could be
> the reason? Is it because, I am using IOC for injecting these classes and
> not class cast scenario?

The CCE only happens when same class loaded by different classloaders, other classes from DAO/UTIL may not run into this situation with your user case ,  but it doesn't mean it's OK for all cases, you should never embed dependency libs in your SA 

> - Is it advisable to have all these shared JARs installed as a separate
> bundles in OSGI container and entry to be added in classpath for all of
> these?
Yeah, this is the way to go.
> 
> Please help.
> 
> Thanks in advance,
> 
> Regards,
> Tanvi
> 
> 
> 
> 
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/Class-cast-exception-while-sending-message-from-JBI-to-other-using-NMR-tp5715233p5715240.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Class cast exception while sending message from JBI to other using NMR

Posted by Tanvi <ta...@gmail.com>.
Hi Freeman,

Thanks for your reply :)

I have an independent project (JAR) of VOs which is added as a dependency in
POM of each of SU. Since each SU has set of JBIs, which use this VO JAR, VO
project is a part of each of zip built for an SU.

As per your suggestion, I performed below steps:
1. Changed VO packaging from JAR to bundle
2. Installed VO bundle independently in SMX-4
3. Added symbolic name of VO bundle in classpath of each of SU.

with this I could remove the class cast exception. :)

My next query is, similar to this VO jar, I have some of the other projects
like DAO layer, Delegate layer, UTIL layer which are shared across SUs i.e.
each SU pom.xml has dependency of these projects. 

- I did not get any such classloader problem for other JARs, what could be
the reason? Is it because, I am using IOC for injecting these classes and
not class cast scenario?
- Is it advisable to have all these shared JARs installed as a separate
bundles in OSGI container and entry to be added in classpath for all of
these?

Please help.

Thanks in advance,

Regards,
Tanvi




--
View this message in context: http://servicemix.396122.n5.nabble.com/Class-cast-exception-while-sending-message-from-JBI-to-other-using-NMR-tp5715233p5715240.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Class cast exception while sending message from JBI to other using NMR

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

The ClassCastException here has nothing to do with SMXCOMP-397.

It's actually from that com.test.vo.TransitVO loaded by different classloaders, in OSGi container, it means two bundles contain class com.test.vo.TransitVO, most likely your SA embed the com.test.vo.TransitVO, which is incorrect.

You should ensure only one bundle contain com.test.vo.TransitVO and from you SA bundles, you refer this class but not embed this class.
likely in your SA/SU, add
<classpath>
  <library>osgi:Bundle-SymbolicName-which-contain-Bundle-SymbolicName</library>
</classpath>

Freeman

-------------
Freeman(Yue) Fang

Red Hat, Inc. 
FuseSource is now part of Red Hat
Web: http://fusesource.com | http://www.redhat.com/
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: @Freeman小屋

On 2012-12-11, at 下午6:23, Tanvi wrote:

> Hi,
> 
> I am trying to have communication between 2 JBIs via NMR in service mix 4
> assembly. I am able to pass various standard java parameters e.g. String,
> int etc. But facing problem during sending collection object of custom data
> type.
> 
> I am sending a list of VO from a JBI and trying to read the same List as
> incoming message in the next JBI.
> e.g. List<TransitVO> transitList - is sent from source and same is to be
> read at destination.
> 
> I could print the class of the object received from NMR as 'ArrayList' and I
> am able to read the list size properly i.e. list is not NULL at destination. 
> A simple for loop used for iterating through this list is giving me a class
> cast exception.
> 
>                for (TransitVO transitVO : transitList) {
>                	LOGGER.debug("******* Bank No :: " +
> transitVO.getBankNo());
>                }
> 
> A ClassCastException of kind, com.test.vo.TransitVO can not be cast to
> com.test.vo.TransitVO is thrown Both data types in exception are same.
> A Similar kind of issue found at below link :
> https://issues.apache.org/jira/browse/SMXCOMP-397
> Tried the solution suggested. It did not work. 
> 
> Please help.
> 
> Regards,
> Tanvi.
> 
> 
> 
> 
> 
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/Class-cast-exception-while-sending-message-from-JBI-to-other-using-NMR-tp5715233.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.