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 sp
I know the question is already answered, but I wanted to do the same (execute java code in service task) without creating work item definition (I did't want to use a custom task but a service task as it is). This is how I solved it:
here I read about the ServiceTaskHandler but I couldn't find very good info about the usage.
I read the ServiceTaskHandler code, it uses reflection to run your java code.
I found this (it says jbpm5-samples but I tested with jbpm 6.3), it uses a service task, the service task executes method "hello" from a Class (HelloService) you create:
package com.test;
import java.util.HashMap;
import java.util.Map;
public class HelloService {
public DataOutput hello(com.test.DataInput name) {
Map dataMap = new HashMap();
dataMap.put("s", "Hello " + name.getDataMap().get("s") + "!");
DataOutput output = new DataOutput(dataMap);
return output;
}
}
The ServiceTaskHandler is registered the same way as the step (5) in the answer marked correct:
//Get session
KieSession ksession = runtime.getKieSession();
//Register handlers
ksession.getWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler());
After that I associated the service task with the java class (HelloService - method hello). To do that I used the eclipse bpmn modeler but I didn't find it very intuitive, so I opened the sample's bpmn file (BPMN2-ServiceProcess.bpmn2) with the modeler and filled my service task with the same stuff I read there.