You must maintain a consistent execution interface between
the host application and the managed ruleset.
About this task
Business Rules Embedded includes
a sample for executing a rule project in
Rule Execution Server. The
sample executes the project as a ruleset. The sample can be found
in
<InstallDir>/rules-sdk/samples/com.ibm.rules.sdk.samples.documentrules.tools.execution.
It uses the class
com.ibm.rules.sdk.samples.documentrules.tools.execution.ExecutionManager.
Procedure
- Create the rule service:
// create the rule service
IlrRuleService ruleService = new XMLRuleService(new PrintWriter(System.out));
IlrPath path = new IlrPath("RuleApp", "ruleset");
- Load the ruleset:
InputStream rs = loadRuleset(rulesetArchive);
// deploy the ruleset
Map<String,String>properties = new HashMap<String,String>();
properties.put(IlrRulesetArchiveProperties.KEY_SEQUENTIAL_TRACE_ENABLED, Boolean.toString(true));
ruleService.deployRuleset(path, rs, properties);
- Load data (XML document) to use for execution
InputStream is = this.getClass().getClassLoader().getResourceAsStream( dataFile );
Map<String,Object>params = new HashMap<String,Object>();
params.put( paramName, inputStreamToString( encoding, is ));
- Execute the ruleset and retrieve the results:
IlrSessionResponse response = ruleService.executeRuleset(path, params, true);
- Write a response in the result file:
resultWriter.append(response.getRulesetExecutionOutput());
resultWriter.flush();
resultWriter.close();