OpenRules business decision models can be deployed as a RESTful web service with a single click effectively utilizing SpringBoot and Maven – read how to do it here. In this post we will describe how you can package a business decision model into an executable JAR-file that can be deployed on the local server and tested from POSTMAN or Java.
Creating Executable JAR. The sample project “VacationDaysSpringBoot” includes the batch file “package.bat”. When you double-click on this file, it will generate the file “VacationDaysSpringBoot-1.0-SNAPSHOT.jar” in the folder “target”. You can use this file directly to start a web service on your local or remote server. This file contains everything you need (including Tomcat, Spring, etc.) to run our RESTful decision service. This file is ready to be uploaded to AWS or another cloud repository to invoke the decision service “vacation-days” remotely.
Starting Local Server. You may open a console window in the folder “VacationDaysSpringBoot” and enter the command:
>java -jar VacationDaysSpringBoot-1.0-SNAPSHOT.jar
It will start our service “vacation-days” on the localhost waiting for http-requests on the port 8080:
This service is ready to accept HTTP requests from POSTMAN or Java clients or similar programs.
Testing Decision Service with POSTMAN. To test this web service you may start with the commonly used POSTMAN, that can be downloaded for free from https://www.getpostman.com/. After installation and start, you may fill out this POSTMAN’s form:
You need to select the HTTP method “POST”, enter the service URL http://localhost:8080/vacations-days, and in the tab “Body” enter an input data in the JSON format:
Pay attention that input data starts with the object name “employee”. When you click on the button “Send”, this request will send this JSON input to our web service “vacation-days”, which will respond with a JSON response:
Invoking Decision Service from Java. You may invoke this decision service from Java using Java classes that were automatically generated in the folder “target”. For example, look at the provided class /src/test/java/vacation/days/spring/TestLocalServer.java:
This program first creates a client using the automatically generated Java class DecisionModelVacationDaysClient. For every employee defined in the Excel file “Test.xls”, this program will create a request for this employee using the automatically generated Java class DecisionModelVacationDaysRequest. Then this client will execute this request against our service “vacation-days” and will return a response of the type DecisionModelVacationDaysRequest (that also was automatically generated by OpenRules Decision Manager):
DecisionModelVacationDaysResponse response = client.execute(request);
Thus, this program will test our decision service and will produce the following results:
In the next post we will explain how this JAR-file can be uploaded to AWS EC2 Instance and then be similarly tested from POSTMAN or Java.