WSO2 Business Process Server v3.1.0 Documentation

##### Overview

- Home
- Release Note
- WS-BPEL Compliance
- License

##### Downloads

- Releases

##### Installation Guide

- Installing WSO2 BPS

##### Quick Start Guide

- Modeling the process
- Deploying the process
- Testing the process

##### User Guide

- Deploying BPEL Processes
- Deploying Human Tasks
- Managing BPEL processes
- Managing BPEL process instances
- QoS for BPEL processes
- Securing BPEL processes
- Invoking secured partner services
- Versioning
- Management API

##### Human Task Guide

- Human Tasks Quick Start Guide
- Deploying HumanTasks
- Managing Tasks
- Developing a Human Task Artifact
- Human Task Management and Configuration
- Human Task Concepts

##### Administrator Guide

- External data sources Configuration
- Registry Configuration
- Events
- Unified Endpoints
- BPEL Extensions
- Transaction Factory Configuration
- Message Exchange Interceptors
- OpenJPA specific properties
- JMS Transport Configuration
- Process Instance Cleanup Tasks
- Process Hydration and Dehydration
- Enabling Peer-to-Peer(P2P) Communication
- Setting up a BPS Cluster

##### Best Practices

- Process Deployment Best Practices

##### Concepts

- Process Versioning
- Process instance events
- Partner links

##### WS-BPEL Extensions

- Activity Failure and Recovery
- Extension Activities and Extensible Assign Operations
- XPath Extensions
- Iterable ForEach
- Flexible Assigns
- BPEL4People Extension

##### Samples

- HelloWorld
- If-Else
- ForEach
- While
- Repeat Until
- Flow and Links
- Pick
- Synchronous and Asynchronous Service Invocations
- Fault Handling
- Split
- XslTransform
- Compensation Handler
- Event Handler

##### Resources

- FAQ
- External Articles
- Library
- Source Code

##### Community

- Forum
- Mailing Lists

##### Project Information

- Issue Tracking

# Sample Guide - Compensation Handler

### Table of Content

- Objective
- Prerequisites
- Overall Idea

### Objective

Reversing the effects of a service invocation in a case of a later failure is meant as compensation. The act of undoing any actions that were performed by a successfully completed compensatable activity because of an exception that occurred elsewhere in a workflow is meant as compansation handling. It is represented using <compensationHandler/> construct.

### Prerequisites

- Log in into BPS server admin console.
- Under Business Processes -> Add BPEL.
- Upload the FlightReservationProcess.zip, located at <BPS_HOME>/repository/samples/bpel directory
- Under the Business Processes -> Processes.
- Under the WSDL details widget -> Create instance

### Overall Idea

The following application does two things. First, it books an airline ticket and then it books a hotel. If the hotel booking fails, then the airline booking should be cancelled. The business process can be shown as below.

        <process>

        	<faultHandlers>
        		<catch name="BookHotelFault">
        			<!--Since the hotel booking failed, cancel the airline booking by calling the compensation handler of the scope that did the airline booking-->
        			<compensateScope scope="BookAirlineTktScope"/>

        			</!--Notify that the booking failed--->
        			<reply name="SendBookingFailedReply">
        		</catch>
        	</faultHandlers>

        	<receive name="DoBooking"/>

        	<scope name="A">
        		<compensationHandler>
        			<!--Cancel the airline booking-->
        			<invoke name="CancelAirlineTkt"/>
        		</compensationHandler>

        		<!--Book airline ticket-->
        		<invoke name="BookAirlineTkt"/>
        	</scope>

        	<scope name="B">
        		<!--Book hotel-->
        		<invoke name="BookHotel"/>
        	</scope>

        	<!--Both bookings are successful. Notify-->
        	<reply name="SendBookingSuccessReply"/>

    </process>

At A's scope, does the airline booking. At B's scope, does the hotel booking. The hotel booking may fail which happens when the invoke "BookAirlineTkt" fails and throws a fault "BookHotelFault". This fault is caught by the catch in the process's fault handler. Since the hotel booking failed, we need to cancel the airline booking. Therefore, at the catch block we call the compensation handler of scope A, which has the logic to cancel the airline booking. <compensateScope> activity is used to specify this. So, when the catch executes <compensateScope>, it calls the scope A's compensation handler which in turn invokes the webservice to cancel the airline booking.