camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject Re: Safely copy exchange body
Date Wed, 04 Mar 2015 08:53:04 GMT

There is no 100% safe way for all kind of message body types.

But enabling stream caching helps.
Then files can be converted as well. But mind that for files you may
want to limit the size, in case the files are very big etc. So its
more a case by case.

On Wed, Mar 4, 2015 at 9:27 AM, Niels <> wrote:
> Hey there,
> I was hoping I could pick some brain to gather a idea that can work. But
> first let me explain my intentions.
> So the idea is to save the body and headers of the exchange for auditing
> purposes.
> To get this to work, we're using a Tracer and configured the destination uri
> to point to a route we defined to process the exchanges. At the route we
> have a custom processor which will filter out the information we need from
> the exchange.
> One step of the process is to convert the body of the exchange to a string.
> What we've noticed, is that if we use the traced exchange and convert the
> body to a string. This sometimes has an effect on the body of the original
> exchange and consequently has an effect on the original routing.
> This is of course because no deep copying is performed on the exchange.
> So we tried to work around the problem and see if we could come up with a
> kind of deep copy of our own. We ended up trying this approach:
>     private Exchange copyExchange(Exchange exchange) {
>         CamelContext camelContext = exchange.getContext();
>         DefaultExchangeHolder exchangeHolder =
> DefaultExchangeHolder.marshal(exchange);
>         Exchange newExchange = new DefaultExchange(camelContext);
>         DefaultExchangeHolder.unmarshal(newExchange, exchangeHolder);
>         return newExchange;
>     }
> This approach seemed to work fine, but we encountered some issues. When we
> for example receive a GenericFile from a File component we can't unmarshal
> that request. I got this issue:
> org.apache.camel.RuntimeExchangeException: Message body of type
> org.apache.camel.component.file.GenericFile is not supported by this
> marshaller. on the exchange: Exchange[test.txt]
>     at
> org.apache.camel.impl.DefaultExchangeHolder.marshal([156:org.apache.camel.camel-core:2.13.2]
>     at
> org.apache.camel.impl.DefaultExchangeHolder.marshal([156:org.apache.camel.camel-core:2.13.2]
>     at
> nl.kabisa.flux.transactions.TraceProcessor.copyExchange([272:nl.kabisa.flux.transaction-logger:2.1.1.SNAPSHOT]
> Eventually I only need to make sure I can convert the body safely to a
> string without interfering with the original exchange body. Is there anybody
> with some advise how I could accomplished that?
> PS: using Camel 2.13.2 in Karaf 2.3.6
> Thanks in advance!
> --
> View this message in context:
> Sent from the Camel - Users mailing list archive at

Claus Ibsen
Red Hat, Inc.
Twitter: davsclaus
Author of Camel in Action:

View raw message