Time for action – triggering a fault within the BPEL process

So far, we implemented two <scope> activities that model the book ordering process. However, to trigger <compensationHandler> of the <scope> activities, we need to have either <catch>, <catchAll>, <compensationHandler>, or <terminationHandler>. We will use <catchAll>, and inside this, we will trigger <compensationHandler>. To trigger <catchAll>, we need to throw an explicit fault after the execution of the two scopes. Next, we learn how to throw this fault.

Carry out the following steps:

  1. Add a <sequence> activity named throwFault after the <scope> activity named initiateCreditCardTransaction. Then, drag-and-drop an <if> activity within it and specify its condition, as shown in the following screenshot. This condition will check the content of inputVariable and check whether it contains the compensate value:
    Time for action – triggering a fault within the BPEL process
  2. Add a <throw> activity inside it, so if the content of inputVariable contains the compensate value, it triggers the <throw> activity. Configure this activity to throw a fault named TriggerCompensationFault, as follows:
    Time for action – triggering a fault within the BPEL process
  3. For <else>, add an <empty> activity, so if the content of inputVariable does not contain the compensate value, the fault is not thrown. Then the <sequence> named throwFault looks like what is shown in the following screenshot:
    Time for action – triggering a fault within the BPEL process

What just happened?

In the previous section, we throw a fault from the BPEL process if inputVariable contains a compensate value. This fault is used to trigger the compensation of the created scopes.

Initiating a compensation for scopes within a BPEL process

In the previous section, we throw a fault from the BPEL process if inputVariable contains the compensate value. Now we need to catch it and trigger <compensationHandler> for the registerBookOrder and initiateCreditCardTransaction scopes. For this, we will add a <catchAll> activity to catch the thrown fault and trigger <compensationHandler> within the <catchAll> activity in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset