czwartek, 10 września 2015

Unified KIE Execution Server - Part 2

This blog post is continuation of the first of the series about KIE Execution Server. In this article KIE Server Client will be introduced and used for basic operations on KIE Execution Server.

In the first part, we have went through the details of installation on Wildfly and verification with simple REST client to show it's actually working. This time we do pretty much the same verification although we expand it with further operations and make it via KIE Server Client instead.

So let's get started. We are going to use same container project (hr - org.jbpm:HR:1.0) that includes hiring process, that process has set of user tasks that we will be creating and working with. To be able to work on tasks our user (kieserver) needs to be member of the following roles used by the hiring process:

  • HR
  • IT
  • Accounting
So to add these roles to our user we again use add-user script that comes with wildfly to simply update already existing user


NOTE: don't forget that kieserver user must have kie-server role assigned as well.

With that we are ready to start the server again

KIE Server Client

KIE Server Client is a lightweight library that custom application can use to interact with KIE Execution Server when is written in Java. That library extremely simplifies usage of the KIE Execution Server and make it easier to migrate between versions because it hides all internals that might change between versions. 

To illustrate that it is actually lightweight here is the list of dependencies needed on runtime to execute KIE Server Client


[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ kie-server-client ---
[INFO] org.kie.server:kie-server-client:bundle:6.3.0-SNAPSHOT
[INFO] +- org.kie:kie-api:jar:6.3.0-SNAPSHOT:compile
[INFO] +- org.kie:kie-internal:jar:6.3.0-SNAPSHOT:compile
[INFO] +- org.kie.server:kie-server-api:jar:6.3.0-SNAPSHOT:compile
[INFO] |  +- org.drools:drools-core:jar:6.3.0-SNAPSHOT:compile
[INFO] |  |  +- org.mvel:mvel2:jar:2.2.6.Final:compile
[INFO] |  |  \- commons-codec:commons-codec:jar:1.4:compile
[INFO] |  +- org.codehaus.jackson:jackson-core-asl:jar:1.9.9:compile
[INFO] |  +- com.thoughtworks.xstream:xstream:jar:1.4.7:compile
[INFO] |  |  +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] |  |  \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] |  \- org.apache.commons:commons-lang3:jar:3.1:compile
[INFO] +- org.jboss.resteasy:jaxrs-api:jar:2.3.10.Final:compile
[INFO] |  \- org.jboss.logging:jboss-logging:jar:3.1.4.GA:compile
[INFO] +- org.kie.remote:kie-remote-common:jar:6.3.0-SNAPSHOT:compile
[INFO] +- org.codehaus.jackson:jackson-xc:jar:1.9.9:compile
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.9:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.2:compile
[INFO] +- org.jboss.spec.javax.jms:jboss-jms-api_1.1_spec:jar:1.0.1.Final:compile
[INFO] +- com.sun.xml.bind:jaxb-core:jar:2.2.11:compile
[INFO] \- com.sun.xml.bind:jaxb-impl:jar:2.2.11:compile


So let's setup a simple maven project that will use KIE Server Client to interact with the execution server

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelversion>4.0.0</modelversion>
  <groupid>org.jbpm.test</groupid>
  <artifactid>kie-server-test</artifactid>
  <version>0.0.1-SNAPSHOT</version>
  
  <dependencies>
    <dependency>
        <groupid>org.kie</groupid>
        <artifactid>kie-internal</artifactid>
        <version>6.3.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupid>org.kie.server</groupid>
        <artifactid>kie-server-client</artifactid>
        <version>6.3.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupid>ch.qos.logback</groupid>
      <artifactid>logback-classic</artifactid>
      <version>1.1.2</version>
    </dependency>
  </dependencies>

That's all dependencies that are needed to have KIE Server Client embedded in custom application. Equipped with this we can start running KIE Server Client towards given server instance

Following is code snippet required to construct KIE Server Client instance using REST as transport

String serverUrl = "http://localhost:8230/kie-server/services/rest/server";
String user = "kieserver";
String password = "kieserver1!";

String containerId = "hr";
String processId = "hiring";

