private static String url = "http://192.168.0.100:8080/kie-server/services/rest/server";
private static String username = "kieserver";
private static String password = "kieserver1!";
private static String container = "mary";
private static String kieSession = "kiesession";
public static void main(String[] args) {
Student student = new Student();
student.setName("tom");
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(url, username, password);
config.setMarshallingFormat(MarshallingFormat.JSON);
config.setTimeout(30000L);
KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
RuleServicesClient rules = client.getServicesClient(RuleServicesClient.class);
// boolean deployContainer = true;
// KieContainerResourceList containers = client.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(container)) {
// System.out.println("\t######### Found container " + container + " skipping deployment...");
// deployContainer = false;
// break;
// }
// }
// }
//
//
// // deploy container if not there yet
// if (deployContainer) {
// System.out.println("\t######### Deploying container " + container);
// KieContainerResource resource = new KieContainerResource(container,
// new ReleaseId("u51", "test", "0.0.1-SNAPSHOT"));
// client.createContainer(container, resource);
// }
KieCommands cmdFactory = KieServices.Factory.get().getCommands();
List<Command<?>> commands = new LinkedList<Command<?>>();
GetObjectsCommand getObjectsCommand = new GetObjectsCommand();
getObjectsCommand.setOutIdentifier("out");
commands.add(cmdFactory.newInsert(student, "student"));
commands.add(getObjectsCommand);
commands.add(cmdFactory.newFireAllRules());
ServiceResponse<org.kie.api.runtime.ExecutionResults> response = rules.executeCommandsWithResults(container,
cmdFactory.newBatchExecution(commands, kieSession));
System.out.println(response.getMsg());
ExecutionResults result = response.getResult();
System.out.println(result.getFactHandle("out"));
Collection<String> identifiers = result.getIdentifiers();
for (String string : identifiers) {
//System.out.println(string);
}
List<Location> results = new ArrayList<Location>();
ArrayList objects = (ArrayList) result.getValue("out");
System.out.println(objects.size()); // its will get all object Contains the last sessions object ;
for (Object ob : objects) {
// System.out.println(ob);
// Location lo = (Location)ob;
// System.out.println(lo.getName());
}
//System.out.println(objects);
student = (Student) result.getValue("student"); // its get right
System.out.println(student.getAge());
System.out.println(student.getVersion());
}