Obtaining Java Objects when firing rules with Kie Server Client

985 views
Skip to first unread message

Mike Ramos

unread,
Jun 9, 2016, 5:01:48 AM6/9/16
to Drools Usage
Hi, I have some rules in Kie server container, Im firing rules via Kie Server client and I want to get the result objects to write them in database after rules are fired, I tried an example that I found in google but doesn't worked for me: they told I need to add the command "getObjectCommand getObjectCommand = new GetObjectCommand();" and setting an OutIdentifier to it, but if I add this to my client and run it, that gives me a null pointer exception(because of fact handler) crashing the client.
 my client code is the following:


public class KieServerClient {
public KieServerClient() {
}
String user = "kieserver";
String password = "kieserver1!";
String containerId = "Container";
KieServicesConfiguration cfg = KieServicesFactory.newRestConfiguration(serverUrl, user, password);
cfg.setMarshallingFormat(MarshallingFormat.JAXB);
// configuration.setMarshallingFormat(MarshallingFormat.JAXB);
Set<Class<?>> extraClasses = new HashSet<Class<?>>();
extraClasses.add(TmEmpleados.class);
extraClasses.add(TmPres.class);
cfg.addJaxbClasses(extraClasses);
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(cfg);
List<GenericCommand<?>> commands = new ArrayList<GenericCommand<?>>();
InsertObjectCommand insertObjectCommand = new InsertObjectCommand(factPresencia, "marking");
InsertObjectCommand insertObjectCommand2 = new InsertObjectCommand(factEmpleado, "employee");
GetObjectCommand getObjectCommand = new GetObjectCommand();
getObjectCommand.setOutIdentifier("f1");

FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand();
commands.add(insertObjectCommand);
commands.add(fireAllRulesCommand);
// commands.add(getObjectCommand);

BatchExecutionCommandImpl executionCommand = new BatchExecutionCommandImpl(commands);
executionCommand.setLookup("KSESSIONAP");

String xStreamXml = MarshallerFactory
.getMarshaller(extraClasses, MarshallingFormat.JAXB,
this.getClass().getClassLoader())
.marshall(executionCommand);
RuleServicesClient ruleServicesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
ServiceResponse<String> response  = ruleServicesClient.executeCommands(containerId, xStreamXml); 

}
}

I was following Accelerate your bussiness tutorial but I didnt saw here the way of obtaining jaba objects from the fired rules 
Currently I have workbench and kie server 6.4 and  wb and server 6.3 in another machine and in both servers the client crashes when I add the "getObjectCommand" to the batch execution, does someone know what I'm doing wrong or can tell me the correct way of  building a kie server client for kie server 6.4 and obtain objects from the fired rules?

I have 6.3 snapshot client dependencies maven; currently I'm not interested in JBPM, just rules

Thanks in advance, regards.

Maciej Swiderski

unread,
Jun 9, 2016, 7:48:42 AM6/9/16
to drools...@googlegroups.com
Here is a test case on how to use it on stateless ksession: https://github.com/droolsjbpm/droolsjbpm-integration/blob/master/kie-server-parent/kie-server-tests/kie-server-integ-tests-drools/src/test/java/org/kie/server/integrationtests/drools/StatelessSessionUsageIntegrationTest.java

Make sure you set out identifier on the insert commands so the updated facts are returned

When it comes to null pointer please open jira with reproducer (or at least steps required to reproduce) and the complete stacktrace

Maciej
--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/a38909fa-5e08-4f25-9b53-9550533eab53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mike Ramos

unread,
Jun 9, 2016, 10:41:56 AM6/9/16
to Drools Usage
I added the outidentifier also in insert command but throws same exception:


Exception in thread "main" java.lang.NullPointerException
at org.drools.core.command.runtime.rule.GetObjectCommand.getFactHandleFromString(GetObjectCommand.java:66)
at org.drools.core.command.runtime.rule.GetObjectCommand$JaxbAccessorM_getFactHandleFromString_setFactHandleFromString_java_lang_String.get(MethodAccessor_Ref.java:41)
at com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.print(TransducedAccessor.java:224)
at com.sun.xml.internal.bind.v2.runtime.property.AttributeProperty.serializeAttributes(AttributeProperty.java:86)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeAttributes(ClassBeanInfoImpl.java:368)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:674)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:54)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:157)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:144)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:345)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:578)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:326)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:479)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:308)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:236)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:116)
at org.kie.server.api.marshalling.jaxb.JaxbMarshaller.marshall(JaxbMarshaller.java:185)
at twsp.resources.KieServerClient2.fireRules(KieServerClient2.java:70)






List<GenericCommand<?>> commands = new ArrayList<GenericCommand<?>>();
InsertObjectCommand insertObjectCommand = new InsertObjectCommand(factPresencia, "marcaje");
insertObjectCommand.setOutIdentifier("f1");
InsertObjectCommand insertObjectCommand2 = new InsertObjectCommand(factEmpleado, "employee");
insertObjectCommand2.setOutIdentifier("f2");
GetObjectCommand getObjectCommand = new GetObjectCommand();
GetObjectCommand getObjectCommand2 = new GetObjectCommand();
getObjectCommand.setOutIdentifier("f1");
getObjectCommand2.setOutIdentifier("f2");


I wanted to use same methods of the example you passed but i cand find what is "commandsFactory", I dont use jira so this is the complete stacktrace
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

Maciej Swiderski

unread,
Jun 9, 2016, 4:06:19 PM6/9/16
to drools...@googlegroups.com
CommandsFactory is this one https://github.com/droolsjbpm/droolsjbpm-integration/blob/master/kie-server-parent/kie-server-tests/kie-server-integ-tests-drools/src/test/java/org/kie/server/integrationtests/drools/DroolsKieServerBaseIntegrationTest.java#L30
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/a38909fa-5e08-4f25-9b53-9550533eab53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

Mike Ramos

unread,
Jun 10, 2016, 5:18:01 AM6/10/16
to Drools Usage
Thank you very much I solved it,  In this example is used the method "executeCommandsWithResults" and it isnt in my RuleServiceClient of  6.3.0-SNAPSHOT, so I updated to 6.4 the dependencies and now work correctly.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/a38909fa-5e08-4f25-9b53-9550533eab53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages