Wednesday, April 13, 2011

Manipulating SOAP headers in a BPEL process


Manipulating SOAP headers in a BPEL process

If someone is using a Soap Request and the header in that is propriety to the client or the server.Than the BPEL process may require to send and receive an particular SOAP Header in the Request and Receive that particular Header in Reply and Response. Here we will try to explore the way to do it in 10g version. As enunciated by the oracle the 10g version by default it doesn’t have an out-of-box solution for SOAP header communication so instead what they have done is they have provided an extension for the same with  “bpelx:headerVariable” . Now where to use this and what are the steps needed to do the same are covered in the below article.
Steps to create and use a SOAP HEADER in the BPEL process:
  1. Import the XSD structure for the propriety SOAP Header.
  2. Import/Include the same into the XSD of the WSDL of the BPEL Process.
  3. Create a message type in the WSDL for the same variable.
  4. Create SOAP binding for the same.
  5. Update the Partner link receiving or invoking an operation with propriety Soap Header.
  6. Create a variable for the SOAP Header (eventually in which you will receive the SOAP Header)
  7. Use this variable with “bpelx:headerVariable” in the activities you want to deal with soap header.
  1. <invoke bpelx:inputHeaderVariable="inHeader1 inHeader2 ..." bpelx:outputHeaderVariable="outHeader1 outHeader2 ..."  .../>
  2. <receive bpelx:headerVariable="inHeader1 inHeader2 ..." .../>
  3. <onMessage bpelx:headerVariable="inHeader1 inHeader2 ..." .../>
  4. <reply bpelx:headerVariable="inHeader1 inHeader2 ..." .../>
Different activities and the addition of the Soap header.
Voila!!! You are done.
The variable you created is present as any other variable in a bpel process. Now you can create n no. of variables and copy, forward or receive the SOAP headers in BPEL.
*Some points :
* The BPEL test console does not generate the header in the input xml, you can go to the process >invoke>XML Source and manually add the tags and the data in the xml for the header(I suspect because bpel 10g  doesn’t have default communication activities for SOAP header  that’s why the header is not created in the BPELConsole )
* Alternatively you can go to the URI and run it in the browser there the input header is generated  
These above steps are very easy and a seasoned soa practitioner can easily finish the above steps. Anyways I will create one project and add the screenshots to support the above steps. So below what follows is the step by step process to handle the soap headers in a BPEL process which out of box doesn’t have the necessary communication activities for SOAP header processing.
DETAILED STEPS FOR ADDING SOAP HEADER IN THE BPEL PROCESS:
STEP 1: Import the XSD structure for the propriety SOAP Header.
So here I have a newly created BPEL synch process which currently has nothing to do with the soap headers it may receive or send.
So I  created the XSD with the SOAPHeader element.
STEP 2 & 3: Import/Include the same into the XSD of the WSDL of the BPEL Process.
/Create a message type in the WSDL for the same variable.
Now we need to import/include the same into the WSDL of the BPEL process we want to add the SOAP header communication.
Here we have imported the XSD into the WSDL file and created a message type which we will be binding with the SOAP call.
STEP 4: Create SOAP binding for the same.
This is the important step here we need to bind the particular message to the SOAP protocol in the WSDL. If it already exists in your project than edit it to include the highlighted lines (where the binding for the input and output will be already present) otherwise add the Binding to the particular WSDL
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Binding DEFINITION -SOAP Binding of the SOAP Header with the port types
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
       <binding name="SoapBindingWithHeader" type="client: BPDemoWithSOAPHeader ">
       <soap:binding style="document"
                     transport="http://schemas.xmlsoap.org/soap/http"/>
       <operation name="process">
           <soap:operation soapAction="process"/>
           <input>
               <soap:header message="client:BPDemoSoapHeader"
                            part="SoapHead" use="literal"/>
               <soap:body use="literal" parts="payload"/>
           </input>
           <output>
               <soap:header message="client:BPDemoSoapHeader"
                            part="Header" use="literal"/>
               <soap:body  use="literal" parts="payload"/>
           </output>
       </operation>
   </binding>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
