java


Drools - Retrieve Output object


I am new to Kie Workbench and Execution Server. I am using Java Rest calls to run rules in kie workbench. Please find the code below:
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;
}
The rules are correctly executed and the Output Object are instancied during the rules. One problem is when I again call this method to execute rules for the second time, I receive two Output object and for each subsequent calls I get one additional object. It seems that the objects in the session are stored and not getting cleared for each call. How can I achieve that for every call I will get only one Output object in return?
Since you are new to Drools, you may not know that Drools has two session types, stateless and stateful. Verify the KIE Execution Server session configuration is stateless, as stateful keeps the facts from prior requests processing.

Related Links

My Struts2 application gets Error 404: Resource not available [duplicate]
Joda Period in year month day
How can I manipulate/create a Google Document via API?
Java Multicast Sender + Receiver
How to scroll using jscroll pane in webdriver java
NullPointerException during JSON Deserializtion in Spring
JasperReports: getting “java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory” Exception
scala/java : icon for button with a relative path
Using apache FTPclient to sort and download files using Collections.sort()
Make singleton pattern code stronger [closed]
Cannot connect to MS SQL SERVER
NullPointerException in onProgressUpdate()
Java function matches is not recognizing [0-9]+ for numbers
Hide Apps from Default Launcher
Retina/high-DPI custom cursor in Java?
Spring Security deployment error

Categories

HOME
jdo
fluentd
path-finding
tinymce
relative-path
stock
webstorm
xmpp
graphql
sharepoint-designer
frameworks
fsm
installshield
fingerprint
session-variables
facebook-php-sdk
metatrader4
user-input
spring-kafka
midi
spring-xd
correlation
google-apps-marketplace
apache-cayenne
commonmark
ibm-odm
carthage
caml
vaadin7
aurigma
physics-engine
mps
sox
microsoft-r
lcd
javacv
uninstall
entitlements
applozic
fifo
maquette
libuv
primitive
tasklet
bosh
pdb
google-qpx-express-api
mapbox-gl
appfabric
swisscomdev
hockeyapp
neuroscience
az-application-insights
azure-ml
greenrobot-eventbus
awt
netcdf4
reactive-cocoa-5
websphere-mq-fte
apple-news
cubic-spline
skeleton-css-boilerplate
qwt
google-datalayer
pubmed
git-diff
elgg
colorama
composite-key
lift-json
iso8601
chord-diagram
root-framework
firmata
deadbolt-2
radtreelist
ubuntu-10.04
master-slave
asp.net5
associative-array
maven-tomcat-plugin
ora-00900
jqgrid-formatter
composite
jsapi
system.reflection
camanjs
gadt
javafx-webengine
rdtsc
document-classification
bitcoinj
article
hippomocks
dealloc
resty-gwt
oracle-warehouse-builder
batterylevel
back-stack
eventlistener
libstdc++
dbproviderfactories
work-stealing
netdna-api
blackberry-playbook
joyent
invite
servicehost
pyinotify
sql-server-profiler
visitor-statistic
sproutcore-2
mozilla-prism
temporal-database
sector
port-number
ubuntu-9.04
.net-1.0

Resources

Encrypt Message