| Summary: | Decision Server throwing NullPointerException with JSON commands | ||
|---|---|---|---|
| Product: | [Retired] JBoss BPMS Platform 6 | Reporter: | William Antônio <wsiqueir> |
| Component: | Kie-Server | Assignee: | Maciej Swiderski <mswiders> |
| Status: | CLOSED NOTABUG | QA Contact: | Karel Suta <ksuta> |
| Severity: | unspecified | Docs Contact: | |
| Priority: | high | ||
| Version: | 6.1.0 | CC: | etirelli, wsiqueir |
| Target Milestone: | --- | Keywords: | Reopened |
| Target Release: | --- | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | Bug Fix | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2015-12-23 15:18:08 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
Isn't your JSON command malformed?
I think it should look like the following:
{"commands":[{"fire-all-rules":{}}]}
I successfully used the following on a demo last week:
{
"lookup" : "defaultStatelessKieSession",
"commands" : [
{ "insert" : {
"object" : {"org.demo.insurance.Applicant":{
"name" : "John Doe",
"age" : 22
}}
}
},
{ "insert" : {
"object" : {"org.demo.insurance.Policy":{
"amount" : 50000
}},
"out-identifier" : "policy",
"return-object" : true
}
},
{
"fire-all-rules" : {}
} ]
}
I will close this ticket. If you still see a problem, feel free to reopen.
Hello Edson,
It is the JSON generated by the Client API and it is indeed malformed. When I manually tested it, it worked as well
I do agree it is malformed, however, shouldn't we return BAD REQUEST instead throwing NPE to the client?
This is the code you can try as a test:
KieServicesConfiguration configuration = KieServicesFactory
.newRestConfiguration(SERVER_URL, USER, PASSWORD);
configuration.setMarshallingFormat(MarshallingFormat.JSON);
RuleServicesClient client = new RuleServicesClientImpl(configuration);
List<GenericCommand<?>> cmds = new ArrayList<>();
cmds.add(new FireAllRulesCommand());
BatchExecutionCommand batchCmd = new BatchExecutionCommandImpl(cmds);
String cmdStr = BatchExecutionHelper.newJSonMarshaller().toXML(batchCmd);
System.out.println(cmdStr);
client.executeCommands("test", cmdStr);
Thanks!
William,
you should not use any external marshaller when interacting with KIE Server like this:
String cmdStr = BatchExecutionHelper.newJSonMarshaller().toXML(batchCmd);
first of all, RulesServicesClinet shall be taken out from kieServerClient and not created manually via its impl constructor.
Second of all you can simply pass the batchCmd directly to executeCommands method which will the do the serialization for you.
here is a piece of code that does that:
KieServicesConfiguration configuration = KieServicesFactory.newRestConfiguration(SERVER_URL, USER, PASSWORD);
configuration.setMarshallingFormat(MarshallingFormat.JSON);
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(configuration);
RuleServicesClient ruleClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
List<Command<?>> commands = new ArrayList<Command<?>>();
BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands, "kiesession");
commands.add(commandsFactory.newFireAllRules());
ServiceResponse<String> response = ruleClient.executeCommands("test", batchExecution);
The most important rule here is that use always marshaller from KIE Server that can be created:
Marshaller marshaller = MarshallerFactory.getMarshaller(extraClasses, MarshallingFormat.JSON, classLoader)
I'd close it as not a bug but will leave that to William after confirmation.
I am closing as not a bug.
This works:
----
KieServicesConfiguration configuration = KieServicesFactory.newRestConfiguration(SERVER_URL, USER, PASSWORD);
configuration.setMarshallingFormat(MarshallingFormat.JSON);
RuleServicesClient client = new RuleServicesClientImpl(configuration);
List<GenericCommand<?>> cmds = new ArrayList<>();
cmds.add(new FireAllRulesCommand());
BatchExecutionCommand batchCmd = new BatchExecutionCommandImpl(cmds);
client.executeCommands("test", batchCmd);
----
I only think we should thrown that the Client is sending a bad request instead throwing NPE, but I think this is a subject for another BZ.
Thanks!
|
Description of problem: When sending commands marshalled in JSON to the Decision Server, it throws NullPointerException. Version-Release number of selected component (if applicable): n/a How reproducible: always Steps to Reproduce: 1. Deploy a simple container using the KIE Server - it can be an empty kjar (without rules, processes) 2. Send a command using the Client API and using JSON as the format: KieServicesConfiguration configuration = KieServicesFactory .newRestConfiguration(SERVER_URL, USER, PASSWORD); configuration.setMarshallingFormat(MarshallingFormat.JSON); RuleServicesClient client = new RuleServicesClientImpl(configuration); List<GenericCommand<?>> cmds = new ArrayList<>(); cmds.add(new FireAllRulesCommand()); BatchExecutionCommand batchCmd = new BatchExecutionCommandImpl(cmds); String cmdStr = BatchExecutionHelper.newJSonMarshaller().toXML(batchCmd); System.out.println(cmdStr); client.executeCommands("test", cmdStr); It should generate the following JSON command: {"batch-execution":{"commands":{"fire-all-rules":""}}} 3. Send the command to the server Actual results: NullPointerException and command is not executed (see the stack trace at the end of this message) Expected results: Commands execution. Additional info: The problem is that the commands are never correctly parsed by the JSON Unmarshaller. It always returning null leading to the NPE when executing the BatchExecutionCommand. The same code above works if we change to XML. Stack Trace: ERROR [org.kie.server.services.impl.KieContainerCommandServiceImpl] (http-localhost/127.0.0.1:8080-6) Error calling container 'test': java.lang.NullPointerException at org.drools.core.command.runtime.BatchExecutionCommandImpl.execute(BatchExecutionCommandImpl.java:135) [drools-core-6.3.0.Final-redhat-5.jar:6.3.0.Final-redhat-5] at org.drools.core.command.runtime.BatchExecutionCommandImpl.execute(BatchExecutionCommandImpl.java:51) [drools-core-6.3.0.Final-redhat-5.jar:6.3.0.Final-redhat-5] at org.drools.core.impl.StatefulKnowledgeSessionImpl.execute(StatefulKnowledgeSessionImpl.java:738) [drools-core-6.3.0.Final-redhat-5.jar:6.3.0.Final-redhat-5] at org.drools.core.impl.StatefulKnowledgeSessionImpl.execute(StatefulKnowledgeSessionImpl.java:712) [drools-core-6.3.0.Final-redhat-5.jar:6.3.0.Final-redhat-5] at org.kie.server.services.impl.KieContainerCommandServiceImpl.callContainer(KieContainerCommandServiceImpl.java:103) [kie-server-services-common-6.3.0.Final-redhat-5.jar:6.3.0.Final-redhat-5] at org.kie.server.remote.rest.drools.CommandResource.manageContainer(CommandResource.java:73) [kie-server-rest-drools-6.3.0.Final-redhat-5.jar:6.3.0.Final-redhat-5] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_60] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_60] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_60] at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_60] at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:168) [resteasy-jaxrs-2.3.12.Final-redhat-1.jar:] at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:269) [resteasy-jaxrs-2.3.12.Final-redhat-1.jar:] at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:227) [resteasy-jaxrs-2.3.12.Final-redhat-1.jar:] at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:216) [resteasy-jaxrs-2.3.12.Final-redhat-1.jar:] at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:561) [resteasy-jaxrs-2.3.12.Final-redhat-1.jar:] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:543) [resteasy-jaxrs-2.3.12.Final-redhat-1.jar:] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:128) [resteasy-jaxrs-2.3.12.Final-redhat-1.jar:] at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.12.Final-redhat-1.jar:] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.3.12.Final-redhat-1.jar:] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.12.Final-redhat-1.jar:] at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-2.jar:1.0.2.Final-redhat-2] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.5.11.Final-redhat-1.jar:7.5.11.Final-redhat-1] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.5.11.Final-redhat-1.jar:7.5.11.Final-redhat-1] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231) [jbossweb-7.5.11.Final-redhat-1.jar:7.5.11.Final-redhat-1] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.5.11.Final-redhat-1.jar:7.5.11.Final-redhat-1] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:512) [jbossweb-7.5.11.Final-redhat-1.jar:7.5.11.Final-redhat-1] at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.5.4.Final-redhat-4.jar:7.5.4.Final-redhat-4] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:150) [jbossweb-7.5.11.Final-redhat-1.jar:7.5.11.Final-redhat-1] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.5.11.Final-redhat-1.jar:7.5.11.Final-redhat-1] at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:400) [jbossweb-7.5.11.Final-redhat-1.jar:7.5.11.Final-redhat-1] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.5.11.Final-redhat-1.jar:7.5.11.Final-redhat-1] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) [jbossweb-7.5.11.Final-redhat-1.jar:7.5.11.Final-redhat-1] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:854) [jbossweb-7.5.11.Final-redhat-1.jar:7.5.11.Final-redhat-1] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.5.11.Final-redhat-1.jar:7.5.11.Final-redhat-1] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926) [jbossweb-7.5.11.Final-redhat-1.jar:7.5.11.Final-redhat-1] at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_60]