Reputation: 5602
I have a large XML message read from queue, I need to split it in chunks and convert it into objects and then route them to various destinations based on the object.
So I have configured the routeBuilder to
ChoiceDefinition choice = from(routeConfig.getFromEndpoint())
.split().method(xmlSplitter, "splitMessage").streaming().process(xmlProcessor).choice();
for (RouteConfig filter : filters) {
choice = choice.when(header(REPORT_TYPE_HEADER_NAME).contains(filter.getReportTypeHeaderFilter()))
.to(filter.getToEndpoint());
}
choice.otherwise().to(routeConfig.getErrorEndpoint());
But the routing is not happening at all, All messages are sent to the errorEndpoint. I found the reason to be the splitter deleting the header, as its ahead of the routing.
It seems I cannot use splitting after routing.
What is the solution to solve this problem?
Upvotes: 0
Views: 6471
Reputation: 21005
split() shouldn't remove the headers...are you sure your xmlSplitter/xmlProcessor aren't causing issues?
here is a simple example to show that the headers are preserved...
@EndpointInject(uri = "mock:mock")
protected MockEndpoint mock;
@Test
public void test() throws Exception {
mock.expectedMessageCount(2);
mock.expectedHeaderReceived("foo","bar");
template.sendBodyAndHeader("direct:start", "msg1,msg2", "foo", "bar");
assertMockEndpointsSatisfied();
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.to("log:+++before+++?showHeaders=true")
.split().method(MySplitterBean.class, "splitBody").streaming()
.to("log:+++after+++?showHeaders=true")
.choice().when(header("foo").contains("bar"))
.to("mock:mock")
.otherwise()
.to("mock:error");
}
};
}
public static class MySplitterBean {
public List<String> splitBody(String body) {
List<String> answer = new ArrayList<String>();
String[] parts = body.split(",");
for (String part : parts) {
answer.add(part);
}
return answer;
}
}
Upvotes: 1