Thursday, March 22, 2007

Convert A-Synchronous proccess to Synchronous

Introduction

This article how to convert an Asynchronous to a Synchronous BPEL process. Since BPEL determines whether a process is async or sync by just some small settings in the .bpel file (and some dependency in the wsdl) it is rather easy to convert from one to another.

When creating BPEL processes, three files are created by default:
  1. bpel.xml
  2. .bpel
  3. .wsdl
To determine whether a BPEL process is Asynchronous or Synchronous, it looks at the second file: YourBPELProcess.bpel. Generally, when creating a process based on the Asynchronous template, the .bpel file look like this:

<process
name="BPELProcess1"
targetNamespace="http://xmlns.oracle.com/BPELProcess1"
xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
xmlns:client="http://xmlns.oracle.com/BPELProcess1"
xmlns:ora="http://schemas.oracle.com/xpath/extension"
xmlns:orcl="http://www.oracle.com
/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
xmlns:xp20="http://www.oracle.com
/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
xmlns:bpelx="http://schemas.oracle.com/bpel/extension"
xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
<partnerLinks>
<partnerLink
name="client"
partnerLinkType="client:BPELProcess1"
myRole="BPELProcess1Provider"
partnerRole="BPELProcess1Requester"/>
</partnerLinks>
<variables>
<variable
name="inputVariable"
messageType="client:BPELProcess1RequestMessage"/>
<variable
name="outputVariable"
messageType="client:BPELProcess1ResponseMessage"/>
</variables>
<sequence name="main">
<receive
name="receiveInput"
partnerLink="client"
portType="client:BPELProcess1"
operation="initiate"
variable="inputVariable" createInstance="yes"/>
<invoke
name="callbackClient"
partnerLink="client"
portType="client:BPELProcess1Callback"
operation="onResult"
inputVariable="outputVariable"/>
</sequence>
</process>

The differences between a synchronous and asynchronous process lie in the steps of invoke callback vs. reply difference to return the response. In a synchronous process, the way a reply message is handed back is through a reply. The asynchronous process invokes a callback method to hand back the reply message.

<process … namespace definitions etc … >
<partnerLinks>
<partnerLink name="client"
partnerLinkType="client:BPELProcess3"
myRole="BPELProcess3Provider"/>
</partnerLinks>
<variables>
<variable name="inputVariable"
messageType="client:BPELProcess3RequestMessage"/>
<variable name="outputVariable"
messageType="client:BPELProcess3ResponseMessage"/>
</variables>
<sequence name="main">
<receive name="receiveInput"
partnerLink="client"
portType="client:BPELProcess3"
operation="process"
variable="inputVariable"
createInstance="yes"/>
<reply name="replyOutput"
partnerLink="client"
portType="client:BPELProcess3"
operation="process"
variable="outputVariable"/>
</sequence>
</process>
As shown in the .bpel xml examples, receive, invoke and reply refer to a portType and a partnerLink attribute. These are specified in the .wsdl and also show some differences.
<portType name="BPELProcess1">
<operation name="initiate">
<input message="client:BPELProcess1RequestMessage"/>
</operation>
</portType>
<portType name="BPELProcess1Callback">
<operation name="onResult">
<input message="client:BPELProcess1ResponseMessage"/>
</operation>
</portType>

<plnk:partnerLinkType name="BPELProcess1">
<plnk:role name="BPELProcess1Provider">
<plnk:portType name="client:BPELProcess1"/>
</plnk:role>
<plnk:role name="BPELProcess1Requester">
<plnk:portType name="client:BPELProcess1Callback"/>
</plnk:role>
An asynchronous process specifies two portTypes, each with its own variable. Also it specifies two partnerLinkTypes, because it uses the same client partnerlink to receive from and invoke to (the callback). A synchronous process only specifies one portType holding both the input aswell as the output variable. It requires just one definition of the client partnerlink, because it doesn’t need to be invoked separately. blok

There is also a difference in the operation names (ie. Initiate, onResult and process). Though these are just labels that are referred to, it is good practice to actually rename the to the labels as shown in the default generated code, when changing from async to sync (and vise versa). This makes the xml code better understandable later on.

Summary

In your Asynchronous BPEL process diagram:
  1. Remove the Invoke process step from the diagram
  2. Drag a Reply process step in that place
  3. Connect the Reply process step to the client partnerlink (on the left lane)
  4. In the Edit reply dialog change the name to replyOutput and click OK
  5. Ignore the yellow exclamation mark for now
Now go to the source view of the .bpel file (and auto indent xml):
  1. Within the sequence element find the receive and reply elements
  2. For both of them, set the operation attribute’s value to process
  3. To the reply element, add the attribute variable and assign as value the name of the output variable, by default this is outputVariable.
Open the .wsdl file in source view (and auto indent xml):
  1. Find the two portType definitions
  2. From the one with operation onResult and name Callback prefixed with your service name, copy the input element and paste it after the input element of the first portType (named your service name)
  3. Rename the element you just copy/pasted from input to output
  4. In the current portType, set the value for operation name to process
  5. Remove the element (including its child elements!) from which you copied the input element (the one that’s called Callback prefixed with the name of your process)
  6. Remove the partnerLink role element - plnk:role - (including its child elements!) that has a portType name equal to the earlier removed portType .
Now go back to your .bpel file and open it in diagram view. The yellow exclamation mark should now be gone. If not, open the Reply process step and click the Apply button. Recompile your project and deploy it.

Post a Comment