I am building a BPEL process in Netbeans 6.8 and I invoke a Web Service that returns a list of ints.
<xs:complexType name="getHotelsResponse">
<xs:sequence>
<xs:element name="return" type="xs:int" minOccurs="0" maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:complexType>
I want (if possible - not sure anymore...) to iterate through all those ints and invoke a different Web Service for each one of them.
I tried using a ForEach activity, but I can't figure out the usage for my case. It requires a Start Value and an End Value (if I could somehow get how many ints I got back) but even then inside the ForEach activity if say I put an Assign activity how do I get the current element of the list in each loop?
I used following BPEL snippet to concat the content of a list in to a comma separated string. You can use the same code with an invoke to call external service.
<bpel:forEach parallel="no" counterName="Counter" name="ForEach">
<bpel:startCounterValue>
<![CDATA[1]]>
</bpel:startCounterValue>
<bpel:finalCounterValue><![CDATA[count($input.payload/tns:return)]]></bpel:finalCounterValue>
<bpel:scope>
<bpel:assign validate="no" name="AppendItem">
<bpel:copy>
<bpel:from>
<![CDATA[concat($Response, $input.payload/tns:return[round($Counter)], ", ")]]>
</bpel:from>
<bpel:to variable="Response"></bpel:to>
</bpel:copy>
</bpel:assign>
</bpel:scope>
</bpel:forEach>
You can get the count of elements from the following XPath
count($input.payload/tns:return)
You can access value of the i th element using the following XPath
$input.payload/tns:return[round($Counter)]
You may get rid of the round() function, but I had to use to get rid of an issue in Apache ODE.