Monday, July 25, 2016

foreach sample configuration in WSO2 ESB

foreach mediator helps you to iterate through a element array. For a example, if you need to iterate xml array and concatenate them together, bellow configuration read all the id and concatenate them.


 <foreach xmlns:ns1="http://ws.wso2.org/dataservice"  
          id="Idforeach"  
          expression="//ns1:Entries/ns1:Entry/ns1:id">  
       <sequence>  
        <property name="ID"  
             expression="fn:concat($ctx:ID,//ns1:id, ',')"  
             type="STRING"/>  
       </sequence>  
     </foreach>  
     <log level="custom">  
       <property name="IDs" expression="$ctx:ID"/>  
     </log>  
Ex: ESB will log "IDs = 105,106," for below request payload

 <Entries xmlns="http://ws.wso2.org/dataservice">  
 <Entry><id>105</id></Entry>  
 <Entry><id>106</id></Entry>  
 </Entries>



No comments:

Post a Comment