1 2 Previous Next 20 Replies Latest reply on Mar 30, 2011 6:37 AM by km wen Go to original post
      • 15. Re: Exception handling in JBPM4 ?
        Hernan Rodriguez Newbie

        My solution for the problem is:

         

        Define a abstract class, implementing ExternalActivityBehaviour.

         

        package cl.pred.cmh.bpm.events.controller;
        
        import java.util.Map;
        
        import org.jbpm.api.activity.ActivityExecution;
        import org.jbpm.api.activity.ExternalActivityBehaviour;
        
        
        public abstract class ControllerAbstract implements ExternalActivityBehaviour {
             
             @Override
             public void signal(ActivityExecution activityExecution, String arg1, Map<String, ?> arg2)
             throws Exception {
                  execute(activityExecution);
             }
        
             @Override
             public void execute(ActivityExecution activityExecution) throws Exception {
                  try {               
                       procesar();               
                       activityExecution.takeDefaultTransition();
        
                  } catch (Exception e) {               
                       activityExecution.waitForSignal();
                  }
             }
        
             protected abstract void procesar() throws Exception;
        
        }
        
         
        

         

        Then, define a Controller Class extending the abstract class.

         

        public class Controller extends ControllerAbstract {
        
             @Override
             protected void procesar() throws Exception {
                  BusinessHelper.doSomething();          
             }
             
        }
        
         
        

         

        I defined three custom nodes in my model. These nodes were associated to the Controller Class.

        <?xml version="1.0" encoding="UTF-8"?>
        
        <process name="test" xmlns="http://jbpm.org/4.2/jpdl">
           <start name="start1" g="28,32,48,48">
              <transition name="to custom1" to="custom1" g="-10,-27"/>
           </start>
           <custom name="custom1" g="84,104,92,52" class="cl.pred.cmh.bpm.events.controller.TraspasoController" >
              <transition name="to custom2" to="custom2" g="9,-16"/>
           </custom>
           <custom name="custom2" g="166,176,92,52" class="cl.pred.cmh.bpm.events.controller.TraspasoController">
              <transition name="to custom3" to="custom3" g="-3,-25"/>
           </custom>
           <custom name="custom3" g="258,258,92,52" class="cl.pred.cmh.bpm.events.controller.TraspasoController">
              <transition name="to end1" to="end1" g="30,-36"/>
           </custom>
           <end name="end1" g="354,325,48,48"/>
        </process>
        
         
        

         

        For example, if BusinessHelper.doSomething() throws an Exception in custom 2 node, the "activityExecution.waitForSignal()" method will be invoked. This method commits the transaction and stops the execution.

         

        Then, if we need resume the process, we can use the "executionService.signalExecutionById(processKey)" method from a Web Service, Servlet, EJB, Helper, Timer or whatever. This method will invoke to the signal method of ControllerAbstract class.

         

        This example, with some variations, works for me ... and very good 

        • 16. Re: Exception handling in JBPM4 ?
          Ronald van Kuijk Master

          Compliments, great example and just how it was intended.

           

          Would be nice if someone could extend it this way and make e.g. a real custom node like:

           

          <myNode errorTransition="trans1">
              <transition name="trans1"/>
              <transition name="trans2"/>
          </myNode>
          
          

           

          Hints:

          - make a binding class

          - create e.g. a jbpm.user.jpdl.bindings.xml and add the binding class to that

          - import this file in jbpm.cfg.xml

          - ...

           

          Oh, and if someone would want to create a wiki page out of this would be great, of even a chapter in the dev guide.

           

          Cheers,

           

          Ronald

          • 17. Re: Exception handling in JBPM4 ?
            Ronald van Kuijk Master
            oh, the .... does not mean there is more to do, that should just be it.
            • 18. Re: Exception handling in JBPM4 ?
              Atul Joshi Newbie

              Thanks Harnan,

              This is very good example useful for us. But custom tag could not update the history table i.e (jbpm4_hist_actinst),

              Is there any way do to the same explicitly?

              • 19. Re: Exception handling in JBPM4 ?
                Ronald van Kuijk Master
                The best thing to do is fix this in the jBPM source and contribute the patch back.... ;-)
                • 20. Exception handling in JBPM4 ?
                  km wen Newbie

                  THX, it is very usful

                  1 2 Previous Next