Monday, May 26, 2014

Set & Send SOAP Headers in BPEL

Recently, I am supposed to call a external web service and it require few values in SOAP header to validate the request message. I did following changes in my BPEL process to set & send SOAP headers in request message.

Request Message Format:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header>
<ns2:UsernameToken xmlns:ns2="http://siebel.com">LK@XYZ.COM</ns2:UsernameToken>
<ns3:PasswordText xmlns:ns3="http://siebel.com">Test123</ns3:PasswordText>
   </soapenv:Header>
   <soapenv:Body>
      <..........................SOAP BODY..............>
   </soapenv:Body>
</soapenv:Envelope>

I followed below steps to set these headers in BPEL.

  • Created a XSD having required headers as elements in schema. For ex:

            <?xml version="1.0" encoding="UTF-8" ?>
           <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                               xmlns:ns2="http://siebel.com"
                               targetNamespace="http://siebel.com"
                               elementFormDefault="qualified">
              <xsd:element name="UsernameToken" type="xsd:string"/>
              <xsd:element name="PasswordText" type="xsd:string"/>
           </xsd:schema>

  • In BPEL process created a two variables based on above schema to hold header values.

           <variable name="UsernameToken" element="ns2:UsernameToken"/>
           <variable name="PasswordText" element="ns2:PasswordText"/>

  • Assigned values for these variables using assign activity.

         <assign name="AssignInput">
            <copy>
                <from expression="'LK@XYZ.COM'"/>
                <to variable="UsernameToken" query="/ns2:UsernameToken"/>
           </copy>
           <copy>
               <from expression="'Test123'"/>
               <to variable="PasswordText" query="/ns2:PasswordText"/>
             </copy>
          </assign>

  • Set these variables as Headers in Invoke activity. The Invoke activity looks as below, after adding headers.

          <invoke name="InvokeWS"
            inputVariable="WS_InputVariable"
            outputVariable="WS_OutputVariable" partnerLink="TestWebService"
            portType="ns1:AutoRequest" operation="process"
            bpelx:invokeAsDetail="no"
            bpelx:inputHeaderVariable="UsernameToken,PasswordText"/>


No comments:

Post a Comment

Provide your thoughts !