Friday, May 13, 2016

Invoke a BPEL workflow from WSO2 ESB proxy service


In this blog post I will illustrate how to invoke a BPEL workflow from a proxy service using WSO2 ESB.

1. Deploy a BPEL process on WSO2 BPS Server. (Login to the BPS Management Console and go to Processes -> Add then select the BPEL Archive(zip) file and upload it. If your BPEL process has external web service invocations, you can be hosted those web services WSO2 App Server or axis2Server)

2. Start WSO2 ESB Server and create a custom proxy as below. (Change the port offset to avoid conflicts with the WSO2 BPS Server).

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="bpel_factory"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <payloadFactory media-type="xml">
            <format>
               <p:MultiOperatorServiceRequest xmlns:p="http://wso2.org/bps/operator"><!--Exactly 1 occurrence--><x xmlns="http://wso2.org/bps/operator">$1</x>
                  <!--Exactly 1 occurrence--><y xmlns="http://wso2.org/bps/operator">$2</y>
               </p:MultiOperatorServiceRequest>
            </format>
            <args>
               <arg xmlns:m="http://wso2.org/bps/operator"
                    evaluator="xml"
                    expression="//m:MultiOperatorServiceRequest/x"/>
               <arg xmlns:m="http://wso2.org/bps/operator"
                    evaluator="xml"
                    expression="//m:MultiOperatorServiceRequest/y"/>
            </args>
         </payloadFactory>
         <send>
            <endpoint>
               <address uri="http://10.100.7.75:9763/services/MultiOperatorService.MultiOperatorServicehttpMultiOperatorServiceBindingEndpoint/"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <log level="full"/>
         <respond/>
      </outSequence>
   </target>
   <description/>
</proxy>
                     
Here you can find out the address URL in SOAP-UI after clicking on the TryIt wizard in WSO2 BPS Server.  Payload factory mediator is used to transform the payload in incoming request to the appropriate format that allow by the request for the BPEL process invocation.

you can copy and paste the request body in the SOAP-UI to the format element in payload factory mediator and replace ? with the arguments defined in the message context.  

3. Next you can send a POST request with the payload to the proxy service and see the response as following figure.


In this example I used a BPEL process to solve [(x * y) - (x + y)]^2  formula.
eg: x=5, y=3 =>[(5 * 3) - (5 + 3)]^2 => 49.0


No comments:

Post a Comment