3 Replies Latest reply on Oct 16, 2007 8:51 AM by Yuri Vrancken

    General Exception Handling in JBPM

    Yuri Vrancken Newbie

      In my current work I have a process flow consisting of 20+ nodes. In each node an error from a service call must be redirected to a specific task node.

      This is the test process:

      <process-definition xmlns="" name="TestGeneralExceptionHandling">
       <exception-handler>
       <!-- exception-class="...TestBackendException"> -->
       <action name="action1"
       class="....HandleBackendExceptionActionHandler">
       </action>
       </exception-handler>
       <start-state name="start">
       <transition name="" to="DoSomethingWrong"></transition>
       </start-state>
       <node name="DoSomethingWrong">
       <event type="node-enter">
       <action name="action1" class="...DoSomethingWrongActionHandler">
       </action>
       </event>
       <transition name="" to="succes"></transition>
       </node>
       <task-node name="BackendError"></task-node>
       <end-state name="succes"></end-state>
      </process-definition>


      In my code the exception handler performs the following lines of code:

      public void execute(ExecutionContext executionContext) throws Exception {
       Node targetNode = executionContext.getProcessDefinition().getNode("BackendError");
       Token token = executionContext.getProcessInstance().getRootToken();
       executionContext.setVariable("BackendErrorOriginatingNode", token.getNode().getName());
       Transition errorTransition = new Transition("errorTransition");
       errorTransition.setTo(targetNode);
       token.signal(errorTransition);
       }
      


      As you can see I construct the transition in the code which will be defined at runtime. This enables me to keep the process flow free of extra transitions from each node to be drawn.

      I wonder if this is a robust way to handle exceptions. We then use a client application to view the backend error task node and perform corrective actions on backend systems. Then we will place the token back in the original node where the error occured and retry that node (all programatically).

      Any comments?

      Regards,

      -- Yuri Vrancken

        • 1. Re: General Exception Handling in JBPM
          Ronald van Kuijk Master

          If it works, it sounds like there is nothing wrong with this. I'm only not sure what happens if this occurs in one of the legs of a fork and the join is entered from the 'other' leg.

          Would be nice if you could show us a full example, maybe on the wiki? Many people are interested I think.

          • 2. Re: General Exception Handling in JBPM
            Ronald van Kuijk Master

            Maybe we could even introduce a kind of errortask node that has all this behaviour in it in a nice configurable way.

            • 3. Re: General Exception Handling in JBPM
              Yuri Vrancken Newbie

               

              "kukeltje" wrote:
              If it works, it sounds like there is nothing wrong with this. I'm only not sure what happens if this occurs in one of the legs of a fork and the join is entered from the 'other' leg.

              Would be nice if you could show us a full example, maybe on the wiki? Many people are interested I think.


              Ronald,

              The posted code pretty much shows you which classes you should use. In the
              DoSomethingWrongActionHandler
              class I just throw an exception which is then handled by the jBPM framework and invokes the defined
              HandleBackendExceptionActionHandler
              class.

              I could, however, decide to post the example stuff as attachments on the wiki.
              I didn't test it with forks yet, but will put this on my (oh so overloaded) to do list ;)...

              Tnx for the reply!

              --
              Yuri