camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Why does ExchangeHelper.prepareAggregation modify the in body?
Date Wed, 02 Sep 2009 06:04:17 GMT
Use Exchange properties to preserve data!

On Wed, Sep 2, 2009 at 8:02 AM, snowbug<laji.inbox@gmail.com> 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: http://www.nabble.com/Why-does-ExchangeHelper.prepareAggregation-modify-the-in-body--tp25249162p25252082.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message