Details
-
Documentation
-
Resolution: Done
-
Minor
-
2.5.0-fuse-00-00, 2.6.0-fuse-00-00
-
None
Description
Fintan there is a minor issue in the aggregator docu at
http://fusesource.com/docs/router/2.5/eip/MsgRout-Aggregator.html
In the code
public class MyAggregationStrategy implements AggregationStrategy { public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { String oldBody = oldExchange.getIn().getBody(String.class); String newBody = newExchange.getIn().getBody(String.class); String concatBody = oldBody.concat(newBody); // Concatenate old and new. oldExchange.getIn().setBody(concatBody); // Ignore the message headers! // (in a real application, you would probably do // something more sophisticated here). return oldExchange; } }
You should check that oldExchange is null.
So it should be
public class MyAggregationStrategy implements AggregationStrategy { public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { if (oldExchange == null) { // first time, the oldExchange is null, so just return newExchange as nothing to merge return newExchange; } String oldBody = oldExchange.getIn().getBody(String.class); String newBody = newExchange.getIn().getBody(String.class); String concatBody = oldBody.concat(newBody); // Concatenate old and new. oldExchange.getIn().setBody(concatBody); // Ignore the message headers! // (in a real application, you would probably do // something more sophisticated here). return oldExchange; } }