Hi

You may need to do a deep clone/copy of the message body to make them
independent, but default the copy is a shallow copy.

So when you convert the body to a String its a shallow instance of the
message body which can explain why its changed.

So you have to do this yourself how to do the deep clone/copy which
depends on what type the message body really is and if that is
possible.



On Fri, Jul 14, 2017 at 4:38 PM, Marcelo Ohashi <[email protected]> wrote:
> Hi all,
>
> I'd like to know if there's a way to change the body type without affecting
> the original one.
>
> I need to create an interceptor that retrieves the body from an exchange,
> convert it to string, log, and forward the original exchange to the next
> processor. But, even if I make a copy of my original exchange it doesn't
> prevent it from also change the original one.
>
> Here follows what I have to do:
>
> Exchange newExchange = exchange.copy();
> String payload = newExchange.getIn().getBody(String.class);
> log.info("{}", payload);
>
> target.process(exchange);
>
> newExchange = exchange.copy();
> String payload = newExchange.getIn().getBody(String.class);
> log.info("{}", payload);
>
> So, when I call the target.process(exchange) the exchange gets changed to
> String.
>
> Do you know how I can do it without affecting the original body?
>
> Thanks in advance,
>
>
> --
> Marcelo Ohashi



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

Reply via email to