Samples > Rule Execution Server Integration > How to Generate a Monitored Transparent Decision Service

This sample shows how to use the Rule Studio Web service generation wizard, deploy the transparent decision service, and invoke it.

To invoke a ruleset on the Rule Execution Server, you must write execution code to communicate with the application server and locate the deployed RuleApp that contains the ruleset. This code is best written in Rule Studio inside a client project. Rule Studio provides several project generators to assist with this task. Among them, you will find the Web service code generator. The Web service is implemented with the aid of the Sun Microsystems JAXWS 2.0 reference implementation.

The Web service interface is generated using the ruleset parameters, as shown in the following diagram. This interface contains one method for each ruleset of the RuleApp to run.

images/webdecisionservice_generation.png

Key Features

Keys features include:

Installing the Sample

To install the sample you need to import it, generate the Transparent Decision Service, deploy it, then update the client project.

Before importing the sample:

To import the sample:

  1. Click File > Import.
  2. In the Import Wizard, select ILOG Rule Studio Samples and Tutorials and click Next.
  3. Select the sample: samples > architecture > webdecisionservice.
  4. Click Finish.
  5. If one or more files already exist in your workspace, a warning message is displayed indicating the file(s) were not re-imported. Close the message window.

The imported sample project files are displayed in the Rule Explorer:

To generate the Transparent Decision Service:

  1. Click File > New > Project.
  2. In the New Project wizard, select ILOG Rule Studio > Client Project for RuleApps, then click Next.
  3. Select Rule Execution Server > Web Service, then click Next.
  4. In the Project Name field, type pretradechecks-wds, then click Next.
  5. Select the RuleApp pretradechecks-wds-ruleapp, then click Next.
  6. Select the rule project pretradechecks-wds-rules, then click Next.
  7. This is the project that we want to expose as a transparent decision service.
  8. This rule project contains only one ruleflow, so just click Next to specify the ruleflow task that will be executed when the transparent decision service is invoked.
  9. Click Browse.
  10. Click the Create a configuration.
  11. Click Create a new configuration project.
  12. Click Finish. You have created a Rule Execution Server Configuration.
  13. Select Rule Execution Server Configuration and click Next.
  14. Select the JBoss application server and click Next. The Server Configuration page is displayed.
  15. Click the first Browse button and select <InstallDir>/shared/tools/jboss. The deployment directory is filled automatically.
  16. Enter bres in the Login and Password field.
  17. Click Test Connection. You should receive a Connection Successful message.
  18. Click Next and then Finish.
  19. Expand Rule Execution Server Configuration, select JBoss for pretradechecks-wds.esc and click OK. The RES configuration is set.
  20. Click Next.
  21. In the Execution Options panel, click Finish.
  22. The wizard generates two Java projects: one that implements the transparent decision service and one that implements a client to call this service.
  23. Each project contains a readme file that explains how to use the transparent decision service and client projects. These two readme files are not relevant at this stage, so click No when asked to view each of the files.
  24. Two Java projects are created in your workspace:
  25. - pretradechecks-wds: The transparent decision service project
    - pretradechecks-wds-client: The transparent decision service client project
    You should notice compile errors. This is normal. We will fix them in later step.

You now need to deploy the Transparent Decision Service.

To deploy the Transparent Decision Service:

  1. In Rule Studio, on the Window menu, click Open Perspective >Java to change to the Java perspective.
  2. In the Package Explorer view, click on the project pretradechecks-wds.
  3. On the Project menu, select the toggle Clean projects selected below and make sure that the pretradechecks-wds is selected.
  4. The Clean window is displayed and the pretradechecks-wds project is checked.
  5. Click OK to build the project.
  6. This action corrects the errors in the pretradechecks-wds project. We will fix the errors in the pretradechecks-wds-client project later.
  7. In the Package Explorer, in the pretradechecks-wds project, click on the build.xml file.
  8. Click Run > External Tools > External Tools.
  9. Right click Ant Build and select New.
  10. The pretradechecks-wds build.xml configuration is created.
  11. Click the Targets tab and uncheck all the check boxes.
  12. Check the deploy.war target, then click Run.
  13. A WAR file is created containing your transparent decision service, and is deployed to your JBoss deployment directory:
    <InstallDir>\shared\tools\jboss\server\jrulessamples\deploy
  14. In Rule Studio, on the Run menu, click External Tools > External Tools.
  15. Click pretradechecks-wds build.xml.
  16. Click the Targets tab and uncheck all the check boxes.
  17. Check the deploy.ruleapp target, then click Run to deploy the RuleApp. The RuleApp is deployed to the Rule Execution Server installed on the JBoss application server.
  18. Open a Web browser and type the following URL:
  19. http://localhost:8080/jaxws-pretradecheckswdsruleapp/pretradechecks-wds?wsdl
    The wsdl file content is displayed in your browser.
    The transparent decision service is now deployed and ready to run. In the next step, we will complete the previously-generated sample client project.

To update the Client Project:

  1. In Rule Studio, in the Package Explorer, expand the pretradechecks-wds-client project and click on the build.xml file.
  2. Click Run > External Tools > External Tools.
  3. Right click Ant Build and select New.
  4. The pretradechecks-wds-client build.xml configuration is created.
  5. Click the Targets tab.
  6. Make sure that only the generate-client target is selected in the list, then click Run.
  7. Java classes are generated in the build/src folder of the pretradechecks-wds-client project.
    An XPath evaluation error may be displayed during the source code file generation. You can ignore it.
  8. In the Package Explorer, right-click the pretradechecks-wds-client project and click Refresh to reload the workspace with the new generated files.
  9. This action also corrects the errors in the pretradechecks-wds-client project.
  10. In the pretradechecks-wds-client project, open the file src/pretradecheckswdsruleapp/PretradecheckswdsRunnerClient.java in the Java editor. Click in the editor and press CTRL+SHIFT+F to reformat the generated Java source code.
  11. Locate the following lines:
