14 Replies Latest reply on Jan 24, 2011 12:05 PM by salaboy21

    JBPM5 Exception Handling

    npereira

      Hi Forum,

       

      I have been working with JBPM5 RC1 with great interest.

       

      But one doubt has arisen, and that is regarding Exception Handling.

       

      How is JBPM5 handling exceptions? How can we in a script task. for example, handle a exception that might occur?

       

      Regards

        • 1. JBPM5 Exception Handling
          salaboy21

          Hi there..

          if you are using a Script task with java code in it, you must handle the exception with a Try/Catch block as you normally do it Java. If you are talking about business exceptions (not java, not related with java code at all) that's a different story. But they are not Java exceptions, they are business exceptions.

          Greetings.

          • 2. JBPM5 Exception Handling
            npereira

            Hi,

             

            Thank you for your reply....

             

            The problem I'm facing is,  for example, if I need to contact a webservice.

            If this fails, what can I do besides managing errors in Java Code. Can I for example, suspend the script task? And later come to it and resume it and re-run it?

             

            Another thing is what does the "Error Event" do? How does it work?

             

            Regards

            • 3. JBPM5 Exception Handling
              salaboy21

              Hi there, I recommend you to take a look at work items / custom domain specific nodes... You can create sync and async workitems to have different mechanisms for retrying an execution. Using script task for calling a web service is not recommened. The reasons are all the ones that you mention. (remember that you are basically coding java inside an XML file). The Error Event is about Business Expcetions / that node can be used to model a branch of the process that needs to be executed on exceptional business cases.. (not java / low level related problems).

              Greetings.

              • 4. JBPM5 Exception Handling
                npereira

                Hi there,

                 

                That sounds exactly what I'm looking for.

                 

                Can you please, tell me where I can find more information on sync and async workitems, and in particular how can I create one?

                 

                Regards.

                • 5. JBPM5 Exception Handling
                  salaboy21

                  Hi there.. it's a very simple mechanism. You need to implement the WorkItemHandler interface and put your logic inside the execute() method.

                  Then you need to register you implementation in the workItemManager inside the session:

                  ksession.getWorkItemManager().registerWorkItemHandler( "MyWorkItemManager",

                                                                                 myImplementation );

                  • 6. JBPM5 Exception Handling
                    npereira

                    Hi,

                     

                    Thanks for your answer....

                     

                    Although I was more looking for something along the lines of how to develop a new object to add it on the BPMN UI of eclipse.

                     

                    The idea is that, when I'm modeling new workflows I will be able to use and re-use this object in different occasions.

                     

                    Is this possible? and is there any documentation I should be looking at?

                     

                    Regards

                    • 7. JBPM5 Exception Handling
                      salaboy21

                      The solution that I've proposed to you is exaclty that. You can reuse your work items in different processes and you can also attach workitem definitions to your eclipse palette.

                      Take a look at:

                      http://downloads.jboss.com/drools/docs/5.1.1.34858.FINAL/drools-flow/html_single/index.html#ch.Domain_Specific_Processes

                      To see how to acheive that.

                      Greetings!

                      • 8. JBPM5 Exception Handling
                        npereira

                        Hello,

                         

                        This really seems what I'm looking for, but unfortunately I'm running into some troubles.

                         

                        I don't quite understand the following the "Registering the work definition".

                         

                        It says that we should: "For example, include a drools.rulebase.conf file in the META-INF directory of your project"

                        But I don't have a META-INF on my project!? can I put it any where else?

                        • 9. JBPM5 Exception Handling
                          salaboy21

                          Hi there,

                          No, just create the META-INF directory and the file inside it. Are you using maven? the META-INF directory should be included inside the application classpath, so you probably want to create it in src/java/main/META-INF/

                          Greetings.

                          • 10. JBPM5 Exception Handling
                            npereira

                            Hi there,

                             

                            Thank you for that.

                            I did that, but I think it's not picking up my "MyWorkDefinitions.conf" file

                             

                            I've place this file all over the project, but it continues to say: "Could not parse work definitions MyWorkDefinitions.conf:null"

                             

                            Can you help me out?

                            • 11. JBPM5 Exception Handling
                              salaboy21

                              can you share your MyWorkDefinitions.conf file? probably there is a missing bracket or something missing.

                              Greetings

                              • 12. JBPM5 Exception Handling
                                npereira

                                Sure,

                                Although, after trying several combinations, I remove the file itself from the entire project and tried it again. And the result was the same, "Could not parse work definitions MyWorkDefinitions.conf:null"

                                 

                                But nevertheless, the file is the following:

                                 

                                import org.drools.process.core.datatype.impl.type.StringDataType;

                                [

                                  // the Notification work item

                                  [

                                    "name" : "Notification",

                                    "parameters" : [

                                      "Message" : new StringDataType(),

                                      "From" : new StringDataType(),

                                      "To" : new StringDataType(),

                                      "Priority" : new StringDataType(),

                                    ],

                                    "displayName" : "Notification"

                                  ]

                                 

                                 

                                ]

                                • 13. JBPM5 Exception Handling
                                  npereira

                                  Hi there,

                                   

                                  I was finally able to do it. I don't know why but I created a new project and with the same files, was able to do it.

                                  Just added everything into the Meta-Inf directory and everything worked out!

                                   

                                  Thanks for all the help

                                  • 14. JBPM5 Exception Handling
                                    salaboy21

                                    Great, can you mark this question as answered, so we can close this thread?

                                    Greetings.