Skip to content

rafaeltuelho/process-servicecall-exception-handling

Repository files navigation

Process Servicecall Exception Handling

Process definitions

1. Simple generic exception handler using Intermediate Error Catch Event

ThrowCatchError

2. Service call without Exception Handling strategy.

Use the HTTP Response Code to test the Service Call response.

ServiceCallWithNoExceptionHandler

Make sure the HandleResponseErrors (in the REST Service Task input parameters (Data Mapping)) is set to false.

To use this strategy change the kie-deployment-descriptor.xml to register the Rest Service Task.

     <work-item-handlers>
        <work-item-handler>
            <resolver>mvel</resolver>
            <identifier>new org.jbpm.process.workitem.rest.RESTWorkItemHandler(classLoader)</identifier>
            <parameters/>
            <name>Rest</name>
        </work-item-handler>
    </work-item-handlers>

3. Rest Service Call with Exception Handling using a Sub process

  • Main Process ServiceCallWithNoExceptionHandler

  • Sub process (exception handler) ExceptionHandlerSubProcess

This strategy is explained in detail in this blog post: http://mswiderski.blogspot.com/2018/10/handle-service-exceptions-via-subprocess.html

To use this strategy change the kie-deployment-descriptor.xml to register the Rest Service Task informing the Exception Handler Process Definition Id along with the Service task Completion Strategy:

     <work-item-handlers>
        <work-item-handler>
            <resolver>mvel</resolver>
            <identifier>new org.jbpm.process.workitem.rest.RESTWorkItemHandler(classLoader, "ExceptionHandlerSubProcess", "RETRY")</identifier>
            <parameters/>
            <name>Rest</name>
        </work-item-handler>
    </work-item-handlers>

Note: make sure you set the HandleResponseErrors parameter to true in the Rest Service Task (RESTWorkItemHandler). This parameter is used to properly handle the exception. Otherwise it will just log the Http request error and return the error code in the Result output parameter.

4. Rest Service Call with Error Event Exception Handling using an Event Sub process

Use the HTTP Response Code to test the Service Call response.

ServiceCallWithErrorEvent

Make sure the HandleResponseErrors (in the REST Service Task input parameters (Data Mapping)) is set to false.

To use this strategy change the kie-deployment-descriptor.xml to register the Rest Service Task.

     <work-item-handlers>
        <work-item-handler>
            <resolver>mvel</resolver>
            <identifier>new org.jbpm.process.workitem.rest.RESTWorkItemHandler(classLoader)</identifier>
            <parameters/>
            <name>Rest</name>
        </work-item-handler>
    </work-item-handlers>

In this scenario if the reviwer sets the serviceRetry = true the event Subprocess ends with a Signal Event that will instantiate a new process instance to retry the service call.

5. Rest Service Call with Signal Exception Handling using an Event Sub process

ServiceCallWithExceptionSignalHandler

jBPM comes with a special Work Item handler Wrapper that can be used to decorate the REST Service Task to send a Signal to the process instance when an exception occurs. To use it change the kie-deployment-descriptor.xml to register it:

     <work-item-handlers>
        <work-item-handler>
            <resolver>mvel</resolver>
            <identifier>new org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator(new org.jbpm.process.workitem.rest.RESTWorkItemHandler(classLoader), "Error-serviceErrorSignal")</identifier>
            <parameters/>
            <name>Rest</name>
        </work-item-handler>
    </work-item-handlers>

Note: make sure you set the HandleResponseErrors parameter to true in the Rest Service Task (RESTWorkItemHandler). This parameter is used to properly handle the exception. Otherwise it will just log the Http request error and return the error code in the Result output parameter.

In this scenario if the reviwer sets the serviceRetry = true the event Subprocess ends with a Signal Event that will instantiate a new process instance to retry the service call.

Also in this scenario the main process instance will remain active wainting at the Rest Service task Node...

Testing

After building and deploying your kjar you can test it via Rest API with:

curl --location --request POST 'http://localhost:8080/kie-server/services/rest/server/containers/process-servicecall-exception-handling/processes/<process definition id>/instances' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <base64 credentials>' \
--data-raw '{
    "serviceUrl": "https://api.covid19api.com/summary/x",
    "serviceRequestData": {
        "java.util.HashMap": {
            "data": "test..."
        }
    }
}'

Note: I'm intentionly using https://api.covid19api.com/summary/x which should result in a 404 http error as this url is invalid (/x)

About

Sample RHPAM (jBPM) project to show how to handle exception when calling a Service from a BPM process.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages