camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snowbug <laji.in...@gmail.com>
Subject Why does ExchangeHelper.prepareAggregation modify the in body?
Date Tue, 01 Sep 2009 23:25:25 GMT

When doing aggregation, this code is executed before the actual aggregation:
    /**
     * Prepares the exchanges for aggregation.
     * <p/>
     * This implementation will copy the OUT body to the IN body so when you
do
     * aggregation the body is only in the IN body to avoid confusing end
users.
     *
     * @param oldExchange  the old exchange
     * @param newExchange  the new exchange
     */
    public static void prepareAggregation(Exchange oldExchange, Exchange
newExchange) {
        // copy body/header from OUT to IN
        if (oldExchange != null) {
            if (oldExchange.hasOut()) {
                oldExchange.getIn().copyFrom(oldExchange.getOut());
                oldExchange.setOut(null);
            }
        }

        if (newExchange != null) {
            if (newExchange.hasOut()) {
                newExchange.getIn().copyFrom(newExchange.getOut());
                newExchange.setOut(null);
            }
        }
    }


I have hard time to understand why the IN is overwritten automatically. IN
is the message that comes in and should only be overwritten if I choose to
based on my business logic, not have the framework code to assume this
behavior. 

To make the matter worse, the DefaultExchange.getOut() will automatically
create an empty Message when it is invoked. In other words, if
DefaultExchange.getOut() is called somewhere either in your code or Camel's
code, the OUT message is automatically created, and the hasOut() method will
then be true, and this default empty OUT message is then automatically
copied to the IN. 

If there is a compelling reason shows this behavior is absolutely necessary,
I'd like to create a bug ticket to have it fixed.

Thanks,
-- 
View this message in context: http://www.nabble.com/Why-does-ExchangeHelper.prepareAggregation-modify-the-in-body--tp25249162p25249162.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message