Reputation: 19
I have simple Business process with rule executed before and after RestService WorkItem BPM Process
I also defined the Rest Work Handler definition in the settings. Rest Work Handler Definition Install Rest Work Item Handler.
Using Java KIE API calling RuleServicesClient to execute Rules and BPM Process.
KieServices kieServices = KieServices.Factory.get();
CredentialsProvider credentialsProvider = new EnteredCredentialsProvider(USERNAME, PASSWORD);
KieServicesConfiguration kieServicesConfig = KieServicesFactory.newRestConfiguration(KIE_SERVER_URL, credentialsProvider);
// Set the Marshaling Format to JSON. Other options are JAXB and XSTREAM
kieServicesConfig.setMarshallingFormat(MarshallingFormat.JSON);
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(kieServicesConfig);
// Retrieve the RuleServices Client.
RuleServicesClient rulesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
List<Command<?>> commands = new ArrayList<>();
KieCommands commandFactory = kieServices.getCommands();
commands.add(commandFactory.newInsert(new RestFlowRequest("Sample"), "SampleRequest"));
commands.add(commandFactory.newStartProcess("RuleFlowSample.DecisionRestBPM"));
//commands.add(commandFactory.newFireAllRules("numberOfFiredRules"));
//ProcessServicesClient processService
// = kieServicesClient.getServicesClient(ProcessServicesClient.class);
//processService.startProcess(CONTAINER_ID,"RuleFlowSample.DecisionRestBPM");
BatchExecutionCommand batchExecutionCommand = commandFactory.newBatchExecution(commands);
ServiceResponse<ExecutionResults> response = rulesClient.executeCommandsWithResults(CONTAINER_ID, batchExecutionCommand);
It fails to execute the Rest Service Task with following error Error Thrown By KIE Server
If change the code to start process using ProcessServicesClient then Business Process executes without any issue but rules don't execute.
Upvotes: 0
Views: 780
Reputation: 313
You are using the correct approach using commands.add(commandFactory.newStartProcess("RuleFlowSample.DecisionRestBPM"));"
I tried it using below code(https://github.com/jbossdemocentral/kie-server-client-examples/blob/master/src/main/java/com/redhat/demo/qlb/loan_application/Main.java) and it works fine :
KieServices kieServices = KieServices.Factory.get();
CredentialsProvider credentialsProvider = new EnteredCredentialsProvider(USERNAME, PASSWORD);
KieServicesConfiguration kieServicesConfig = KieServicesFactory.newRestConfiguration(KIE_SERVER_URL, credentialsProvider);
// Set the Marshaling Format to JSON. Other options are JAXB and XSTREAM
kieServicesConfig.setMarshallingFormat(MarshallingFormat.JSON);
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(kieServicesConfig);
// Retrieve the RuleServices Client.
RuleServicesClient rulesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
/*
* Create the list of commands that we want to fire against the rule engine. In this case we insert 2 objects, applicant and loan,
* and we trigger a ruleflow (with the StartProcess command).
*/
List<Command<?>> commands = new ArrayList<>();
KieCommands commandFactory = kieServices.getCommands();
//The identifiers that we provide in the insert commands can later be used to retrieve the object from the response.
commands.add(commandFactory.newInsert(getApplicant(), "applicant"));
commands.add(commandFactory.newInsert(getLoan(), "loan"));
commands.add(commandFactory.newStartProcess("loan-application.loan-application-decision-flow"));
For testing purpose please remove rest handler and try with script task and see the result.
Upvotes: 0