You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by bradtwurst <na...@xoxy.net> on 2006/10/28 02:45:54 UTC

ClassCastException

Hello,

This time, I really am confused and I don't even know where to start to
solve the problem.

Here is my configuration

One service assembly containing three service units.

Service unit 1 is an http based unit that consumes soap messages and directs
the message to service unit 2

Service unit 2 is a jsr181 based unit that contains the function call
'update(Information value)' where the object Information is a 'transfer
object' that contains basic properties (Strings, Longs, Integers) and has no
internal logic.  

Service unit 2 creates a new jbi message and adds to it the Information
object as a property of the message (msg.setProperty("payload", value);).  

Service unit 2 sends the newly created message with the destination
service/endpoint pointing to Service unit 3

Service unit 3 is a lightweight based service that is pojo based.  Inside of
it is an object that has the onMessageExchange event.

Inside the onMessageExchange event, the Information object tries to be
extracted 
          Information values = (Information) message.getProperty("payload");
but insteads receives a ClassCastException.

Now, the weird part is that before SU2 creates the new message, I sysout the
Information object with no problem.

For example, 
      System.out.println(value); returns me "transfer.Information@15e3974"

and in SU3/onMessageExchange, I can perform the command 
        System.out.println(message.getProperty("payload")); and I receive
the same response.

But when I perform
      Information value = (Information) message.getProperty("payload"); 
on the very next line, I get the CCE error.

Is there any help for me?

As a side note, this logic worked great when I was doing unit/integration
testing.

Thanks for the help,
James
-- 
View this message in context: http://www.nabble.com/ClassCastException-tf2524368.html#a7041182
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: ClassCastException

Posted by Guillaume Nodet <gn...@gmail.com>.
The problem comes from the fact that xstream is in the container classpath.
So you need to either:
  * configure xstream so that it uses the thread context classloader
       XStream.setClassLoader(Thread.currentThread().getContextClassLoader());
  * include xstream in your SU and use a self-first classloader (inverse="true"
     attribute on the <classpath/> tag)

