Hi All, how to aggregate multiple unmarshalled objects , please check my
code.
DataFormat bindyForInsert = new BindyCsvDataFormat(User0001.class);
DataFormat bindyForDelete = new BindyCsvDataFormat(User0002.class);
DataFormat bindyForUpdate = new BindyCsvDataFormat(User0003.class);
from("file:{{filepath}}?noop=true")
split(body().tokenize("\n"))
.streaming()
.when().body().startsWith("0001")).to("file:{{file_path}}?fileName={{insertfilename}}.ascii").unmarshal(bindyForInsert)
.when().body().startsWith("0002")).to("file:{{file_path}}?fileName={{defilename}}.ascii").unmarshal(bindyForDelete
)
.when().body().startsWith("0002")).to("file:{{file_path}}?fileName={{upfilename}}.ascii").unmarshal(bindyForUpdate)
.aggregate(constant(true), getFileAggregationStrategy()).end();
The below aggregation logic only gives the last unmarshall object
response(bindyForUpdate), I need all unmarshalled Objects in Exchange.
public Exchange aggregate(Exchange oldEx, Exchange newEx) {
Message newIn = newEx.getIn();
Object newBody = (Object)newEx.getIn().getBody();
List list = null;
if (oldEx == null) {
list = new ArrayList();
list.add(newBody);
newIn.setBody(list);
return newEx;
} else {
Message in = oldEx.getIn();
list = in.getBody(ArrayList.class);
list.add(newBody);
return oldEx;
}
}
--
View this message in context:
http://camel.465427.n5.nabble.com/how-to-aggregate-multiple-unmarshalled-objects-tp5795209.html
Sent from the Camel - Users mailing list archive at Nabble.com.