You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Wang Yan <wy...@gmail.com> on 2019/07/17 07:41:26 UTC

exchange.getIn().setBody() does not work for OnException block

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();

Re: exchange.getIn().setBody() does not work for OnException block

Posted by Claus Ibsen <cl...@gmail.com>.
Use

exchange.getMessage()

And if you really want to use IN or OUT then check with exchange.hasOut() first

On Wed, Jul 17, 2019 at 9:41 AM Wang Yan <wy...@gmail.com> wrote:
>
> 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();



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2