Wednesday 18 May 2016

Creating an array of XML element in BPEL

The objective of this post is to generate an XML response which has array of XML element using BPEL.

Problem Statement:

Input to the BPEL process : n / integer
Output from BPEL process : result / String array of length n

Solution:

To solve this problem, we can use <bpelx:append>  which is an BPEL extension function

namespace for bplex is xmlns:bpelx="http://schemas.oracle.com/bpel/extension"

Below is the code snippet where it inserts a node using bpelx:append

<bpel:assign name="InsertResponse">
  <bpelx:append>
    <bpelx:from>

        <result xmlns="http://xmlns.oracle.com/HelloWorlsApp/ArrayOutput/Collection">StringTest
        </result>
    </bpelx:from>
    <bpelx:to bpelx:language="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0" variable="outputVariable" part="payload" query="/client:processResponse"/>
   </bpelx:append>      
 </bpel:assign>


This assignment we can keep it inside a <bpel:while> with a condition like index should be less than the input n.


Sample Input

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
     <ns1:process xmlns:ns1="http://xmlns.oracle.com/HelloWorlsApp/ArrayOutput/Collection">
      <ns1:input>3</ns1:input>
       </ns1:process>
    </soap:Body>
</soap:Envelope>


Sample Output

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
  <env:Body>
<processResponse xmlns="http://xmlns.oracle.com/HelloWorlsApp/ArrayOutput/Collection">
<result>StringTest</result>
<result>StringTest</result>
<result>StringTest</result>
</processResponse>
  </env:Body>
</env:Envelope>


No comments:

Post a Comment