title: WSO2 ESB : Aggregate node droppping message after aggregation
body: <p>I am implementing the Fan out -- Fan in splitter EIP inside a proxy , whereby :</p>
  
  <pre><code>                |-----&gt; shoe store-(1-M)-------------
  productSearchRq --                                     |--&gt;Rs
                  |-----&gt; ack clothes store-(0-1)------
  </code></pre>
  
  <p>Shoe store = Data service and Clothes store = Axis 2 service .</p>
  
  <p>So in short I implement the pattern above ; I clone the request , send it , get responses , format them using payloadFactory: </p>
  
  <pre><code>&lt;productDetails&gt;
     &lt;productID&gt;$1&lt;/productID&gt;
     &lt;productName&gt;$2&lt;/productName&gt;
     &lt;productSize&gt;$3&lt;/productSize&gt;
     &lt;productColour&gt;$4&lt;/productColour&gt;
     &lt;productType&gt;$5&lt;/productType&gt;
     &lt;sourceID&gt;$6&lt;/sourceID&gt;
  &lt;/productDetails&gt;
  </code></pre>
  
  <p>on both responses ( and iterate [//productDetails , iterate id = iT] on shoe products since it's one to many). Then in the following response handler , I try to aggregate all these productDetails. </p>
  
  <pre><code>&lt;sequence xmlns="http://ws.apache.org/ns/synapse" name="productSearchHandler"&gt;
     &lt;log level="custom"&gt;
        &lt;property name="pocSearchRsHandlerSeq reached" value="++++++++++++++=========Aggregating now========+++++++++++++++++=="&gt;&lt;/property&gt;
     &lt;/log&gt;
     &lt;aggregate id="iT"&gt;
        &lt;completeCondition&gt;
           &lt;messageCount min="-1" max="-1"&gt;&lt;/messageCount&gt;
        &lt;/completeCondition&gt;
        &lt;onComplete xmlns:ns="http://org.apache.synapse/xsd" expression="//productDetails"&gt;
           &lt;log level="custom" separator=","&gt;
              &lt;property name="::::" value="======================= Formatting the Aggregated Responses. ==============="&gt;&lt;/property&gt;
           &lt;/log&gt;
           &lt;log level="full"&gt;&lt;/log&gt;
        &lt;/onComplete&gt;
     &lt;/aggregate&gt;
     &lt;aggregate&gt;
        &lt;completeCondition&gt;
           &lt;messageCount min="-1" max="-1"&gt;&lt;/messageCount&gt;
        &lt;/completeCondition&gt;
        &lt;onComplete xmlns:ns="http://org.apache.synapse/xsd" expression="//productDetails"&gt;
           &lt;payloadFactory media-type="xml"&gt;
              &lt;format&gt;
                 &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prod="http://za.co.pepkor/product_service/"&gt;
                    &lt;soapenv:Body&gt;
                       &lt;prod:productSearchResp&gt; $1                                                                                                &lt;/prod:productSearchResp&gt;
                    &lt;/soapenv:Body&gt;
                 &lt;/soapenv:Envelope&gt;
              &lt;/format&gt;
              &lt;args&gt;
                 &lt;arg expression="//productDetails" evaluator="xml"&gt;&lt;/arg&gt;
              &lt;/args&gt;
           &lt;/payloadFactory&gt;
           &lt;switch source="get-property('CallType')"&gt;
              &lt;case regex="SOAP"&gt;
                 &lt;send&gt;&lt;/send&gt;
              &lt;/case&gt;
              &lt;case regex="REST"&gt;
                 &lt;property name="messageType" value="application/json" scope="axis2" type="STRING"&gt;&lt;/property&gt;
                 &lt;send&gt;&lt;/send&gt;
              &lt;/case&gt;
              &lt;default&gt;&lt;/default&gt;
           &lt;/switch&gt;
        &lt;/onComplete&gt;
     &lt;/aggregate&gt;
  &lt;/sequence&gt;
  </code></pre>
  
  <p>The filter's there to cater for the API implementation of this proxy. And I do need 2 aggregators because I use a clone AND iterator mediator. </p>
  
  <p>So I am wondering why before my second aggregator , the message is being "reset" to an empty soap message and therefore the 2nd agg fails to find //productDetails. See following log entries :</p>
  
  <p>After 1st agg which aggregates shoe prods:</p>
  
  <pre><code>TID: [0] [ESB] [2015-02-27 09:46:24,520] DEBUG {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Merging message : &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;soapenv:Body&gt;&lt;productDetails&gt;&lt;productID&gt;1124596&lt;/productID&gt;&lt;productName&gt;REEBOK_SNEAKERS&lt;/productName&gt;&lt;productSize&gt;7&lt;/productSize&gt;&lt;productColour&gt;BROWN&lt;/productColour&gt;&lt;productType&gt;SHOES&lt;/productType&gt;&lt;sourceID&gt;SHC&lt;/sourceID&gt;&lt;/productDetails&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt; using XPath : //productDetails {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}
  TID: [0] [ESB] [2015-02-27 09:46:24,522] DEBUG {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Merged result : &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;soapenv:Body&gt;&lt;productDetails&gt;&lt;productID&gt;1452168&lt;/productID&gt;&lt;productName&gt;PUMPS&lt;/productName&gt;&lt;productSize&gt;7&lt;/productSize&gt;&lt;productColour&gt;ORANGE&lt;/productColour&gt;&lt;productType&gt;SHOE&lt;/productType&gt;&lt;sourceID&gt;SHC&lt;/sourceID&gt;&lt;/productDetails&gt;&lt;productDetails&gt;&lt;productID&gt;1124596&lt;/productID&gt;&lt;productName&gt;REEBOK_SNEAKERS&lt;/productName&gt;&lt;productSize&gt;7&lt;/productSize&gt;&lt;productColour&gt;BROWN&lt;/productColour&gt;&lt;productType&gt;SHOES&lt;/productType&gt;&lt;sourceID&gt;SHC&lt;/sourceID&gt;&lt;/productDetails&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt; {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}
  TID: [0] [ESB] [2015-02-27 09:46:24,523] DEBUG {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Merging message : &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;soapenv:Body&gt;&lt;productDetails&gt;&lt;productID&gt;1123456&lt;/productID&gt;&lt;productName&gt;NIKE_SHIRTS&lt;/productName&gt;&lt;productSize&gt;7&lt;/productSize&gt;&lt;productColour&gt;RED&lt;/productColour&gt;&lt;productType&gt;SHIRT&lt;/productType&gt;&lt;sourceID&gt;SHC&lt;/sourceID&gt;&lt;/productDetails&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt; using XPath : //productDetails {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}
  TID: [0] [ESB] [2015-02-27 09:46:24,525] DEBUG {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Merged result : &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;soapenv:Body&gt;&lt;productDetails&gt;&lt;productID&gt;1452168&lt;/productID&gt;&lt;productName&gt;PUMPS&lt;/productName&gt;&lt;productSize&gt;7&lt;/productSize&gt;&lt;productColour&gt;ORANGE&lt;/productColour&gt;&lt;productType&gt;SHOE&lt;/productType&gt;&lt;sourceID&gt;SHC&lt;/sourceID&gt;&lt;/productDetails&gt;&lt;productDetails&gt;&lt;productID&gt;1124596&lt;/productID&gt;&lt;productName&gt;REEBOK_SNEAKERS&lt;/productName&gt;&lt;productSize&gt;7&lt;/productSize&gt;&lt;productColour&gt;BROWN&lt;/productColour&gt;&lt;productType&gt;SHOES&lt;/productType&gt;&lt;sourceID&gt;SHC&lt;/sourceID&gt;&lt;/productDetails&gt;&lt;productDetails&gt;&lt;productID&gt;1123456&lt;/productID&gt;&lt;productName&gt;NIKE_SHIRTS&lt;/productName&gt;&lt;productSize&gt;7&lt;/productSize&gt;&lt;productColour&gt;RED&lt;/productColour&gt;&lt;productType&gt;SHIRT&lt;/productType&gt;&lt;sourceID&gt;SHC&lt;/sourceID&gt;&lt;/productDetails&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt; {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}
  </code></pre>
  
  <p>Then as we are going into 2nd agg :</p>
  
  <pre><code>TID: [0] [ESB] [2015-02-27 09:46:24,545] DEBUG {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Generating Aggregated message from : &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;soapenv:Body&gt;&lt;productDetails&gt;&lt;noItemFound&gt;No item in Ackerman's&lt;/noItemFound&gt;&lt;/productDetails&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt; {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}
  TID: [0] [ESB] [2015-02-27 09:46:24,547] DEBUG {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Merging message : &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;soapenv:Body&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt; using XPath : //productDetails {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}
  TID: [0] [ESB] [2015-02-27 09:46:24,550] ERROR {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Error evaluating expression: //productDetails {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}
  </code></pre>
  
  <p>What I want is to merge </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;soapenv:Body&gt;&lt;productDetails&gt;&lt;productID&gt;1452168&lt;/productID&gt;&lt;productName&gt;PUMPS&lt;/productName&gt;&lt;productSize&gt;7&lt;/productSize&gt;&lt;productColour&gt;ORANGE&lt;/productColour&gt;&lt;productType&gt;SHOE&lt;/productType&gt;&lt;sourceID&gt;SHC&lt;/sourceID&gt;&lt;/productDetails&gt;&lt;productDetails&gt;&lt;productID&gt;1124596&lt;/productID&gt;&lt;productName&gt;REEBOK_SNEAKERS&lt;/productName&gt;&lt;productSize&gt;7&lt;/productSize&gt;&lt;productColour&gt;BROWN&lt;/productColour&gt;&lt;productType&gt;SHOES&lt;/productType&gt;&lt;sourceID&gt;SHC&lt;/sourceID&gt;&lt;/productDetails&gt;&lt;productDetails&gt;&lt;productID&gt;1123456&lt;/productID&gt;&lt;productName&gt;NIKE_SHIRTS&lt;/productName&gt;&lt;productSize&gt;7&lt;/productSize&gt;&lt;productColour&gt;RED&lt;/productColour&gt;&lt;productType&gt;SHIRT&lt;/productType&gt;&lt;sourceID&gt;SHC&lt;/sourceID&gt;&lt;/productDetails&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>with </p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;soapenv:Body&gt;&lt;productDetails&gt;&lt;noItemFound&gt;No item in Ackerman's&lt;/noItemFound&gt;&lt;/productDetails&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt;
  </code></pre>