http://camel.465427.n5.nabble.com/exchange-getIn-setBody-does-not-work-for-OnException-block-tc5838544.html

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
W.Y
Reply | Threaded
Open this post in threaded view
|

http://camel.465427.n5.nabble.com/exchange-getIn-setBody-does-not-work-for-OnException-block-tc5838544.html

W.Y
This post was updated on .
@ Claus
Thanks for your quick reply. i used exchange.getMessage(), it does not work
it prints out below information , what i expected result should be "Error
happened , please contact Admin"

###############################
This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.
##################################

According to document (
https://camel.apache.org/using-getin-or-getout-methods-on-exchange.html),
when we modify body of exchange, we should use exchange.getIn().setBody()
instead of exchange.getOut().setBody()

It ususally works. but for OnException block, it does not work , I have to
use exchange.getOut().setBody
Any hints are more than suggest or hints are more than welcome!





onException(Exception.class).convertBodyTo(String.class).log(LoggingLevel.INFO,
.process(exchange -> {
exchange.getIn().setHeader("Content-Type", "text/xml; charset=UTF-8");
exchange.getOut().setBody(" Error happend , please contact Admin ");
//exchange.getIn().setBody(" Error happend , please contact Admin ");  ->
exchange.getIn().setBody does not work here!!!
}).handled(true).end();



###############################
This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.
##################################


>
> According to document (
> https://camel.apache.org/using-getin-or-getout-methods-on-exchange.html),
> when we modify body of exchange, we should use exchange.getIn().setBody()
> instead of exchange.getOut().setBody()
>
> It ususally works. but for OnException block, it does not work , I have to
> use exchange.getOut().setBody
> Any hints are more than suggest or hints are more than welcome!
>
>
>
>
>
> onException(Exception.class).convertBodyTo(String.class).log(LoggingLevel.INFO,
> .process(exchange -> {
> exchange.getIn().setHeader("Content-Type", "text/xml; charset=UTF-8");
> exchange.getOut().setBody(" Error happend , please contact Admin ");
> //exchange.getIn().setBody(" Error happend , please contact Admin ");  ->
> exchange.getIn().setBody does not work here!!!
> }).handled(true).end();
«  [hide part of quote]