You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Alan Camillo <al...@gmail.com> on 2014/12/09 05:48:43 UTC
TypeConversionException RabbitMQ
Look like a simple problem, but I can't see the solution.
I have a class like the follow:
public class A {
public List<B> Bs;
// getters and setters
}
Than I receive this class from a RabbitMQ:
from("rabbitmq://{{rabbitmq.host}}:{{rabbitmq.port}}/*sendmsg*
").routeId("sendmsg")
.convertBodyTo(A.class)
.setHeader("BODY", new SimpleExpression("${body}"))
.setHeader("SIZE", new SimpleExpression("${body.bs.size}"))
.loop(new SimpleExpression("${header.SIZE}") )
.log("contador: ${header.CamelLoopIndex}")
.process(new IterateEmailsProcessor()) //<<<<<<<<< Here I
put a *B.class* in the body to send to another process and I get the error
.inOnly("rabbitmq://{{rabbitmq.host}}:{{rabbitmq.port}}/
*othermsg*") //<<<<<<<<<< Exception came from here
.end() ;
Caused by: [org.apache.camel.TypeConversionException - Error during type
conversion from type: byte[] to the required type: *A* with value
[B@2aa6b2f7 due Cannot cast *B* to *A*]
Can't I exchange different types through rabbitmq component?
Thank you!
Alan Camillo
Re: TypeConversionException RabbitMQ
Posted by Alan Camillo <al...@gmail.com>.
Just to close this...
I should have used a marshal/unmarshal before and after send and receive a
message from RabbitMQ. It's lot of safer!
Thanks any way! ;)
On Tue, Dec 9, 2014 at 3:19 PM, Alan Camillo <al...@gmail.com> wrote:
> Someone knows if this behavior is it normal?
>
> Thanks again!
> Alan Camillo
>
> On Tue, Dec 9, 2014 at 12:31 PM, Alan Camillo <al...@gmail.com>
> wrote:
>
>> Sure! Here it is:
>>
>> ...
>> @Override
>> public void *process*(Exchange exchange) throws Exception {
>>
>> A a = exchange.getIn()
>> .getHeader("BODY", *A.class*);
>>
>> exchange.getIn().*setBody*(
>> a.getBs().get(
>> exchange.getProperty("CamelLoopIndex",
>> Integer.class))
>> , *B.class*);
>> }
>> ...
>> Thanks!
>> Alan Camillo
>>
>> On Tue, Dec 9, 2014 at 3:45 AM, Willem Jiang <wi...@gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> Can you show us the code of IterateEmailsProcessor?
>>>
>>> --
>>> Willem Jiang
>>>
>>> Red Hat, Inc.
>>> Web: http://www.redhat.com
>>> Blog: http://willemjiang.blogspot.com (English)
>>> http://jnn.iteye.com (Chinese)
>>> Twitter: willemjiang
>>> Weibo: 姜宁willem
>>>
>>>
>>>
>>> On December 9, 2014 at 12:51:03 PM, Alan Camillo (alancamillo@gmail.com)
>>> wrote:
>>> > Look like a simple problem, but I can't see the solution.
>>> >
>>> > I have a class like the follow:
>>> > public class A {
>>> > public List Bs;
>>> > // getters and setters
>>> > }
>>> >
>>> > Than I receive this class from a RabbitMQ:
>>> >
>>> > from("rabbitmq://{{rabbitmq.host}}:{{rabbitmq.port}}/*sendmsg*
>>> > ").routeId("sendmsg")
>>> > .convertBodyTo(A.class)
>>> > .setHeader("BODY", new SimpleExpression("${body}"))
>>> > .setHeader("SIZE", new SimpleExpression("${body.bs.size}"))
>>> > .loop(new SimpleExpression("${header.SIZE}") )
>>> > .log("contador: ${header.CamelLoopIndex}")
>>> > .process(new IterateEmailsProcessor()) //<<<<<<<<< Here I
>>> > put a *B.class* in the body to send to another process and I get the
>>> error
>>> > .inOnly("rabbitmq://{{rabbitmq.host}}:{{rabbitmq.port}}/
>>> > *othermsg*") //<<<<<<<<<< Exception came from here
>>> > .end() ;
>>> >
>>> > Caused by: [org.apache.camel.TypeConversionException - Error during
>>> type
>>> > conversion from type: byte[] to the required type: *A* with value
>>> > [B@2aa6b2f7 due Cannot cast *B* to *A*]
>>> >
>>> > Can't I exchange different types through rabbitmq component?
>>> > Thank you!
>>> > Alan Camillo
>>> >
>>>
>>>
>>
>
Re: TypeConversionException RabbitMQ
Posted by Alan Camillo <al...@gmail.com>.
Someone knows if this behavior is it normal?
Thanks again!
Alan Camillo
On Tue, Dec 9, 2014 at 12:31 PM, Alan Camillo <al...@gmail.com> wrote:
> Sure! Here it is:
>
> ...
> @Override
> public void *process*(Exchange exchange) throws Exception {
>
> A a = exchange.getIn()
> .getHeader("BODY", *A.class*);
>
> exchange.getIn().*setBody*(
> a.getBs().get(
> exchange.getProperty("CamelLoopIndex",
> Integer.class))
> , *B.class*);
> }
> ...
> Thanks!
> Alan Camillo
>
> On Tue, Dec 9, 2014 at 3:45 AM, Willem Jiang <wi...@gmail.com>
> wrote:
>
>> Hi,
>>
>> Can you show us the code of IterateEmailsProcessor?
>>
>> --
>> Willem Jiang
>>
>> Red Hat, Inc.
>> Web: http://www.redhat.com
>> Blog: http://willemjiang.blogspot.com (English)
>> http://jnn.iteye.com (Chinese)
>> Twitter: willemjiang
>> Weibo: 姜宁willem
>>
>>
>>
>> On December 9, 2014 at 12:51:03 PM, Alan Camillo (alancamillo@gmail.com)
>> wrote:
>> > Look like a simple problem, but I can't see the solution.
>> >
>> > I have a class like the follow:
>> > public class A {
>> > public List Bs;
>> > // getters and setters
>> > }
>> >
>> > Than I receive this class from a RabbitMQ:
>> >
>> > from("rabbitmq://{{rabbitmq.host}}:{{rabbitmq.port}}/*sendmsg*
>> > ").routeId("sendmsg")
>> > .convertBodyTo(A.class)
>> > .setHeader("BODY", new SimpleExpression("${body}"))
>> > .setHeader("SIZE", new SimpleExpression("${body.bs.size}"))
>> > .loop(new SimpleExpression("${header.SIZE}") )
>> > .log("contador: ${header.CamelLoopIndex}")
>> > .process(new IterateEmailsProcessor()) //<<<<<<<<< Here I
>> > put a *B.class* in the body to send to another process and I get the
>> error
>> > .inOnly("rabbitmq://{{rabbitmq.host}}:{{rabbitmq.port}}/
>> > *othermsg*") //<<<<<<<<<< Exception came from here
>> > .end() ;
>> >
>> > Caused by: [org.apache.camel.TypeConversionException - Error during type
>> > conversion from type: byte[] to the required type: *A* with value
>> > [B@2aa6b2f7 due Cannot cast *B* to *A*]
>> >
>> > Can't I exchange different types through rabbitmq component?
>> > Thank you!
>> > Alan Camillo
>> >
>>
>>
>
Re: TypeConversionException RabbitMQ
Posted by Alan Camillo <al...@gmail.com>.
Sure! Here it is:
...
@Override
public void *process*(Exchange exchange) throws Exception {
A a = exchange.getIn()
.getHeader("BODY", *A.class*);
exchange.getIn().*setBody*(
a.getBs().get(
exchange.getProperty("CamelLoopIndex",
Integer.class))
, *B.class*);
}
...
Thanks!
Alan Camillo
On Tue, Dec 9, 2014 at 3:45 AM, Willem Jiang <wi...@gmail.com> wrote:
> Hi,
>
> Can you show us the code of IterateEmailsProcessor?
>
> --
> Willem Jiang
>
> Red Hat, Inc.
> Web: http://www.redhat.com
> Blog: http://willemjiang.blogspot.com (English)
> http://jnn.iteye.com (Chinese)
> Twitter: willemjiang
> Weibo: 姜宁willem
>
>
>
> On December 9, 2014 at 12:51:03 PM, Alan Camillo (alancamillo@gmail.com)
> wrote:
> > Look like a simple problem, but I can't see the solution.
> >
> > I have a class like the follow:
> > public class A {
> > public List Bs;
> > // getters and setters
> > }
> >
> > Than I receive this class from a RabbitMQ:
> >
> > from("rabbitmq://{{rabbitmq.host}}:{{rabbitmq.port}}/*sendmsg*
> > ").routeId("sendmsg")
> > .convertBodyTo(A.class)
> > .setHeader("BODY", new SimpleExpression("${body}"))
> > .setHeader("SIZE", new SimpleExpression("${body.bs.size}"))
> > .loop(new SimpleExpression("${header.SIZE}") )
> > .log("contador: ${header.CamelLoopIndex}")
> > .process(new IterateEmailsProcessor()) //<<<<<<<<< Here I
> > put a *B.class* in the body to send to another process and I get the
> error
> > .inOnly("rabbitmq://{{rabbitmq.host}}:{{rabbitmq.port}}/
> > *othermsg*") //<<<<<<<<<< Exception came from here
> > .end() ;
> >
> > Caused by: [org.apache.camel.TypeConversionException - Error during type
> > conversion from type: byte[] to the required type: *A* with value
> > [B@2aa6b2f7 due Cannot cast *B* to *A*]
> >
> > Can't I exchange different types through rabbitmq component?
> > Thank you!
> > Alan Camillo
> >
>
>
Re: TypeConversionException RabbitMQ
Posted by Willem Jiang <wi...@gmail.com>.
Hi,
Can you show us the code of IterateEmailsProcessor?
--
Willem Jiang
Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang
Weibo: 姜宁willem
On December 9, 2014 at 12:51:03 PM, Alan Camillo (alancamillo@gmail.com) wrote:
> Look like a simple problem, but I can't see the solution.
>
> I have a class like the follow:
> public class A {
> public List Bs;
> // getters and setters
> }
>
> Than I receive this class from a RabbitMQ:
>
> from("rabbitmq://{{rabbitmq.host}}:{{rabbitmq.port}}/*sendmsg*
> ").routeId("sendmsg")
> .convertBodyTo(A.class)
> .setHeader("BODY", new SimpleExpression("${body}"))
> .setHeader("SIZE", new SimpleExpression("${body.bs.size}"))
> .loop(new SimpleExpression("${header.SIZE}") )
> .log("contador: ${header.CamelLoopIndex}")
> .process(new IterateEmailsProcessor()) //<<<<<<<<< Here I
> put a *B.class* in the body to send to another process and I get the error
> .inOnly("rabbitmq://{{rabbitmq.host}}:{{rabbitmq.port}}/
> *othermsg*") //<<<<<<<<<< Exception came from here
> .end() ;
>
> Caused by: [org.apache.camel.TypeConversionException - Error during type
> conversion from type: byte[] to the required type: *A* with value
> [B@2aa6b2f7 due Cannot cast *B* to *A*]
>
> Can't I exchange different types through rabbitmq component?
> Thank you!
> Alan Camillo
>