On 10/30/06, bradtwurst <na...@xoxy.net> wrote:
>
> Guillaume,
>
> Ok, I've tried your first suggestion of putting the jar containing the
> 'transfer objects' in the lib of servicemix and that remove the class cast
> exception.  However, I really would prefer to have the jar's located within
> the lib of each service unit since it would be a cleaner implementation.
>
> So, I've created logic that would convert the object to xml via xstream
> inside the jsr181 service unit and it converts it back to an object in the
> lightweight component.
>
> This works great in my programmatic tests, but it fails when I deploy the
> SU's to a stand alone SM.
>
> The message that I get is a CannotResolveClassException when I do the
> xstream.fromXml(xmlString) in the lightweight component.
>
> Now, if I put the jar back at the SM/lib level (instead of the SU level),
> the conversion works correctly.
>
> Is this still a class loading issue?  If so, is there anything that I can do
> to resolve this?
>
> Is it possibly due to the fact that I have the classpath in the LW component
> set to inverse='true' and I don't have it set this way in the JSR181
> component.
>
> Everytime that I think that I am getting to understand the configuration and
> how the classloader works, I step on another landmine.  Definitely
> frustrating.
>
>
> gnodet wrote:
> >
> > On 10/28/06, bradtwurst <na...@xoxy.net> wrote:
> >>
> >>
> >> In terms of serialization, would converting the object to, say, an
> >> xstream
> >> source be appropriate?
> >>
> >
> > Yes.
> >
> >> James
> >>
> >>
> >> gnodet wrote:
> >> >
> >> > This is a classic problem wrt to classloaders.
> >> > The same class loaded from two different class loaders
> >> > is considered by the JVM as two different classes.
> >> > Thus you can not cast your object because I guess
> >> > the class has been embedded in two different SUs.
> >> >
> >> > The only workaround is to serialize it somehow (binary, xml)
> >> > or to put this class in a common classloader.  In this case,
> >> > it would mean the container classloader.
> >> >
> >> > On 10/28/06, bradtwurst <na...@xoxy.net> wrote:
> >> >>
> >> >> Hello,
> >> >>
> >> >> This time, I really am confused and I don't even know where to start
> >> to
> >> >> solve the problem.
> >> >>
> >> >> Here is my configuration
> >> >>
> >> >> One service assembly containing three service units.
> >> >>
> >> >> Service unit 1 is an http based unit that consumes soap messages and
> >> >> directs
> >> >> the message to service unit 2
> >> >>
> >> >> Service unit 2 is a jsr181 based unit that contains the function call
> >> >> 'update(Information value)' where the object Information is a
> >> 'transfer
> >> >> object' that contains basic properties (Strings, Longs, Integers) and
> >> has
> >> >> no
> >> >> internal logic.
> >> >>
> >> >> Service unit 2 creates a new jbi message and adds to it the
> >> Information
> >> >> object as a property of the message (msg.setProperty("payload",
> >> value);).
> >> >>
> >> >> Service unit 2 sends the newly created message with the destination
> >> >> service/endpoint pointing to Service unit 3
> >> >>
> >> >> Service unit 3 is a lightweight based service that is pojo based.
> >> Inside
> >> >> of
> >> >> it is an object that has the onMessageExchange event.
> >> >>
> >> >> Inside the onMessageExchange event, the Information object tries to be
> >> >> extracted
> >> >>           Information values = (Information)
> >> >> message.getProperty("payload");
> >> >> but insteads receives a ClassCastException.
> >> >>
> >> >> Now, the weird part is that before SU2 creates the new message, I
> >> sysout
> >> >> the
> >> >> Information object with no problem.
> >> >>
> >> >> For example,
> >> >>       System.out.println(value); returns me
> >> >> "transfer.Information@15e3974"
> >> >>
> >> >> and in SU3/onMessageExchange, I can perform the command
> >> >>         System.out.println(message.getProperty("payload")); and I
> >> receive
> >> >> the same response.
> >> >>
> >> >> But when I perform
> >> >>       Information value = (Information)
> >> message.getProperty("payload");
> >> >> on the very next line, I get the CCE error.
> >> >>
> >> >> Is there any help for me?
> >> >>
> >> >> As a side note, this logic worked great when I was doing
> >> unit/integration
> >> >> testing.
> >> >>
> >> >> Thanks for the help,
> >> >> James
> >> >> --
> >> >> View this message in context:
> >> >> http://www.nabble.com/ClassCastException-tf2524368.html#a7041182
> >> >> Sent from the ServiceMix - User mailing list archive at Nabble.com.
> >> >>
> >> >>
> >> >
> >> >
> >> > --
> >> > Cheers,
> >> > Guillaume Nodet
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/ClassCastException-tf2524368.html#a7043045
> >> Sent from the ServiceMix - User mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> > --
> > Cheers,
> > Guillaume Nodet
> >
> >
>
> --
> View this message in context: http://www.nabble.com/ClassCastException-tf2524368.html#a7079512
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet

Re: ClassCastException

Posted by bradtwurst <na...@xoxy.net>.
Guillaume,

Ok, I've tried your first suggestion of putting the jar containing the
'transfer objects' in the lib of servicemix and that remove the class cast
exception.  However, I really would prefer to have the jar's located within
the lib of each service unit since it would be a cleaner implementation.

So, I've created logic that would convert the object to xml via xstream
inside the jsr181 service unit and it converts it back to an object in the
lightweight component.

This works great in my programmatic tests, but it fails when I deploy the
SU's to a stand alone SM.

The message that I get is a CannotResolveClassException when I do the
xstream.fromXml(xmlString) in the lightweight component.

Now, if I put the jar back at the SM/lib level (instead of the SU level),
the conversion works correctly.

