6.3.0.Final KEI Server returning empty result set

1,144 views
Skip to first unread message

Bill S

unread,
Feb 25, 2016, 1:45:54 PM2/25/16
to Drools Usage
Hello,
I am very new to Drools, so I may just be missing a step (or two).  I have deployed the 6.3.0.Final Docker Showcase images for both the Workbench and Execution Server.  I have not modified them at all, but did use the --link command.  I also deployed the default "mortgages" project to the KIE-ES.

I have written a simple java program based off

Example 22.16

 and 

Example 22.17

 from the 6.3.0 documentation.  The program seems to run fine except that I am always getting an empty result set back. What am I doing wrong?

I have also attached my simple learning Eclipse/Maven project, and included key snippets below.

Thanks, Bill

XML stream
<batch-execution>
  <insert>
    <org.mortgages.LoanApplication>
      <amount>140000</amount>
      <deposit>10000</deposit>
      <lengthYears>30</lengthYears>
    </org.mortgages.LoanApplication>
  </insert>
  <insert>
    <org.mortgages.IncomeSource>
      <amount>100</amount>
      <type>Asset</type>
    </org.mortgages.IncomeSource>
  </insert>
  <fire-all-rules/>
</batch-execution>

Response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<execution-results>
    <results/>
    <facts/>
</execution-results>

Main:
package org.jboss.docs;

import java.util.ArrayList;
import java.util.List;
import org.drools.core.command.impl.GenericCommand;
import org.drools.core.command.runtime.BatchExecutionCommandImpl;
import org.drools.core.command.runtime.rule.FireAllRulesCommand;
import org.drools.core.command.runtime.rule.InsertObjectCommand;
import org.kie.api.command.BatchExecutionCommand;
import org.kie.internal.runtime.helper.BatchExecutionHelper;
import org.kie.server.api.model.ServiceResponse;
import org.kie.server.client.KieServicesClient;
import org.kie.server.client.KieServicesConfiguration;
import org.kie.server.client.KieServicesFactory;
import org.mortgages.IncomeSource;
import org.mortgages.LoanApplication;

public class DecisionClient {
public static void main(String args[]) {
LoanApplication app = new LoanApplication();
        app.setAmount(1);
        
        IncomeSource source = new IncomeSource();
        source.setType("Asset");
        source.setAmount(100);

        InsertObjectCommand insertApp = new InsertObjectCommand(app);
        InsertObjectCommand insertSource = new InsertObjectCommand(source);
        FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand();

        List<GenericCommand<?>> commands = new ArrayList<GenericCommand<?>>();
        commands.add(insertApp);
        commands.add(insertSource);
        commands.add(fireAllRulesCommand);
        BatchExecutionCommand command = new BatchExecutionCommandImpl(commands);

        String xStreamXml = BatchExecutionHelper.newXStreamMarshaller().toXML(command); // actual XML request
        System.out.println(xStreamXml);
        
      //user "anton" must have role "kie-server" assigned
        KieServicesConfiguration config =  KieServicesFactory.
                newRestConfiguration("http://10.33.65.82:32823/kie-server/services/rest/server",
                "kieserver",
                "kieserver1!");
         KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
        // the request "xStreamXml" we generated in previous step
        // "ListenerReproducer" is the name of the Container
        ServiceResponse<String> response = client.executeCommands("instances/mortgages", xStreamXml); 
        System.out.println(response.getResult());
}
}
 
DroolsLearning.zip

Maciej Swiderski

unread,
Feb 26, 2016, 1:19:54 AM2/26/16
to Drools Usage
there are two options - either you set out-identifer on your insert command - second parameter in the InsertCommand constructor or you use queries to collect data you would like to return. There is another QueryCommand that should be added

You can read more about drools queries here http://docs.jboss.org/drools/release/6.3.0.Final/drools-docs/html_single/index.html#QuerySection

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/a300c1c9-988c-4004-95a1-35947bb2b732%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bill S

unread,
Feb 29, 2016, 9:05:32 PM2/29/16
to Drools Usage
Maciej,

Thank you for the response.  Sorry it took me a little while to get back with you on this. I have been trying to set up a minimal environment and run as small a system as possible and get some results...  Nothing has been successful for me...

