Using Java logic (not explicitly modeled in BPMN), e.g. catch a database persistence exception from a Service Task and direct it to a User Task (another sequence flow for the failure case).
In this case, my plan is that the Service Task implements ActivityBehavior instead of Java Delegate.
Is this a viable and preferred approach? If not, please suggest alternatives. I am using Activiti 5.16.1.
Yes that's a viable approach. Another way would be to throw a BPMN error in that case and catch it with a boundary error event that connects to a user task. And it's also possible to use an exclusive gateway and check on a specific variable you set in the service task.
BTW, are you referring to the approach mentioned in the user guide for ActivityBehavior. If yes,
1) Is it possible without specifying exception and no-exception sequence flows in the workflow spec i.e. in .bpmn file? If yes, any pointers on this please?
Details extracted teh User Guide as below. <xml> serviceTask id="javaService" name="Java service invocation" activiti:class="org.activiti.ThrowsExceptionBehavior" /serviceTask sequenceFlow id="no-exception" sourceRef="javaService" targetRef="theEnd" / sequenceFlow id="exception" sourceRef="javaService" targetRef="fixException" /
and the sample code snippet looks like <java> public class ThrowsExceptionBehavior implements ActivityBehavior {
public void execute(ActivityExecution execution) throws Exception { String var = (String) execution.getVariable("var");