当我在kie工作台中创建引导式决策表时,执行无状态或全状态kie会话时会出现空指针异常。更具体地说,我使用drools 7,并且使用java和grizzly公开了一个简单的rest服务。当我使用简单的drl文件时,规则会正确触发并执行,但是当我将决策表部署到jar中时,我会得到NPE。
Java代码:
public CustomerDto executeStatelessPOC(final String param,
final StatelessKieSession kSession ,final KieServices kServices) {
//Myexample is just the entry fact
InputDTO example = new InputDTO();
example.setField1(param);
CustomerDto response = new CustomerDto();
try {
KieCommands kieCommands = kServices.getCommands();
List<Command> cmds = new ArrayList<Command>();
cmds.add(kieCommands.newInsert(example));
cmds.add(kieCommands.newInsert(response, "customerResponse"));
//Execute rules with facts provided before
ExecutionResults results = kSession.execute(kieCommands.newBatchExecution(cmds));
//Get the response as part of the results
response = (CustomerDto) results.getValue("customerResponse");
return response;
} catch (Exception e) {
System.out.println("Exception e: " + e.toString());
System.out.println("Exception e: " + Arrays.toString(e.getStackTrace()));
}
return response;
}
指导决策表的源代码:
package gr.maven.test.testbuildinmaven;
//从行号开始:1
规则“第1行TestDecisionTable”
方言“ mvel”
什么时候
输入:InputDTO(field1 ==“ Test1”)
然后
CustomerDto fact0 =新的CustomerDto();
fact0.setCustomerMessage(“ yesss”);
insertLogical(fact0);
结束
//从行号开始:2
规则“第2行TestDecisionTable”
方言“ mvel”
什么时候
输入:InputDTO(field1 ==“ Test2”)
然后
CustomerDto fact0 =新的CustomerDto();
fact0.setCustomerMessage(“ yes2”);
insertLogical(fact0);
结束
//从行号开始:3
规则“第3行TestDecisionTable”
方言“ mvel”
什么时候
输入:InputDTO(field1 ==“ Test3”)
然后
CustomerDto fact0 =新的CustomerDto();
fact0.setCustomerMessage(“ yesss”);
insertLogical(fact0);
结束
例外:
WARNING: The following warnings have been detected: WARNING: Unknown HK2 failure detected:
MultiException堆栈2之1
java.lang.ExceptionInInitializerError
在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)处
在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
在java.lang.reflect.Constructor.newInstance(Constructor.java:423)
在org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1129)
在org.jvnet.hk2.internal.ClazzCreator.createMe(ClazzCreator.java:274)
在org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:368)
在org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)
在org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:162)
在org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2064)
在org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:711)
在org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:653)
在org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:169)
在org.glassfish.jersey.server.model.MethodHandler $ ClassBasedMethodHandler.getInstance(MethodHandler.java:185)
在org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:74)
在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:109)
在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
在org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:92)
在org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:61)
在org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)
在org.glassfish.jersey.server.ServerRuntime $ 2.run(ServerRuntime.java:297)
在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:271)
在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:267)
在org.glassfish.jersey.internal.Errors.process(Errors.java:315)
在org.glassfish.jersey.internal.Errors.process(Errors.java:297)
在org.glassfish.jersey.internal.Errors.process(Errors.java:267)
在org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
在org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:288)
在org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1110)
在org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:381)
在org.glassfish.grizzly.http.server.HttpHandler $ 1.run(HttpHandler.java:219)
在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:565)
在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:545)
在java.lang.Thread.run(Thread.java:748)
造成原因:java.lang.NullPointerException
在org.drools.compiler.builder.impl.KnowledgeBuilderImpl.guidedDecisionTableToPackageDescr(KnowledgeBuilderImpl.java:411)处
在org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl $ ResourceToPkgDescrMapper.lambda $ static $ 6(CompositeKnowledgeBuilderImpl.java:309)
在org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.buildResource(CompositeKnowledgeBuilderImpl.java:187)
在org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.buildPackageDescr(CompositeKnowledgeBuilderImpl.java:176)
在org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.buildPackages(CompositeKnowledgeBuilderImpl.java:109)
在org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:99)
在org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:247)
在org.drools.compiler.kie.builder.impl.AbstractKieModule.createKieBase(AbstractKieModule.java:210)
在org.drools.compiler.kie.builder.impl.KieContainerImpl.createKieBase(KieContainerImpl.java:389)
在org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBase(KieContainerImpl.java:357)
在org.drools.compiler.kie.builder.impl.KieContainerImpl.newStatelessKieSession(KieContainerImpl.java:550)
在org.drools.compiler.kie.builder.impl.KieContainerImpl.newStatelessKieSession(KieContainerImpl.java:460)
在org.drools.compiler.kie.builder.impl.KieContainerImpl.newStatelessKieSession(KieContainerImpl.java:455)
在com.mycompany.grizzlypoc.rest.services.StatelessService。(StatelessService.java:37)
...更多37
MultiException堆栈2之2
java.lang.IllegalStateException:无法执行操作:在com.mycompany.grizzlypoc.rest.services.StatelessService上创建
在org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:395)
在org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)
在org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:162)
在org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2064)
在org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:711)
在org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:653)
在org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:169)
在org.glassfish.jersey.server.model.MethodHandler $ ClassBasedMethodHandler.getInstance(MethodHandler.java:185)
在org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:74)
在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:109)
在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
在org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:92)
在org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:61)
在org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)
在org.glassfish.jersey.server.ServerRuntime $ 2.run(ServerRuntime.java:297)
在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:271)
在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:267)
在org.glassfish.jersey.internal.Errors.process(Errors.java:315)
在org.glassfish.jersey.internal.Errors.process(Errors.java:297)
在org.glassfish.jersey.internal.Errors.process(Errors.java:267)
在org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
在org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:288)
在org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1110)
在org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:381)
在org.glassfish.grizzly.http.server.HttpHandler $ 1.run(HttpHandler.java:219)
在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:565)
在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:545)
在java.lang.Thread.run(Thread.java:748)
我是一名优秀的程序员,十分优秀!