Skip to main content

Fault Handlers in OpenESB BPEL Processes

In OpenESB, many services are orchestrated using BPEL, and the Fault Handler in BPEL is essential for exception management. Fault Handlers can be defined either at the process level or within a scope.

Inside a Fault Handler, we can use:

  • <catch>: allows capturing specific faults that may occur during the execution of a process or scope, either thrown by invoked services or by the BPEL engine itself.

  • <catchAll>: acts as a generic handler that captures all unhandled faults.

When handling these errors, we can use exit, throw, or rethrow. Below is an explanation of how each one works.

When an <exit> is executed, OpenESB marks the process as finished, and this is registered in the BPEL engine logs as a warning. No notification is sent to the client. If the BPEL process was handling a service that receives requests and sends responses, and the <exit> is executed before the process reaches the <reply> activity, the client that invoked the service will not receive any response.

It is useful in situations where an abrupt termination is necessary, but it must be used carefully, as it may lead to missing responses for clients or inconsistencies in complex processes.

The <throw> and <rethrow> activities are designed to handle exceptions (errors) within a process, but they serve different purposes.

<throw>

Used to raise new exceptions when an error occurs that must be handled. It interrupts the process flow and allows the Fault Handlers to take action.

<rethrow>

Used to re-raise an exception that has already been caught, allowing it to continue propagating to higher levels if necessary.

FAULT HANDLER IN A SCOPE

A Scope in BPEL is a structure that allows isolating a group of activities and defining specific rules for that group of activities. Inside a Scope, faults can be handled locally using the <faultHandlers>, <catch>, and <catchAll> tags, which is useful for managing errors without affecting the entire process.

Benefits of Using Fault Handlers in Scopes

Localized Error Handling

Scopes allow faults to be handled locally, meaning that errors occurring inside the Scope can be managed without affecting the rest of the process. This is especially useful when you want to handle an error at a specific point in the process without interrupting the complete flow; therefore, the process can continue.

Logic Isolation

Defining a Scope allows isolating the logic of a set of activities, including fault management. This facilitates a more modular and flexible BPEL process design.

Use of Compensations and Transactions

In addition to fault handling, compensations and transactions can also be defined inside a Scope. This is particularly important in processes involving multiple distributed operations that must be rolled back if an error occurs.

Common Use Cases for Fault Handlers in Scopes

External Service Invocation

If you are invoking an external web service within the Scope and want to handle specific faults such as timeouts or connection errors.

Transactional Processes

If you have operations that must be managed transactionally, you can use a Scope to define both fault and compensation handlers.

Retry of Failed Operations

You can encapsulate an operation within a Scope and handle the fault locally in order to retry the operation without affecting the general process flow.

Flow in Case of Failure

  • If a fault occurs within the Scope activities, the local Fault Handlers defined inside that Scope are searched first.

  • If a Fault Handler (such as <catch> or <catchAll>) is found, the logic defined there is executed. The process will continue unless the error is propagated to a higher level.

  • If no Fault Handler is found within the Scope, the fault propagates to the next higher level in the BPEL process, where other fault handlers may exist.

FAULT HANDLER AT PROCESS LEVEL

A process-level Fault Handler is a mechanism designed to capture and handle exceptions occurring anywhere within the complete process. This provides a centralized way of managing errors that were not handled in more localized scopes.

  • A process-level Fault Handler captures and manages exceptions globally for the entire BPEL process.

  • <catch> handlers manage specific faults, while <catchAll> handles any fault not previously captured.

  • This is a useful strategy to prevent a BPEL process from failing uncontrollably and allows centralized error management.

