Reputation: 31
I'm using jbpm-console (6.0.0.Final) with custom work item handlers. I've embedded a custom work item handlers JAR in my jbpm-console WAR as described in post #7 here:
https://community.jboss.org/thread/221748
This is all fine so far, as I can successful start a process definition in jbpm-console, and it kicks off my custom WorkItemHandler code.
However, in my WorkItemHandler, I want to set some variables on the ProcessInstance. When I try something like this:
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
// BLOWS UP HERE
//
KieSession session = kContainer.newKieSession();
WorkflowProcessInstance processInstance =
session.getProcessInstance(workItem.getProcessInstanceId());
// SET VARIABLE
processInstance.setVariable("foo", "bar");
}
It "Cannot find a default KieSession":
11:21:03,177 ERROR Exception: java.lang.RuntimeException: Cannot find a default KieSession
at org.drools.compiler.kie.builder.impl.KieContainerImpl.findKieSessionModel(KieContainerImpl.java:302) [drools-compiler-6.0.0.Final.jar:6.0.0.Final]
at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:295) [drools-compiler-6.0.0.Final.jar:6.0.0.Final]
at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:278) [drools-compiler-6.0.0.Final.jar:6.0.0.Final]
What am I missing here? Do I have to set something additional up? I'm just using the out-of-the-box (with the exception of the custom work item handler embedded jar) "demo" install from here:
http://sourceforge.net/projects/jbpm/files/jBPM%206/jbpm-6.0.0.Final
Thanks!
Upvotes: 2
Views: 3729
Reputation: 1
Pass your kieSession into your workItemHandler as a constructor parameter. Then your kieSession is available to your workItemHandler.
You can register your workItemHandler when you need it with the appropriate kieSession, you do not have to do it only once.
Or you pass the rulesManager at the start and generate a kieSession on demand
Upvotes: 0
Reputation: 394
Do you have a kmodule.xml in your resources folder? If not maybe that's the problem. You can have a pretty simple xml file like:
<kmodule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/kie/6.0.0/kmodule">
</kmodule>
Upvotes: 5