Samples > Rule Execution Server Integration > How to Use a Rule Session in Java EE

The sample shows you how to execute a simple stateless rule session on a Java EE application server. You can execute the sample on the Web using Java Server Pages (JSP), or by using a Java client.

Key Features

Key features include:

Installing the Sample

Before installing the sample, you will need to start the Rule Execution Server Console using:

Configuring the Samples Property File

If you are using an application server other than the JBoss Samples Server, configure the sample property files for your application server as follows:

WebLogic:

<InstallDir>/executionserver/samples/j2eerulesession/weblogic92|100/build.properties:

WL_HOME=${env.WL_HOME}. By default the variable is set to your WL_HOME environment variable.

<InstallDir>/executionserver/samples/j2eerulesession/weblogic92|100/jndi.properties:

java.naming.provider.url=<JNDIService>. This defines the URI of the machine running the JNDI service. For example: java.naming.provider.url=t3://localhost:7001/

WebSphere:

<InstallDir>/executionserver/samples/j2eerulesession/websphere6/build.properties:

WAS_HOME=${env.WAS_HOME}. By default the variable is set to your WAS_HOME environment variable.

<InstallDir>/executionserver/samples/j2eerulesession/websphere6/jndi.properties:

java.naming.provider.url=<JNDIService>. This defines the URI of the machine running the JNDI service.

JBoss:

<InstallDir>/executionserver/samples/j2eerulesession/jboss40/build.properties:

jboss.home=<JBoss_Installation_Directory> . By default the path is set to the Samples Server.

jboss.config=<JBoss_Configuration>. By default this property is set to the configuration file of the Samples Server.

<InstallDir>/executionserver/samples/j2eerulesession/jboss40/jndi.properties:

java.naming.provider.url=<JNDIService>. This defines the URI of the machine running the JNDI service. By default, this property is set to the Samples Server URI.

Sun AS 82:

<InstallDir>/executionserver/samples/j2eerulesession/sunas82/build.properties:

SUNAS82_HOME=${env.SUNAS_HOME}. By default the variable is set to your SUNAS_HOME environment variable.

Oracle10g:

<InstallDir>/executionserver/samples/j2eerulesession/oracle10g/build.properties:

ORACLE_HOME=${env.ORACLE_HOME}. By default the variable is set to your ORACLE_HOME environment variable.

<InstallDir>/executionserver/samples/j2eerulesession/oracle10g/jndi.properties:

java.naming.provider.url=<JNDIService>. This defines the URI of the machine running the JNDI service.

Building the Sample

You need to build the sample if you are using an application server other than the JBoss Samples Server.

To build the sample:

  1. Go to the Samples Console and locate the sample executionserver > j2eerulesession > <APPLICATION_SERVER_NAME>
  2. where <APPLICATION_SERVER_NAME> is one of the following:
    - weblogic92 for WebLogic 9.2
    - weblogic100 for WebLogic 10.0
    - websphere6 for WebSphere 6.1
    - jboss40 for JBoss 4.0
    - oracle10g for Oracle10g AS
    - sunas82 for Sun AS 82
  3. Execute the ear command to build the XOM classes and package the following files:
  4. - the Web Archive Resource (WAR) including the JSPs
    - the rule session Java Archive Resources (JARs)
    - the Enterprise Archive Resource (EAR)
    The EAR file is generated in the directory <JRULES_HOME>/executionserver/samples/j2eerulesession/<APPLICATION_SERVER_NAME>/build.

Installing the Sample on JBoss

To install the sample on JBoss through the sample server:

  1. Start the Samples Console and wait for it to complete (the Samples documentation will open).
  2. In the Samples Explorer open:
  3. executionserver/j2eerulesession/jboss40/J2eerulesession Sample: JBoss platform
  4. Double-click ear.
  5. When the build is successful, double-click deploy.

The EARs for the other application servers should be deployed through the respective application server console.

Running the Sample

The sample can only be run through the Samples Console.

To run the sample:

  1. Open a web browser and type the appropriate URL for your application server:
  2. JBoss Samples Server: http://localhost:8080/rulesession
    WebLogic 9.2/10.0: http://localhost:7001/rulesession
    WebSphere 6.1: http://localhost:9080/rulesession
    JBoss 4.0: http://localhost:8080/rulesession
    Oracle10g: http://localhost:8888/rulesession
    SunAS 82: http://localhost:8080/rulesession
  3. Login using the following details:
  4. Username: bres
    Password: bres
  5. Click the RuleApp Management tab. The list of available rulesets are displayed.
  6. Click the View to view BAL rules contained in the ruleset.
  7. Click Deploy to deploy the ruleset (for example, balsample2).
  8. Select the Execution tab.
  9. The Java (POJO) rule session produces an execution report. In the section Rules execution each icon represents a different mode of launching a ruleset. For more information about these three modes, see Execution.
  10. Click the icon under Java Rule Session.
  11. Examine the rule execution results and the execution report:
  12. Execution results:
    - Messages: Displays any output parameters whose values are affected by the execution of the rules
    - Normal Price: The normal price of the item.
    - Discount: The discount calculated by the rules.
    - Final Price: The cost of the item minus the calculated discount.
    Execution report:
    Using the IlrExecutionResult class, you have access to a lot of information about the execution, such as: working memory, execution times, number of rules fired, and so on. In the sample we have displayed the following information:
    - The number of rules fired
    - The rules fired
    - Execution time
  13. You can also execute the rules remotely using a Java client, as follows:
    1. Go to the Samples Console and locate the sample: executionserver > j2eerulesession > <APPLICATION_SERVER_NAME>
    2. Ensure that you have deployed the ruleset, as described in Step 5.
    3. Execute the run command.

The Java client connects to the Remote EJB Rulesession, executes the rules and displays the output.

Source Files

The sample is located in:

<InstallDir>/executionserver/samples/j2eerulesession

The XOM source files located are in:

<InstallDir>/executionserver/samples/j2eerulesession/src/shopmodel

The source files for the web tier control classes are located in:

<InstallDir>/executionserver/samples/j2eerulesession/src/controller

The source file for the Java remote client is located in:

<InstallDir>/executionserver/samples/j2eerulesession/src/client

The JSP source files are located in:

<InstallDir>/executionserver/samples/j2eerulesession/src/WebContent

Highlights

The sample demonstrates a Java EE execution stack use case in EJB, POJO, and JSR-94 modes.

In the sample you can:

The sample can be deployed and executed on all JRules supported platforms.

images/bresj2eearchitecture.png

Rebuilding the Sample

You can rebuild the sample through the Samples Console.

To rebuild the sample from the Java source files:

  1. Go to the Samples Console and locate the sample executionserver > j2eerulesession > jboss40.
  2. Execute the ear command to build the XOM classes and package the following files:
  3. - the Web Archive Resource (WAR), including the JSPs
    - the rule session Java Archive Resources (JARs)
    - the Enterprise Archive Resource (EAR)
  4. Execute the deploy command to deploy the EAR on the Samples Server.

Related Concepts

Execution
Management and Monitoring
Rule Engine Interactions Using JSR-94
Rule Sessions

Related Tasks

Defining a Java XOM