You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Martin Kuhn <ma...@gmx.at> on 2008/12/10 12:54:16 UTC

Strange ClassCastException on sending an object as attachment from one smx-bean to another

I'm working with SMX4 and want to send an object from one servicemix-bean to
another.

Here is my code:

In the sender bean:
...
EntryObject entryObject = ....;
DataHandler dataHandler = new DataHandler(entryObject,
"application/octet-stream");
normalizedMessage.addAttachment(Constants.AUDITLOGENTRY_OBJECT,
dataHandler);
...


In the receiver bean:

DataHandler dataHandler=
message.getAttachment(Constants.AUDITLOGENTRY_OBJECT);
Object object=dataHandler.getContent();
System.out.println(object.getClass().getName());

// here I get a class cast exception ->  java.lang.ClassCastException:
com.xyz.EntryObject cannot be cast to com.xyz.EntryObject
EntryObject entryObject = (EntryObject)object;



This is really strange for me. Also debugging shows me that the object
received is the same as sent.

Could anybody of you give me a hint what's wrong?

TIA

Regards 

Martin
-- 
View this message in context: http://www.nabble.com/Strange-ClassCastException-on-sending-an-object-as-attachment-from-one-smx-bean-to-another-tp20933798p20933798.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Strange ClassCastException on sending an object as attachment from one smx-bean to another

Posted by Martin Kuhn <ma...@gmx.at>.


gnodet wrote:
> 
> The reason is that when using the DataHandler, the object is not
> really serialized.
> You need to make sure the object is serialized, or use a single copy
> (which will prove to be difficult if using the JBI packaging).
> To serialize the object, you could use a ObjectOutputStream /
> ObjectInputStream pair.
> 

Thanks, the serializing approach works.

Regards,
Martin

-- 
View this message in context: http://www.nabble.com/Strange-ClassCastException-on-sending-an-object-as-attachment-from-one-smx-bean-to-another-tp20933798p20936413.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Strange ClassCastException on sending an object as attachment from one smx-bean to another

Posted by Guillaume Nodet <gn...@gmail.com>.
The reason is that when using the DataHandler, the object is not
really serialized.
You need to make sure the object is serialized, or use a single copy
(which will prove to be difficult if using the JBI packaging).
To serialize the object, you could use a ObjectOutputStream /
ObjectInputStream pair.


On Wed, Dec 10, 2008 at 1:26 PM, Martin Kuhn <ma...@gmx.at> wrote:
>
>
> gnodet wrote:
>>
>> THis is certainly a classloader issue.
>> Do you have two copies of the object in two different bundles ?
>> If yes, that would explain the problem.  The solution is to create a
>> bundle that contain this shared class and import the package from your
>> two other bundles.
>>
>
> What do you mean with "two copies of the object in two different bundles".
>
> The two smx-beans are defined in two different Serviceassemblies. At
> deployment time, every assembly contains an archive which contains the class
> I want to pass from one bean to another. (The object I want to pass from one
> bean to another is defined in a common project)
>
> So from my point of view the class should be usable in the receiver bean.
>
> When I debug I see that the received object is the same as the sent.
>
> --
> View this message in context: http://www.nabble.com/Strange-ClassCastException-on-sending-an-object-as-attachment-from-one-smx-bean-to-another-tp20933798p20934328.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com

Re: Strange ClassCastException on sending an object as attachment from one smx-bean to another

Posted by Martin Kuhn <ma...@gmx.at>.

gnodet wrote:
> 
> THis is certainly a classloader issue.
> Do you have two copies of the object in two different bundles ?
> If yes, that would explain the problem.  The solution is to create a
> bundle that contain this shared class and import the package from your
> two other bundles.
> 

What do you mean with "two copies of the object in two different bundles".

The two smx-beans are defined in two different Serviceassemblies. At
deployment time, every assembly contains an archive which contains the class
I want to pass from one bean to another. (The object I want to pass from one
bean to another is defined in a common project)

So from my point of view the class should be usable in the receiver bean.

When I debug I see that the received object is the same as the sent.

-- 
View this message in context: http://www.nabble.com/Strange-ClassCastException-on-sending-an-object-as-attachment-from-one-smx-bean-to-another-tp20933798p20934328.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Strange ClassCastException on sending an object as attachment from one smx-bean to another

Posted by Guillaume Nodet <gn...@gmail.com>.
THis is certainly a classloader issue.
Do you have two copies of the object in two different bundles ?
If yes, that would explain the problem.  The solution is to create a
bundle that contain this shared class and import the package from your
two other bundles.

On Wed, Dec 10, 2008 at 12:54 PM, Martin Kuhn <ma...@gmx.at> wrote:
>
> I'm working with SMX4 and want to send an object from one servicemix-bean to
> another.
>
> Here is my code:
>
> In the sender bean:
> ...
> EntryObject entryObject = ....;
> DataHandler dataHandler = new DataHandler(entryObject,
> "application/octet-stream");
> normalizedMessage.addAttachment(Constants.AUDITLOGENTRY_OBJECT,
> dataHandler);
> ...
>
>
> In the receiver bean:
>
> DataHandler dataHandler=
> message.getAttachment(Constants.AUDITLOGENTRY_OBJECT);
> Object object=dataHandler.getContent();
> System.out.println(object.getClass().getName());
>
> // here I get a class cast exception ->  java.lang.ClassCastException:
> com.xyz.EntryObject cannot be cast to com.xyz.EntryObject
> EntryObject entryObject = (EntryObject)object;
>
>
>
> This is really strange for me. Also debugging shows me that the object
> received is the same as sent.
>
> Could anybody of you give me a hint what's wrong?
>
> TIA
>
> Regards
>
> Martin
> --
> View this message in context: http://www.nabble.com/Strange-ClassCastException-on-sending-an-object-as-attachment-from-one-smx-bean-to-another-tp20933798p20933798.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com