Creating a Stateless Rule Session and Executing a Ruleset
|
PREVIOUS
NEXT
|
To invoke a stateless rule session you can:
-
Call
executeRules(request).
Where the request's descriptor specifies the ruleset path.
-
Set the
ruleapp.interceptor.classname property on the RuleApp to the implemented ruleset execution interceptor and call executeRules(request).
Where the request's descriptor specifies the RuleApp path or the ruleset path, and its
enableInterceptor value is set to
true.
| Note |
| The ruleset should be previously deployed.
|
To create a stateless rule session and execute the ruleset using the executeRules method:
// Creates the stateless rule session
IlrStatelessRuleSession rs = rsProvider.createStatelessRuleSession();
// Creates the execution request
IlrSessionRequest request = new IlrSessionRequest("/ruleapp/ruleset1");
IlrSessionDescriptor desc = request.getSessionDescriptor();
desc.setUserData("testRuleset");
// Sets the IN and INOUT parameters
IlrSessionExecutionSettings execSettings = request.getExecutionSettings();
SerializableObject so = new SerializableObject();
so.value = new String("Value1");
IlrSessionParameters params = execSettings.getInputParameters();
params.setParameter("paramJava", so);
params.setParameter("paramXml", getXmlString());
// Executes the ruleset (by default the interceptor is disabled: see the IlrSessionDescriptor class)
IlrSessionResponse response = rs.executeRules(request);
System.out.println(response);
IlrSessionExecutionResult result = response.getExecutionResult();
IlrSessionParameters outputParameters = result.getOutputParameters();
so = (SerializableObject)outputParameters.getObjectValue("paramJava");
You can also create a stateless rule session and execute a ruleset with a RuleApp path. In the following example, we assume that a ruleset execution interceptor has been set on the RuleApp that redirects the RuleApp call to a ruleset of this RuleApp.
To create a stateless rule session and execute a ruleset with a RuleApp path:
-
Use code such as the following:
// Creates the stateless rule session
IlrStatelessRuleSession rs = rsProvider.createStatelessRuleSession();
// Creates the execution request
IlrSessionRequest request = new IlrSessionRequest("/ruleapp");
IlrSessionDescriptor desc = request.getSessionDescriptor();
desc.setUserData("testInterceptorRuleApp");
// Enable the interceptor
desc.setEnableInterceptor(true);
// Sets the In and INOUT parameters
IlrSessionExecutionSettings execSettings = request.getExecutionSettings();
SerializableObject so = new SerializableObject();
so.value = new String("Value1");
IlrSessionParameters params = execSettings.getInputParameters();
params.setParameter("paramJava", so);
params.setParameter("paramXml", getXmlString());
// Executes the ruleset (by default the interceptor is disabled: see the IlrSessionDescriptor class)
IlrSessionResponse response = rs.executeRules(request);
System.out.println(response);
IlrSessionExecutionProperties execProperties = response.
getExecutionProperties();
System.out.println(" ruleset executed is " + execProperties.
getCanonicalRulesetPath());
IlrSessionExecutionResult result = response.getExecutionResult();
IlrSessionParameters outputParameters = result.getOutputParameters();
so = (SerializableObject)outputParameters.getObjectValue("paramJava");
Related Concepts
Related Tasks
Related Samples and Tutorials