REST API in Java sample details
This sample uses the REST API in Java™ to provide a service that builds, tests, and deploys a decision service.
Running the sample
Follow these instructions to run the sample:
- Start the sample server and open the Samples Console:
-
- Start the sample server (see Starting and stopping the sample server).
- Open the Samples Console in the en_US (American English) locale (see Running samples from the Samples Console).
- Deploy the Loan Validation Service decision service:
-
- In the Samples Console, expand .
- Run the deploy.decision.service command.
The command does the following tasks:
- Builds a snapshot of the Loan Validation Service decision service in Decision Center.
- Tests the snapshot by using the test suites in the decision service.
- Deploys the snapshot to Rule Execution Server. It uses the test deployment deployment configuration.
This operation can take some time to complete. It posts messages to the console during the run, and when it ends, it displays a JSON object that shows all the reports:

- Check the snapshot in the Business console:
-
- Open the Business console by using its link in the Sample Server view (see Opening Decision Center on the sample server).
- Enter Paul as the username and password to log in to the console.
- Open the Library tab. Click inside the Loan Validation Service box, and then click main.
- Open the Snapshots tab. You see the snapshot that was created by the deployment command.
- Open . Open the reports that were created by the deployment command.
- Close the reports, and log out of the Business console.
- Check the decision service in the Rule Execution Server console:
-
- Open the Rule Execution Server console by using its link in the Sample Server view (see Opening the Rule Execution Server console on the sample server).
- Enter resAdmin as the username and password to log in to the console.
- Open the Explorer tab. It shows the test_deployment RuleApp that was created by the deployment command. The RuleApp contains two rulesets.
- Log out of the Rule Execution Server console.
- Run the fail command:
-
- In the Samples Console, expand .
- Run the deploy.decision.service.fail command.
The command displays an error that the deployment configuration cannot be found.
Rebuilding the sample
Under REST API in Java in the Samples Console, double-click build. The command builds the classes.
To restore the sample server database, see Restoring sample databases.
How the sample works
This sample uses an HTTPClient to call the Decision Center REST API. It works as follows:
- Gets all the decision services in the Decision Center database.
- Gets the Loan Validation Service test deployment configuration.
- Builds the deployment configuration.
- Checks the results, and takes the snapshot name that was created by the command.
- Tests the snapshot by using all the test suites.
- Checks the results.
- Deploys the snapshot.
The operation checks the JSON objects in the responses to determine whether to continue.
The operation logs messages on the console, and returns a JSON object that contains all the details for a more complete report if necessary.
Source files
This sample is in <InstallDir>/teamserver/samples/dcrestapi/src/client. The JavaClient class defines an API to build, test, and deploy a decision service. It delegates the following operations:
- Management of the input parameters to an InputParameters instance.
- Management of the output parameters to an OutputParameters instance. The parameters are built during the run.
- Calling the REST API to an HTTPClient instance.
- Reporting the run to a Reporter instance, which extracts the run results from the JSON objects and builds the outputParameters.
You can also view and modify the sample source files in Rule Designer. To import the sample into your workspace, click the Import projects link in the Samples and Tutorials view.
There are two Java launch configurations (Loan Validation Service and Miniloan Service) to show the use of classes. Open the run configuration and look at the Arguments tab to see how to adapt your decision service, for example:
