Hello,
I try to use dynamic endpoint uri with recipientList and then combine old
body with the new one, to enrich the message However in
AggregationStrategy.aggregate method the
oldExchange is null.
I suppose recipientList clears the old body. Is there a way to combine two
exchanges after recipientList? The test throwing
IllegalArgumentException("oldExchange is null"):
package com.mycompany.cameltest;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.processor.aggregate.AggregationStrategy;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
public class MyRouteBuilderTest extends CamelTestSupport {
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.recipientList(simple("${body.url}"))
.aggregationStrategy(new AggregationStrategy() {
@Override
public Exchange aggregate(Exchange oldExchange,
Exchange newExchange) {
if (oldExchange == null) {
throw new
IllegalArgumentException("oldExchange is null");
}
String newBody =
newExchange.getIn().getBody(String.class);
PojoObject pojo =
oldExchange.getIn().getBody(PojoObject.class);
pojo.setResult(newBody);
newExchange.getIn().setBody(pojo);
return newExchange;
}
});
}
};
}
@Test
public void testConfigure() {
context.setTracing(Boolean.TRUE);
PojoObject pojo = new PojoObject();
pojo.setUrl("mock:http");
template.sendBody("direct:start", pojo);
}
public class PojoObject {
private String url = "http://foo";
private Object result;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Object getResult() {
return result;
}
public void setResult(Object result) {
this.result = result;
}
@Override
public String toString() {
return "PojoBody{" + "url=" + url + '}';
}
}
}
--
View this message in context:
http://camel.465427.n5.nabble.com/How-to-enrich-with-recipient-list-tp5749644.html
Sent from the Camel - Users mailing list archive at Nabble.com.