Monday, 12 June 2017

Compensation Handler


Compensation Handler -

Compensation occurs when the BPEL process cannot complete a series of operations after some of them have already completed, and the BPEL process must backtrack and undo the previously completed transactions.
For example, if a BPEL process is designed to book a rental car, a hotel, and a flight, it may book the car and the hotel and then be unable to book a flight for the right day. In this case, the BPEL flow performs compensation by going back and unbooking the car and the hotel.




1)      Create  a Simple Bpel Code with below mentioned xsd parameters-


<?xml version="1.0" encoding="UTF-8"?>
<schema attributeFormDefault="unqualified"
                elementFormDefault="qualified"
                targetNamespace="http://xmlns.oracle.com/Application1/compensation_practice/Compensation_Practice"
                xmlns="http://www.w3.org/2001/XMLSchema">
                <element name="process">
                                <complexType>
                                                <sequence>
                                                                <element name="input" type="integer"/>
<element name="input1" type="integer"/>
                                                </sequence>
                                </complexType>
                </element>
                <element name="processResponse">
                                <complexType>
                                                <sequence>
                                                                <element name="addition" type="integer"/>
<element name="subtraction" type="integer"/>
<element name="multiplication" type="integer"/>
                                                </sequence>
                                </complexType>
                </element>
</schema>


2)      Below Is the complete bpel flow -




3)      How It Works ?-In this flow we will create a simple scope for addition and one for division. If input has 0 it will throw  an error and flow control will go to catch all block from where compensate will revert back all previous assigned values.









First -Create a scope for addition. Inside assign, logic will be –   [ input 1 + input 2 ] as shown below –








Next- Add compensation block  on the same scope by selecting arrow button  on left side,add assign activity and update  values as shown below  -











Create one more scope for division. Here logic is- if value for input1 is 0 it would throw an error and move to catch all block  as shown below –






















Logic For Catch All Block –

Here in catch all- compensate activity will revert back all previous values and  assign  new one based on  logic written in compensation handler block within each scope.








Testing –


Provide the input parameters  as shown below –(positive test case) –










Response –



Compensation Test Case –


Provide 0 in input1 as shown below –











Response    ( It compensates the addition value and resets to 0 )










1 comment:

  1. thanks for your kind words-this will motivate me...i write blog to help people and keep it as simple as possible for better understanding...

    ReplyDelete