Samples > Rule Execution Server Integration > How to Generate a Rule Service Bean

This sample shows how to use a new RuleApp code execution generator to create a rule service bean. A set of generators is provided to create execution code, with the necessary configuration parameters and resources in a new Java project. These generators can be extended to add other facilities.

Key Features

Key features include:

Installing the Sample

This sample extends the Rule Studio API, and the required sample plug-ins are delivered as pre-deployed. If you have not already done so, you must install the plug-in samples extension site in Eclipse before importing the sample project files and running the sample.

To install the plug-in samples extension site:

  1. Click Help > Software Updates > Manage Configuration
  2. In the Product Configuration dialog, click the Add an Extension Location link.
  3. In the Browse dialog, select the following folder: <InstallDir>/studio/samples/eclipse.
  4. If prompted to restart the Eclipse Workbench, click Yes.
  5. Eclipse shuts down and restarts.

To check that the Ruleservice Sample feature is enabled:

  1. Click Help > Software Updates > Manage Configuration.
  2. In the left pane of the Product Configuration page, expand <InstallDir>/studio/samples/eclipse and check that Ruleservice Sample 1.0.0. is listed.

To import the sample project files:

  1. Click File > Import.
  2. In the Import wizard, select ILOG Rule Studio Samples and Tutorials.
  3. Click Next.
  4. On the Sample or Tutorial page, select the sample: samples > architecture > ruleservice.
  5. Click Finish.
  6. If one or more files already exist in your workspace, a warning message is displayed indicating that the file(s) were not re-imported. Close the message window.
  7. The imported sample project files are imported and displayed in the Rule Explorer:
    - loanvalidation-rules: rule project
    - loanvalidation-xom: XOM project
    - ruleservice-ruleapp: The RuleApp project that contains the loanvalidation-rules ruleset archive.

Running the Sample

You start by generating the loanruleservice project, then you deploy and execute your RuleApp in a Java EE environment.

To generate the loanruleservice project:

  1. Click File > New > Project.
  2. In the New Project wizard, select ILOG Rule Studio > Client Project for RuleApps then click Next.
  3. On the New Client Project for RuleApps page, expand the Other tree item and select Ruleservice sample template with velocity facility then click Next.
  4. In the Project Name field, type loanruleservice then click Next.
  5. Select the RuleApp project ruleservice-ruleapp then click Next.
  6. Select the ruleset archive loanvalidation-rules then click Next.
  7. On the Ruleset Parameters page, select the borrower parameter then click Change.
  8. In the Edit Ruleset Parameter dialog, select the Method radio button.
  9. Replace the contents of the Borrower get_borrower_value() { box with the following code:
Borrower borrower = new loan.Borrower("John", "Doe",
 loan.DateUtil.makeDate(1968, java.util.Calendar.MAY, 12),
 "123456789");
borrower.setZipCode("91320");
borrower.setCreditScore(600);
borrower.setYearlyIncome(100000);
return borrower;
  1. Click OK.
  2. On the Ruleset Parameters page, select the loan parameter then click Change.
  3. In the Edit Ruleset Parameter dialog, select the Method radio button.
  4. Replace the contents of the loan get_loan_value() { box with the following code:
Loan result = new loan.Loan(loan.DateUtil.makeDate(2005,java.util.Calendar.JUNE, 1),
72, 100000, 0.7d);return result;
  1. Click OK, then Finish.

The loanruleservice project is generated and appears in the Rule Explorer. You are now ready to deploy and then execute your RuleApp in a Java EE environment.

To deploy your RuleApp in a Java EE environment:

  1. Start the Samples Server.
  2. For information on how to start and stop the Samples Server, see Samples Server.
  3. When the Samples Server has started, return to Rule Studio and expand the loanruleservice project in the Rule Explorer.
  4. In the src directory, you should see the generated source files for the EJB and the web application.
  5. Expand the jboss40 folder and click the build.xml target.
  6. Click Run > External Tools  > External Tools.
  7. In the External Tools wizard, right-click Ant Build and select New.
  8. Click the Targets tab.
  9. Make sure that all the check boxes are unchecked except the ear target check box, then click the Run button.
  10. The Console view opens, showing the progress of the Ant Build process. When the Build is complete, you can deploy the EAR file.
  11. In the Rule Explorer, click the build.xml target again.
  12. Click Run > External Tools > External Tools.
  13. Select loanruleservice build.xml.
  14. Click the Targets tab.
  15. Uncheck the ear check box, select the deploy target check box, then click Run.
  16. The Sample Console shows the progress of the EAR file deployment process. The BUILD SUCCESSFUL statement indicates that your Java EE Archive is now deployed.
    Wait for the following message:
    [EARDeployer] Started J2EE application: file:<INSTALL_DIR>/shared/tools/jboss/server/jrulessamples/deploy/loan.ear

Now the application is ready to execute.

To execute the Java EE Archive:

  1. Open a web browser and enter the following URL: http://localhost:8080/loan.
  2. Click the Execute Ruleset loanvalidationrules link.
  3. The ruleset is executed and the ruleset loanvalidationrules details displayed. The Try again link gives you an opportunity to execute the ruleset again.

Source Files

The sample is located in <InstallDir>/studio/samples/architecture/ruleservice.

The Velocity templates (.vm) are located in <InstallDir>/studio/samples/eclipse/plugins/ilog.rules.studio.samples.ruleservice_1.0.0/templates/velocity.

Layout:

These classes are used to generate samples source files:

To display the source code of the ruleservice Eclipse plug-in:

  1. Click File > Import.
  2. In the Import Wizard, select External Plug-ins and Fragments and click Next.
  3. In the Import As section, select the Projects with source folders option and click Next.
  4. In the Plug-ins and Fragments Found list, scroll down and select the ilog.rules.studio.samples.ruleservice plug-in (be careful not to select ilog.rules.studio.samples.ruleservice.source), then click Add.
  5. Click Finish.
  6. The source code of the plug-in is imported and appears in the Rule Explorer.
  7. Switch to the Plug-in Development perspective.
  8. In the Package Explorer, navigate to the Java source files. The following source file is of interest here:
  9. Ilog.rules.studio.samples.ruleservice.RuleserviceGenerator.java

Highlights

A rule service is a software component that encapsulates runtime rule processing elements. The component provides a ready-to-run business rule application. A rule service simplifies the process of integrating business rules with popular application platforms. Java programming is only required if you want to customize the rule service component.

A rule service component is invoked using a programming language or a communication protocol. The following graphic shows a high level view of a rule service and the function it performs.

images/ruleservicebean_intro.png

A rule service component is a stateless Enterprise Java Bean (EJB). It contains one or more extracted rulesets, Java classes and interface source files, and an Ant script file and other resource files to enable the rule engine to execute a ruleset on a specified platform.

images/ruleserviceappli.png

The rule service generates descriptors for JBoss. The use of XDoclet enables support for other application server platforms.

images/ruleservice_ruleappgen.png

Related Concepts

RuleApps and RuleApp Projects

Related Tasks

Creating RuleApp Projects
Maintaining Execution Code Generators

Related Samples and Tutorials

Tutorial: RuleApp Management