cancel
Showing results for 
Search instead for 
Did you mean: 

How to signal an error event

checco
Champ in-the-making
Champ in-the-making
Hi folks,
Is there a way to signal an error event from a JavaDelegate?

I have a serviceTask with a ErrorBoundaryEvent attached but i don't know how to follow the error path instead of the default path.

After googling and searching in alfresco/activiti forum i have found this exception http://activiti.org/javadocs/index.html?org/activiti/engine/delegate/BpmnError.html  but it seems that it is introduced in activiti 5.9 and unfortunately alfresco 4.0.1 uses activiti 5.7.

Shuld i  use the WorkflowService.fireEvent(String pathId,String eventName) method?  in this case which eventName and pathId i have to use?
1 REPLY 1

checco
Champ in-the-making
Champ in-the-making
Hi myself  Smiley Very Happy,
looking at the examples provided with Activiti 5.7 i have found the JavaServiceTaskTest.testExceptionHandling.bpmn20.xml in which the error is handled via API and not via BPMN2.0.

Infact the process definition is quite simple:

<process id="exceptionHandling">
    <startEvent id="theStart" />
    <sequenceFlow id="flow1" sourceRef="theStart" targetRef="javaService" />
    <serviceTask id="javaService"
                 name="Java service invocation"
                 activiti:class="org.activiti.examples.bpmn.servicetask.ThrowsExceptionBehavior">           
    </serviceTask>
    <sequenceFlow id="no-exception" sourceRef="javaService" targetRef="theEnd" />
    <sequenceFlow id="exception" sourceRef="javaService" targetRef="fixException" />
    <userTask id="fixException" name="Fix Exception" />   
    <sequenceFlow id="flow4" sourceRef="fixException" targetRef="theEnd" />
    <endEvent id="theEnd" />
  </process>
And the trick is done inside the ThrowsExceptionBehavior:

public class ThrowsExceptionBehavior implements ActivityBehavior {

  public void execute(ActivityExecution execution) throws Exception {
    String var = (String) execution.getVariable("var");
    PvmTransition transition = null;
    try {
      executeLogic(var);
      transition = execution.getActivity().findOutgoingTransition("no-exception");
    } catch (Exception e) {
      transition = execution.getActivity().findOutgoingTransition("exception");
    }
    execution.take(transition);
  }
 
  protected void executeLogic(String value) {
    if (value.equals("throw-exception")) {
      throw new RuntimeException();
    }
  }
}

But in this way i can't put an ErrorBoundaryEvent to serviceTask because the method findOutgoingTransition look for transition directly attached to the serviceTask and not for transition attached to BoundaryEvent of serviceTask.

So my question is: it is possible to use BoundaryErrorEvent attached to a task? and how can I signal the error to the process instance?

Thanks