Task 6: Calling the rules from a client application

This task is optional. Now that you have deployed the rules from the decision service, you can use them in a client application. This task shows you how to set up the application, which calls rules from an execution server in your cloud portal.

Before you begin

This task describes how the Miniloan application uses the rules from the decision service. It also explains how to set up and run the application. This task is optional because it requires some technical knowledge. To set up the application, you must be familiar with Maven and Java™ application servers such as IBM® WebSphere® Liberty.

About this task

When you deployed the rules to Rule Execution Server, you sent them in a ruleset to the execution server. The Miniloan application can now call the ruleset from the server.

When the application opens, it displays default input data:

Image shows the default values in the Miniloan application.

In the Server tab, the parameters are set to call the ruleset from the decision service in the development environment:

Image shows the server connection parameters.

The application uses the REST API, and JavaScript Object Notation (JSON) for input and output data. When the Request loan button is clicked, the application processes the default data and produces the following results:

Image shows rejection message.

Installing the client application on a custom server

Follow these steps to set up the Miniloan application.

Before you begin

This list shows the prerequisites for this task:

Step 1: Setting up the sample application

You use Maven to build and deploy the Miniloan application.

Procedure

  1. Download the Liberty application server listed in the prerequisites.
  2. Decompress the Liberty file to a directory on your computer. The directory is referred to as <WLP_Home> in the following steps.
  3. Go to the <InstallDir>/odm-cloud-getting-started-master/miniloan-server directory.
    InstallDir is your directory for the extracted files from the GitHub repository that is listed in the prerequisites.
  4. Set the property <liberty-path> in the file pom.xml to <WLP_Home>, the directory that contains Liberty.
  5. In a command prompt, call mvn clean install.
    The command does the following actions:
    • Creates the client application WAR file.
    • Creates and starts a Liberty server.
    • Deploys the client application to the server.

    You can use the application when you see the message BUILD SUCCESS.

    Note: If you want to modify and build the application again, follow the instructions in Step 3: Stopping and rebuilding the application server.

Step 2: Using the sample application

Now, you can run the Miniloan application.

Procedure

  1. Use the following URL in your web browser to open the application:
    http://localhost:9080/odm-cloud-miniloan-server-0.1-SNAPSHOT/

    Miniloan opens and displays the default input values:

    Image shows the default values in the Miniloan application.
  2. Open the Server tab to configure the connection to your decision server ruleset. Enter the decision service URL that corresponds to your environment (/odm/dev, /odm/test or /odm/prod), a user email address or a service credential, its password, and the ruleset corresponding to your deployment.
    Image shows the server connection parameters.
  3. Click Request loan to process the default values.
    The application processes the request and returns the following message in JSON:
    Image shows rejection message.

    You can get additional information by selecting Trace enabled in the Server tab and processing the default values again. The new information shows that one rule, eligibility.minimum_income, is run.

Step 3: Stopping and rebuilding the application server

About this task

When you stop using the application or want to rebuild it, follow these instructions:

Procedure

  1. To stop the Liberty server, run the following command in the <WLP_HOME>/bin directory:
    ./server stop testODMGettingStarted
  2. To remove the Liberty server, delete the directory <path to Liberty>/usr/servers/testODMGettingStarted.
  3. To rebuild the sample and create the Liberty server again, run the following command in the miniloan-server directory:
    mvn clean install

Results

You have completed the getting started tutorial. The tutorial showed you the artifacts a decision service branch, how to update and test rules, and how to deploy the rules from the decision service to an execution server. You also looked at using the rules with a client application.