KieServicesConfiguration configuration = KieServicesFactory.newRestConfiguration(serverUrl, user, password);
// other formats supported MarshallingFormat.JSON or MarshallingFormat.XSTREAM
configuration.setMarshallingFormat(MarshallingFormat.JAXB);
// in case of custom classes shall be used they need to be added and client needs to be created with class loader that has these classes available 
//configuration.addJaxbClasses(extraClasses);
//KieServicesClient kieServicesClient =  KieServicesFactory.newKieServicesClient(configuration, kieContainer.getClassLoader());
KieServicesClient kieServicesClient =  KieServicesFactory.newKieServicesClient(configuration);

Once we have the the client instance we can start executing operations. We start with checking if the container we want to work with is already deployed and if not deploy it

boolean deployContainer = true;
KieContainerResourceList containers = kieServicesClient.listContainers().getResult();
// check if the container is not yet deployed, if not deploy it
if (containers != null) {
    for (KieContainerResource kieContainerResource : containers.getContainers()) {
        if (kieContainerResource.getContainerId().equals(containerId)) {
            System.out.println("\t######### Found container " + containerId + " skipping deployment...");
            deployContainer = false;
            break;
        }
    }
}
// deploy container if not there yet        
if (deployContainer) {
    System.out.println("\t######### Deploying container " + containerId);
    KieContainerResource resource = new KieContainerResource(containerId, new ReleaseId("org.jbpm", "HR", "1.0"));
    kieServicesClient.createContainer(containerId, resource);
}

Next let's check what is there available, in terms of processes and get some details about process id we are going to start


// query for all available process definitions
QueryServicesClient queryClient = kieServicesClient.getServicesClient(QueryServicesClient.class);
List<ProcessDefinition> processes = queryClient.findProcesses(0, 10);
System.out.println("\t######### Available processes" + processes);

ProcessServicesClient processClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
// get details of process definition
ProcessDefinition definition = processClient.getProcessDefinition(containerId, processId);
System.out.println("\t######### Definition details: " + definition);

We have all the details so we are ready to start the process instance for hiring process. We set two process variables:

  • name - of type string 
  • age - of type integer


// start process instance
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", "john");
params.put("age", 25);
Long processInstanceId = processClient.startProcess(containerId, processId, params);
System.out.println("\t######### Process instance id: " + processInstanceId);

Once we started we can fetch tasks waiting to be completed for kieserver user

UserTaskServicesClient taskClient = kieServicesClient.getServicesClient(UserTaskServicesClient.class);
// find available tasks
List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(user, 0, 10);
System.out.println("\t######### Tasks: " +tasks);

// complete task
Long taskId = tasks.get(0).getId();

taskClient.startTask(containerId, taskId, user);
taskClient.completeTask(containerId, taskId, user, null);


since the task has been completed and it has moved to another one we can continue until there are tasks available or we can simply abort the process instance to quit the work on this instance. Before we abort process instance let's examine what nodes has been completed so far

List<NodeInstance> completedNodes = queryClient.findCompletedNodeInstances(processInstanceId, 0, 10);
System.out.println("\t######### Completed nodes: " + completedNodes);

This will give us information if the task has already been completed and process moved on. Now let's abort the process instance

// at the end abort process instance
processClient.abortProcessInstance(containerId, processInstanceId);

ProcessInstance processInstance = queryClient.findProcessInstanceById(processInstanceId);
System.out.println("\t######### ProcessInstance: " + processInstance);

In the last step we get the process instance out to check if it was properly aborted - process instance state should be set to 3.

Last but not least, KIE Server Client can be used to insert facts and fire rules in very similar way

// work with rules
List<GenericCommand> commands = new ArrayList<GenericCommand>();
BatchExecutionCommandImpl executionCommand = new BatchExecutionCommandImpl(commands);
executionCommand.setLookup("defaultKieSession");

InsertObjectCommand insertObjectCommand = new InsertObjectCommand();
insertObjectCommand.setOutIdentifier("person");
insertObjectCommand.setObject("john");

FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand();

commands.add(insertObjectCommand);
commands.add(fireAllRulesCommand);