Is this still a class loading issue?  If so, is there anything that I can do
to resolve this?

Is it possibly due to the fact that I have the classpath in the LW component
set to inverse='true' and I don't have it set this way in the JSR181
component.

Everytime that I think that I am getting to understand the configuration and
how the classloader works, I step on another landmine.  Definitely
frustrating.


gnodet wrote:
> 
> On 10/28/06, bradtwurst <na...@xoxy.net> wrote:
>>
>>
>> In terms of serialization, would converting the object to, say, an
>> xstream
>> source be appropriate?
>>
> 
> Yes.
> 
>> James
>>
>>
>> gnodet wrote:
>> >
>> > This is a classic problem wrt to classloaders.
>> > The same class loaded from two different class loaders
>> > is considered by the JVM as two different classes.
>> > Thus you can not cast your object because I guess
>> > the class has been embedded in two different SUs.
>> >
>> > The only workaround is to serialize it somehow (binary, xml)
>> > or to put this class in a common classloader.  In this case,
>> > it would mean the container classloader.
>> >
>> > On 10/28/06, bradtwurst <na...@xoxy.net> wrote:
>> >>
>> >> Hello,
>> >>
>> >> This time, I really am confused and I don't even know where to start
>> to
>> >> solve the problem.
>> >>
>> >> Here is my configuration
>> >>
>> >> One service assembly containing three service units.
>> >>
>> >> Service unit 1 is an http based unit that consumes soap messages and
>> >> directs
>> >> the message to service unit 2
>> >>
>> >> Service unit 2 is a jsr181 based unit that contains the function call
>> >> 'update(Information value)' where the object Information is a
>> 'transfer
>> >> object' that contains basic properties (Strings, Longs, Integers) and
>> has
>> >> no
>> >> internal logic.
>> >>
>> >> Service unit 2 creates a new jbi message and adds to it the
>> Information
>> >> object as a property of the message (msg.setProperty("payload",
>> value);).
>> >>
>> >> Service unit 2 sends the newly created message with the destination
>> >> service/endpoint pointing to Service unit 3
>> >>
>> >> Service unit 3 is a lightweight based service that is pojo based. 
>> Inside
>> >> of
>> >> it is an object that has the onMessageExchange event.
>> >>
>> >> Inside the onMessageExchange event, the Information object tries to be
>> >> extracted
>> >>           Information values = (Information)
>> >> message.getProperty("payload");
>> >> but insteads receives a ClassCastException.
>> >>
>> >> Now, the weird part is that before SU2 creates the new message, I
>> sysout
>> >> the
>> >> Information object with no problem.
>> >>
>> >> For example,
>> >>       System.out.println(value); returns me
>> >> "transfer.Information@15e3974"
>> >>
>> >> and in SU3/onMessageExchange, I can perform the command
>> >>         System.out.println(message.getProperty("payload")); and I
>> receive
>> >> the same response.
>> >>
>> >> But when I perform
>> >>       Information value = (Information)
>> message.getProperty("payload");
>> >> on the very next line, I get the CCE error.
>> >>
>> >> Is there any help for me?
>> >>
>> >> As a side note, this logic worked great when I was doing
>> unit/integration
>> >> testing.
>> >>
>> >> Thanks for the help,
>> >> James
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/ClassCastException-tf2524368.html#a7041182
>> >> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>> > --
>> > Cheers,
>> > Guillaume Nodet
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/ClassCastException-tf2524368.html#a7043045
>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Cheers,
> Guillaume Nodet
> 
> 

-- 
View this message in context: http://www.nabble.com/ClassCastException-tf2524368.html#a7079512
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: ClassCastException

Posted by Guillaume Nodet <gn...@gmail.com>.
On 10/28/06, bradtwurst <na...@xoxy.net> wrote:
>
>
> In terms of serialization, would converting the object to, say, an xstream
> source be appropriate?
>

Yes.