A test project was created to verify the behavior of exception handling:

  • Scope without Fault Handler: the error would be handled by the process-level Fault Handler if it exists. If there is no process-level Fault Handler, a SEVERE error would occur, and the process would either terminate with an error or remain stuck.

    image-20240925-154222.png

  • Scope with fualtHandler:

    1. Using only <exit> produces a SEVERE error, and the process execution does not continue.

      <![CDATA[2024-09-20T19:07:05.506+0200 WARNING [com.sun.jbi.engine.bpel.BPELSEHelper] (sun-bpel-engine-thread-4) BPJBI-6001: Sending ERROR status (Service Name = {http://vico.org/bpel/TestFaultHandler/testFaultHandler }entrada, Endpoint Name = testFaultHandlerPortTypeRole_myRole, Operation Name = {http://vico.org/wsdl/testFaultHandler }inicarTestFaultHandler, Message Exchange Id = 255470873525441-49956-139461448254300030)

       Error properties

        com.sun.jbi.crl.faultcode = Server

        com.sun.jbi.crl.faultstring = BPCOR-6054: Sending errors for the pending requests in the process scope, since the process instance is being terminated

        com.sun.jbi.crl.faultactor = sun-bpel-engine

        com.sun.jbi.crl.faultdetail =

         BPCOR-6054: Sending errors for the pending requests in the process scope, since the process instance is being terminated

      2024-09-20T19:07:05.506+0200 WARNING [com.sun.jbi.engine.bpel.core.bpel.model.runtime.impl.BPELProcessInstanceImpl] (sun-bpel-engine-thread-4) BPCOR-6156: The process instance has been terminated because an exit activity was encountered.

      2024-09-20T19:07:05.506+0200 SEVERE [com.sun.jbi.httpsoapbc.OutboundMessageProcessor] (HTTPBC-InboundReply-1) HTTPBC-E00720: El punto final [testFaultHandlerPort]  del proveedor de servicio  [{http://vico.org/wsdl/testFaultHandler }testFaultHandlerService] respondió con un estado de error. El detalle de error es: BPCOR-6054: Sending errors for the pending requests in the process scope, since the process instance is being terminated]]>

      image-20240925-154919.png

    2. El <reply> envía respuesta al cliente, al hacer <exit> no continúa con la ejecución del proceso, es decir lo que hay debajo del Scope no se ejecuta, a nivel de log el proceso genera un WARNING.

      image-20240925-155117.png

      <![CDATA[2024-09-20T19:12:53.087+0200 WARNING [com.sun.jbi.engine.bpel.core.bpel.model.runtime.impl.BPELProcessInstanceImpl] (sun-bpel-engine-thread-0) BPCOR-6156: The process instance has been terminated because an exit activity was encountered]]>
    3. Reply without exit: the reply sends a response to the client but the process execution continues, executing what is after the scope. At the log level, everything is correct and therefore no trace is generated.

      image-20240925-155218.png

    4. A controlled error catch will handle the error and continue the process execution by executing the actions after the scope.

      image-20240925-155256.png

    5. If the error is uncontrolled, it will be thrown to the faultHandler of the process, which, in case it does not exist, will generate a SEVERE and the execution will terminate with an error.

  • Process without faultHandler, it would produce a SEVERE in the log and the process would terminate with an error.

    image-20240925-155405.png

  • Processo withfualt Handler:

    1. Even having a catch for a controlled error, if an uncontrolled error occurs and there is no catchAll, then a SEVERE will be generated and the process will terminate with an error.

      image-20240925-160351.png

    2. Controlled error with reply and exit: the message is returned to the client and the process terminates generating a warning due to the exit, example log:

      <![CDATA[2024-09-20T21:26:12.669+0200 WARNING [com.sun.jbi.engine.bpel.core.bpel.model.runtime.impl.BPELProcessInstanceImpl] (sun-bpel-engine-thread-1) BPCOR-6156: The process instance has been terminated because an exit activity was encountered.]]>

      image-20240925-160318.png

    3. Controlled error with reply only: a response message is returned to the client and the execution does not continue with the remaining actions after the error. The process is considered to have finished correctly.

      image-20240925-160257.png

    4. Uncontrolled error but with catchAll and reply, reply only: a response message is returned to the client and the execution does not continue with the remaining actions after the error. The process is considered to have finished correctly; in no case does the execution resume from the point where the error was thrown.

      image-20240925-160228.png

    5. Uncontrolled error but with catchAll, reply and exit: a response message is returned to the client and a warning is generated in the log due to the process exit, the same as in point b.

      image-20240925-160203.png

    6. Uncontrolled error but with catchAll without reply or exit → SEVERE, example log:

      <![CDATA[2024-09-20T21:45:16.433+0200 SEVERE [com.sun.jbi.httpsoapbc.OutboundMessageProcessor] (HTTPBC-InboundReply-2) HTTPBC-E00720: El punto final [testFaultHandlerPort]  del proveedor de servicio  [{http://vico.org/wsdl/testFaultHandler }testFaultHandlerService] respondió con un estado de error. El detalle de error es: BPCOR-6136: Sending errors for the pending requests in the process scope since, the process instance has completed.]]>

image-20240925-160123.png

  1. Summary of test process logs

------------------------------------------------------- Crida amb catcha nivell de proces i repy--------------------------------------------

2024-09-20T22:03:44.863+0200 FINE [com.sun.jbi.engine.bpel.EngineChannel] (sun-bpel-engine-thread-0)ClassName=com.sun.jbi.engine.bpel.EngineChannel;MethodName=sendFault; I18N: BPJBI-3020: Sending Fault for MessageEx id 255470873525441-49956-139461554247570082 faultName: {http://vico.org/wsdl/testFaultHandler }error

2024-09-20T22:03:44.863+0200 FINEST [com.sun.jbi.engine.bpel.EngineChannel] (sun-bpel-engine-thread-0)ClassName=com.sun.jbi.engine.bpel.EngineChannel;MethodName=sendFault; I18N: BPJBI-3018: The contents of the message are : <jbi:message xmlns:msgns="http://vico.org/wsdl/testFaultHandler " type="msgns:testFaultHandlerException" version="1.0" xmlns:jbi="http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper ">jbi:part<testFaultHandler_Exception xmlns="http://vico.org/schema/testFaultHandler ">FALLO DE AUTENTICACION</testFaultHandler_Exception></jbi:part></jbi:message>

2024-09-20T22:03:44.863+0200 FINER [com.sun.jbi.engine.bpel.com.sun.jbi.common.qos.messaging.MessagingChannel] (sun-bpel-engine-thread-0)ClassName=com.sun.jbi.common.qos.messaging.BaseMessagingChannel;MethodName=removeTemplates; Removed template 1.d9a5fe59-4c4d-4b95-81ea-379b765f785c from mTemplatesMap, now have: []

2024-09-20T22:03:44.866+0200 FINE [com.sun.jbi.engine.bpel.BPELSEInOutThread] (sun-bpel-engine-thread-0)ClassName=com.sun.jbi.engine.bpel.BPELSEInOutThread;MethodName=processMsgEx; I18N: BPJBI-3002: Pattern for exchange Id 255470873525441-49956-139461554247570082 is http://www.w3.org/2004/08/wsdl/in-out

2024-09-20T22:03:44.866+0200 FINE [com.sun.jbi.engine.bpel.BPELSEInOutThread] (sun-bpel-engine-thread-0)ClassName=com.sun.jbi.engine.bpel.BPELSEInOutThread;MethodName=processMsgEx; I18N: BPJBI-3003: Received in-out message status for M Ex 255470873525441-49956-139461554247570082 content is Done

---------------------------------------------------------- crida amb atenticació correcte -----------------------------------------------------------------------------------

2024-09-21T06:17:54.746+0200 FINEST [com.sun.jbi.engine.bpel.EngineChannel] (sun-bpel-engine-thread-8)ClassName=com.sun.jbi.engine.bpel.EngineChannel;MethodName=reply; I18N: BPJBI-3018: The contents of the message are : <jbi:message xmlns:msgns="http://vico.org/wsdl/testFaultHandler " type="msgns:testFaultHandlerResponse" version="1.0" xmlns:jbi="http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper ">jbi:part<testFaultHandler_Out xmlns="http://vico.org/schema/testFaultHandler ">D00401081Fd_NanCh8</testFaultHandler_Out></jbi:part></jbi:message>

2024-09-21T06:17:54.746+0200 FINER [com.sun.jbi.engine.bpel.com.sun.jbi.common.qos.messaging.MessagingChannel] (sun-bpel-engine-thread-8)ClassName=com.sun.jbi.common.qos.messaging.BaseMessagingChannel;MethodName=removeTemplates; Removed template 1.e63f4b5a-dcfd-4ad0-8741-07feda72998c from mTemplatesMap, now have: []

2024-09-21T06:17:54.750+0200 FINE [com.sun.jbi.engine.bpel.BPELSEInOutThread] (sun-bpel-engine-thread-8)ClassName=com.sun.jbi.engine.bpel.BPELSEInOutThread;MethodName=processMsgEx; I18N: BPJBI-3002: Pattern for exchange Id 255470873525441-49956-139461850746410094 is http://www.w3.org/2004/08/wsdl/in-out

2024-09-21T06:17:54.750+0200 FINE [com.sun.jbi.engine.bpel.BPELSEInOutThread] (sun-bpel-engine-thread-8)ClassName=com.sun.jbi.engine.bpel.BPELSEInOutThread;MethodName=processMsgEx; I18N: BPJBI-3003: Received in-out message status for M Ex 255470873525441-49956-139461850746410094 content is Done

-----------------------------------------------------------Crida amb cacthall i reply sense exit------------------------------------------------------------------------

2024-09-21T06:23:05.563+0200 FINER [com.sun.jbi.engine.bpel.com.sun.jbi.common.qos.messaging.MessagingChannel] (sun-bpel-engine-thread-8)ClassName=com.sun.jbi.common.qos.messaging.BaseMessagingChannel;MethodName=removeTemplates; Removed template 2.7632e502-71e8-4e8e-ad4c-9360f2fb28ba from mTemplatesMap, now have: []

2024-09-21T06:23:05.567+0200 FINE [com.sun.jbi.engine.bpel.BPELSEInOutThread] (sun-bpel-engine-thread-8)ClassName=com.sun.jbi.engine.bpel.BPELSEInOutThread;MethodName=processMsgEx; I18N: BPJBI-3002: Pattern for exchange Id 255470873525441-49956-139461853855530097 is http://www.w3.org/2004/08/wsdl/in-out

2024-09-21T06:23:05.567+0200 FINE [com.sun.jbi.engine.bpel.BPELSEInOutThread] (sun-bpel-engine-thread-8)ClassName=com.sun.jbi.engine.bpel.BPELSEInOutThread;MethodName=processMsgEx; I18N: BPJBI-3003: Received in-out message status for M Ex 255470873525441-49956-139461853855530097 content is Done

-----------------------------------------------------------Crida amb cachall reply i exit----------------warning --------------------------------------------------------

2024-09-21T06:26:10.302+0200 FINE [com.sun.jbi.engine.bpel.BPELSEInOutThread] (sun-bpel-engine-thread-8)ClassName=com.sun.jbi.engine.bpel.BPELSEInOutThread;MethodName=processMsgEx; I18N: BPJBI-3002: Pattern for exchange Id 255470873525441-49956-139461855702870098 is http://www.w3.org/2004/08/wsdl/in-out

2024-09-21T06:26:10.302+0200 FINE [com.sun.jbi.engine.bpel.BPELSEInOutThread] (sun-bpel-engine-thread-8)ClassName=com.sun.jbi.engine.bpel.BPELSEInOutThread;MethodName=processMsgEx; I18N: BPJBI-3003: Received in-out message status for M Ex 255470873525441-49956-139461855702870098 content is Done

2024-09-21T06:26:10.303+0200 WARNING [com.sun.jbi.engine.bpel.core.bpel.model.runtime.impl.BPELProcessInstanceImpl] (sun-bpel-engine-thread-8) BPCOR-6156: The process instance has been terminated because an exit activity was encountered.

-----------------------------------------------------------Crida amb cachall exit----------------------SEVERE-------------------------------------------------------

2024-09-21T06:28:35.864+0200 WARNING [com.sun.jbi.engine.bpel.BPELSEHelper] (sun-bpel-engine-thread-8) BPJBI-6001: Sending ERROR status (Service Name = {http://vico.org/bpel/TestFaultHandler/testFaultHandler }entrada, Endpoint Name = testFaultHandlerPortTypeRole_myRole, Operation Name = {http://vico.org/wsdl/testFaultHandler }inicarTestFaultHandler, Message Exchange Id = 255470873525441-49956-139461857158570099)

 Error properties

  com.sun.jbi.crl.faultcode = Server

  com.sun.jbi.crl.faultstring = BPCOR-6054: Sending errors for the pending requests in the process scope, since the process instance is being terminated

  com.sun.jbi.crl.faultactor = sun-bpel-engine

  com.sun.jbi.crl.faultdetail =

   BPCOR-6054: Sending errors for the pending requests in the process scope, since the process instance is being terminated

2024-09-21T06:28:35.864+0200 FINER [com.sun.jbi.engine.bpel.com.sun.jbi.common.qos.messaging.MessagingChannel] (sun-bpel-engine-thread-8)ClassName=com.sun.jbi.common.qos.messaging.BaseMessagingChannel;MethodName=removeTemplates; Removed template 1.f9806543-d5c8-4509-bbb8-782a2c3c0e09 from mTemplatesMap, now have: []

2024-09-21T06:28:35.865+0200 SEVERE [com.sun.jbi.httpsoapbc.OutboundMessageProcessor] (HTTPBC-InboundReply-2) HTTPBC-E00720: El punto final [testFaultHandlerPort]  del proveedor de servicio  [{http://vico.org/wsdl/testFaultHandler }testFaultHandlerService] respondió con un estado de error. El detalle de error es: BPCOR-6054: Sending errors for the pending requests in the process scope, since the process instance is being terminated.