-
Notifications
You must be signed in to change notification settings - Fork 1
/
KieClient.java
77 lines (60 loc) · 2.89 KB
/
KieClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.myspace.ruleflow;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.kie.api.KieServices;
import org.kie.api.command.BatchExecutionCommand;
import org.kie.api.command.Command;
import org.kie.api.command.KieCommands;
import org.kie.api.runtime.ExecutionResults;
import org.kie.server.api.marshalling.MarshallingFormat;
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.kie.server.client.RuleServicesClient;
public class KieClient {
private static final String URL = "http://localhost:8080/kie-server/services/rest/server";
private static final String user = System.getProperty("username", "donato");
private static final String password = System.getProperty("password", "donato");
private static final String CONTAINER = "ruleflow_1.0.0-SNAPSHOT";
public static void main(String[] args) {
KieClient clientApp = new KieClient();
long start = System.currentTimeMillis();
clientApp.ruleflow("ruleflow.RuleFlow");
long end = System.currentTimeMillis();
System.out.println("elapsed time: " + (end - start));
}
private void ruleflow(String processId) {
try {
KieServicesClient client = getClient();
var commands = new ArrayList<Command<?>>();
KieCommands commandsFactory = KieServices.Factory.get().getCommands();
commands.add(commandsFactory.newInsert(new String("ok")));
commands.add(commandsFactory.newStartProcess(processId));
commands.add(commandsFactory.newGetObjects());
BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands, "ksession");
RuleServicesClient ruleClient = client.getServicesClient(RuleServicesClient.class);
ServiceResponse<ExecutionResults> results = ruleClient.executeCommandsWithResults(CONTAINER, batchExecution);
System.out.println(results);
} catch (Exception e) {
e.printStackTrace();
}
}
private KieServicesClient getClient() {
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(URL, user, password);
// Configuration for JMS
// KieServicesConfiguration config =
// KieServicesFactory.newJMSConfiguration(connectionFactory, requestQueue,
// responseQueue, username, password)
// Marshalling
config.setMarshallingFormat(MarshallingFormat.JSON);
Set<Class<?>> extraClasses = new HashSet<Class<?>>();
config.addExtraClasses(extraClasses);
Map<String, String> headers = null;
config.setHeaders(headers);
KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
return client;
}
}