Sunday, February 21, 2016

WSO2 ESB Iterate mediator sample

Following is a small API using WSO2 ESB iterate mediator.

<api xmlns="http://ws.apache.org/ns/synapse" name="simpleIterator" context="/simpleIterator">
   <resource methods="POST">
      <inSequence>
         <property name="root_element">
            <responses/>
         </property>
         <iterate expression="//symbols/symbol" sequential="true">
            <target>
               <sequence>
                  <property name="messageType" value="application/xml" scope="axis2"/>
                  <send>
                     <endpoint>
                        <http method="POST" uri-template="http://localhost:8080/sample-responses/simpleQuote"/>
                     </endpoint>
                  </send>
               </sequence>
            </target>
         </iterate>
      </inSequence>
      <outSequence>
         <aggregate>
            <completeCondition>
               <messageCount min="-1" max="-1"/>
            </completeCondition>
            <onComplete expression="//response" enclosingElementProperty="root_element">
               <log level="full"/>
               <respond/>
            </onComplete>
         </aggregate>
      </outSequence>
   </resource>
</api>
                        

sample (curl) request :

curl -d @symbols.xml -H "Content-Type: application/xml"  http://localhost:8280/simpleIterator -v 

symbols.xml
<symbols>
   <symbol>WSO2</symbol>
   <symbol>MSFT</symbol>
   <symbol>IBM</symbol>
   <symbol>ADBE</symbol>
   <symbol>AAPL</symbol>
   <symbol>ORCL</symbol>
   <symbol>RHT</symbol>
   <symbol>FB</symbol>
   <symbol>TWTR</symbol>
   <symbol>LNKD</symbol>
</symbols>

Sample backend can be found here.