Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

jbpm - JBPM6 Service task to execute java code

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.

Thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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) 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) Create a Work Item Handler Config file in src/main/resources/META-INF/CustomWorkItemHandlers.conf

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

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

drools.workItemHandlers = CustomWorkItemHandlers.conf

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) 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());

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...