I found this youtube tutorial and followed that, and it does not work for me either, and have based my most simple learning experiment on that.  (https://www.youtube.com/watch?v=Bb2wdaPglCY)

Running from Java and SoapUI, I get a marshalling error on the server side, and a NULL response in the client.  From a previous message thread, you suggested to change the content type to JAXB or JSON.  I am not sure how to send the message as either of those types while running in Java...


22:20:44,558 ERROR [org.kie.server.services.impl.KieContainerCommandServiceImpl] (default task-15) Error calling container 'loan1': org.kie.
server.api.marshalling.MarshallingException: Can't marshall input object: org.drools.core.runtime.impl.ExecutionResultImpl@2fc581ab
        at org.kie.server.api.marshalling.jaxb.JaxbMarshaller.marshall(JaxbMarshaller.java:187) [kie-server-api-6.3.0.Final.jar:6.3.0.Final]
        at org.kie.server.services.impl.KieContainerCommandServiceImpl.callContainer(KieContainerCommandServiceImpl.java:114) [kie-server-se
rvices-common-6.3.0.Final.jar:6.3.0.Final]

Please let me know if you want to review any specific java code or Drools, and I can post those as well.


public static final String svrUrlLcl = "http://192.168.99.100:32775/kie-server/services/rest/server";
public static final String MINILOAN = "loan1/";

public static void main(String args[]) {
MiniLoanTest(svrUrlLcl, MINILOAN);
}

public static void MiniLoanTest(String svrUrl, String container) {

Borrower borrower = new Borrower();
borrower.setName("John Doe");
borrower.setCreditScore(230);
borrower.setYearlyIncome(80000);
Loan loan = new Loan();
loan.setAmount(3500);
loan.setDuration(20);
loan.setInterestRage(0.5);
InsertObjectCommand iocB = new InsertObjectCommand(borrower, "borrower");
InsertObjectCommand iocL = new InsertObjectCommand(loan, "MiniLoan");
FireAllRulesCommand farc = new FireAllRulesCommand();

List<GenericCommand<?>> commands = new ArrayList<GenericCommand<?>>();
commands.add(iocB);
commands.add(iocL);
commands.add(farc);
BatchExecutionCommand command = new BatchExecutionCommandImpl(commands);

String xStreamXml = BatchExecutionHelper.newXStreamMarshaller().toXML(
command); // actual XML request
System.out.println("------------------------------");
System.out.println(xStreamXml);

KieServicesConfiguration config = KieServicesFactory
.newRestConfiguration(svrUrl, "kieserver", "kieserver1!");
KieServicesClient client = KieServicesFactory
.newKieServicesClient(config);

ServiceResponse<String> response = client.getServicesClient(
RuleServicesClient.class)
.executeCommands(container, xStreamXml);
System.out.println("------------------------------");
System.out.println(response.getResult());
}



Maciej Swiderski

unread,
Mar 1, 2016, 1:41:03 AM3/1/16
to Drools Usage
Bill,

don't use this for marshaling request/response:

String xStreamXml = BatchExecutionHelper.newXStreamMarshaller().toXML(
command); // actual XML request
System.out.println("------------------------------");
System.out.println(xStreamXml);
you can simply pass the list of commands to executeCommands method and the client will take care of marshaling for you.

when it comes to changing marshaling format, this is done on client configuration object where you set the marshaling format (one of following - JAXB (default), JSON, XSTREAM).


ServiceResponse<String> response = client.executeCommands("instances/mortgages", xStreamXml);

instances/mortgages does not seem like a valid container id, I believe you should use only mortgages instead.


Hope this helps
Maciej



Bill S

unread,
Mar 1, 2016, 2:46:57 PM3/1/16
to Drools Usage
Maciej,

I think we are getting closer, and that link has some good learning information, but I also think there is a misunderstanding.  What I am trying to do is execute a "Stateless Knowledge session" using the Docker KIE Execution Server.  Essentially I want to execute the 6.1.1. Stateless Knowledge Session: a java program calling a rule (specifically a Guided Decision Table) developed in the WorkBench deployed to the Execution Service.


Here is a snippet of the code that I have, but this fails when it tries to serialize (setObject(...)) on the class.

Borrower borrower = new Borrower("John Doe", 530, 80000);
Loan loan = new Loan(3500, 20, 0.5);

InsertObjectCommand iocB = new InsertObjectCommand();
iocB.setObject(borrower);
iocB.setOutIdentifier("borrower");
iocB.setReturnObject(true);

InsertObjectCommand iocL = new InsertObjectCommand();
iocL.setObject(loan);
iocB.setOutIdentifier("loan");
iocL.setReturnObject(true);
...
ServiceResponse<String> response = ruleClient.executeCommands(
containerId, executionCommand);


Exception in thread "main" org.kie.server.client.KieServicesException: Error while serializing request data!
at org.kie.server.client.impl.AbstractKieServicesClientImpl.serialize(AbstractKieServicesClientImpl.java:430)
at org.kie.server.client.impl.AbstractKieServicesClientImpl.makeHttpPostRequestAndCreateServiceResponse(AbstractKieServicesClientImpl.java:169)
at org.kie.server.client.impl.RuleServicesClientImpl.executeCommands(RuleServicesClientImpl.java:52)



When I use a String as you do in the test code, it does marshal and I do get a response from the KIE Execution Server, but the result does not contain any useful information.  The Decision table should return whether the loan is approved or rejected.  But I am getting back is essentially what I am sending.

RuleServicesClient ruleClient = kieServicesClient
.getServicesClient(RuleServicesClient.class);
ServiceResponse<String> response = ruleClient.executeCommands(
containerId, executionCommand);

System.out.println("------------------------------");
System.out.println(response.getResult());


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<execution-results>
    <results>
        <item key="person">
            <value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">john</value>
        </item>
        <item key="loan">
            <value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">borrower</value>
        </item>
    </results>
    <facts>
        <item key="person">
            <value xsi:type="defaultFactHandle" external-form="0:94:1078503604:3267851:94:DEFAULT:NON_TRAIT:java.lang.String" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
        </item>
        <item key="loan">
            <value xsi:type="defaultFactHandle" external-form="0:95:1648091748:2097810786:95:DEFAULT:NON_TRAIT:java.lang.String" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
        </item>
    </facts>
</execution-results>

Thanks,

Bill


Greg MERRITT

unread,
Mar 29, 2017, 4:42:15 PM3/29/17
to Drools Usage
Hi Bill,

I am seeing similar behavior. Have you been able to find a solution?

Thanks!

-Greg

David Jimenez

unread,
Jan 11, 2018, 10:04:12 AM1/11/18
to Drools Usage
Any news on this topic?  Did you find a solution? I have the same behavior....

Regards
David
Reply all
Reply to author
Forward
0 new messages