ILOG JRules User Guide > Executing Rules > Tasks > Executing a Ruleset Using Rule Execution Server > Invoking a Ruleset Using a Stateless Rule Session > Creating a Stateless Rule Session and Executing a Ruleset

To invoke a stateless rule session you can:

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:

// 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

Implementing a Ruleset Execution Interceptor
Rule Sessions
Stateless rule sessions

Related Tasks

Creating a POJO Client Project for RuleApps
Creating a Web Service or Monitored Transparent Decision Service Project for RuleApps
Creating an SCA Component Client Project for RuleApps
Maintaining Execution Code Generators
Invoking a Ruleset Using a Stateful Rule Session
Invoking a Ruleset Using a Message-Driven Rule Bean
Tracing Ruleset Execution
Monitoring Ruleset Execution Using the MBeans Accessor API
Handling Rule Engine Exceptions in Rule Execution Server

Related Samples and Tutorials

How to Use a Rule Session in Java SE
How to Use a Rule Session in Java EE
How to Use a Message-Driven Rule Bean