Customer customerParameter = null; // TODO set the initial value
 
Order orderParameter = null; // TODO set the initial value
  1. Replace these lines with the following:
Customer customerParameter = new Customer (); 
customerParameter.setName("John Smith");
customerParameter.setOwner("George Smith@ILOG");
customerParameter.setInitialValue(2000.0f);
customerParameter.setCurrentValue(800.0f);
customerParameter.setSectorPosition(800.0f);
customerParameter.setBankStockPosition(800.0f);
customerParameter.setOilStockPosition(800.0f);
customerParameter.setRailStockPosition(800.0f);
customerParameter.setBondPosition(800.0f);
customerParameter.setFuturnPosition(800.0f);
customerParameter.setStockPosition(800.0f);
customerParameter.setCurrency("Euro");
Order orderParameter = new Order();
orderParameter.setId("order000192-2006");
orderParameter.setStock("Company X");
orderParameter.setAmount(90);
orderParameter.setExchange("Nouveau Marche");
orderParameter.setCurrency("Euro");
orderParameter.setDestination("France");
orderParameter.setAction("Buy");
orderParameter.setSecurityType("Stock");
orderParameter.setSector("Oil");
orderParameter.setStatus("Pending");
orderParameter.setReasons("");
  1. Locate the following line:
System.out.println("done");
  1. Replace this line with the following code:
System.out.println("Returned reasons = " + hreportParameter.value.getReasons() );
  1. Save the file.
  2. Click Run > External Tools > External Tools.
  3. Select the pretradechecks-wds-client build.xml configuration.
  4. Click the Targets tab and uncheck all the check boxes.
  5. Check the compile target, then click Run.
  6. The client side application is compiled and ready to run.
    An XPath evaluation error may be displayed during the source code file generation. This can be ignored.

Running the Sample

The sample can only be run through the Samples Console.

At this stage, the transparent decision service has been created, compiled and deployed. The client side application has been created and compiled, and is now ready to run.

To run the client side application:

  1. Click Run > External Tools > External Tools.
  2. Select the pretradechecks-wds-client build.xml configuration.
  3. Click the Targets tab and uncheck all the check boxes.
  4. Check the run target, then click Run.
  5. A request is sent via a Web service call to the Rule Execution Server, to execute the main ruleflow of the deployed ruleset.
    The client side application runs and the following output is displayed:
Returned reasons = Black Listed Stocks

When the Web application is initialized, the transparent decision service is registered in the Rule Execution Server. When the transparent decision service is executed, performance metrics are sent to the Rule Execution Server Console, which you can go and view.

Viewing the Decision Service Performance Metrics

To view the performance metrics:

  1. Open a Web browser and go to the Rule Execution Server Console login page. For example:
  2. http://localhost:8080/jrules-bres-management
    or
    http://localhost:8080/bres
  3. Log in using the following details:
  4. Username bres
    Password bres.
  5. Click the Explorer tab, and in the left pane click Decision Services.
  6. In the right-pane, click the following link: PretradecheckswdsruleappPretradecheckswdsrulesDecisionService
  7. In the right-pane, click View Statistics.
  8. Performance metrics are displayed as follows:
    images/webdecisionservice_performance.png

Source Files

The source files used in the sample are automatically generated by the wizard. This wizard generates two Java projects, one that implements the transparent decision service, and one that implements a simple client application to call the service.

Transparent Decision Service

The following files are generated:

The transparent decision services use the following Java classes:

Constraints:

The component named PretradecheckswdsRunner is implemented as a Web service. This Web service is implemented with the aid of the Sun Microsystems JAXWS 2.0 reference implementation. Therefore, the serialization mechanism used assumes that Web service parameters respect the JavaBean specification.

Transparent Decision Service Client

The following files are generated:

The transparent decision service client uses PretradecheckswdsRunnerClient.java. This is a client class that calls the transparent decision service.

Constraints:

To be able to run the client, the transparent decision service must be correctly installed on Tomcat. The client is not "ready-to-run". PretradecheckswdsRunnerClient.java needs to be updated in order to add the IN parameters. You also need to run the provided generate-client Ant task that generates proxy client classes.

Highlights

We used the Web service wizard to generate two Java projects, one that implements a transparent decision service, and one that implements a simple client application to call this service.

The transparent decision service can be deployed on a JBoss 4.0.5 (or Tomcat 6.0) server using the Ant build.xml file provided.

The client side application contains just one simple class. Client artifact classes can be generated in the build/src directory using the provided Ant build.xml file.

The overall runtime feature is shown in the following diagram:

images/webdecisionservice_overall.png

Related Concepts

Transparent Decision Services
RuleApps and RuleApp Projects
Management and Monitoring

Related Tasks

Creating a Web Service or Monitored Transparent Decision Service Project for RuleApps
Adding RuleApp Execution Artifacts to an Existing Project
Maintaining Execution Code Generators
Invoking a Ruleset Using a Stateless Rule Session
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
Installing Rule Execution Server on Tomcat 6.0

Related Samples and Tutorials

How to Generate a Rule Service Bean
Tutorial: Executing a Hosted Transparent Decision Service
Tutorial: RuleApp Management