Step 4: Executing the managed rule project ruleset

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

  1. Create the rule service:
    // create the rule service
    IlrRuleService ruleService = new XMLRuleService(new PrintWriter(System.out));
    IlrPath path = new IlrPath("RuleApp", "ruleset");
  2. 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);
  3. 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 ));
  4. Execute the ruleset and retrieve the results:
    IlrSessionResponse response = ruleService.executeRuleset(path, params, true);
  5. Write a response in the result file:
    resultWriter.append(response.getRulesetExecutionOutput());
    resultWriter.flush();
    resultWriter.close();