Ruleset management and execution sample details
This sample demonstrates the use of the REST API in Java™ in different scenarios. To run the sample, you use the Samples Console.
Running this sample
First, open the Samples Console as explained in Setting up the ruleset management and execution sample.
Important: You must
run the scenarios in the following order to make them work.
- RuleApp scenario: Lists, adds, and modifies RuleApps.
- Execution scenario: Takes the parameters of a ruleset in the XML format and runs the ruleset.
- Execution with the JSON request scenario: Takes the parameters of a ruleset in the JSON object format and runs the ruleset.
- Clean scenario: Removes all the new artifacts.
The output trace is formatted as follows:
- ** Announces the action.
- >> URL: Reports the requested URL.
- << RESPONSE - Status code: Reports the returned status.
- The JSON response.
RuleApp scenario
- Open the Samples Console.
- In the Samples Commands tab, expand .
- Double-click the deploy.ruleapp command. The command compiles the code and processes as follows:
- Checks whether the scenario can run.
- Lists all the RuleApps in the execution server database. The contents of the list depends on what has already been done in the sample server.
- Deploys a RuleApp archive generated in the sample setup.
- Lists all the RuleApps again to show the new one.
- Modifies the RuleApp description.
- Shows the modified RuleApp.
- To see the results, open a web browser and enter the following URL to start the Rule Execution Server console: http://localhost:<PORT>/res
- Use resAdmin as the user name and password.
- Click the Explorer tab. In the RuleApps view, you
can see the RuleApp
Miniloan. - Click the RuleApp to see its description: Miniloan generated with Build Command and deployed by REST API. It contains only the Miniloan_ServiceRuleset, which has a managed URI.
Execution scenario
- Open the Samples Console.
- Open the Samples Commands tab and expand .
- Double-click the execute command. The command compiles the code and processes as follows:
- Checks whether the scenario can run.
- Passes the ruleset parameters in XML format, and runs the ruleset to apply for a loan in the amount of 5,000.
- Shows the XML response: In the output parameter loan, the
approvedfield is set to true.
- In the Samples Commands view, double-click the executeNotApproved command to run the ruleset. The amount of the requested loan is 500,000. This time, the loan is not approved.
Execution with the JSON request scenario
- Open the Samples Console.
- Open the Samples Commands tab and expand .
- Double-click the execute.json command. The command compiles the code and
processes as follows:
- Checks whether the scenario can run.
- Passes the ruleset parameters in
JSONObjectformat, and runs the ruleset to apply for a loan in the amount of 5,000. - Shows the JSON response: In the output parameter
loan, the approved field is set totrue.
- Open the Samples Commands tab and expand .
- Double-click the executeNotApproved.json command to run the ruleset. The amount of the requested loan is 500,000. This time, the loan is not approved. The reject message is also displayed.
Clean scenario
- Open the Samples Commands tab and expand .
- Double-click the clean command. The command compiles the code and processes as follows:
- Checks whether the scenario can run.
- Removes the
Miniloanapplication. - Lists all the RuleApps to show that
Miniloandoes not exist any more. - Lists all the resources to show that miniloan-xom.zip is no longer referenced.
- Removes the miniloan.xom resource.
- Removes the Miniloan library.
- To see the results, open the Rule Execution Server console as shown in the RuleApp scenario.
- Click the Explorer tab. All the miniloan artifacts are no longer displayed.
Rebuilding this sample
To rebuild this sample:
- Return to the Samples Console.
- Open the Samples Commands tab and expand .
- Double-click the build command to build the classes.
Source files
You can find this sample in <InstallDir>/executionserver/samples/restapi. The Build Command builds the RuleApp from the Miniloan decision service in the project directory by using the description Miniloan.properties. The JavaClient.java file is the class that calls the REST API.
- The constructor creates the
HttpClientinstance and sets the preemptive authentication. All further requests use theapiauthURL where the credentials are already given. - The class defines one
runXXScenariomethod for each scenario. The method first calls acanRunXXScenariomethod to check whether the scenario runs. - The
canRunXXScenariomethod runs a GET request that returns a JSON result to check whether the artifact to be added is already there. - The
runXXscenariomethod makes several requests of type GET, POST, UPDATE, or DELETE, according to the scenario.
You can also view and modify the sample source files in Rule Designer:
- Open the Samples Console.
- Open the Samples and Tutorials tab and expand .
- Under Ruleset management and execution, click Import projects.
- Switch to the Java perspective to view and modify the projects.