Simple execution sample details

You use a web browser to run the sample application.

Running this sample application

To run the sample application:

  1. Open a web browser, and enter the URL for the sample application:

    http://localhost:9090/rulesession

    The following page opens in your browser:

    Image shows the sample application.
  2. Click the Validate Loan button. You get a message that says the loan is rejected.
  3. Change the Amount field to 20000, and click the Validate Loan button. The loan is approved this time.

Removing the sample application

To remove the sample application:

  1. Open the Rule Execution Server console:
    • URL: http://localhost:9090/res
    • User name and password: resAdmin
  2. In the Explorer tab, you can see that the my_deployment RuleApp is deployed.
  3. In the Samples Console, open the Samples Command tab and expand Samples Commands > Rule Execution Server > Simple execution.
  4. Double-click undeployMiniloan to use the command.
  5. Refresh the Rule Execution Server console. The RuleApp and resources are no longer deployed.

If you try to use the rulesession application now, you get an error that says the decision service is not deployed.

Rebuilding the sample

To rebuild the sample:

  1. Open the Samples Console.
  2. In the Samples Command tab,expand Samples Commands > Rule Execution Server > Simple execution.
  3. Double-click the clean command. This command removes the built classes, and the RuleApp and its XOM from the Rule Execution Server database.

How this sample works

This sample demonstrates how to call a decision service by using its REST API in a web application. You build a RuleApp by using the Build Command, and deploy it to Rule Execution Server in the sample server by using the Ant task res-desploy. Then, you run a decision service from a web interface in Java™ Script. The call is done by processing a POST request in AJAX:

  • The parameters are provided as JSON objects.
  • The RuleApp URL is used: /DecisionService/rest/v1/my_deployment/my_operation.
  • The data from the request is parsed to get the information to display.
Note: The sample works because Rule Execution Server and the web application are on the same server. If the RuleApp and the web application are on separate servers, Java code is required for the security check.

Source files

The source files for this sample are in the following directories:
  • Sample project for the web application: <InstallDir>/executionserver/samples/j2eerulesession/miniloan-rest

    Look in the src/main/webapp/js/main.js Java script file for the call to the REST API.

  • XOM source files: <InstallDir>/gettingstarted/DecisionServer/start/miniloan-xom
  • Decision service files: <InstallDir>/gettingstarted/DecisionServer/answer/Miniloan Service
You can also view and modify the sample source files in Rule Designer. To import the sample into your workspace:
  1. Open the Samples Console.
  2. Open the Samples and Tutorials tab and expand Rule Execution Server > Samples.
  3. Under Simple execution, click Import projects.
  4. Switch to the Java perspective to view and modify the projects.