Saturday, February 5, 2011

Transaction Handling in FileAdapter



I struggled a lot while implementing transaction handling in file adapter and come to a solution of using compensation handler for implementation of rollback of files.
Below is the scenario for my requirement: -
We have been provided 2 types of files to different partners and as per our scenario if 1st File transfer is success and the second transfer got failed then the first transfer should also get rolled back.
The solution implemented is: -
1. Create an empty BPEL Process.
2. Create File adapter(1) with read operation linked with receive activity
3. Create a Partner1(File Adapter with write Operation) linked with invoke activity
4. Create another File Adapter with Synch Read Operation linked to another Invoke activty and mapped to another Partner2(File Adapter with write Operation) linked with invoke activity
5. For Implementing Transaction handling, Compensation handler is implemented at scope level and in Compensation handler Partner1 is called for synch read operation and file is written back to location of File Adapter(1).
Below is the bpel code for the above requirement: -
<?xml version = “1.0″ encoding = “UTF-8″ ?>
<process name=”BPELProcess3″
targetNamespace=”http://xmlns.oracle.com/BPELProcess3″
xmlns=”http://schemas.xmlsoap.org/ws/2003/03/business-process/”
xmlns:bpws=”http://schemas.xmlsoap.org/ws/2003/03/business-process/”
xmlns:xp20=”http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20″
xmlns:ns4=”http://xmlns.oracle.com/pcbpel/adapter/file/FileAdapter_SynchRead/”
xmlns:ns7=”http://xmlns.oracle.com/pcbpel/adapter/file/File_Compensate_Write/”
xmlns:ldap=”http://schemas.oracle.com/xpath/extension/ldap”
xmlns:xsd=”http://www.w3.org/2001/XMLSchema”
xmlns:ns5=”http://xmlns.oracle.com/pcbpel/adapter/file/Partner2/”
xmlns:client=”http://xmlns.oracle.com/BPELProcess3″
xmlns:ns6=”http://xmlns.oracle.com/pcbpel/adapter/file/FileCompensate_Rollback/”
xmlns:ora=”http://schemas.oracle.com/xpath/extension”
xmlns:ns1=”http://xmlns.oracle.com/pcbpel/adapter/file/n/”
xmlns:ns3=”http://xmlns.oracle.com/pcbpel/adapter/opaque/”
xmlns:ns2=”http://xmlns.oracle.com/pcbpel/adapter/file/m/”
xmlns:bpelx=”http://schemas.oracle.com/bpel/extension”
xmlns:orcl=”http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc”>
<partnerLinks>
<partnerLink myRole=”Read_role” name=”FileAdapter1″
partnerLinkType=”ns1:Read_plt”/>
<partnerLink name=”Partner1″ partnerRole=”Write_role”
partnerLinkType=”ns2:Write_plt”/>
<partnerLink name=”FileAdapter_SynchRead” partnerRole=”SynchRead_role”
partnerLinkType=”ns4:SynchRead_plt”/>
<partnerLink name=”Partner2″ partnerRole=”Write_role”
partnerLinkType=”ns5:Write_plt”/>
<partnerLink name=”FileCompensate_Rollback” partnerRole=”SynchRead_role”
partnerLinkType=”ns6:SynchRead_plt”/>
<partnerLink name=”File_Compensate_Write” partnerRole=”Write_role”
partnerLinkType=”ns7:Write_plt”/>
</partnerLinks>
<variables>
<variable name=”Receive_1_Read_InputVariable” messageType=”ns1:Read_msg”/>
<variable name=”Invoke_1_Write_InputVariable” messageType=”ns2:Write_msg”/>
<variable name=”Invoke_2_SynchRead_InputVariable”
messageType=”ns4:Empty_msg”/>
<variable name=”Invoke_2_SynchRead_OutputVariable”
messageType=”ns4:SynchRead_msg”/>
<variable name=”Invoke_3_Write_InputVariable” messageType=”ns5:Write_msg”/>
<variable name=”Invoke_4_SynchRead_InputVariable”
messageType=”ns6:Empty_msg”/>
<variable name=”Invoke_4_SynchRead_OutputVariable”
messageType=”ns6:SynchRead_msg”/>
<variable name=”Invoke_5_Write_InputVariable” messageType=”ns7:Write_msg”/>
</variables>
<sequence name=”main”>
<scope name=”Scope_1″>
<faultHandlers>
<catchAll>
<compensate name=”Compensate_1″ scope=”Scope_3″/>
</catchAll>
</faultHandlers>
<sequence name=”Sequence_1″>
<sequence name=”Sequence_1″>
<receive name=”Receive_1″ partnerLink=”FileAdapter1″
portType=”ns1:Read_ptt” operation=”Read”
variable=”Receive_1_Read_InputVariable”
createInstance=”yes”/>
<scope name=”Scope_3″>
<compensationHandler>
<sequence name=”Sequence_2″>
<scope name=”Scope_2″>
<sequence name=”Sequence_3″>
<invoke name=”Invoke_4″
partnerLink=”FileCompensate_Rollback”
portType=”ns6:SynchRead_ptt” operation=”SynchRead”
inputVariable=”Invoke_4_SynchRead_InputVariable”
outputVariable=”Invoke_4_SynchRead_OutputVariable”/>
<assign name=”Assign_3″>
<copy>
<from variable=”Invoke_4_SynchRead_OutputVariable”
part=”opaque” query=”/ns3:opaqueElement”/>
<to variable=”Invoke_5_Write_InputVariable”
part=”opaque” query=”/ns3:opaqueElement”/>
</copy>
</assign>
<invoke name=”Invoke_5″ partnerLink=”File_Compensate_Write”
portType=”ns7:Write_ptt” operation=”Write”
inputVariable=”Invoke_5_Write_InputVariable”/>
</sequence>
</scope>
</sequence>
</compensationHandler>
<sequence name=”Sequence_4″>
<assign name=”Assign_1″>
<copy>
<from variable=”Receive_1_Read_InputVariable” part=”opaque”
query=”/ns3:opaqueElement”/>
<to variable=”Invoke_1_Write_InputVariable” part=”opaque”
query=”/ns3:opaqueElement”/>
</copy>
</assign>
<invoke name=”Invoke_1″ partnerLink=”Partner1″
portType=”ns2:Write_ptt” operation=”Write”
inputVariable=”Invoke_1_Write_InputVariable”/>
</sequence>
</scope>
<scope name=”Scope_4″>
<sequence name=”Sequence_5″>
<invoke name=”Invoke_2″ partnerLink=”FileAdapter_SynchRead”
portType=”ns4:SynchRead_ptt” operation=”SynchRead”
inputVariable=”Invoke_2_SynchRead_InputVariable”
outputVariable=”Invoke_2_SynchRead_OutputVariable”/>
<assign name=”Assign_2″>
<copy>
<from variable=”Invoke_2_SynchRead_OutputVariable”
part=”opaque” query=”/ns3:opaqueElement”/>
<to variable=”Invoke_3_Write_InputVariable” part=”opaque”
query=”/ns3:opaqueElement”/>
</copy>
</assign>
<invoke name=”Invoke_3″ partnerLink=”Partner2″
portType=”ns5:Write_ptt” operation=”Write”
inputVariable=”Invoke_3_Write_InputVariable”/>
</sequence>
</scope>
</sequence>
</sequence>
</scope>
</sequence>
</process>

No comments:

Post a Comment

B2B Features with OIC

During last couple of months various new features are getting introduced in Oracle Integration Cloud, out of those there is a new feature f...