RuleServicesClient ruleClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
ruleClient.executeCommands(containerId, executionCommand);
System.out.println("\t######### Rules executed");

So that concludes simple usage scenario of KIE Server Client that covers

  • containers
  • processes
  • tasks
  • rules
A complete maven project with this sample execution can be found here.

Enjoy and stay tuned for more to come about awesome KIE Execution Server :)



38 komentarzy:

  1. I get this error in my pom using 6.3.0.FINAL and 6.3.1-SNAPSHOT
    Missing artifact org.jboss.logging:jboss-logging:jar:3.1.4.GA- redhat-1

    This apparently was fixed in 6.1.3.CR2 - see https://bugzilla.redhat.com/show_bug.cgi?id=1257907

    Thx.

    Steven Elliott

    OdpowiedzUsuń
  2. Hi Maciej
    I really appreciate your posts. They are very helpful. Many thanks.
    I am using the kie-server in my application and I want to register the DBUserGroupCallback.

    I use: -Dorg.jbpm.ht.callback=db to run the Wildfly server

    What is missing is how to make the kie-server pick up jbpm.usergroup.callback.properties file.

    Where exactly should I but this file?

    Your help is very much appreciated.

    a. Taha

    OdpowiedzUsuń
    Odpowiedzi
    1. you can either place this file on root of the class path (kid-server.war/WEB-INF/classes or specify exact (and absolute) location via system property: -Djbpm.usergroup.callback.properties=valid url location to jbpm.usergroup.callback.properties e.g. file:///mypath/jbpm.usergroup.callback.properties

      Usuń
  3. Many thanks for your prompt reply.
    The Second approach worked for me.

    Best regards;
    A. Taha

    OdpowiedzUsuń
  4. I can't add libraries, I tried with maven but appear error:
    "Missing artifact org.kie:kie-internal:jar:6.3.0-SNAPSHOT"
    I also tried manually downloading libraries and putting them on build path but in each version it misses some methods: for example now im using kie api/client/internal 6.3.0.CR2 and tells me:
    "java.lang.NoClassDefFoundError: org/kie/api/command/Command"

    OdpowiedzUsuń
    Odpowiedzi
    1. all is based on maven so you must have maven properly configured to download proper versions of the artifacts. There is no way to add them manually to class path. Moreover make sure you don't mix versions as that will result in exactly the errors you mentioned.

      Usuń
    2. Ten komentarz został usunięty przez autora.

      Usuń
    3. Ten komentarz został usunięty przez autora.

      Usuń
    4. Ten komentarz został usunięty przez autora.

      Usuń
  5. Hi again Maciej, if I fire rules from the kie execution server, can the fired rules call methods like "insertIntoDb(fact1)" when they are activated (action)? If yes how can it be done? adding a DAO object as fact and call its methods like "fact2.insertIntoDb(fact1)?
    Thank you very much

    OdpowiedzUsuń
    Odpowiedzi
    1. better to use global for service like objects. Or provide static access to your service so you can directly look it up via static method to call dao - MyDao.get().insertObjectIntoDb()

      Usuń
    2. Thanks for your reply, by global you mean global variables of kie workbench? or retrieve data from the response of executed rules? sorry but I'm newbie in drools and kie

      Usuń
    3. globals can be declared in rules and then set before executing rules. See drools docs for details.

      although for your use case simply doing a API lookup seems easier approach. So just build dao layer that your rule consequence can use.

      Usuń
  6. Hi, Maciej.

    I'm trying to use both business-central and kie-server for executing tasks. I can get tasks through kie-server-services API but when I try to perform task operations through business-central i'm getting the following error:

    19:43:45,548 WARN [org.jbpm.kie.services.impl.UserTaskServiceImpl] (http-127.0.0.1:8083-2) Cannot find runtime manager for task 2


    -The first step was configuring EAP server with these properties:













    -The second step was creating the JbpmServer user with kie-server role and creating a container with a deployed unit and a process inside it. Once the container is created, I start it.

    -Third step: creating a process instance through this code:
    String containerId = "container1";
    String processId = "process1";

    KieServicesConfiguration configuration = KieServicesFactory.newRestConfiguration(
    "http://localhost:8083/kie-server/services/rest/server", user, password);
    configuration.setMarshallingFormat(MarshallingFormat.JSON);
    KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(configuration);

    ProcessServicesClient processClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);

    processClient.startProcess(containerId, processID);


    -When I log into business-central with the potential owner of the first and only task of the process, I see two weird things:
    +There are no process instances in "Process Instances" tab.
    +There is one task in "Task" tab, but when I click on it I get that error message in server console, and when I open the "Work" tab of that task it shows with no data, completely empty.

    Do I need to do anything else? Is it possible to instantiate a process through kie-server API and to perform its tasks through business-central?

    Thanks in advance.

    OdpowiedzUsuń
    Odpowiedzi
    1. currently this is not supported, business central and kie server are considered different runtimes and thus you can't simply use business central UI as client for kie server. This is going to be in version 7 - see a preview here https://www.youtube.com/watch?v=pxdRSeis92s

      Usuń
    2. Many thanks for your answer (and now I'm a subscriptor of your youtube channel ;)). May you tell me if I'm wrong with these two sentences?
      -In order to use Business-central as runtime for remote web apps I should use kie-remote-client module.
      -If I use kie-server as runtime I should use kie-server-services module. As I've seen in some PoC's, it has more capabilities than kie-remote-client, am I wrong?
      -Which are the advantages or disadvantages of using kie-server instead of business-central runtime? Which approach might you use if you want to design a process in business-central, deploy and execute it from a remote web application?

      Thanks in advance.

      Usuń
    3. -In order to use Business-central as runtime for remote web apps I should use kie-remote-client module.
      correct, if you want to use business central as your runtime environment then use kie remote client to interact with it from other apps

      -If I use kie-server as runtime I should use kie-server-services module. As I've seen in some PoC's, it has more capabilities than kie-remote-client, am I wrong?
      you should use kie-server-client to interact with kie server from other application. Indeed it has more capabilities than business central and moreover runtime in business central is going to be removed in v7 as illustrated in that video

      -Which are the advantages or disadvantages of using kie-server instead of business-central runtime? Which approach might you use if you want to design a process in business-central, deploy and execute it from a remote web application?

      I'd go with kie server from now on, mainly because it's more advanced and will be the only runtime environment from v7 onwards

      Usuń
  7. we are getting exception java.lang.IllegalAccessError: tried to access class org.kie.remote.common.rest.Base64Util from class org.kie.server.client.credentials.EnteredCredentialsProvider
    while executing following code but the same credentials are working fine when we are trying to access kie-server over the explorer


    final String URL = "http://localhost:8080/kie-server/services/rest/server";
    final String USER = "kieserver";
    final String PASSWORD = "kieserver1!";

    final MarshallingFormat FORMAT = MarshallingFormat.JSON;

    final KieServicesConfiguration conf = KieServicesFactory.newRestConfiguration(URL, USER, PASSWORD);;
    conf.setMarshallingFormat(FORMAT);
    conf.setPassword(PASSWORD);


    final KieServicesClient kieServicesClient1= KieServicesFactory.newKieServicesClient(conf);;

    OdpowiedzUsuń
    Odpowiedzi
    1. you'd have to provide more details on how you use kie server client as it seems there is some library conflict that causes IllegalAccessError

      Usuń
  8. Thanks for your article. It is really helpful.

    When I tried to hit the kie-server im getting java.lang.ClassNotFoundException: jxl.Workbook error.


    Not sure what i'm doing wrong. please provide insight into this error.

    Thanks in advance.

    OdpowiedzUsuń
  9. The following is the exception log.

    2016-09-26 12:53:42,710 ERROR [io.undertow.request] (default task-55) UT005023: Exception handling request to /kie-server/services/rest/server/containers/instances/test_service: org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError: jxl/Workbook
    at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)
    at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)
    at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.DisableCacheHandler.handleRequest(DisableCacheHandler.java:33)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)

    OdpowiedzUsuń
  10. Maciej Swiderski:
    I want run a test in Jmeter ,I can run a java application for http request but i don't konw how to spell a json,could you help me ? just a simple java Object such as Student have age and name field;

    OdpowiedzUsuń
    Odpowiedzi
    1. look at this article that describes json use case http://mswiderski.blogspot.com/2015/09/unified-kie-execution-server-part-4.html

      Usuń
  11. Hi Maciej,

    We are having a product hierarchy stored in DB and each node in hierarchy has a rule attached to it. So we need to execute these rules in a particular order i.e. top-down or bottom-up along with some dynamic rule creation. We have complete a PoC for it in standalone and works fine. We are also exposing a REST service for it to take input from application client. Similar to rule execution, we also have small atomic process execution which depends in hierarchy and input data.

    Now we need to deploy it on KieServer and keep same REST service exposed. Going for if any changes happened then we need to us KieScanner to deploy the new artifacts.

    Can you please let us know how to achieve it.

    Regards
    Sandip Desale

    OdpowiedzUsuń
    Odpowiedzi
    1. see this article on how to add extra REST endpoints to KIE Server as most likely that will to allow to have custom REST endpoints that you already have next to KIE Server and still benefit from invoking rules through kie server internals http://mswiderski.blogspot.com/2015/12/kie-server-extend-existing-server.html

      Usuń
  12. Hi Maciej
    your posts are very useful, thank you very much. I have a question: in this post you explain how to use kie-server-client to interact with the execution server, but the official documentation says to use kie-remote-client: https://docs.jboss.org/jbpm/release/6.5.0.Final/jbpm-docs/html/ch17.html#_remote_rest_java_api_client_configuration.
    What is the difference between kie-server-client and kie-remote-client?

    Thanks,
    Marco

    OdpowiedzUsuń
    Odpowiedzi
    1. kie-server-client is a client for KIE Server while kie-remote-client is (or was as in v7 it does not exist any longer) for workbench/business central REST api. So I strongly recommend to use kie server client and kie server

      Usuń
  13. Hi Maciej,

    I am using kie-server 7.0 and kie java client 7.0.
    I have written a simple rule in work bench:-

    rule "Hello World"

    when
    a:CartDetails(minPurchaseAmt==10000)
    then
    a.setMinPurchaseAmt(20.0f);
    System.out.println( "Test rule executed success");

    end

    This is my client code:-

    Command insert = commandsFactory.newInsert(fact, "CartDetails",true,"DEFAULT");
    Command fireAllRules = commandsFactory.newFireAllRules();
    Command factObjects = commandsFactory.newGetObjects();
    Command batchCommand = commandsFactory.newBatchExecution(Arrays.asList(insert,fireAllRules,factObjects));
    ServiceResponse executeResponse = rulesClient.executeCommandsWithResults("couponengine_1.0", batchCommand);

    Getting "SUCCESS" in response but not getting updated object.(As I am calling setMinPurchaseAmt() in 'then' part of rule)

    Please tell if you need more inputs.

    OdpowiedzUsuń
    Odpowiedzi
    1. can you see the system out being printed on the server? Maybe your rule is simply not invoked? and how do you retrieve the results?

      Usuń
    2. System.out not getting printed on server console.
      I tried by setting a:CartDetails(minPurchaseAmt==minPurchaseAmt).
      So that rule will get fired everytime.

      I am retrieving results the way it is given in drools documentation:-
      ServiceResponse executeResponse = rulesClient.executeCommandsWithResults("couponengine_1.0", batchCommand);
      if (executeResponse.getType() == ResponseType.SUCCESS) {
      System.out.println("Commands executed with success! Response: ");
      System.out.println(executeResponse.getResult());
      } else {
      System.out.println("Error executing rules. Message: ");
      System.out.println(executeResponse.getMsg());
      }

      Usuń
    3. so that means your rule does not match.
      a:CartDetails()
      is better if you want to match directly on all facts of that type

      Usuń
    4. Still not working. Changed rule to a:CartDetails().
      Request payload:-
      {
      "lookup" : null,
      "commands" : [ {
      "insert" : {
      "object" : {"com.vc.domain.reqres.CartDetailsFact":{
      "couponCode" : "OS1000",
      "startDate" : 1498212076969,
      "expiryDate" : 1498212076969,
      "minPurchaseAmt" : 10000.0,
      "maxDiscountAmt" : null,
      "newUser" : true,
      "excludeProductCodes" : [ "RN123456" ],
      "isDefault" : null,
      "discountAmt" : null,
      "discountPercentage" : null
      }},
      "out-identifier" : "CartDetails",
      "return-object" : true,
      "entry-point" : "DEFAULT",
      "disconnected" : false
      }
      }, {
      "fire-all-rules" : {
      "max" : -1,
      "out-identifier" : null
      }
      }, {
      "get-objects" : {
      "class-object-filter" : null,
      "out-identifier" : "objects"
      }
      } ]
      }

      Response:-
      {
      "type" : "SUCCESS",
      "msg" : "Container couponengine_1.0 successfully called.",
      "result" : {
      "execution-results" : {
      "results" : [ {
      "value" : {"com.vc.domain.reqres.CartDetailsFact" : {
      "couponCode" : "OS1000",
      "startDate" : 1498212076969,
      "expiryDate" : 1498212076969,
      "minPurchaseAmt" : 10000.0,
      "maxDiscountAmt" : null,
      "newUser" : true,
      "excludeProductCodes" : [ "RN123456" ],
      "isDefault" : null,
      "discountAmt" : null,
      "discountPercentage" : null
      }},
      "key" : "CartDetails"
      }, {
      "value" : [{
      "com.vc.domain.reqres.CartDetailsFact" : {
      "couponCode" : "OS1000",
      "startDate" : 1498212076969,
      "expiryDate" : 1498212076969,
      "minPurchaseAmt" : 10000.0,
      "maxDiscountAmt" : null,
      "newUser" : true,
      "excludeProductCodes" : [ "RN123456" ],
      "isDefault" : null,
      "discountAmt" : null,
      "discountPercentage" : null
      }
      },{
      "com.vc.domain.reqres.CartDetailsFact" : {
      "couponCode" : "OS1000",
      "startDate" : 1498211161535,
      "expiryDate" : 1498211161535,
      "minPurchaseAmt" : 10000.0,
      "maxDiscountAmt" : null,
      "newUser" : true,
      "excludeProductCodes" : [ "RN123456" ],
      "isDefault" : null,
      "discountAmt" : null,
      "discountPercentage" : null
      }
      }],
      "key" : "objects"
      } ],
      "facts" : [ {
      "value" : {"org.drools.core.common.DefaultFactHandle":{
      "external-form" : "0:2:948847818:-469868683:2:DEFAULT:NON_TRAIT:java.util.LinkedHashMap"
      }},
      "key" : "CartDetails"
      } ]
      }
      }

      I am not sure for entry-point key, I have randomly set it as "DEFAULT". Is that cause for failure?

      Usuń
    5. the main reason why it does not work is that you don't have matching classes - in rules you declare CartDetails and then you send over the wire com.vc.domain.reqres.CartDetailsFact so there is no way these two can find each other.

      Usuń
    6. It worked for me. Thanks Maciej.

      Usuń
  14. Thanks for the previous help and sorry because I am troubling you again.
    I have use case where I want to find:-
    In case of rule failure, which exact condition in that rule casued that rule to fail.

    OdpowiedzUsuń
  15. Hey Maciej Swiderski this tutorial is very much helpfull but it returns instance of process executed,
    what if I want to get the data object as result the output of rule fired in my java code??
    I am new to drools please help!

    OdpowiedzUsuń
    Odpowiedzi
    1. take a look at docs https://docs.jboss.org/drools/release/6.5.0.Final/drools-docs/html/ch22.html#d0e25070 there are number of commands you can send to kie server to fire rules and then get results.

      Usuń
  16. Thank you Maciej,
    I am getting below error related to processInstanceId
    org.kie.server.client.KieServicesException: Unexpected HTTP response code when requesting URI 'http://192.168.11.235:8080/kie-server/services/rest/server/containers/testCreditScore/processes/instances/48'! Error code: 500, message: Unexpected error during processing: Could not find process instance for id 48

    OdpowiedzUsuń