6 Replies Latest reply on Apr 30, 2013 12:52 PM by Shobhit Tyagi

    Register more than one WorkItemHandler

    Shobhit Tyagi Master

      How do I register the workitem handler if I have both human tasks and mail tasks in my process?

      Thanks.

        • 1. Re: Register more than one WorkItemHandler
          Demian Calcaprina Master

          should it be

           

          session.getWorkItemManager().registerWorkItemHandler("Human Task",

          wsHumanTaskHandler);

          session.getWorkItemManager().registerWorkItemHandler("Email",

          emailHandler);

           

          ?

          • 2. Re: Register more than one WorkItemHandler
            Shobhit Tyagi Master

            I have tried that Demian. It doesnt work. It just takes the Human Task handler and ignores the other one.

            • 3. Re: Register more than one WorkItemHandler
              Sergey Kornilov Newbie

              you have dependency for  workItemHandlers

                          <dependency>

                          <groupId>org.jbpm</groupId>

                          <artifactId>jbpm-workitems</artifactId>

                          <version>5.4.0.Final</version>

                          <exclusions>

                              <exclusion>

                                 <groupId>dom4j</groupId>

                                 <artifactId>dom4j</artifactId>

                              </exclusion>

                          </exclusions>           

                      </dependency> ?

               

                      ksession.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler);

                      ksession.getWorkItemManager().registerWorkItemHandler("Service Task", new org.jbpm.process.workitem.bpmn2.ServiceTaskHandler(ksession));

                      ksession.getWorkItemManager().registerWorkItemHandler("Email", new org.jbpm.process.workitem.email.EmailWorkItemHandler("smtp.yandex.ru","587","email@yandex.ru","password"));

                      ksession.getWorkItemManager().registerWorkItemHandler("Log", new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler());

               

              I try EmailWorkItemHandler, it work. Or you have custom emailhandler?

              • 4. Re: Register more than one WorkItemHandler
                Shobhit Tyagi Master

                Sergey,

                 

                I use a custom email handler, but it doesnt work with the EmailWorkItemHandler either. I dont use maven. Below is the stack trace after I try to complete the task,

                 

                   org.jbpm.workflow.instance.WorkflowRuntimeException: [com.sample.mailTestProcess:36 - Email:4] -- Could not find work item handler for Email
                at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:132)
                at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerNodeInstance(NodeInstanceImpl.java:279)
                at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:238)
                at org.jbpm.workflow.instance.impl.ExtendedNodeInstanceImpl.triggerCompleted(ExtendedNodeInstanceImpl.java:47)
                at org.jbpm.workflow.instance.node.StateBasedNodeInstance.triggerCompleted(StateBasedNodeInstance.java:216)
                at org.jbpm.workflow.instance.node.StateBasedNodeInstance.triggerCompleted(StateBasedNodeInstance.java:196)
                at org.jbpm.workflow.instance.node.WorkItemNodeInstance.triggerCompleted(WorkItemNodeInstance.java:247)
                at org.jbpm.workflow.instance.node.HumanTaskNodeInstance.triggerCompleted(HumanTaskNodeInstance.java:90)
                at org.jbpm.workflow.instance.node.WorkItemNodeInstance.workItemCompleted(WorkItemNodeInstance.java:309)
                at org.jbpm.workflow.instance.node.WorkItemNodeInstance.signalEvent(WorkItemNodeInstance.java:285)
                at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.signalEvent(WorkflowProcessInstanceImpl.java:342)
                at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.completeWorkItem(JPAWorkItemManager.java:121)
                at org.drools.command.runtime.process.CompleteWorkItemCommand.execute(CompleteWorkItemCommand.java:69)
                at org.drools.command.runtime.process.CompleteWorkItemCommand.execute(CompleteWorkItemCommand.java:32)
                at org.drools.command.impl.DefaultCommandService.execute(DefaultCommandService.java:36)
                at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:373)
                at org.drools.command.impl.CommandBasedStatefulKnowledgeSession$1.completeWorkItem(CommandBasedStatefulKnowledgeSession.java:150)
                at pe.com.bcp.model.BpmAPI.completeWorkItem(BpmAPI.java:428)
                at pe.com.bcp.model.BpmAPI.completeTask(BpmAPI.java:273)
                at pe.com.bcp.ejb.JbpmAPIUtilEJB.completeTask(JbpmAPIUtilEJB.java:50)
                at pe.com.bcp.ejb.remote.EJSRemote0SLJbpmAPIUtilEJB_b19ab225.completeTask(EJSRemote0SLJbpmAPIUtilEJB_b19ab225.java)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
                at java.lang.reflect.Method.invoke(Method.java:611)
                at com.ibm.rmi.util.ProxyUtil$4.run(ProxyUtil.java:609)
                at java.security.AccessController.doPrivileged(AccessController.java:280)
                at com.ibm.rmi.util.ProxyUtil.invokeWithClassLoaders(ProxyUtil.java:606)
                at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDelegate.java:1177)
                at $Proxy164.completeTask(Unknown Source)
                at pe.com.bcp.ejb.remote._JbpmAPIUtilEJBRemote_Stub.completeTask(_JbpmAPIUtilEJBRemote_Stub.java:1)
                at pe.com.bcp.bean.TaskBean.completeTask(TaskBean.java:165)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
                at java.lang.reflect.Method.invoke(Method.java:611)
                at org.apache.el.parser.AstValue.invoke(AstValue.java:266)
                at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
                at org.apache.myfaces.view.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:83)
                at javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBinding.java:88)
                at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:100)
                at javax.faces.component.UICommand.broadcast(UICommand.java:120)
                at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:973)
                at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:275)
                at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1285)
                at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:711)
                at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:34)
                at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
                at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
                at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1214)
                at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:774)
                at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:456)
                at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
                at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1027)
                at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3703)
                at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
                at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:962)
                at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
                at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
                at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
                at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:522)
                at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:311)
                at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:87)
                at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
                at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
                at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
                at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
                at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
                at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
                at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
                at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1783)
                Caused by: org.drools.WorkItemHandlerNotFoundException: Could not find work item handler for Email
                at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.throwWorkItemNotFoundException(JPAWorkItemManager.java:62)
                at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.internalExecuteWorkItem(JPAWorkItemManager.java:57)
                at org.jbpm.workflow.instance.node.WorkItemNodeInstance.internalTrigger(WorkItemNodeInstance.java:107)
                at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:126)
                ... 71 more

                • 5. Re: Register more than one WorkItemHandler
                  Sergey Kornilov Newbie

                  I add new WorkItemHandler to WorkDefinitions and create process with it

                   

                  [

                      "name" : "CustomHandler",

                      "parameters" : [

                        "Message" : new StringDataType()

                      ],

                      "displayName" : "CustomHandler",

                      "icon" : ""

                    ]

                  for answer3.png

                   

                   

                   

                   

                  create new class

                   

                  import org.drools.process.instance.WorkItemHandler;

                   

                         class CustomWorkItemHandler implements WorkItemHandler{

                   

                              @Override
                              public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
                                  // TODO Auto-generated method stub
                                  System.out.println("**************************** CustomWorkItemHandler executeWorkItem"+ workItem.getProcessInstanceId());
                              }

                   

                              @Override
                              public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
                                  // TODO Auto-generated method stub
                                  System.out.println("**************************** CustomWorkItemHandler abortWorkItem" + workItem.getProcessInstanceId());
                              }
                                
                         }

                   

                  register  WorkItemHandler

                           

                  ksession.getWorkItemManager().registerWorkItemHandler("CustomHandler", new CustomWorkItemHandler());

                   

                  run process and get result

                  19:00:18,103 INFO  [stdout] (http--0.0.0.0-8080-34) **************************** CustomWorkItemHandler executeWorkItem170

                   

                  you have some error when register your custom email handler?

                  • 6. Re: Register more than one WorkItemHandler
                    Shobhit Tyagi Master

                    Sergey,

                     

                    Thanks for your response. But this thing doesnt work with the EmailWorkItemHandler either. This is the code I use to start the process.

                     

                    StatefulKnowledgeSession ksession = BpmRepositoryConfig.createSession();
                      KnowledgeRuntimeLogger logger1 = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "testlog", 1000);
                      taskHandler = new HornetQHTWorkItemHandler(ksession);
                      taskHandler.setIpAddress(ipAddress);
                      taskHandler.setPort(port);
                      ksession.getWorkItemManager().registerWorkItemHandler("Human Task", taskHandler);
                      EmailWorkItemHandler emailHandler1 = new EmailWorkItemHandler();
                      emailHandler1.setConnection("localhost","25", "styagi@bcp.com.pe", "Tyagi04");
                      emailHandler1.getConnection().setStartTls(true);
                      ksession.getWorkItemManager().registerWorkItemHandler("Email",emailHandler1);
                         JPAWorkingMemoryDbLogger logger2 = new JPAWorkingMemoryDbLogger(ksession);
                           ksession.startProcess(processDefId);
                      ksession.fireAllRules();
                      if(taskHandler.isConnected())
                      {
                       taskHandler.dispose();
                      }
                      logger2.dispose();
                      logger1.close();
                      ksession.dispose();

                     

                    I dont face a problem starting the process. There is one human task followed by one mail node in my process definition.

                    I complete the task and it gives me No handler found for Email exception.