3 Replies Latest reply on Jul 20, 2015 9:57 AM by abhijithumbe

    jBPM 6.2 : Sample code to invoke a java method from service task

    qwirkle101

      Hi

       

       

      I'm new to JBPM and looking for some help to invoke a java method from service node. I've created a processes from JBpm console and added a service node, but I could not find any document which clearly shows how to build the jar and deploy to the console. Can you please provide any sample code which provide step by step instruction to achieve this?  Any pointers is really appreciated.

        • 1. Re: jBPM 6.2 : Sample code to invoke a java method from service task
          abhijithumbe

          Build standard jar of workItemHandler class using jar -cvf command and add jar with handler class under jbpm-console.war/WEB-INF/lib or classes directory.

                       OR

          Upload jar with handler class into business-central via Authoring -> Artifact Repository.

          Add this artifact as a project dependency via `Authoring -> Project Authoring -> Tools -> Project Editor -> Project Settings -> Dependencies -> Add from Repository.

           

           

          Register WorkItem handler in kmodule.xml of your project(kajr), like this:

          ~~~

          <workItemHandlers> 

              <workItemHandler name="Sysout" type="new com.sample.helloworld.workitem.SystemOutWorkItemHandler()"/>

          </workItemHandlers>     

          ~~~

          In jBPM 6.2 we can register workItemHandler through jbpm-console.war/WEB-INF/classes/META-INF/kie-wb-deployment-descriptor.xml as well.

          Hope it helps

          • 2. Re: jBPM 6.2 : Sample code to invoke a java method from service task
            qwirkle101

            Thanks Abhijit. I followed the below steps

             

             

            1. Created jar with an WIH

             

            public class HelloWorkItemHandler implements WorkItemHandler {

             

              public void abortWorkItem(WorkItem wi, WorkItemManager wim) {

              System.out.println("Oh no, my item aborted..");

              }

             

              public void executeWorkItem(WorkItem wi, WorkItemManager wim) {

              System.out.println("Hello World!");

              }

             

            }

             

            2. Imported it to the repository

            3. Add it to the project (HR) as a project dependency. PS: I added a new process to the jpm-playground - HR  

               Service Task Entry

                      - Service Interface: mytest.jbpm.HelloWorkItemHandler

                      - Service Operation: executeWorkItem

             

            4. Registered workItemHandler through jbpm-console.war/WEB-INF/classes/META-INF/kie-wb-deployment-descriptor.xml

             

            I'm getting the error when I run the instance  : "java.lang.NoSuchMethodException: mytest.jbpm.HelloWorkItemHandler.executeWorkItem(java.lang.Object)"

             

            Alos, I see the following exception in the log:

             

            "2015-07-18 22:17:16,487 WARN  [org.jbpm.kie.services.impl.KModuleDeploymentService] (MSC service thread 1-8) Unexpected error while deploying unit org.guvnor:guvnor-asset-mgmt-project:6.2.0.Final: java.lang.RuntimeException: [Error: could not resolve class: mytest.jbpm.HelloWorkItemHandler from [Module "deployment.jbpm-console.war:main" from Service Module Loader]]

            [Near : {... new mytest.jbpm.HelloWorkItemHandl ....}]"

             

             

            Am I missing anything?

            • 3. Re: jBPM 6.2 : Sample code to invoke a java method from service task
              abhijithumbe

              Hi,

              java.lang.NoSuchMethodException: Looks like you are using different version of JDK at compile time and at runtime. Make sure you are using same version of JDK.

              I have attached WorkItemHandler jar and kjar for your reference, take a look at it.