END
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
It will show up in the design view:
So now you are able to see the soap header in the binding and its ready to be recioeved by the BPEL process so the next steps are to create a variable to receive the header in the BPEL flow and send it back in a synch call.
         * Remember to add  xmlns:soap=”http://schemas.xmlsoap.org/wsdl/soap/"  the namespace definition if its not already added to the wsdl.
STEP 5: Update the Partner link receiving or invoking an operation with propriety Soap Header.
Refresh it and update the WSDL in the partner link
STEP 6: Create a variable for the SOAP Header (eventually in which you will receive the SOAP Header)
STEP 7: Use this variable with “bpelx:headerVariable” in the activities you want to deal with soap header.
Format for all the activities which may require sending or receiving the SOAP Header.
  1. <invoke bpelx:inputHeaderVariable="inHeader1 inHeader2 ..." bpelx:outputHeaderVariable="outHeader1 outHeader2 ..."  .../>
  2. <receive bpelx:headerVariable="inHeader1 inHeader2 ..." .../>
  3. <onMessage bpelx:headerVariable="inHeader1 inHeader2 ..." .../>
  4. <reply bpelx:headerVariable="inHeader1 inHeader2 ..." .../>
Now we have added the Headers and particular BPEL attributes in the receive/reply/invoke/pick activity we can deploy the process on the SOA domain and see the results.
Get the URI of the Deployed BPEL Process and open in the browser:
Sending request with soap header
Receiving the response from the BPEL with soap header.
Or you can go to soap UI and Run the same:
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "HTTP/1.1 200 OK[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "HTTP/1.1 200 OK[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "Date: Tue, 12 Apr 2011 15:34:32 GMT[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "Server: Oracle-Application-Server-10g/10.1.3.5.0 Oracle-HTTP-Server[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "Content-Length: 1890[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "Content-Type: text/xml; charset=UTF-8[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "            xmlns="http://www.example.org"[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "            targetNamespace="http://xmlns.oracle.com/BPDemoWithSOAPHeader"[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "            elementFormDefault="qualified">[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "    <xsd:element name="SOAPHeader">[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "        <xsd:complexType>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "            <xsd:sequence>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                <xsd:element name="HeaderType">[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                    <xsd:complexType>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                        <xsd:sequence>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                            <xsd:element name="RequestType" type="xsd:string"[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                                         minOccurs="0" maxOccurs="1"/>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                            <xsd:element name="RequestTimeStamp"[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                                         type="xsd:dateTime" minOccurs="0"[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                                         maxOccurs="1"/>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                            <xsd:element name="MessageID" type="xsd:string"[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                                         minOccurs="0" maxOccurs="1"/>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                            <xsd:element name="ChannelID" type="xsd:string"[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                                         minOccurs="0" maxOccurs="1"/>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                            <xsd:element name="ChannelType" type="xsd:string"[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                                         minOccurs="0" maxOccurs="1"/>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                            <xsd:element name="UserID" type="xsd:string"[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                                         minOccurs="0" maxOccurs="1"/>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                            <xsd:element name="Sender" type="xsd:string"[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                                         minOccurs="0" maxOccurs="1"/>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                            <xsd:element name="Reciever" type="xsd:string"[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                                         minOccurs="0" maxOccurs="1"/>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                        </xsd:sequence>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                    </xsd:complexType>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "                </xsd:element>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "            </xsd:sequence>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "        </xsd:complexType>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "    </xsd:element>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "</xsd:schema>[\r][\n]"
Tue Apr 12 21:07:51 IST 2011:DEBUG:<< "[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "POST /orabpel/mnp_domain/BPDemoWithSOAPHeader/1.0 HTTP/1.1[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "Accept-Encoding: gzip,deflate[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "Content-Type: text/xml;charset=UTF-8[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "SOAPAction: "process"[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "Host: D-113028954[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "Content-Length: 1172[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bpd="http://xmlns.oracle.com/BPDemoWithSOAPHeader">[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "   <soapenv:Header>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "      <bpd:SOAPHeader>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "         <bpd:HeaderType>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <!--Optional:-->[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <bpd:RequestType>AIX</bpd:RequestType>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <!--Optional:-->[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <bpd:RequestTimeStamp>2011-01-14T19:32:15.000+05:30</bpd:RequestTimeStamp>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <!--Optional:-->[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <bpd:MessageID>CRM-ZMR-123</bpd:MessageID>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <!--Optional:-->[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <bpd:ChannelID>CRM</bpd:ChannelID>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <!--Optional:-->[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <bpd:ChannelType>CRMUI</bpd:ChannelType>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <!--Optional:-->[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <bpd:UserID>AIXUSER</bpd:UserID>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <!--Optional:-->[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <bpd:Sender>CRM</bpd:Sender>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <!--Optional:-->[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "            <bpd:Reciever>INV</bpd:Reciever>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "         </bpd:HeaderType>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "      </bpd:SOAPHeader>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "   </soapenv:Header>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "   <soapenv:Body>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "      <bpd:BPDemoWithSOAPHeaderProcessRequest>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "         <bpd:input>Sending Recieving SOAP Header</bpd:input>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "      </bpd:BPDemoWithSOAPHeaderProcessRequest>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "   </soapenv:Body>[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:>> "</soapenv:Envelope>"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "HTTP/1.1 200 OK[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "HTTP/1.1 200 OK[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "Date: Tue, 12 Apr 2011 15:37:01 GMT[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "Server: Oracle-Application-Server-10g/10.1.3.5.0 Oracle-HTTP-Server[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "Content-Length: 1109[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "SOAPAction: ""[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "Content-Type: text/xml; charset=UTF-8[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "[\r][\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header><bpd:SOAPHeader xmlns:bpd="http://xmlns.oracle.com/BPDemoWithSOAPHeader">[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "         <bpd:HeaderType>[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <!--Optional:-->[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <bpd:RequestType>AIX</bpd:RequestType>[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <!--Optional:-->[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <bpd:RequestTimeStamp>2011-01-14T19:32:15.000+05:30</bpd:RequestTimeStamp>[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <!--Optional:-->[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <bpd:MessageID>CRM-ZMR-123</bpd:MessageID>[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <!--Optional:-->[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <bpd:ChannelID>CRM</bpd:ChannelID>[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <!--Optional:-->[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <bpd:ChannelType>CRMUI</bpd:ChannelType>[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <!--Optional:-->[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <bpd:UserID>AIXUSER</bpd:UserID>[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <!--Optional:-->[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <bpd:Sender>CRM</bpd:Sender>[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <!--Optional:-->[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "            <bpd:Reciever>INV</bpd:Reciever>[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "         </bpd:HeaderType>[\n]"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "      </bpd:SOAPHeader></env:Header><env:Body><BPDemoWithSOAPHeaderProcessResponse xmlns="http://xmlns.oracle.com/BPDemoWithSOAPHeader"><"
Tue Apr 12 21:10:19 IST 2011:DEBUG:<< "result>Sending Recieving SOAP Header</result></BPDemoWithSOAPHeaderProcessResponse></env:Body></env:Envelope>"

And run the service and see the http logs showing the passing SOAP Header.

3 comments:

  1. Kewl Man...how many nights did you spent for this?
    And , yes where is Cloud Computing part ???

    ReplyDelete
  2. Hmmm i just started off with this ....that's where (Cloud computing) i want to lead it to ....So look out for the new posts......

    ReplyDelete
  3. I try this tutorial in jdev 11.1.1.7 not work, on response message miss custom header
    Is it possible download an example ?

    ReplyDelete