> James
>
>
> gnodet wrote:
> >
> > This is a classic problem wrt to classloaders.
> > The same class loaded from two different class loaders
> > is considered by the JVM as two different classes.
> > Thus you can not cast your object because I guess
> > the class has been embedded in two different SUs.
> >
> > The only workaround is to serialize it somehow (binary, xml)
> > or to put this class in a common classloader.  In this case,
> > it would mean the container classloader.
> >
> > On 10/28/06, bradtwurst <na...@xoxy.net> wrote:
> >>
> >> Hello,
> >>
> >> This time, I really am confused and I don't even know where to start to
> >> solve the problem.
> >>
> >> Here is my configuration
> >>
> >> One service assembly containing three service units.
> >>
> >> Service unit 1 is an http based unit that consumes soap messages and
> >> directs
> >> the message to service unit 2
> >>
> >> Service unit 2 is a jsr181 based unit that contains the function call
> >> 'update(Information value)' where the object Information is a 'transfer
> >> object' that contains basic properties (Strings, Longs, Integers) and has
> >> no
> >> internal logic.
> >>
> >> Service unit 2 creates a new jbi message and adds to it the Information
> >> object as a property of the message (msg.setProperty("payload", value);).
> >>
> >> Service unit 2 sends the newly created message with the destination
> >> service/endpoint pointing to Service unit 3
> >>
> >> Service unit 3 is a lightweight based service that is pojo based.  Inside
> >> of
> >> it is an object that has the onMessageExchange event.
> >>
> >> Inside the onMessageExchange event, the Information object tries to be
> >> extracted
> >>           Information values = (Information)
> >> message.getProperty("payload");
> >> but insteads receives a ClassCastException.
> >>
> >> Now, the weird part is that before SU2 creates the new message, I sysout
> >> the
> >> Information object with no problem.
> >>
> >> For example,
> >>       System.out.println(value); returns me
> >> "transfer.Information@15e3974"
> >>
> >> and in SU3/onMessageExchange, I can perform the command
> >>         System.out.println(message.getProperty("payload")); and I receive
> >> the same response.
> >>
> >> But when I perform
> >>       Information value = (Information) message.getProperty("payload");
> >> on the very next line, I get the CCE error.
> >>
> >> Is there any help for me?
> >>
> >> As a side note, this logic worked great when I was doing unit/integration
> >> testing.
> >>
> >> Thanks for the help,
> >> James
> >> --
> >> View this message in context:
> >> http://www.nabble.com/ClassCastException-tf2524368.html#a7041182
> >> Sent from the ServiceMix - User mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> > --
> > Cheers,
> > Guillaume Nodet
> >
> >
>
> --
> View this message in context: http://www.nabble.com/ClassCastException-tf2524368.html#a7043045
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet

Re: ClassCastException

Posted by bradtwurst <na...@xoxy.net>.
Guillaume,

Thanks again for another quick response.

