[jboss-user] [JBoss jBPM] - Sub process exception handling, strange behaviour

norwaytoheaven do-not-reply at jboss.com
Wed Sep 26 08:08:55 EDT 2007


Hi,

It seems that exceptions occuring in a subprocess can be handled by a wrong exception handler:
According to the source code (ProcessState.java), if an exception has occured during sub process execution, no exception handler is called at the process state level. If the node before the process state is of type Node, the exception will be catched in the execute method, and then possibly call this node's exception handler.

Here's a unit test to illustrate this:
package test;
  | 
  | import org.jbpm.graph.def.ActionHandler;
  | import org.jbpm.graph.def.ProcessDefinition;
  | import org.jbpm.graph.exe.ExecutionContext;
  | import org.jbpm.graph.exe.ProcessInstance;
  | 
  | import junit.framework.TestCase;
  | 
  | public class Test extends TestCase {
  | 	
  | 	public static String actionHandler = null;
  | 	
  | 	public void test() throws Exception {
  | 		ProcessDefinition def = ProcessDefinition.parseXmlResource("main/processdefinition.xml");
  | 		ProcessInstance p = def.createProcessInstance();
  | 		
  | 		p.signal();
  | 		
  | 		// The exception thrown in the subprocess has been handled by the Node1 exception handler.
  | 		assertEquals("Node1", actionHandler);
  | 		
  | 	}
  | 
  | 	
  | 	public static class ProcessStateExceptionHandler implements ActionHandler {
  | 
  | 		public void execute(ExecutionContext executionContext) throws Exception {
  | 			actionHandler = "ProcessState";
  | 		}
  | 	}
  | 	
  | 	public static class Node1ExceptionHandler implements ActionHandler {
  | 
  | 		public void execute(ExecutionContext executionContext) throws Exception {
  | 			actionHandler = "Node1";
  | 		}
  | 	}
  | 	
  | 	public static class ProcessDefinitionExceptionHandler implements ActionHandler {
  | 
  | 		public void execute(ExecutionContext executionContext) throws Exception {
  | 			actionHandler = "ProcessDefinition";
  | 		}
  | 	}
  | 	
  | 	public static class Node1ActionHandler implements ActionHandler {
  | 		public void execute(ExecutionContext executionContext) throws Exception {
  | 			executionContext.leaveNode();
  | 		}
  | 	}
  | 	
  | 	public static class Node2ActionHandler implements ActionHandler {
  | 		public void execute(ExecutionContext executionContext) throws Exception {
  | 			throw new Exception();
  | 		}
  | 	}
  | }
  | 

Main process :
<?xml version="1.0" encoding="UTF-8"?>
  | 
  | <process-definition
  |   xmlns="urn:jbpm.org:jpdl-3.2"  name="main">
  |    <start-state name="start">
  |       <transition name="" to="node1"></transition>
  |    </start-state>
  |    <node name="node1">
  |    	  <action class="test.Test$Node1ActionHandler" />
  |       <transition name="" to="process1"></transition>
  |       <exception-handler>
  |       	<action class="test.Test$Node1ExceptionHandler" />
  |       </exception-handler>
  |    </node>
  |    <process-state name="process1">
  |       <sub-process name="sub"/> 
  |       <transition name="" to="end1"></transition>
  |       <exception-handler>
  |       	<action class="test.Test$ProcessStateExceptionHandler" />
  |       </exception-handler>
  |    </process-state>
  |    <end-state name="end1"></end-state>
  |    <exception-handler>
  |       	<action class="test.Test$ProcessDefinitionExceptionHandler" />
  |     </exception-handler>
  | </process-definition>

sub process :

  | <?xml version="1.0" encoding="UTF-8"?>
  | 
  | <process-definition
  |   xmlns="urn:jbpm.org:jpdl-3.2"  name="sub">
  |    <start-state name="start">
  |       <transition name="" to="node2"></transition>
  |    </start-state>
  |    <end-state name="end1"></end-state>
  |    <node name="node2">
  |    	  <action class="test.Test$Node2ActionHandler"/>
  |       <transition name="" to="end1"></transition>
  |    </node>
  | </process-definition>
  | 

Shouldn't there be a try { } catch (Exception) { raiseException(exception, executionContext);} in the excecute() method of the process state, so that the exception handler mechanism works with that kind of node?
If not, how are we supposed to deal with exceptions occuring in a sub process?

Regards,

Erwan

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4088800#4088800

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4088800



More information about the jboss-user mailing list