Accessing KieSession from jbpm6 WorkItemHandler

微笑、不失礼 提交于 2019-12-24 04:22:42

问题


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!


回答1:


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>


来源:https://stackoverflow.com/questions/20862350/accessing-kiesession-from-jbpm6-workitemhandler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!