14 Replies Latest reply on Feb 8, 2010 7:22 PM by Flavio N.

    Exception handling in JBPM4

    Peter Weemeeuw Newbie
      Hi,
      I have some questions about exception handling in JBPM4.
      1) It seems we can't yet use exception handlers in JBPM4, we don't see any examples covering this and the JBPM4 documentation about exception handling is not clear (http://docs.jboss.com/jbpm/v4/devguide/html_single/#d0e2126). In "known limitations" it is mentioned as not yet available in JBPM4? If this is not yet usable then what is the recommended way to handle exceptions? Or should we use JBPM3 because there the exception handlers are implemented?
      2) If an unhandled runtime exception occurs, I cannot see any history of the process because everything is rolled back. What is the recommended way to achieve this? Or should we always catch all exceptions? Is there documentation and/or examples for these situations?
      Thanks and best regards,
      Peter
        • 1. Re: Exception handling in JBPM4
          M Porter Newbie

          I am trying to implement some error handling in jBPM 4.2 and also would like to know how it should be done. We are attempting to implement error handling subflows with automatic retry and then manual task. But we are running into lots of issues with subflows not working etc.

          I am sure that someone must have already done this in jBPM 4.X as it is a common use case...unless everyone is building just huge single process apps which I find hard to believe ?.

           

          Has anyone got any pointers on how to best design and implement error handling with jBPM 4.X ?.

           

          We are attempting to encapsulate our business system interaction with session EJB and then invoke those actions as custom java classes from jBPM so that the whole interaction will take place in a JTA transaction (read this related to a JBPM article). However I dont know if this is the best way to do it or if it is the recommended way. Hoping that someone has already done it and may have some advice.

           

          Regards

          Martin

          • 2. Re: Exception handling in JBPM4
            ciccio ciccio Newbie

            Hi ppl,

            how is possible that noone catches exceptions? Im sure im missing something! Is there someone that knows how to catch a simple java.lang.Exception in desing mode (jBPM 4.3)?

            Thanks for help.

            Bye

            • 3. Re: Exception handling in JBPM4
              Flavio N. Newbie

              This is my first exeperience in JBPM 4 and I can't believe it does not have a way to handle Exceptions in Java, especially if it was in JBPM 3.

              Consider a very simple example:

               

              jbpm.png

               

              corresponding to code:

               

              <?xml version="1.0" encoding="UTF-8"?>

              <process name="MyProcess" xmlns="http://jbpm.org/4.3/jpdl">

                  <start g="122,135,48,48" name="startBlock">
                      <transition g="-55,-18" name="execute method" to="Call Java Method" />
                  </start>

                  <java name="Call Java Method" class="org.jbpm.helloworld.MyClass" continue="sync"
                      g="291,136,112,52" method="doSomething">
                      <transition name="terminate process" to="endBlock" g="-42,-18" />
                  </java>

                  <end g="519,136,48,48" name="endBlock" />

              </process>

               

              If my Java method throws an Exeception, HOW CAN IT BE HANDLED IN JBPM 4? Obviously I don't want to wrap each class to make a try-catch, so I suppose there is a way to define exception handler and redirect execution to a specified transition or something.

              A sample code will be appreciate.

              Thanks in advance

              • 4. Re: Exception handling in JBPM4
                M Porter Newbie

                Well the simple option is to use <custom> instead of <java> and then you have access to the process Exection context and you can then use the execution.take(transition-name) to define which transition should be taken on the error case and not throw it back to the BPM engine. We wrap this in a subprocess so the subprocess implements the business service (java code) and handles the error/retry/timeout and then the return from the subprocess defines which transition is taken in the parent process.

                 

                I am sure there are plenty of other ways however but this is working for us.

                 

                Regards

                Martin

                • 5. Re: Exception handling in JBPM4
                  Flavio N. Newbie
                  use <custom> instead of <java>

                   

                  custom seems to do not support "var" argument, so where can I put the result value of the Java method?

                   

                  you have access to the process Exection context and you can then use the execution.take(transition-name) to define which transition should be taken on the error case

                   

                  Conceptually I understand, but probably I am still not familiar with JBPM:

                  where exactly execution.take(transition-name) takes place? Is it Java code or what? If it should be placed in the Java method I call, it assumes I have to modify Java methods to handle errors in JBPM???

                  I supposed there was some code to put in jpdl.xml to perform this. If you can modify the simple code I posted to show me what you're talking about it could be great.

                   

                  Thanks

                  • 6. Re: Exception handling in JBPM4
                    M Porter Newbie

                    You can store the result in the process execution using execution.setVariable(). Your custom class would implement the ExternalActivityBehaviour and hence inside the execute() method you do your processing and at the end you call execution.takeXXXXX() with the name of the transition. Alternatively you can store a variable in the process execution and then have a decision handler implementing DecisionHandler in which you can check its value and return the transition from the decide() method.

                     

                    Regards

                    Martin

                    • 7. Re: Exception handling in JBPM4
                      Flavio N. Newbie

                      jedizippy ha scritto:

                       

                      Your custom class would implement the ExternalActivityBehaviour

                       

                      Well, the custom class - MyClass in the example I posted - is a third-party class and I can't modify it; I have to call its method as-is and I'd like to handle the exception. Because it's not the only class and method I would like to call in the process and they have different input and output parameters it's not feasible to wrap all of them with implementations of ExternalActivityBehaviour.

                      Is it not possible to make the same things with XML elements in the jpdl.xml file?

                      • 8. Re: Exception handling in JBPM4
                        M Porter Newbie

                        I _think_ you can use an EventListener but I have not tried it. Otherwise maybe this related post helps.....

                         

                        http://community.jboss.org/thread/147634?tstart=0

                         

                        Regards

                        Marrin

                        • 9. Re: Exception handling in JBPM4
                          Sebastian Schneider Master

                          I am not sure but I think it's not possible with EventListeners. My question for the core developers would be: Is it possible to create such an event and to enable users to define an exception handler for java activities?

                          • 10. Re: Exception handling in JBPM4
                            Sebastian Schneider Master
                            Seems I found the answer to question nr.2 which I forgot to ask: Does it make sense? As Ronald stated in a different thread it does not. Hope I understood you correctly, Ronald.
                            • 11. Re: Exception handling in JBPM4
                              Ronald van Kuijk Master

                              VegaMilano wrote:

                               


                              jedizippy ha scritto:

                               

                              Your custom class would implement the ExternalActivityBehaviour

                               

                              Well, the custom class - MyClass in the example I posted - is a third-party class and I can't modify it; I have to call its method as-is and I'd like to handle the exception.

                               

                              Because it's not the only class and method I would like to call in the process and they have different input and output parameters it's not feasible to wrap all of them with implementations of ExternalActivityBehaviour.

                              Is it not possible to make the same things with XML elements in the jpdl.xml file?

                              No, currently it is not and there is no priority for it. Simply because handling low level exceptions like java exceptions should normally not 'bubble up' to the processlevel. In 3 it was also not adviced to change the process state runtime in exceptionhandlers... So.... Personally if there are java exeptions , I would just want them to roll back my transaction to the state it was and have a retry. What I do not get is why you would not want to wrap them in another java class but do want to handle the exeption in a certain node where you most likely need to create custom java classes per class you have.

                               

                              How many classes are we talking about? 4? 6? 100?

                               

                              If there are many, you can always look at the implementation of JavaActivity and JavaBehaviour and create ONE custom node that does waht you want AND can direct/steer the process.... So... be creative, be patient, be polite....

                               

                              Cheers,

                               

                              Ronald

                              • 12. Re: Exception handling in JBPM4
                                Flavio N. Newbie

                                kukeltje ha scritto:


                                handling low level exceptions like java exceptions should normally not 'bubble up' to the processlevel. In 3 it was also not adviced to change the process state runtime in exceptionhandlers... So.... Personally if there are java exeptions , I would just want them to roll back my transaction to the state it was and have a retry. What I do not get is why you would not want to wrap them in another java class but do want to handle the exeption in a certain node where you most likely need to create custom java classes per class you have.

                                 

                                How many classes are we talking about? 4? 6? 100?

                                 

                                If there are many, you can always look at the implementation of JavaActivity and JavaBehaviour and create ONE custom node that does waht you want AND can direct/steer the process.... So... be creative, be patient, be polite....

                                 

                                Sorry if I seemed rude.

                                 

                                However thanks for the answer. It seems I had a wrong concept about BPM and I expected to can handle our classes directly from jBPM flow; giving credti to your answer it's now clear there are no better (other) way than handle custom classes which manage everything else (our classes including exceptions) inside them, returning state value or variables to evaluate in flow.

                                 

                                I still am worry about I was not able to find an example or testcase about something like this: if you are able to give us a reference, the name of an example or a link to something it can be useful for us. Obviously I am talking about something that works in JBPM4 version.

                                 

                                Thanks in advance

                                Flavio

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

                                  Sorry for the late response, totally forgot about this thread and it is not personal :-) and forget about the 'rude' thing, no sweat. Lets be constructive.

                                   

                                  Your request about how to do 'this' is what is unclear to me. There is an example of calling a java class in the examples folder in the distribution. You can do whatever you want in that class. You can e.g. pass a variable in that as a value has the FQCN and via reflection call a method (you can also pass that as a variable).

                                   

                                  If you go the custom node way (maybe even in the form of a kind of java activity of which you can use the source code as an basis) there also is one in the examples folder.

                                   

                                  So please have a look at those first, be a little creative and get back with more detailed requests. We're more then willing to help out then.

                                  • 14. Re: Exception handling in JBPM4
                                    Flavio N. Newbie

                                    kukeltje ha scritto:

                                     

                                    Your request about how to do 'this' is what is unclear to me. There is an example of calling a java class in the examples folder in the distribution. You can do whatever you want in that class.

                                     

                                    The point was we expected to call our classes directly in Java or custom nodes, and so we was searching on how to handle exeception or errors, while - as you explained before - in this nodes we have to call custom classes in which we manage our classes, errors and so on returning or setting variables or transiction name useful for jBPM.

                                    We read examples and guides for sure, but you have to understand we are evaluating different products and we aspect to have a quick start to understand their potentiality and learning curve.

                                    Actually, we are still implementing some basic workflows working with our classes and we hope to get a result in a few days.