Sunday 6 May 2012

What is the use of 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.

You can invoke a compensation handler by using the compensate activity, which names the scope for which the compensation is to be performed (that is, the scope whose compensation handler is to be invoked). A compensation handler for a scope is available for invocation only when the scope completes normally. Invoking a compensation handler that has not been installed is equivalent to using the empty activity (it is a no-op). This ensures that fault handlers do not have to rely on state to determine which nested scopes have completed successfully. The semantics of a process in which an installed compensation handler is invoked more than once are undefined.If an invoke activity has a compensation handler defined inline, then the name of the activity is the name of the scope to be used in the compensate activity.

Below Picture for Compensation Handler:

       Picture 1)



  
So that , Here i Create three Synchronous BPEL PROCESS'S
1) One for HotelBooking
2) one for AirticketBooking
3) one for TravalBooking 


Step 1). Now am creating
 AirticketBooking Synchrronous BPEL Process

XSD for  AirticketBooking like below:
<?xml version="1.0" encoding="UTF-8"?>
<schema attributeFormDefault="unqualified"
    elementFormDefault="qualified"
    targetNamespace="http://xmlns.oracle.com/CompensationHandlerDemo_jws/AirticketBooking/AirtickingBooking"
    xmlns="http://www.w3.org/2001/XMLSchema">
    <element name="AirticketBookingRequest">
        <complexType>
            <sequence>
                <element name="Name" type="string"/>
            </sequence>
        </complexType>
    </element>
    <element name="AirticketBookingResponse">
        <complexType>
            <sequence>
                <element name="ConfimtaionCode" type="string"/>
        <element name="Status" type="string"/>
            </sequence>
        </complexType>
    </element>
  <element name="AirticketCancelaionRequest">
        <complexType>
            <sequence>
                <element name="ConfimtaionCode" type="string"/>
            </sequence>
        </complexType>
    </element>
  <element name="AirticketCancelationResponse">
        <complexType>
            <sequence>
                <element name="ConfimtaionCode" type="string"/>
        <element name="Status" type="string"/>
            </sequence>
        </complexType>
    </element>
</schema>


Abstract WSDL: Like Below









Then Composite.xml



Then Open BPEL Process like Below:








Source code for BPEL Process:-





Then Deploy Bpel Process into Your server
and Test it Like below




Then go to EM Console and Test it Like Below
Then Select Operation : AirticketBooking
and pass Input as Name: Your own name and Test Web Service
Like below

Then see out put: Like below


Then select Operation: AirticketCancellation
and pass input as previous output like "966e46fd40865118:4688f92a:13720e4271b:-7ffb"
and test web service
then see what is the output like below



step2:- Then Create bpel process for HotelBooking

It is also same as it is same of above process

Step 3): Create BPEL Process for TravalBooking
In this process Invoke above two bpel process

Please see picture 1)

this is source code for TravalBooking:
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Generated by Oracle SOA Modeler version 1.0 at [4/23/12 2:20 PM]. -->
<composite name="TravalBookingProcess"
           revision="1.0"
           label="2012-04-23_14-20-33_703"
           mode="active"
           state="on"
           xmlns="http://xmlns.oracle.com/sca/1.0"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
           xmlns:orawsp="http://schemas.oracle.com/ws/2006/01/policy"
           xmlns:ui="http://xmlns.oracle.com/soa/designer/">
  <import namespace="http://xmlns.oracle.com/CompensationHandlerDemo_jws/TravalBookingProcess/TravalBpelProcess"
          location="TravalBpelProcess.wsdl" importType="wsdl"/>
  <import namespace="http://xmlns.oracle.com/CompensationHandlerDemo_jws/HotelBookingProcess/HotelBpelProcess"
          location="HotelBpelProcess.wsdl" importType="wsdl"/>
  <import namespace="http://xmlns.oracle.com/CompensationHandlerDemo_jws/AirticketBooking/AirtickingBooking"
          location="AirtickingBooking.wsdl" importType="wsdl"/>
  <service name="TravalBookingService_ep"
           ui:wsdlLocation="TravalBpelProcess.wsdl">
    <interface.wsdl interface="http://xmlns.oracle.com/CompensationHandlerDemo_jws/TravalBookingProcess/TravalBpelProcess#wsdl.interface(TravalBpelProcess)"/>
    <binding.ws port="http://xmlns.oracle.com/CompensationHandlerDemo_jws/TravalBookingProcess/TravalBpelProcess#wsdl.endpoint(TravalBookingService_ep/TravalBpelProcess_pt)"/>
  </service>
  <component name="TravalBpelProcess">
    <implementation.bpel src="TravalBpelProcess.bpel"/>
  </component>
  <reference name="HotelBookingService" ui:wsdlLocation="HotelBpelProcess.wsdl">
    <interface.wsdl interface="http://xmlns.oracle.com/CompensationHandlerDemo_jws/HotelBookingProcess/HotelBpelProcess#wsdl.interface(HotelBpelProcess)"/>
    <binding.ws port="http://xmlns.oracle.com/CompensationHandlerDemo_jws/HotelBookingProcess/HotelBpelProcess#wsdl.endpoint(hotelbookingservice_ep/HotelBpelProcess_pt)"
                location="hotelbookingservice_ep.wsdl" soapVersion="1.1">
      <property name="weblogic.wsee.wsat.transaction.flowOption"
                type="xs:string" many="false">WSDLDriven</property>
    </binding.ws>
  </reference>
  <reference name="AirticketBookingService"
             ui:wsdlLocation="AirtickingBooking.wsdl">
    <interface.wsdl interface="http://xmlns.oracle.com/CompensationHandlerDemo_jws/AirticketBooking/AirtickingBooking#wsdl.interface(AirtickingBooking)"/>
    <binding.ws port="http://xmlns.oracle.com/CompensationHandlerDemo_jws/AirticketBooking/AirtickingBooking#wsdl.endpoint(airtickingbooking_client_ep/AirtickingBooking_pt)"
                location="airtickingbooking_client_ep.wsdl" soapVersion="1.1">
      <property name="weblogic.wsee.wsat.transaction.flowOption"
                type="xs:string" many="false">WSDLDriven</property>
    </binding.ws>
  </reference>
  <wire>
    <source.uri>TravalBookingService_ep</source.uri>
    <target.uri>TravalBpelProcess/TravalBookingService</target.uri>
  </wire>
  <wire>
    <source.uri>TravalBpelProcess/HotelBookingService</source.uri>
    <target.uri>HotelBookingService</target.uri>
  </wire>
  <wire>
    <source.uri>TravalBpelProcess/AirticketBookingService</source.uri>
    <target.uri>AirticketBookingService</target.uri>
  </wire>
</composite>





I hope this is very usefull  for you................













9 comments:

  1. Nice Article.....


    And I also like above comment.... :D

    ReplyDelete
  2. This is very helpful and informative too.Thanks for sharing it here.

    ReplyDelete
  3. Thanks for sharing...very useful.

    ReplyDelete
  4. Thanks for sharing.. its good

    ReplyDelete
  5. It will be good if you can share SOA project for this example

    Oracle SOA 12c online training

    ReplyDelete
  6. How this "compensation handler" is different from other implementation, Like i can design a flow where if any layer of calling failed then my second layer will call cancel operation of same service which is called for creation.. How you can define it.

    ReplyDelete
    Replies
    1. Even in your implementation, you are invoking seprately cancel activity with second BPEL operation, then how it will control in case where there is a non-xa data source of data base?

      Delete