camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niels <>
Subject Safely copy exchange body
Date Wed, 04 Mar 2015 08:27:43 GMT
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

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 =
        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]

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

View raw message