cancel
Showing results for 
Search instead for 
Did you mean: 

How to attach boundary error event to a service task

rgoel
Champ in-the-making
Champ in-the-making
Hi,
   I have a requirement to attach boundary error event to a service task. This service task is part of the same process in which the error is thrown . I have seen examples in activiti source code where boundary error event is either attached to user task or to a subprocess.

Here is my bpmn xml file:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsd="http://www.w3.org/2001/XMLSchema" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">

  <process id="POCAsyncProcessWith2AsyncAndErrorHandling" name="Example of usage of 2 Asynch process with error handling" isExecutable="true">
    <startEvent id="startevent1" name="Start">
      <extensionElements>
        <activiti:executionListener event="start" delegateExpression="${activitiStartWorkflowExecutionListener}"></activiti:executionListener>
      </extensionElements>
    </startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <serviceTask id="poc_task1" name="poc task1" activiti:delegateExpression="${activitiPOCTask1}"></serviceTask>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="poc_task1"></sequenceFlow>
    <serviceTask id="poc_task2" name="poc task2" activiti:async="true" activiti:delegateExpression="${activitiPOCTask2}"></serviceTask>
    <serviceTask id="poc_task3" name="poc task3" activiti:delegateExpression="${activitiPOCTask3}"></serviceTask>
    <sequenceFlow id="flow10" sourceRef="poc_task2" targetRef="poc_task3"></sequenceFlow>
    <serviceTask id="poc_task4" name="poc task4" activiti:async="true" activiti:delegateExpression="${activitiPOCTask4}"></serviceTask>
    <sequenceFlow id="flow11" sourceRef="poc_task3" targetRef="poc_task4"></sequenceFlow>
    <serviceTask id="poc_taskerror" name="poc error task" activiti:delegateExpression="${activitiPOCTaskError}"></serviceTask>
    <sequenceFlow id="flow12" sourceRef="poc_task1" targetRef="poc_taskerror"></sequenceFlow>
    <sequenceFlow id="flow13" sourceRef="poc_taskerror" targetRef="poc_task2"></sequenceFlow>
    <sequenceFlow id="flow14" sourceRef="poc_task4" targetRef="endevent1"></sequenceFlow>
    <serviceTask id="poc_task_error_handler" name="poc task error handler" activiti:delegateExpression="${activitiPOCTaskErrorHandler}"></serviceTask>
    <sequenceFlow id="flow16" sourceRef="poc_task_error_handler" targetRef="endevent1"></sequenceFlow>
    [H1]<boundaryEvent id="catchError" name="catchError" attachedToRef="poc_task1">[/H1]
      <errorEventDefinition errorRef="BusinessExceptionOccurred"></errorEventDefinition>
    </boundaryEvent>
    <sequenceFlow id="flow17" sourceRef="catchError" targetRef="poc_task_error_handler"></sequenceFlow>
    <textAnnotation id="versionNumber">
       <text>2.3</text>
    </textAnnotation>
  </process>

Here, if I  have attachedToRef="poc_taskerror", it works fine as poc_taskerror is the task which throws bpmn error and activiti is able to find all errorEventDefinitions in the scope. It then transfers flow to  poc_task_error_handler.

But when I have attachedToref to another service task , in the same process before the task which throws error, activiti is not able to figure out any  errorEventDefinitions  in the scope .

My question is " Can we attach boundary error events only to subprocess or usertask ?

Appreciate response.

regards,
rgoel
6 REPLIES 6

rgoel
Champ in-the-making
Champ in-the-making
Attaching the bpmn txt file

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Rgoel,

error boundary event can be attached to another tasks too (e.g. Script tasks, Service task….)

Regards
Martin

rgoel
Champ in-the-making
Champ in-the-making
Thanks Martin for replying. I have tried attaching it to first service task in a bpmn process. I am throwing bpmn error in 3rd service task in the same  process. But my task handler is not invoked, as activiti does not find any error event listeners in the scope. But when I attach to the third service task which is also throwing  the error , it works.

Question is whether this can be solved without creating a subprocess ?

martin_grofcik
Confirmed Champ
Confirmed Champ
I am not sure what are you asking for.
Examples can be found org.activiti.engine.test.bpmn.event.error.BoundaryErrorEventTest on github

Regards
Martin

osganian
Champ in-the-making
Champ in-the-making
Hi, I am using Activiti version 5.17.0 and I am having a similar issue.  I have a custom java class that implements ActivityBehavior (actually extends from AbstractBpmnActivityBehavior) and I am throwing a BpmnError from it but my error boundary event isn't catching it.  If I use a JavaDelegate instead of an ActivityBehavior then my error boundary event catches the thrown exception.  Are error boundary events unable to catch exceptions thrown from an ActivityBehavior and only JavaDelegates?

Any help would be appreciated.
Mike

osganian
Champ in-the-making
Champ in-the-making
Ok figured it out, in my custom ActivityBehavior class I was just throwing a BpmnError out of it.  If instead I use the ErrorPropagation.propagateError(bpmnError, execution); then it works.

Thanks,
Mike