Je suis nouveau sur Kie Workbench et Execution Server. J'utilise des appels Java Rest pour exécuter des règles dans kie workbench. Veuillez trouver le code ci-dessous:Drools - Récupère l'objet de sortie
private String kieServerUrl;
private String kieServerContainerId;
private String KieServerUsername;
private String kieServerPassword;
private RuleServicesClient ruleClient;
private static final String INPUT_OUT_IDENTIFIER = "Input";
private static final String SESSION_OBJECTS = "SessionObjects";
private static final String RUN_ALL_RULES = "RunAllRules";
public void init() {
final KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(kieServerUrl, KieServerUsername, kieServerPassword);
config.setMarshallingFormat(MarshallingFormat.XSTREAM);
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(config);
ruleClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
}
@Override
public Output process(final Input input) {
Output output = null;
logger.debug("Running rules ..");
BatchExecutionCommandImpl executionCommand = new BatchExecutionCommandImpl();
executionCommand.getCommands().add(new InsertObjectCommand(input, INPUT_OUT_IDENTIFIER));
executionCommand.getCommands().add(new FireAllRulesCommand(RUN_ALL_RULES));
executionCommand.getCommands().add(new GetObjectsCommand(null, SESSION_OBJECTS));
logger.debug("Sending commands to the server");
ServiceResponse<ExecutionResults> response = ruleClient.executeCommandsWithResults(kieServerContainerId, executionCommand);
if(response.getType().equals(ServiceResponse.ResponseType.SUCCESS)){
logger.debug("Commands executed with success! Response: ");
final ExecutionResultImpl result = (ExecutionResultImpl) response.getResult();
ArrayList<Object> values = (ArrayList<Object>)result.getValue(SESSION_OBJECTS);
}else{
logger.error("Error executing rules. Message: {}", response.getMsg());
}
logger.debug("...finished running rules.");
return output;
}
Les règles sont correctement exécutées et l'objet de sortie est instancié pendant les règles. Un problème est quand j'appelle à nouveau cette méthode pour exécuter des règles pour la deuxième fois, je reçois deux objet de sortie et pour chaque appel suivant j'obtiens un objet supplémentaire. Il semble que les objets de la session sont stockés et ne sont pas effacés pour chaque appel. Comment puis-je obtenir cela pour chaque appel, je n'aurai qu'un seul objet Output en retour?
Comment vérifier la configuration de la session d'exécution de KIE Server est apatride? –
J'ai mis à jour avec comment vérifier. Veuillez accepter la réponse si complète. – Jeff