Feeds

Programming constructs in BPEL

Part 3: BPELJ and Compensation

Securing Web Applications Made Simple and Scalable

What compensation is not

So having indicated that compensation is essentially like an undo facility for BPEL, let us now consider what it is not. It is not an exception handling or fault handling mechanism. It is also not an exception handling mechanism (this is worth saying, as a scope looks a bit like a try block within Java - at least conceptually). A suitable analogy might be that if you are using an editor and undo some operations; this is because you have decided to take a different course of action - not because the editor has generated an error.

Indeed, you'll find that BPEL also includes the ability to catch and handle errors at different levels of activity nesting. A fault handler can be defined on any scope and either bound to a particular kind of fault (defined by the fault's qualified name - a bit like an exception, or its message type) or to any faults not caught by a more specific handler. A handler simply contains an activity that will run in case an error occurs. For example, it might contain a reply activity that notifies a partner that an error has occurred.

This makes it clear that Compensation is not error handling - it is what should happen when I want to roll back some activities within the overall business process. I use the term roll-back here - but also do not want to imply that this is some form of distributed transaction rollback - instead, you have to decide what happens to undo any effects of what has gone before. There is nothing automatic in this, there is no DBMS handling the rollback.

Compensation example

In the overview of compensation, I introduced the idea of a holiday booking BPEL script that allowed hotel, hire car and flight bookings to be made. The following BPEL extracts illustrate how these scopes might be defined with compensation being provided to facilitate undoing some element of the booking process if one element fails. For example, the following scope defines a sequence for booking a hotel room and a compensation handler that can be invoked if required:

<scope name="BookHotel">

    <!-- define a compensation handler -->

    <compensationHandler>

      <!-- call cancel ticked -->

        <invoke name="Invoke_CancelBooking" 

                partnerLink="HotelBookingService"

                portType="hotel:hotelBooking"

                operation="cancelRoom"/>

    </compensationHandler>

    <sequence name="Sequence_1">

        <invoke name="Invoke_BookRoom" 

                partnerLink="HotelBookingService"

                portType="hotel:hotelBooking"

                operation="reserveRoom"/>

    </sequence>

  </scope>

The compensation handler in the above cancels a hotel room that has previously been booked by the service called by this step in the BPEL script.

The following scope defines what happens when we try to book seats on a flight to go along with the hotel room bookings. In this case, a sequence is defined to book the seats, but associated with it is a fault handler that is invoked when no seats are available for the selected dates.

  <scope name="BookFLight">

    <faultHandlers>

      <catch faultName="flight:NoSeatsAvailfault"

        <throw name="cancelBooking" 

               faultName="client:cancelBooking"/>

      </catch>

    </faultHandlers>

    <sequence name="Sequence_2"

      <invoke name="Invoke_BookFLight" 

              partnerLink="airline" 

              portType="ReservationSystem" 

              operation="bookSeats"/>

    </sequence>

  </scope>

In the above code, a catch block is defined to catch the specific fault and throws itself a cancelBooking fault to the parent scope. That will trigger the compensation we have defined earlier.

The last part is to define a catch block on the parent scope, that triggers in case of a cancelBooking fault and fires the compensation defined on the BookHotel scope.

<faultHandlers>

    <!-- catch the rollback fault and call -->

    <catch faultName="client:cancelBooking">

      <compensate name="CompensateBoookings" 

                  scope="BookHotel"/>

    </catch>

  </faultHandlers>

Bridging the IT gap between rising business demands and ageing tools

Next page: Summary

More from The Register

next story
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
DARPA-derived secure microkernel goes open source tomorrow
Hacker-repelling, drone-protecting code will soon be yours to tweak as you see fit
Put down that Oracle database patch: It could cost $23,000 per CPU
On-by-default INMEMORY tech a boon for developers ... as long as they can afford it
Google shows off new Chrome OS look
Athena springs full-grown from Chromium project's head
Apple: We'll unleash OS X Yosemite beta on the MASSES on 24 July
Starting today, regular fanbois will be guinea pigs, it tells Reg
HIDDEN packet sniffer spy tech in MILLIONS of iPhones, iPads – expert
Don't panic though – Apple's backdoor is not wide open to all, guru tells us
prev story

Whitepapers

Designing a Defense for Mobile Applications
Learn about the various considerations for defending mobile applications - from the application architecture itself to the myriad testing technologies.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Top 8 considerations to enable and simplify mobility
In this whitepaper learn how to successfully add mobile capabilities simply and cost effectively.
Seven Steps to Software Security
Seven practical steps you can begin to take today to secure your applications and prevent the damages a successful cyber-attack can cause.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.