cancel
Showing results for 
Search instead for 
Did you mean: 

Handling exceptions of Spring ServiceTasks

gunnar1
Champ in-the-making
Champ in-the-making
Hi folks,
in the Userguide you're going to find a sample on how to implement dedicated Exception handling for java services.
More precisely there is a chapter Handling exceptions describing how to route process execution through another path in case some exception occurs: we just have to implement ActivityBehavior and do something like the following:


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);
  }
 
}

So far so good. The point is, I want to do the same with Spring Services…

  • Is there a sample on how to do this when calling Spring Beans?

  • Is there some kind of involved superclass when calling a Spring Bean so that I can have a look at the standard logic and provide a custom subclass?

  • What about an annotation defining the outgoing transition (better: an error event) in case of a specific exception…?

  • The best solution would be to have the BPMN intermediate error event available as boundary event with service tasks (and not only on subprocesses) as well.
I think you guys have a cool solution or at least an idea?

Thanks in advance
Gunnar
5 REPLIES 5

diogosaad
Champ in-the-making
Champ in-the-making
Hello Folks,

I'm also in doubt on how to handle exceptions in Spring Service Tasks. Does anyone know?

Thanks,
Diogo.

trademak
Star Contributor
Star Contributor
Hi,

You could do a similar implementation like the ActivityBehavior class.
When invoking the Spring bean in the BPMN 2.0 XML you can pass the Execution instance and you can do the same thing like you included in your post.
so activiti:expression="#{springBean.method(execution)}"

Best regards,

gunnar1
Champ in-the-making
Champ in-the-making
Thanks for your hint. I already tried that.

Have you a working sample using activiti:expression="#{springBean.method(execution)}"
and calling "execution.take(transition);" from the source code?

My experience is that setting process variables using the execution parameter works well ("execution.setVariable(…)"), but explicitely calling "execution.take(transition)" leads to exceptions signalling database unique constraint violations 😞

Gunnar

gant
Champ in-the-making
Champ in-the-making
Hi,

I use a boundary error event to handle exceptions in spring service tasks. but you have to add this construct directly in the xml, since you can't model it in the designer.

I created my own BoundaryEventAwareServiceTaskExpressionActivityBehavior class to handle the exception and changed BPMNParse to instantiate this. instaed of standard ServiceTaskExpressionActivityBehavior. If an exception occurs while calling my service, i signal the boundary error event (after evaluating the errorCode).

regards,
michael

gunnar1
Champ in-the-making
Champ in-the-making
Hi Michael,

thank you very much. Looks like this would be the preferred BPMN like way  Smiley Happy
I'll have a look at ServiceTaskExpressionActivityBehavior.

Regards
Gunnar