14 Replies Latest reply on Jul 1, 2014 3:44 AM by lauradp

    Example of simple process of executing a service task in JBPM Console.

    dmwpepper

      Hi, I'm looking for examples on creating a simple process (start->service task->end)  that executes Java code in the JBPM Console, not Eclipse.  The examples I've seen don't show adding Java code to service tasks or they refer to executing the BPMN2 process in Eclipse, instead of the JBPM Console. I'm using JBPM5.4.  I'm sure someone's done this many times over, I'm just trying to get some ideas.  Thanks!

        • 1. Re: Example of simple process of executing a service task in JBPM Console.
          calca

          I guess you have to:

          - Create work item definition with some name, for example "MyTask".

          - Add a jar file with your WorkItemHandler implementation.

          - Create a session template attaching your custom work item handler to "My task".

          https://github.com/droolsjbpm/jbpm/blob/5.4.x/jbpm-gwt/jbpm-gwt-core/src/test/resources/default.session.template

           

          This will make that the Knowledge Session is able to execute the My Task node.

           

          But I think, to write your own work item handlers, you should have to use eclipse or some other IDE.

           

          HTH

           

          Demian

          • 2. Re: Example of simple process of executing a service task in JBPM Console.
            dmwpepper

            >> to write your own work item handlers, you should have to use eclipse or some other IDE.

             

            Well, that's where I'm confused.  I created the work item definitions with the Process Designer's built-in editor and the work items show up as tasks in the Process Designer.  The JBPM Console sees the BPMN2 process created in Process Designer, as its supposed to.

             

            If the BPMN2 process contains the work item definitions and the JBPM Console executes the BPMN2 process, shouldn't the work items also be executed by the Console?

            • 3. Re: Example of simple process of executing a service task in JBPM Console.
              calca

              What does your own work item definition do? Could you please mention an example of what you are trying to achieve?

               

              For example, if you have a custom work item definition, "Ping Server". Then, you will have to have some code that pings a server. You can have it inside the Console classpath, using it as I explained in the previuos comment. Or maybe calling a webservice?

               

              Demian

              • 4. Re: Example of simple process of executing a service task in JBPM Console.
                dmwpepper

                What I really want to do, as a first step, is to insert Java code into a Service task and run it in the JBPM Console. Using work item definitions is secondary.

                 

                For example, executing Java code in a Script task is easy.  I simple put the code in the script attribute, save the process and run the process containing the Script task in the JBPM Console.  

                 

                Service tasks are less obvious.  Setting aside the issue of work items, how do you insert Java code into a Service task in the way you can with a Script task? I'm just looking first to get a simple process containing one service task to run in the JBPM Console.

                • 5. Re: Example of simple process of executing a service task in JBPM Console.
                  salaboy21

                  Hi David,

                  As Demian mention, the only other way (and recommended way) to add your custom Java code is via a WorkItemHandler implementation. For that you will need a Java class. Once you have your java class you will need to create a Jar file (container of compiled java classes) and add that jar file to the jbpm console class path in order to use it. This means that the jbpm console needs to have access to your compiled class, in the same ways as any other application.

                   

                  This is a really common way of accepting extensions for any other java application, so it should be simple for you to create that.

                  • 6. Re: Example of simple process of executing a service task in JBPM Console.
                    dmwpepper

                    Ok, thanks, Mauricio and Demian.  I'm seeing now how this all fits, though I don't think I'll need the referenced template at this point. Thanks!

                    • 7. Re: Example of simple process of executing a service task in JBPM Console.

                      Hi David,

                       

                      Was your problem resolved? I'm doing things similar to what you were doing ... i wanted to create a Domain Specific service task called "CallaJava" for that i wrote the below workietm definition (WID)

                       

                      [

                        "name" : "CallJava",

                        "parameters" : [

                          "Interface" : new StringDataType(),

                          "Operation" : new StringDataType(),

                          "ParameterType" : new StringDataType(),

                          "Parameter" : new ObjectDataType("com.sample.service.Student")

                        ],

                        "results" : [

                          "Result" : new ObjectDataType("java.util.Map")

                        ],

                        "displayName" : "CallJava",

                        "icon" : "http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/java-icon/binary" ,

                        "defaultHandler" : "com.sample.service.ExtendedServiceTaskHandler"

                        ]

                       

                      I've put the jar containing my custom WorkItemHandler, a class called "com.sample.service.ExtendedServiceTaskHandler" witin jbpm-gwt-console-server.war/WEB-INF/lib

                       

                      I've added an entry in the jbpm-gwt-console-server.war/WEB-INF/classes/META-INF/CustomWorkItemHandlers.conf (like below)

                       

                      [

                        "Log": new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler(),

                        "CallJava": new com.sample.service.ExtendedServiceTaskHandler(ksession),

                      ]

                       

                      Now i can get this handler invoked with parameters that i mentioned in the WID, i can have any java code invoked from within the handler, BUT my problem is that i can't pass any variables from the process flow (defined in the BPMN process in designer) into this handler - i can only pass literal values (of primitive types like String, int etc.). Have you been able to do that?

                       

                       

                      Thanks

                      Sumeru

                      ---

                      • 8. Re: Example of simple process of executing a service task in JBPM Console.
                        dmwpepper

                        Thanks Sumeru.   I haven't gotten this far, yet.  Do you have to put the default handler in the work item definition?

                        • 9. Re: Example of simple process of executing a service task in JBPM Console.
                          alvinuw

                          I developed the process in eclipse. Let's say I generate a "process.jar" from eclipse. It contains the main file and also the handler class "ExtendedServiceTaskHandler.class".

                          If I just put "process.jar", instead of "com.sample.service.ExtendedServiceTaskHandler.jar", can it work?

                           

                          Actually, I tried this way. It seems it doesn't work.

                          Does it mean we have to jar the handler class, then put it in war, instead of the project jar?

                          Thanks.

                          • 10. Re: Example of simple process of executing a service task in JBPM Console.

                            Hi David - thanks for your reply. I've got this problem resolved of creating Domain specific service handlers.

                             

                            @Alvinuw - I'm not sure if you're also trying the same stuff as i was doing but below are the steps i did for getting a domain specific handler working in jBPM 5.4 & jBoss BRMS 5.3

                             

                            1. Modify the Work definition in Guvnor

                            2. Upload the icon image for your new Domain specific service (for my case CallJava) into Guvnor

                             

                            ** After these 2 steps done successfully, the new Service Task icon will start appearing in your component pallete of the designer under the section Service Task

                             

                            3. Put the jar containing custom work item handler class into jbpm-gwt-console-server.war (for jbpm 5.4) or jbpm-business-central-server.war (for jboss brms) -> WEB-INF/lib

                            4. Modify and added an entry in the (...)-server.war/WEB-INF/classes/META-INF/CustomWorkItemHandlers.conf (like below)

                            [

                              "Log": new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler(), // this was existing from before

                              "CallJava": new com.sample.service.ExtendedServiceTaskHandler(ksession),

                            ]

                            5. If the drools.session.conf file is present in (...)-server.war/WEB-INF/classes/META-INF/, make sure it has the below line. (In BRMS, these 2 files drools.sssion.conf & CustomWorkItemhandler.conf  are not there initially, you need to create them in brms. jBPM 5.4 already had these files)


                            drools.workItemHandlers = CustomWorkItemHandlers.conf

                            6. Include the service task in your BPMN2 flow and do proper Parameter Mapping (Data Input Assignments) to pass in Process Variables. Make sure whatever values you want to pass into the handler's "execute" method, they're already set into kcontext by executing the kcontext.setVariable("someProcessVar", someProcessVar)

                             

                            Hope these help.

                             

                            Thanks

                            Sumeru

                            ---

                            • 11. Re: Example of simple process of executing a service task in JBPM Console.
                              alvinuw

                              Hi Sumeru,

                               

                              Thank you for your information.

                               

                              For your 6th point, I do have two variables to pass into my handler.

                              Which file should I add "kcontext.setVariable("someProcessVar", someProcessVar)"

                              Actually, I use eclipse to develop the process, I have one main.java, and two handler.java.

                               

                              Thanks.

                              • 12. Re: Example of simple process of executing a service task in JBPM Console.
                                dmwpepper

                                Thanks Sumeru, I came to the same solution over this weekend.  Your responses helped a lot.  It seems to me that .jar files should be automatically deployable in an application server instead of having to open .war files, but I may be wrong.

                                 

                                Thanks again,

                                Dave

                                • 13. Re: Example of simple process of executing a service task in JBPM Console.
                                  harish.dasari

                                  Hi sumeru, Iam using workitemhandler to call java class, how can i call my java class within workitemhandler, can u please show me the example

                                  • 14. Re: Example of simple process of executing a service task in JBPM Console.
                                    lauradp

                                    Hi,

                                    Is editing bpm-gwt-console-server.war the only way for having custom workitem handlers workingin the designer???

                                     

                                    Laura