You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by bocamel <jo...@gmail.com> on 2014/07/23 17:13:43 UTC

setBody(Object body, Class type) does not seem to set the body type

I have the following in my camel context:

<onException>
  <exception>org.apache.cxf.binding.soap.SoapFault</exception>
  <handled>true</handled>
  <to uri="a bean that sets the body to a new string, i.e.
exchange.getIn().setBody(something, String.class)" />
  <to uri="file:/..." />
</onException>

It does not matter what I set in the body (the something above), the file
would be empty.  I noticed that the body type is still CxfPayload after I
did the setBody(something, String.class).  However, if I add a convertBodyTo
String before the bean is called, then everything would work fine:

<onException>
  <exception>org.apache.cxf.binding.soap.SoapFault</exception>
  <handled>true</handled>
  *<convertBodyTo type="String" />*
  <to uri="a bean that sets the body to String, i.e.
exchange.getIn().setBody(something, String.class)" />
  <to uri="file:/..." />
</onException>

Should setBody(something, String.class) set the body to String?

Thanks in advance for any insight.



--
View this message in context: http://camel.465427.n5.nabble.com/setBody-Object-body-Class-T-type-does-not-seem-to-set-the-body-type-tp5754307.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: setBody(Object body, Class type) does not seem to set the body type

Posted by bocamel <jo...@gmail.com>.
Hi Willem,

You are absolutely right!  After I switched to use Out message, it worked! 
Furthermore, I did not even need to copy the headers from the In message to
the Out message, they were already there.

This link
http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html
taught me to use In instead of Out.  But obviously there are situations
where only Out would work.  Can you please shed some light (or point me to
the right document) on when Out should be used?

Thanks!



--
View this message in context: http://camel.465427.n5.nabble.com/setBody-Object-body-Class-T-type-does-not-seem-to-set-the-body-type-tp5754307p5754541.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: setBody(Object body, Class type) does not seem to set the body type

Posted by Willem Jiang <wi...@gmail.com>.
You need to set up the out message body instead of in message body.

--  
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 July 27, 2014 at 12:52:08 AM, bocamel (johnzyin@gmail.com) wrote:
> Thanks Claus!
>  
> I tried a Processor, but the same error occurred. I do not know whether the
> fact that this is on an OnException path made any difference. What I am
> trying to do is to replace the soap fault from a web services server
> (CxfPayload) with some meaningful response message (a string).
>  
> Like I said in my original post, I do have a workaround - > type="String" /> before I try to replace the fault message in the processor.
> It is just not very elegant.
>  
> Thanks again for your help!
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/setBody-Object-body-Class-T-type-does-not-seem-to-set-the-body-type-tp5754307p5754475.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>  


Re: setBody(Object body, Class type) does not seem to set the body type

Posted by bocamel <jo...@gmail.com>.
Thanks Claus!  

I tried a Processor, but the same error occurred.  I do not know whether the
fact that this is on an OnException path made any difference.  What I am
trying to do is to replace the soap fault from a web services server
(CxfPayload) with some meaningful response message (a string).

Like I said in my original post, I do have a workaround - <c:convertBodyTo
type="String" /> before I try to replace the fault message in the processor. 
It is just not very elegant.

Thanks again for your help!



--
View this message in context: http://camel.465427.n5.nabble.com/setBody-Object-body-Class-T-type-does-not-seem-to-set-the-body-type-tp5754307p5754475.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: setBody(Object body, Class type) does not seem to set the body type

Posted by Claus Ibsen <cl...@gmail.com>.
Use a processor instead of a bean if you want to mutate the exchange,
or make the bean return exchange

On Wed, Jul 23, 2014 at 5:13 PM, bocamel <jo...@gmail.com> wrote:
> I have the following in my camel context:
>
> <onException>
>   <exception>org.apache.cxf.binding.soap.SoapFault</exception>
>   <handled>true</handled>
>   <to uri="a bean that sets the body to a new string, i.e.
> exchange.getIn().setBody(something, String.class)" />
>   <to uri="file:/..." />
> </onException>
>
> It does not matter what I set in the body (the something above), the file
> would be empty.  I noticed that the body type is still CxfPayload after I
> did the setBody(something, String.class).  However, if I add a convertBodyTo
> String before the bean is called, then everything would work fine:
>
> <onException>
>   <exception>org.apache.cxf.binding.soap.SoapFault</exception>
>   <handled>true</handled>
>   *<convertBodyTo type="String" />*
>   <to uri="a bean that sets the body to String, i.e.
> exchange.getIn().setBody(something, String.class)" />
>   <to uri="file:/..." />
> </onException>
>
> Should setBody(something, String.class) set the body to String?
>
> Thanks in advance for any insight.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/setBody-Object-body-Class-T-type-does-not-seem-to-set-the-body-type-tp5754307.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/