OpenRules business decision models can be deployed as a RESTful web service that accepts HTTP requests at your local or remote server and produces the proper responses in the JSON format.
OpenRules provides powerful while simple mechanisms for the deployment of business decision models as RESTful web services. You may choose between two deployment options for the creation of RESTful decision services:
- OpenRules REST – a lightweight implementation that utilizes Undertow (see sample-project “VacationDaysRest”)
- SpringBoot – an implementation that utilizes SpringBoot (see sample-project “VacationDaysSpringBoot”) .
Both these projects are included in the standard installation to demonstrate how to convert our business decision model “VacationDays” into a RESTful Web Service that can accept HTTP requests at http://localhost:8080/vacations-days and will respond with proper responses in the JSON format.
You may read more about these projects in the User Manual for Developers but you don’t have to be an expert in these popular software frameworks.
As usual, you create and test your decision model in Excel and then simply add the property “deployment=rest” or “deployment=spring-boot” to the file “project.properties”. Then you double-click on the provide file “runLocalServer.bat” (the same for both projects). When you double-click on it for the first time, it will install the necessary software (including Undertow or SpringBoot jar-files). Then it will build your model in such a way that it can be deployed as a RESTful web service on the local server. After a successful start of the server you should see a console screen that looks like this one:
To test your RESTful web service, double-click on the provide file “testLocalServer.bat” (the same for all models). When you double-click on this file, it will run a test and you will see the results on both (server and client) screens similar to this picture:
Invoking the Service From Java. The example “SampleGeneratedClient.java” (in the folder “src/test/java”) demonstrates how to invoke the deployed service from Java. Here is the code:
Here are the execution results:
Result: Employee(id=Mary Grant, vacationDays=24, eligibleForExtra5Days=false, eligibleForExtra3Days=false, eligibleForExtra2Days=true, age=46, service=18)
Elapsed time: 123 ms
You also may test your model with the commonly used POSTMAN.
You can package your application into a jar-file by double-clicking on the provided file “package.bat”. It will generate an executable JAR file such as “VacationDaysRest-1.0-SNAPSHOT.jar” in the folder “target”. You can use this file directly to start your web service on your local or remote server with the standard command “java -jar VacationDaysRest-1.0-SNAPSHOT.jar“. You may move this jar-file to any location and it will work as well. This file is ready to be uploaded to AWS or another cloud repository to invoke our decision service remotely.