I have to admit that my knowledge is this area is lacking (as if you
couldn't tell :)

I understand that I could put the transfer objects in the container
classloader, but I would prefer not to do that if at all possible.

In terms of serialization, would converting the object to, say, an xstream
source be appropriate?

James


gnodet wrote:
> 
> This is a classic problem wrt to classloaders.
> The same class loaded from two different class loaders
> is considered by the JVM as two different classes.
> Thus you can not cast your object because I guess
> the class has been embedded in two different SUs.
> 
> The only workaround is to serialize it somehow (binary, xml)
> or to put this class in a common classloader.  In this case,
> it would mean the container classloader.
> 
> On 10/28/06, bradtwurst <na...@xoxy.net> wrote:
>>
>> Hello,
>>
>> This time, I really am confused and I don't even know where to start to
>> solve the problem.
>>
>> Here is my configuration
>>
>> One service assembly containing three service units.
>>
>> Service unit 1 is an http based unit that consumes soap messages and
>> directs
>> the message to service unit 2
>>
>> Service unit 2 is a jsr181 based unit that contains the function call
>> 'update(Information value)' where the object Information is a 'transfer
>> object' that contains basic properties (Strings, Longs, Integers) and has
>> no
>> internal logic.
>>
>> Service unit 2 creates a new jbi message and adds to it the Information
>> object as a property of the message (msg.setProperty("payload", value);).
>>
>> Service unit 2 sends the newly created message with the destination
>> service/endpoint pointing to Service unit 3
>>
>> Service unit 3 is a lightweight based service that is pojo based.  Inside
>> of
>> it is an object that has the onMessageExchange event.
>>
>> Inside the onMessageExchange event, the Information object tries to be
>> extracted
>>           Information values = (Information)
>> message.getProperty("payload");
>> but insteads receives a ClassCastException.
>>
>> Now, the weird part is that before SU2 creates the new message, I sysout
>> the
>> Information object with no problem.
>>
>> For example,
>>       System.out.println(value); returns me
>> "transfer.Information@15e3974"
>>
>> and in SU3/onMessageExchange, I can perform the command
>>         System.out.println(message.getProperty("payload")); and I receive
>> the same response.
>>
>> But when I perform
>>       Information value = (Information) message.getProperty("payload");
>> on the very next line, I get the CCE error.
>>
>> Is there any help for me?
>>
>> As a side note, this logic worked great when I was doing unit/integration
>> testing.
>>
>> Thanks for the help,
>> James
>> --
>> View this message in context:
>> http://www.nabble.com/ClassCastException-tf2524368.html#a7041182
>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Cheers,
> Guillaume Nodet
> 
> 

-- 
View this message in context: http://www.nabble.com/ClassCastException-tf2524368.html#a7043045
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: ClassCastException

Posted by Guillaume Nodet <gn...@gmail.com>.
This is a classic problem wrt to classloaders.
The same class loaded from two different class loaders
is considered by the JVM as two different classes.
Thus you can not cast your object because I guess
the class has been embedded in two different SUs.

The only workaround is to serialize it somehow (binary, xml)
or to put this class in a common classloader.  In this case,
it would mean the container classloader.

On 10/28/06, bradtwurst <na...@xoxy.net> wrote:
>
> Hello,
>
> This time, I really am confused and I don't even know where to start to
> solve the problem.
>
> Here is my configuration
>
> One service assembly containing three service units.
>
> Service unit 1 is an http based unit that consumes soap messages and directs
> the message to service unit 2
>
> Service unit 2 is a jsr181 based unit that contains the function call
> 'update(Information value)' where the object Information is a 'transfer
> object' that contains basic properties (Strings, Longs, Integers) and has no
> internal logic.
>
> Service unit 2 creates a new jbi message and adds to it the Information
> object as a property of the message (msg.setProperty("payload", value);).
>
> Service unit 2 sends the newly created message with the destination
> service/endpoint pointing to Service unit 3
>
> Service unit 3 is a lightweight based service that is pojo based.  Inside of
> it is an object that has the onMessageExchange event.
>
> Inside the onMessageExchange event, the Information object tries to be
> extracted
>           Information values = (Information) message.getProperty("payload");
> but insteads receives a ClassCastException.
>
> Now, the weird part is that before SU2 creates the new message, I sysout the
> Information object with no problem.
>
> For example,
>       System.out.println(value); returns me "transfer.Information@15e3974"
>
> and in SU3/onMessageExchange, I can perform the command
>         System.out.println(message.getProperty("payload")); and I receive
> the same response.
>
> But when I perform
>       Information value = (Information) message.getProperty("payload");
> on the very next line, I get the CCE error.
>
> Is there any help for me?
>
> As a side note, this logic worked great when I was doing unit/integration
> testing.
>
> Thanks for the help,
> James
> --
> View this message in context: http://www.nabble.com/ClassCastException-tf2524368.html#a7041182
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet