cancel
Showing results for 
Search instead for 
Did you mean: 

'already taking a transition' exception from listener

awelsh
Champ in-the-making
Champ in-the-making
I'm trying to add some exception paths into workflows using executionListeners to check conditions during the end event of an activity.

I am passing the execution as a parameter to a bean method on the end event of a service task as follows…

checkForErrorCondition(ActivityExecution execution) {
   if(errorCondition()) {
      PvmTransition exceptionTransition = execution.getActivity().findOutgoingTransition("exception");
      execution.take(exceptionTransition);
   }
}

when errorCondition() evaluates to true, and it tries to take the "exception" flow, an exception with the message "already taking a transition" is thrown.
I get the same exception when doing the same on the start event.

I wanted to check if this is the expected behaviour (i.e. there is no way to influence the execution flow from a listener)

As well as the above, I noticed that when calling the checkForErrorCondition method from a serviceTask directly (rather than through a listener) it works fine, but if the service task is part of an embedded subprocess, when transitioning out of the subprocess the same exception ("already taking a transition") is thrown.
5 REPLIES 5

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
you should *not* influence the flow in listeners. It can lead to all kinds of unexpected behaviour. Look in other posts in the forum

frederikherema1
Star Contributor
Star Contributor
Better to use an error boundry-event for this kind of behaviour I would say: http://activiti.org/userguide/index.html#bpmnBoundaryErrorEvent

awelsh
Champ in-the-making
Champ in-the-making
Thanks for replies,

Is it possible to trigger an error boundary event any way other than following a pre-defined flow to an error end event?

I have a use case where a message can be received to trigger cancellation of an in-progress workflow.
This should also trigger the cancellation of any sub-processes, but need to do some cleanup in each of the subprocesses when this occurs so calling deleteProcessInstance isnt an option.

I'm looking for a way to "jump" out to an error end event without having to add an extra error path to every transition.
Also prefer not to use explicit receive task/signal() combination for this since I already have these as part of the business processes so wouldnt want to trigger a cancellation with a normal signal() call.

Any advice welcome.

jbarrez
Star Contributor
Star Contributor
No, currently that's the only way.

But readin your process, it seems that maybe by modeling your process differently you could do it out of the box?

gwaptiva
Champ in-the-making
Champ in-the-making
Not sure if this is still accurate or even of interest, but in order to save myself (and other flow authors of our embedded Activiti setup) a lot of boiler plate "if error a else b" gateway XML, I have extended the *ActivitiBehaviour classes to take an (optional) Expression that defines the error handling service task to jump to on a Java exception.

Now, if any Java exception happens within a ServiceTask (as an exmple), the subclass will change the outgoing transition to the Activity defined in the Expression, and flow out there. Note that there's only a single instance/object in the context for each service task, so upon entering you'll have to ensure the outgoing transitions are reset to their "normal" exits.

May not be totally "per-standard" but thus far running well in our setup