JBPM6服务任务执行java代码 [英] JBPM6 Service task to execute java code

查看:471
本文介绍了JBPM6服务任务执行java代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JBPM6的新手。我的场景是这样的,我想使用JBPM服务任务执行一些Java代码。从文档中我无法理解如何在这种类型的代码中使用特定于域的进程和工作项处理程序。
如果有人有示例,请分享。这将非常有用。

I am new in JBPM6. My scenario is like this that i want to execute some java code using JBPM service task.From documentation i am not able to understand how to use domain specific process and Work Item Handler in this type of code. If someone have sample example of it please share.That will be very much helpful.

提前谢谢。

推荐答案

以下是在Eclipse maven项目中添加处理程序的方法。我称之为Awesome处理程序,但你应该选择一个更具体的名称。

Here is how to add a handler inside a Eclipse maven project. I call it the Awesome handler, but your should pick a more specific name.

1)首先在src / main / resources / WorkItemDefinitions.wid中创建一个工作项定义文件。我的图标文件位于src / main / resources中。

1) First create a work item definition file in src/main/resources/WorkItemDefinitions.wid. My icon file is located in src/main/resources.

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

[
  [
    "name" : "Awesome",
    "parameters" : [
      "Message1" : new StringDataType(),
       "Message2" : new StringDataType()
     ],
    "displayName" : "Awesome",
    "icon" : "icon-info.gif"
  ]
]

2)在src / main / resources / META-中创建工作项处理程序配置文件INF / CustomWorkItemHandlers.conf

2) Create a Work Item Handler Config file in src/main/resources/META-INF/CustomWorkItemHandlers.conf

[
  "Awesome": new org.jbpm.examples.util.handler.AwesomeHandler()
]

3)创建一个drools会话配置文件:src / main / resources /META-INF/drools.session.conf

3) Create a drools session config file: src/main/resources/META-INF/drools.session.conf

drools.workItemHandlers = CustomWorkItemHandlers.conf

4)创建您的处理程序,使其与您在步骤2中定义的类匹配

4) Create your Handler so that it matches the class you defined in step 2

public class AwesomeHandler implements WorkItemHandler {

    public AwesomeHandler() {
        super();
    }

    public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
        System.out.println("Executing Awesome handler");
        manager.completeWorkItem(workItem.getId(), null);
    }

    public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
        System.out.println("Aborting");
    }
}

5)建立处理程序后,必须注册与你的会话。

5) After you establish the handler, you must register it with your session.

//Get session
KieSession ksession = runtime.getKieSession();

//Register handlers
ksession.getWorkItemManager().registerWorkItemHandler("Awesome", new AwesomeHandler());

此时你应该重启eclipse。当eclipse打开时,调色板中应该有一个自定义任务选项卡。它应该包含一个标有'Awesome'并带有指定图标的条目。

At this point you should restart eclipse. When eclipse opens, there should be a 'Custom Tasks' tab in the palette. It should contain an entry labeled 'Awesome' with the specified icon.

这篇关于JBPM6服务任务执行java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