我已经在drools工作台(版本7.16.0.Final)上的项目中注册了一个工作项。我正在做的是在指导决策表中执行此工作项。
我可以看到当条件匹配时工作项就被执行了,但是不知道为什么抛出该异常。
2019-01-22 17:22:30.014 [http-nio-9043-exec-3] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is Exception executing consequence for rule "Row 2 decisiontable" in com.myproj.cdi: [Error: wim.internalExecuteWorkItem( wiQianhaiAddrWorkItemHandler ): null]
[Near : {... org.drools.core.process.instan ....}]
^
[Line: 1, Column: 1]] with root cause
java.lang.UnsupportedOperationException: null
at org.drools.core.impl.StatefulKnowledgeSessionImpl$DummyInternalProcessRuntime.getProcessInstance(StatefulKnowledgeSessionImpl.java:2223)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.getProcessInstance(StatefulKnowledgeSessionImpl.java:1884)
at org.drools.core.process.instance.impl.DefaultWorkItemManager.completeWorkItem(DefaultWorkItemManager.java:142)
at com.myproj.group.digital.cdi.QianhaiAddrWorkItemHandler.executeWorkItem(QianhaiAddrWorkItemHandler.java:32)
at org.drools.core.process.instance.impl.DefaultWorkItemManager.internalExecuteWorkItem(DefaultWorkItemManager.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1119)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1002)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:396)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:163)
at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113)
at org.mvel2.MVEL.executeExpression(MVEL.java:929)
at org.drools.core.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:110)
at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:431)
at org.drools.core.phreak.RuleExecutor.fireActivation(RuleExecutor.java:379)
at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:135)
at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:88)
at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:34)
at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1066)
at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1013)
at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1005)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1330)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1321)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1305)
at com.group.myproj.digital.cdi.decision.engine.service.CdiKieWbService.checkAddress(CdiKieWbService.java:57)
at com.group.myproj.digital.cdi.decision.engine.controller.ApsKieController.checkAddressValidity(ApsKieController.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
这是我用来执行决策表中定义的规则的Java代码段。
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("com.myproj.poc", "cdi", "1.0.0");
KieContainer kContainer = ks.newKieContainer(releaseId);
KieScanner kScanner = ks.newKieScanner(kContainer);
kScanner.scanNow();
KieSession kSession = kContainer.newKieSession("cdiStatefulKieSession");
kSession.insert(request);
kSession.fireAllRules();
不知道为什么调用DummyInternalProcessRuntime。有人可以提示吗?
按照Tibor的建议。我已经用jBPM替换了Drools工作台,并在我的Java项目中添加了jBPM依赖项。但是,这次我又遇到了一个例外。
2019-01-24 13:53:53.865 [http-nio-9043-exec-2] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.ExceptionInInitializerError] with root cause
java.lang.ClassCastException: org.jbpm.assembler.BPMN2AssemblerService cannot be cast to org.kie.api.internal.assembler.KieAssemblerService
at org.kie.internal.services.KieAssemblersImpl.accept(KieAssemblersImpl.java:31)
at org.kie.api.internal.utils.ServiceDiscoveryImpl.buildMap(ServiceDiscoveryImpl.java:174)
at org.kie.api.internal.utils.ServiceDiscoveryImpl.getServices(ServiceDiscoveryImpl.java:97)
at org.kie.api.internal.utils.ServiceRegistryImpl.<init>(ServiceRegistryImpl.java:36)
at org.kie.api.internal.utils.ServiceRegistryImpl$LazyHolder.<clinit>(ServiceRegistryImpl.java:32)
at org.kie.api.internal.utils.ServiceRegistry.getInstance(ServiceRegistry.java:27)
at org.kie.api.KieServices$Factory$LazyHolder.<clinit>(KieServices.java:341)
at org.kie.api.KieServices$Factory.get(KieServices.java:348)
这是pom.xml中的依赖项。
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-workbench-models-guided-dtable</artifactId>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-flow</artifactId>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-flow-builder</artifactId>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-bpmn2</artifactId>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-persistence-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-human-task-core</artifactId>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-runtime-manager</artifactId>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-executor</artifactId>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-kie-services</artifactId>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-services-api</artifactId>
</dependency>
Kie服务器显示BPM已经具备功能。访问http://localhost:8080/kie-server/services/rest/server时,我看到如下响应。
<response type="SUCCESS" msg="Kie Server info">
<kie-server-info>
<capabilities>KieServer</capabilities>
<capabilities>BRM</capabilities>
<capabilities>BPM</capabilities>
<capabilities>CaseMgmt</capabilities>
<capabilities>BPM-UI</capabilities>
<capabilities>BRP</capabilities>
<capabilities>DMN</capabilities>
<capabilities>Swagger</capabilities>
<location>
http://localhost:8080/kie-server/services/rest/server
</location>
<messages>
<content>
Server KieServerInfo{serverId='sample-server', version='7.16.0.Final', name='sample-server', location='http://localhost:8080/kie-server/services/rest/server', capabilities=[KieServer, BRM, BPM, CaseMgmt, BPM-UI, BRP, DMN, Swagger], messages=null}started successfully at Sat Jan 26 17:15:20 CST 2019
</content>
<severity>INFO</severity>
<timestamp>2019-01-26T17:15:20.444+08:00</timestamp>
</messages>
<name>sample-server</name>
<id>sample-server</id>
<version>7.16.0.Final</version>
</kie-server-info>
</response>
答案 0 :(得分:0)
看起来您的项目中没有jBPM依赖项。 jBPM是一个流程运行时。当不在类路径上时,Drools将使用虚拟进程运行时来处理不支持所有可能操作的进程(因此是工作项),因此会出现异常。如果现在仅使用Drools工作台,请使用jBPM工作台[1],这基本上是相同的,只是具有额外的处理功能(捆绑了jBPM)。 jBPM项目是与Drools来自同一社区项目组(KieGroup)的项目。
答案 1 :(得分:0)
您能再描述一下您的用例吗?您如何在drools-wb中注册工作项处理程序,因为drools-wb中没有这样的功能。如果您有一个流程,并且该流程具有某个类型的节点,则将使用工作项处理程序,该节点将由工作项处理程序处理。如果您在决策表中有事实和规则,则不需要任何工作项处理程序来触发这些规则。
更新:
对不起,是的,您现在可以在决策表中使用工作项处理程序。
以下是适用于我们测试的配置:
kie-deployment-descriptor.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<deployment-descriptor xsi:schemaLocation="http://www.jboss.org/jbpm deployment-descriptor.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<persistence-unit>org.jbpm.domain</persistence-unit>
<audit-persistence-unit>org.jbpm.domain</audit-persistence-unit>
<audit-mode>JPA</audit-mode>
<persistence-mode>JPA</persistence-mode>
<runtime-strategy>SINGLETON</runtime-strategy>
<marshalling-strategies/>
<event-listeners/>
<task-event-listeners/>
<globals/>
<work-item-handlers>
<work-item-handler>
<resolver>mvel</resolver>
<identifier>new org.jbpm.process.workitem.bpmn2.ServiceTaskHandler(ksession, classLoader)</identifier>
<parameters/>
<name>Service Task</name>
</work-item-handler>
<work-item-handler>
<resolver>mvel</resolver>
<identifier>new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler()</identifier>
<parameters/>
<name>Log</name>
</work-item-handler>
<work-item-handler>
<resolver>mvel</resolver>
<identifier>new org.jbpm.process.workitem.webservice.WebServiceWorkItemHandler(ksession, classLoader)</identifier>
<parameters/>
<name>WebService</name>
</work-item-handler>
<work-item-handler>
<resolver>mvel</resolver>
<identifier>new org.jbpm.process.workitem.rest.RESTWorkItemHandler()</identifier>
<parameters/>
<name>Rest</name>
</work-item-handler>
<work-item-handler>
<resolver>reflection</resolver>
<identifier>new org.jboss.qa.brms.workitems.ResultWIHandler()</identifier>
<parameters/>
<name>ResultWI</name>
</work-item-handler>
<work-item-handler>
<resolver>reflection</resolver>
<identifier>new org.jboss.qa.brms.workitems.SimpleWIHandler()</identifier>
<parameters/>
<name>SimpleWI</name>
</work-item-handler>
</work-item-handlers>
<environment-entries/>
<configurations/>
<required-roles/>
<remoteable-classes/>
</deployment-descriptor>
所以我们已经注册了ResultWI和SimpleWI WIH。
现在kmodule.xml:
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<kbase name="kbase1" default="true" eventProcessingMode="stream" equalsBehavior="identity">
<ksession name="ksession" type="stateful" default="true" clockType="realtime">
<workItemHandlers>
<workItemHandler type="org.jboss.qa.brms.workitems.ResultWIHandler" name="ResultWI"/>
<workItemHandler type="org.jboss.qa.brms.workitems.SimpleWIHandler" name="SimpleWI"/>
</workItemHandlers>
</ksession>
</kbase>
<kbase name="defaultKieBase" default="false" eventProcessingMode="stream" equalsBehavior="identity"/>
</kmodule>
最后是WID文件:
resultWID.wid
import org.drools.core.process.core.datatype.impl.type.StringDataType;
import org.drools.core.process.core.datatype.impl.type.ObjectDataType;
[
[
"name" : "ResultWI",
"parameters" : [
"value" : new StringDataType()
],
"results" : [
"result" : new StringDataType()
],
"displayName" : "ResultWI"
]
]
simpleWID.wid
import org.drools.core.process.core.datatype.impl.type.StringDataType;
[
[
"name" : "SimpleWI",
"parameters" : [
"value" : new StringDataType()
],
"displayName" : "SimpleWI"
]
]
您可以确认您具有类似的配置吗?如果仍然无法正常运行,请尝试在KIE服务器上打开jBPM功能。而且您不必在类路径中包括jbpm依赖项,因为您的部署是在KIE Server中运行的,其中所有依赖项均可用。希望对您有所帮助。