Here's what I am trying to do. I have to read two files that has this content
<Person>
<Requestor>Dinesh</Requestor>
</Person>
To do this I created a route
<route id="getPerson">
<from uri="file:src/main/resources/xml?noop=true"/>
</route>
Next I need to read another file called Address
<Address>
<City>New York </City>
</Address>
Here is my second route
<route id="getAddress">
<from uri="file:src/main/resources/xmlAddress?noop=true"/>
</route>
How do I merge these two xmls into one Using Enricher or Aggregate to make the final xml message look like this
<Person>
<Requestor>Dinesh</Requestor>
<Address>
<City>New York</City>
</Address>
</Person>
Any ideas? I tried following the documentation but all it says is send to some web service uri.
The above scenario is toned down version of what I actually want to do. The real life situation for me is to do this- Step 1. Read an xml file, Step 2: Call a web service and get the response. Step 3: Merge Response in Step 2 and add it o Xml body in Step 1
EDIT 1: I can write the custom AggregatorStartegy class. I wrote something like this
public class AggregationStrategy implements org.apache.camel.processor.aggregate.AggregationStrategy{
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
newExchange.getOut().setBody("<all>"
+ oldExchange.getIn().getBody(String.class)
+ newExchange.getIn().getBody(String.class)
+ "</all>");
return newExchange;
}
}
What I am struggling with is how to write write the Spring xml where I can tell here is my message or file 1+ message or file 2, go join them. Here's how my actual context.xml looks like
<camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:src/main/resources/xmlPerson?noop=true"/>
<camel:to uri="direct:enrichMessage"></camel:to>
</route>
<route >
<from uri="file:src/main/resources/xmlAddress?noop=true"/>
<log message="**************RESPONSE FROM CATASK DSS:: \n ${body}" id="log_output"/>
<camel:to uri="direct:enrichMessage"></camel:to>
</route>
<route id="enrichMessage">
<from uri="direct:enrichMessage"/>
<camel:enrich strategyRef="aggregationBean" />
<log message="**************MERGED RESPONSE :: \n ${body}"/>
</route>