Exception Handling in BPEL Process

Introduction:-

With Service Oriented Architecture, we need strong Exception Handling process to make the service more efficient and reusable. Without exception handling block, can impact on service reusability. Exception handling process allows BPEL process to handle errors or exceptions in activity level. Exception handler can handle exception returned by invoked web services also. We will see the use of Fault Management Framework in composite level or in activity level to catch the errors and will perform different user defined actions. SOA provides an efficient way to handle exception using throw, catch and catch all activities same as JAVA uses constructs such as try, catch and finally. We can attach exception in two levels in BPEL a�� scope level and process level.

Exception can be classified into two categories in BPEL process a��

Business Fault:- Business faults will be thrown during the processing of service due to invalid business rules or invalid data.

Runtime Fault:- Runtime faults will occur when system will throw exception. For example, when invoked web service is not reachable or there is a problem with SOAP binding or problem with the remote server.

BPEL process has some standard faults also to catch the errors. Screenshot is attached of standard faults.BPEL_Exception_handling_1

Leta��s go for some example of Exception Handling.

Here, I will use calculator service (refer pick activity calculator service) to implement all the possible exception activities. In this example I will show the use of throw, catch and catch all activity. Follow the below steps.

  1. Create a separate application for exception example. Go to File -> New -> Application. Select SOA Application under General category. Enter application name ExceptionApplication
  2. Click on Next button and enter project name ExceptionDemo. Select Composite With BPEL Process in the next wizard.
  3. Click on Finish button and BPEL creation wizard will open. Enter BPEL process name CalcBPELProcess and select synchronous BPEL process in template field.BPEL_Exception_handling_2
  4. Select SOAP web service from component palate and drag and drop it in External References lane. Enter the WSDL URL of pick activity and select the checkbox copy WSDL and its dependent artifacts into the project.BPEL_Exception_handling_3
  5. Now SOA composite will look like below screenshotBPEL_Exception_handling_4
  6. Double click on BPEL component and drag and drop INVOKE activity in between receiveInput and replyOutputBPEL_Exception_handling_5
  7. Drag a wire from invoke activity to CalcSOAPReference partner link and editor window of invoke activity will open. Enter invoke activity name and select addition operation. Create input and output variable by clicking green plus icon.BPEL_Exception_handling_6
  8. I am adding one more element in CalcBPELProcess.xsd as calculator service requires two input valuesBPEL_Exception_handling_7
  9. Drag and drop two ASSIGN activity in the component lane, one is before invoke activity and other is after invoke. In 1st assign activity, map two input payload with the input variable of invoke activity and in 2nd assign activity, map the output variable of invoke with the output payload.
  10. Move the Invoke activity into a scope. So place the scope like below screenshotBPEL_Exception_handling_8
  11. Add a fault handler in this application. Add a CATCH block in the scope around the invoke activity.BPEL_Exception_handling_9
  12. Double click on catch and editor of catch wizard will open. Select remoteFault from the system fault by clicking on glass icon and enter fault variable name as catch_faultVar.BPEL_Exception_handling_10
  13. Drag and drop an ASSIGN activity within catch block and assign output variable of invoke activity as -1
  14. Add CATCH ALL block in scope1 like below screenshotBPEL_Exception_handling_11
  15. Add an ASSIGN activity under Catch all block also and assign -2 to the output variable of invoke activity. Now the BPEL process will look like this.BPEL_Exception_handling_12
  16. Make the application which is called up by the current application unavailable (undeploy it or stop it) and test this application. You will get the output as -1. Catch block will handle the remote fault due to unavailability of service

Now see the use of THROW activity within exception block. Catch block will throw the exception using THROW activity and catch all will catch the error.

  1. Remove the assign activity from catch block and Drag and drop THROW activity in place of assign activity.BPEL_Exception_handling_13
  2. Double click on throw and editor of throw will open. Select same remote fault here and select the catch variable here.BPEL_Exception_handling_14
  3. Add one more scope outside of scope1and add CATCH ALL to scope2BPEL_Exception_handling_15
  4. Assign some value to the out variable of invoke activity. We need add assign activity within catch all block and assign -3. Save the BPEL process and BPEL will be like below screenshot.BPEL_Exception_handling_16
  5. Test the application and see the outcome of BPEL process.BPEL_Exception_handling_17

Catch block catches the exception and throw activity throws the exception which will be caught by Catch All block.

We can handle exception through Fault Policy and Fault Management Framework also. Check this link.

Leave a Reply

Your email address will not be published. Required fields are marked *

Show my latest post here