title: Apache Camel merge two files from different routes
body: <p>Here's what I am trying to do. I have to read two files that has this content</p>
  
  <pre><code>&lt;Person&gt;
  &lt;Requestor&gt;Dinesh&lt;/Requestor&gt;
  &lt;/Person&gt;
  </code></pre>
  
  <p>To do this I created a route</p>
  
  <pre><code>&lt;route id="getPerson"&gt;
      &lt;from uri="file:src/main/resources/xml?noop=true"/&gt;
      &lt;/route&gt;
  </code></pre>
  
  <p>Next I need to read another file called Address</p>
  
  <pre><code>&lt;Address&gt;
    &lt;City&gt;New York &lt;/City&gt;
  &lt;/Address&gt;
  </code></pre>
  
  <p>Here is my second route</p>
  
  <pre><code>&lt;route id="getAddress"&gt;
      &lt;from uri="file:src/main/resources/xmlAddress?noop=true"/&gt;
      &lt;/route&gt;
  </code></pre>
  
  <p>How do I merge these two xmls into one Using Enricher or Aggregate to make the final xml message look like this</p>
  
  <pre><code>&lt;Person&gt;
    &lt;Requestor&gt;Dinesh&lt;/Requestor&gt;
    &lt;Address&gt;
       &lt;City&gt;New York&lt;/City&gt;
    &lt;/Address&gt;
  &lt;/Person&gt;
  </code></pre>
  
  <p>Any ideas? I tried following the documentation but all it says is send to some web service uri.</p>
  
  <p>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</p>
  
  <p><strong>EDIT 1:</strong> I can write the custom AggregatorStartegy class. I wrote something like this</p>
  
  <pre><code>public class AggregationStrategy implements org.apache.camel.processor.aggregate.AggregationStrategy{
  
  @Override
  public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
      newExchange.getOut().setBody("&lt;all&gt;" 
                + oldExchange.getIn().getBody(String.class) 
                + newExchange.getIn().getBody(String.class) 
                + "&lt;/all&gt;");
              return newExchange;
  }
  
     }
  </code></pre>
  
  <p>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</p>
  
  <pre><code>&lt;camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring"&gt;
  &lt;route&gt;
      &lt;from uri="file:src/main/resources/xmlPerson?noop=true"/&gt;
  
      &lt;camel:to uri="direct:enrichMessage"&gt;&lt;/camel:to&gt;
  &lt;/route&gt; 
  &lt;route  &gt;
      &lt;from uri="file:src/main/resources/xmlAddress?noop=true"/&gt; 
      &lt;log message="**************RESPONSE FROM CATASK DSS:: \n ${body}" id="log_output"/&gt;
      &lt;camel:to uri="direct:enrichMessage"&gt;&lt;/camel:to&gt; 
  
  &lt;/route&gt;
   &lt;route id="enrichMessage"&gt;
      &lt;from uri="direct:enrichMessage"/&gt;
      &lt;camel:enrich strategyRef="aggregationBean" /&gt;
      &lt;log message="**************MERGED RESPONSE :: \n ${body}"/&gt;
  &lt;/route&gt;
  </code></pre>
  
  <p></p>