- Deploy or dispose KIE containers
- Retrieve and update KIE container information
- Return KIE Server status and basic information
- Retrieve and update business asset information
- Execute business assets (such as rules and processes)
kie-server. To view configured user roles for your jBPM distribution, navigate to ~/$SERVER_HOME/standalone/configuration/application-roles.properties and ~/application-users.properties.
To add a user with the kie-server role, navigate to ~/$SERVER_HOME/bin and run the following command:
<version> for jBPM dependencies is the Maven artifact version for jBPM currently used in your project (for example, 7.67.2.Final).
Client request configuration
All Java client requests with the KIE Server Java client API must define at least the following server communication components:
- Credentials of the
kie-serveruser - KIE Server location, such as
http://localhost:8080/kie-server/services/rest/server - Marshalling format for API requests and responses (JSON, JAXB, or XSTREAM)
- A
KieServicesConfigurationobject and aKieServicesClientobject, which serve as the entry point for starting the server communication using the Java client API - A
KieServicesFactoryobject defining REST protocol and user access - Any other client services used, such as
RuleServicesClient,ProcessServicesClient, orQueryServicesClient
Basic client configuration example
Advanced client configuration example with additional client services
Sending requests with the KIE Server Java client API
The KIE Server Java client API enables you to connect to KIE Server using REST protocol from your Java client application. You can use the KIE Server Java client API as an alternative to the KIE Server REST API to interact with your KIE containers and business assets (such as business rules, processes, and solvers) in jBPM without using the Business Central user interface. Prerequisites- KIE Server is installed and running.
- You have
kie-serveruser role access to KIE Server. - You have a Java project with jBPM resources.
-
In your client application, ensure that the following dependencies have been added to the relevant classpath of your Java project:
-
In the
~/kie/server/clientfolder of the Java client API in GitHub, identify the relevant Java client for the request you want to send, such asKieServicesClientto access client services for KIE containers and other assets in KIE Server. -
In your client application, create a
.javaclass for the API request. The class must contain the necessary imports, KIE Server location and user credentials, aKieServicesClientobject, and the client method to execute, such ascreateContaineranddisposeContainerfrom theKieServicesClientclient. Adjust any configuration details according to your use case.You define service responses using theCreating and disposing a containerorg.kie.server.api.model.ServiceResponse<T>object, whereTrepresents the type of returned response. TheServiceResponseobject has the following attributes:String message: Returns the response messageResponseType type: Returns eitherSUCCESSorFAILURET result: Returns the requested object
ServiceResponsereturns aVoidresponse. When you create a container, theServiceResponsereturns aKieContainerResourceobject.A conversation between a client and a specific KIE Server container in a clustered environment is secured by a uniqueconversationID. TheconversationIDis transferred using theX-KIE-ConversationIdREST header. If you update the container, unset the previousconversationID. UseKieServicesClient.completeConversation()to unset theconversationIDfor the Java API. -
Run the configured
.javaclass from your project directory to execute the request, and review the KIE Server response. If you enabled debug logging, KIE Server responds with a detailed response according to your configured marshalling format, such as JSON. Example server response for a new KIE container (log):If you encounter request errors, review the returned error code messages and adjust your Java configurations accordingly.
Supported KIE Server Java clients
The following are some of the Java client services available in theorg.kie.server.client package of your jBPM distribution. You can use these services to interact with related resources in KIE Server similarly to the KIE Server REST API.
KieServicesClient: Used as the entry point for other KIE Server Java clients, and used to interact with KIE containersJobServicesClient: Used to schedule, cancel, re-queue, and get job requestsRuleServicesClient: Used to send commands to the server to perform rule-related operations, such as executing rules or inserting objects into the KIE sessionProcessServicesClient: Used to start, signal, and abort processes or work itemsQueryServicesClient: Used to query processes, process nodes, and process variablesUserTaskServicesClient: Used to perform all user-task operations, such as starting, claiming, or canceling a task, and to query tasks by a specified field, such as by user or by process instance IDUIServicesClient: Used to get a String representation of forms (XML or JSON) and of a process image (SVG)ProcessAdminServicesClient: Provides an interface for operations with process instances (found in~/org/kie/server/client/admin)UserTaskAdminServicesClient: Provides an interface for operations with user tasks (found in~/org/kie/server/client/admin)
getServicesClient method provides access to any of these clients:
Example requests with the KIE Server Java client API
The following are examples of KIE Server Java client API requests for basic interactions with KIE Server. For the full list of available KIE Server Java clients, see the Java client API source in GitHub. Listing KIE Server capabilities You can use theorg.kie.server.api.model.KieServerInfo object to identify server capabilities. The KieServicesClient client requires the server capability information to correctly produce service clients. You can specify the capabilities globally in KieServicesConfiguration; otherwise they are automatically retrieved from KIE Server.
Example request to return KIE Server capabilities
org.kie.server.api.model.KieContainerResource object. The list of resources is represented by the org.kie.server.api.model.KieContainerResourceList object.
Example request to return KIE containers from KIE Server
org.kie.server.api.model.KieContainerResourceFilter class, which is passed to the org.kie.server.client.KieServicesClient.listContainers() method.
Example request to return KIE containers by release ID and status
createContainer and disposeContainer methods in the KieServicesClient client to dispose and create KIE containers. In this example, when you dispose a container, the ServiceResponse returns a Void response. When you create a container, the ServiceResponse returns a KieContainerResource object.
Example request to dispose and re-create a KIE container
org.drools.core.command.runtime package in your jBPM instance.
You can use the org.kie.api.command.KieCommands class to insert commands, and use org.kie.api.KieServices.get().getCommands() to instantiate the KieCommands class. If you want to add multiple commands, use the BatchExecutionCommand wrapper.
Example request to insert an object and fire all rules
A conversation between a client and a specific KIE Server container in a clustered environment is secured by a unique
conversationID. The conversationID is transferred using the X-KIE-ConversationId REST header. If you update the container, unset the previous conversationID. Use KieServicesClient.completeConversation() to unset the conversationID for the Java API.QueryServicesClient client to list available process definitions. The QueryServicesClient methods use pagination, so in addition to the query you make, you must provide the current page and the number of results per page. In this example, the query starts on page 0 and lists the first 1000 results.
Example request to list business processes in KIE Server
ProcessServicesClient client to start a business process. Ensure that any custom classes that you require for your process are added into the KieServicesConfiguration object, using the addExtraClasses() method.
Example request to start a business process
QueryDefinition object of the QueryServicesClient client to register and execute custom queries in KIE Server.
Example request to register and execute a custom query in KIE Server
target instructs the query service to apply default filters. Alternatively, you can set filter parameters manually. The Target class supports the following values: