Chapter 6. Decision Manager controller Java client API for Decision Server templates and instances
Red Hat Decision Manager provides a Decision Manager controller Java client API that enables you to connect to the Decision Manager controller using REST or WebSocket protocol from your Java client application. You can use the Decision Manager controller Java client API as an alternative to the Decision Manager controller REST API to interact with your Decision Server templates (configurations), Decision Server instances (remote servers), and associated KIE containers (deployment units) in Red Hat Decision Manager without using the Business Central user interface. This API support enables you to maintain your Red Hat Decision Manager servers and resources more efficiently and optimize your integration and development with Red Hat Decision Manager.
With the Decision Manager controller Java client API, you can perform the following actions also supported by the Decision Manager controller REST API:
- Retrieve information about Decision Server templates, instances, and associated KIE containers
- Update, start, or stop KIE containers associated with Decision Server templates and instances
- Create, update, or delete Decision Server templates
- Create, update, or delete Decision Server instances
Decision Manager controller Java client API requests require the following components:
- Authentication
The Decision Manager controller Java client API requires HTTP Basic authentication for the following user roles, depending on controller type:
-
rest-alluser role if you installed Business Central and you want to use the built-in Decision Manager controller -
kie-serveruser role if you installed the headless Decision Manager controller separately from Business Central
To view configured user roles for your Red Hat Decision Manager distribution, navigate to
~/$SERVER_HOME/standalone/configuration/application-roles.propertiesand~/application-users.properties.To add a user with the
kie-serverrole or therest-allrole or both, navigate to~/$SERVER_HOME/binand run the following command with the role or roles specified:./add-user.sh -a --user <USERNAME> --password <PASSWORD> --role kie-server,rest-all
$ ./add-user.sh -a --user <USERNAME> --password <PASSWORD> --role kie-server,rest-allCopy to Clipboard Copied! Toggle word wrap Toggle overflow To configure the
kie-serverorrest-alluser with Decision Manager controller access, navigate to~/$SERVER_HOME/standalone/configuration/standalone-full.xml, uncomment theorg.kie.serverproperties (if applicable), and add the controller user login credentials and controller location (if needed):<property name="org.kie.server.location" value="http://localhost:8080/kie-server/services/rest/server"/> <property name="org.kie.server.controller" value="http://localhost:8080/decision-central/rest/controller"/> <property name="org.kie.server.controller.user" value="baAdmin"/> <property name="org.kie.server.controller.pwd" value="password@1"/> <property name="org.kie.server.id" value="default-kieserver"/>
<property name="org.kie.server.location" value="http://localhost:8080/kie-server/services/rest/server"/> <property name="org.kie.server.controller" value="http://localhost:8080/decision-central/rest/controller"/> <property name="org.kie.server.controller.user" value="baAdmin"/> <property name="org.kie.server.controller.pwd" value="password@1"/> <property name="org.kie.server.id" value="default-kieserver"/>Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information about user roles and Red Hat Decision Manager installation options, see Planning a Red Hat Decision Manager installation.
-
- Project dependencies
The Decision Manager controller Java client API requires the following dependencies on the relevant classpath of your Java project:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
<version>for Red Hat Decision Manager dependencies is the Maven artifact version for Red Hat Decision Manager currently used in your project (for example, 7.23.0.Final-redhat-00002).NoteInstead of specifying a Red Hat Decision Manager
<version>for individual dependencies, consider adding the Red Hat Business Automation bill of materials (BOM) dependency to your projectpom.xmlfile. The Red Hat Business Automation BOM applies to both Red Hat Decision Manager and Red Hat Process Automation Manager. When you add the BOM files, the correct versions of transitive dependencies from the provided Maven repositories are included in the project.Example BOM dependency:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information about the Red Hat Business Automation BOM, see What is the mapping between RHDM product and maven library version?.
- Client request configuration
All Java client requests with the Decision Manager controller Java client API must define at least the following controller communication components:
-
Credentials of the
rest-alluser if you installed Business Central, or thekie-serveruser if you installed the headless Decision Manager controller separately from Business Central Decision Manager controller location for REST or WebSocket protocol:
-
Example REST URL:
http://localhost:8080/decision-central/rest/controller -
Example WebSocket URL:
ws://localhost:8080/headless-controller/websocket/controller
-
Example REST URL:
- Marshalling format for API requests and responses (JSON or JAXB)
-
A
KieServerControllerClientobject, which serves as the entry point for starting the server communication using the Java client API -
A
KieServerControllerClientFactorydefining REST or WebSocket protocol and user access -
The Decision Manager controller client service or services used, such as
listServerTemplates,getServerTemplate, orgetServerInstances
The following are examples of REST and WebSocket client configurations with these components:
Client configuration example with REST
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Client configuration example with WebSocket
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Credentials of the
6.1. Sending requests with the Decision Manager controller Java client API Copy linkLink copied to clipboard!
The Decision Manager controller Java client API enables you to connect to the Decision Manager controller using REST or WebSocket protocols from your Java client application. You can use the Decision Manager controller Java client API as an alternative to the Decision Manager controller REST API to interact with your Decision Server templates (configurations), Decision Server instances (remote servers), and associated KIE containers (deployment units) in Red Hat Decision Manager without using the Business Central user interface.
Prerequisites
- Decision Server is installed and running.
- The Decision Manager controller or headless Decision Manager controller is installed and running.
-
You have
rest-alluser role access to the Decision Manager controller if you installed Business Central, orkie-serveruser role access to the headless Decision Manager controller installed separately from Business Central. - You have a Java project with Red Hat Decision Manager resources.
Procedure
In your client application, ensure that the following dependencies have been added to the relevant classpath of your Java project:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Download the Red Hat Decision Manager 7.4.0 Source Distribution from the Red Hat Customer Portal and navigate to
~/rhdm-7.4.0-sources/src/droolsjbpm-integration-$VERSION/kie-server-parent/kie-server-controller/kie-server-controller-client/src/main/java/org/kie/server/controller/clientto access the Decision Manager controller Java clients. -
In the
~/kie/server/controller/clientfolder , identify the relevant Java client implementation for the request you want to send, such as theRestKieServerControllerClientimplementation to access client services for Decision Server templates and KIE containers in REST protocol. In your client application, create a
.javaclass for the API request. The class must contain the necessary imports, the Decision Manager controller location and user credentials, aKieServerControllerClientobject, and the client method to execute, such ascreateServerTemplateandcreateContainerfrom theRestKieServerControllerClientimplementation. Adjust any configuration details according to your use case.Creating and interacting with a Decision Server template and KIE containers
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the configured
.javaclass from your project directory to execute the request, and review the Decision Manager controller response.If you enabled debug logging, Decision Server responds with a detailed response according to your configured marshalling format, such as JSON. If you encounter request errors, review the returned error code messages and adjust your Java configurations accordingly.
6.2. Supported Decision Manager controller Java clients Copy linkLink copied to clipboard!
The following are some of the Java client services available in the org.kie.server.controller.client package of your Red Hat Decision Manager distribution. You can use these services to interact with related resources in the Decision Manager controller similarly to the Decision Manager controller REST API.
-
KieServerControllerClient: Used as the entry point for communicating with the Decision Manager controller -
RestKieServerControllerClient: Implementation used to interact with Decision Server templates and KIE containers in REST protocol (found in~/org/kie/server/controller/client/rest) -
WebSocketKieServerControllerClient: Implementation used to interact with Decision Server templates and KIE containers in WebSocket protocol (found in~/org/kie/server/controller/client/websocket)
For the full list of available Decision Manager controller Java clients, download the Red Hat Decision Manager 7.4.0 Source Distribution from the Red Hat Customer Portal and navigate to ~/rhdm-7.4.0-sources/src/droolsjbpm-integration-$VERSION/kie-server-parent/kie-server-controller/kie-server-controller-client/src/main/java/org/kie/server/controller/client.
6.3. Example requests with the Decision Manager controller Java client API Copy linkLink copied to clipboard!
The following are examples of Decision Manager controller Java client API requests for basic interactions with the Decision Manager controller. For the full list of available Decision Manager controller Java clients, download the Red Hat Decision Manager 7.4.0 Source Distribution from the Red Hat Customer Portal and navigate to ~/rhdm-7.4.0-sources/src/droolsjbpm-integration-$VERSION/kie-server-parent/kie-server-controller/kie-server-controller-client/src/main/java/org/kie/server/controller/client.
- Creating and interacting with Decision Server templates and KIE containers
You can use the
ServerTemplateandContainerSpecservices in the REST or WebSocket Decision Manager controller clients to create, dispose, and update Decision Server templates and KIE containers, and to start and stop KIE containers, as illustrated in this example.Example request to create and interact with a Decision Server template and KIE containers
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Listing Decision Server templates and specifying connection timeout (REST)
When you use REST protocol for Decision Manager controller Java client API requests, you can provide your own
javax.ws.rs.core.Configurationspecification to modify the underlying REST client API, such as connection timeout.Example REST request to return server templates and specify connection timeout
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Listing Decision Server templates and specifying event notifications (WebSocket)
When you use WebSocket protocol for Decision Manager controller Java client API requests, you can enable event notifications based on changes that happen in the particular Decision Manager controller to which the client API is connected. For example, you can receive notifications when Decision Server templates or instances are connected to or updated in the Decision Manager controller.
Example WebSocket request to return server templates and specify event notifications
Copy to Clipboard Copied! Toggle word wrap Toggle overflow