camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snowbug <>
Subject Re: Why does ExchangeHelper.prepareAggregation modify the in body?
Date Wed, 02 Sep 2009 16:50:29 GMT

In the splitter, I was setting the exchange property to preserve the data
(see my posted code), but it is not working and I believe it's because the
exchange passed into the splitter is a copy, not the actual. I dumped the
object identity of the exchange objects passed into my splitter and my next
processor and they are different object.

What this mean is that the in the splitter, there is no way to set the
exchange property and preserve it. I think this could be revised to pass in
the original exchange instead of a copy, but of course, I don't know the
reason to use a copy in the first place.

Claus Ibsen-2 wrote:
> Use Exchange properties to preserve data!
> On Wed, Sep 2, 2009 at 8:02 AM, snowbug<> wrote:
>> Thanks for the explanation, it makes sense, especially for the pipeline
>> pattern.
>> Based on your recommendation, looking into setting the exchange property
>> for
>> storing information that I'd like to persist, I encountered some problem.
>> In
>> my splitter bean, the split method looks like this (modified for this
>> post
>> to make the discussion easier):
>>    @Handler
>>    public List<MyMessage> split(Exchange exchange) throws Exception {
>>        MyMessage msg = (MyMessage) exchange.getIn().getBody();
>>        exchange.setProperty("myheader", msg.getHeader());
>>        List<MyMessage> splitted = new ArrayList<MyMessage>();
>>        for (int i=0; i<5; i++) {
>>            // create a new message
>>            MyMessage part = messageUtil.newMsg(msg);
>>            part.getBody().setId(i);
>>            splitted.add(part);
>>        }
>>        return splitted;
>>    }
>> What I found is that the property I set "myheader" is not preserved in
>> the
>> next endpoint where the splitted method is processed. It seems that the
>> splitter used a copy of the exchange when invoking this method, thus any
>> header I set to the exchange is lost when the copy is discarded.
>> So any workaround for me to preserve some information? What I can think
>> of
>> is to add a bean processing after the previous step to create the
>> "myheader"
>> property before hitting split (haven't tried but should work), but I'd
>> like
>> to know if there is any easier approach, or if I am doing anything wrong
>> -
>> I'm quite new to Camel.
>> BTW, I think it's shouldn't be rare to have the need to preserve the
>> original message during the processing of generating the response. One
>> often
>> need to correlate the response with the original message.
>> Thanks, Alan
>> --
>> View this message in context:
>> Sent from the Camel - Users mailing list archive at
> -- 
> Claus Ibsen
> Apache Camel Committer
> Open Source Integration:
> Blog:
> Twitter:

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message