Luke Hamaty created CAMEL-7271:
----------------------------------

             Summary: AbstractListGroupedExchangeAggregationStrategy produces 
failed exchange if first received exchange fails
                 Key: CAMEL-7271
                 URL: https://issues.apache.org/jira/browse/CAMEL-7271
             Project: Camel
          Issue Type: Bug
          Components: camel-core
    Affects Versions: 2.12.2, 2.11.3
            Reporter: Luke Hamaty


If the first exchange received by a (concrete implementation of) 
AggregationStrategy  contains an exception, then the result of the aggregation 
will also contain that exception, and so will not continue routing without 
error. This makes the first received exchange have an effect that subsequent 
exchanges do not have.

The specific use case multicasts to GroupedExchangeAggregationStrategy. The 
MulticastProcessor.doDone function uses ExchangeHelper.copyResults to copy the 
aggregated result to the original exchange. The copyResults method copies the 
exception as well, thereby propagating the error.

 The attached unit test has 3 tests, testAFail, testBFail, and testAllGood. All 
three of these should pass, but testAFail does not.

What is happening is that AbstractListAggregationStrategy is directly storing 
its values on and returning the first exchange:
    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
        List<V> list;

        if (oldExchange == null) {
            list = getList(newExchange);
        } else {
            list = getList(oldExchange);
        }

        if (newExchange != null) {
            V value = getValue(newExchange);
            if (value != null) {
                list.add(value);
            }
        }

        return oldExchange != null ? oldExchange : newExchange;
    }

The pre-CAMEL-5579 version of GroupedExchangeAggregationStrategy created a 
fresh exchange to store and return the aggregated exchanges:
    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
        List<Exchange> list;
        Exchange answer = oldExchange;

        if (oldExchange == null) {
            answer = new DefaultExchange(newExchange);
            list = new ArrayList<Exchange>();
            answer.setProperty(Exchange.GROUPED_EXCHANGE, list);
        } else {
            list = oldExchange.getProperty(Exchange.GROUPED_EXCHANGE, 
List.class);
        }

        if (newExchange != null) {
            list.add(newExchange);
        }
        return answer;
    }




--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to