1 Reply Latest reply on Sep 16, 2009 5:14 AM by kukeltje

    Exeception Handeling problem in JBPM

      Hi All,
      In my JBPM approval process, I have a requirement that, if at any point of time JBPM exception happens during the process work flow., the control should delegate to a separate TaskNode called Admin node, and the normal process flow should stop. Inside Admin node the admin user decides , from which task node now the process should continue, and accordingly the flow continues

      Taking into consideration this requirement I designed a admin node and a exception handler as follows..

      <task-node name="Moduladministrator">
       <task name="AdministratorInteraction" description="Moduladministrator-Interaction">
       <assignment class="com.sample.action.AssignAdminAction"></assignment>
       </task>
       </task-node>
      <exception-handler>
       <action name="TravelExceptionHandler" class="com.sample.action.TravelExecptionHandler" ></action>
       </exception-handler>
      
      

      The Exception action handler is ass follows , which transfer the flow to Admin node and creates the Taskinstance at Admin node
      public class TravelExecptionHandler implements ActionHandler {
      
       private static Log log = LogFactory.getLog(TravelExecptionHandler.class);
       private static final long serialVersionUID = 1L;
      
       public void execute(ExecutionContext executionContext) throws Exception {
      
       log.debug("#################### ERROR HANDELING ##################");
       log.debug("========================================================");
       log.debug("#################### ERROR HANDELING ##################");
       try {
      
      
       log.debug("Error comes from --" + executionContext.getNode().getName());
       log.debug("Error is -- -- --" + executionContext.getException().getMessage());
      
       Node targetNode = executionContext.getProcessDefinition().findNode("Moduladministrator");
       log.debug("Admin node is--" + targetNode.getName());
      
       TaskInstance faultyTaskInstance = executionContext.getTaskInstance();
      
       if (faultyTaskInstance != null) {
       faultyTaskInstance.setEnd(new Date());
       }
       TaskNode targetTaskNode = (TaskNode) targetNode;
       targetTaskNode.enter(executionContext);
       TaskMgmtInstance taskManagementInstance = executionContext.getTaskMgmtInstance();
      
       taskManagementInstance.getTaskMgmtDefinition().setStartTask((Task) targetTaskNode.getTasks().iterator().next());
      
       log.info("Now Controll is with " + targetTaskNode.getName() + " node");
      
      
       } catch (Exception e) {
       log.debug("Error---" + e.getCause());
       e.printStackTrace();
       }
      
       }
      }
      

      This above code part is working find with creating the taskinstance at admin task node.
      Now after the task is assigned to a admin user, the admin take decision from which task node the process should start, again.

      The code i am using to delegate the flow from admin node to any desired task node is--
       String faultNode = (String) contextInstance.getVariable("ErrorOriginatingNode");
       Node faultyNode = processInstance.getProcessDefinition().findNode(faultNode);
       Collection col = processInstance.getTaskMgmtInstance().getTaskInstances();
       int cnt = 0;
       ArrayList arrayLst = new ArrayList(col);
       log.debug("Total task is- " + arrayLst.size());
      
       for (int i = 0; i < arrayLst.size(); i++) {
       TaskInstance taskInstance = (TaskInstance) arrayLst.get(i);
       log.debug("-----TaskName = " + taskInstance.getName() + "----TaskId = " + taskInstance.getId()
       + "----Is task active-- " + !taskInstance.hasEnded());
       if (!taskInstance.getName().equalsIgnoreCase("AdministratorInteraction") && !taskInstance.hasEnded()) {
      
       log.debug("-----Task = " + taskInstance.getName() + " is ending ");
       taskInstance.setEnd(new Date());
       cnt++;
       }
       }
       log.debug("Total "+cnt+"tasks got ended");
       List nodes = processInstance.getProcessDefinition().getNodes();
       for (int i = 0; i < nodes.size(); i++) {
       Node tempNode = (Node) nodes.get(i);
       if(tempNode instanceof TaskNode)
       log.debug("TaskNode " + i + "---" + tempNode.getName());
       }
       log.info("Error Occurred in work flow.Entering Admin Node -- -- --");
       log.info("*********Please provide any of the above Node you want to proceed with**************");
      
       String node = conInput.getConsoleInput();
       log.debug("Selected for TaskNode--" + node);
       TaskNode targetNode = (TaskNode)processInstance.getProcessDefinition().findNode(node);
       Transition errorTransition = new Transition("to" + targetNode.getName());
      
       targetNode.addArrivingTransition(errorTransition);
       faultyNode.addLeavingTransition(errorTransition);
      
       errorTransition.setTo(targetNode);
       TaskMgmtInstance taskManagementInstance = processInstance.getTaskMgmtInstance();
       taskManagementInstance.getTaskMgmtDefinition().setStartTask((Task) targetNode.getTasks().iterator().next());
      
       adminTaskInstance.end(errorTransition);
      
      

      Unfortunately, I am not able to achieve my requirement. The problem I am facing is even the control is delegating to admin node, still the process continues to move forward with the selected transition from the node where exception occurs..

      So basically , I am not able to stop and resume the work flow from a desired Tasknode, as a admin.

      Please suggest how to achieve this ..

      As per the JBPM document 10.7. Exception handling

      Note that the exception handling mechanism of jBPM is not completely similar to the java exception handling. In
      java, a caught exception can have an influence on the control flow. In the case of jBPM, control flow cannot be
      changed by the jBPM exception handling mechanism.


      So then , how to achieve my requirement ..Any work around is there?


      Please suggest..

      Thanks in advance for your valuable reply..

      Prajatna Mahunta
      prajatna.mahunta@daimler.com


        • 1. Re: Exeception Handeling problem in JBPM
          kukeltje

          You initial assumption is wrong:

          In my JBPM approval process, I have a requirement that, if at any point of time JBPM exception happens during the process work flow., the control should delegate to a separate TaskNode called Admin node,


          Because as you state yourself, this contradicts the documentation:

          Note that the exception handling mechanism of jBPM is not completely similar to the java exception handling. In
          java, a caught exception can have an influence on the control flow. In the case of jBPM, control flow cannot be
          changed by the jBPM exception handling mechanism.


          So think out of the box. A JbpmException should be handled by the delegationclass in which it occurs. What you can try (never did this, only did escalation with timers) is to raise an event, catch this event in your task and in the delegationclass in the eventhandler move the *token* to the corresponding node and move it back to the originating task when the admin task should be ended.