Skip to main content
jBPM provides a KIE Server Java client API that 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. This API support enables you to maintain your jBPM resources more efficiently and optimize your integration and development with jBPM. With the KIE Server Java client API, you can perform the following actions also supported by the KIE Server REST API:
  • 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 Java client API requests require the following components: Authentication The KIE Server Java client API requires HTTP Basic authentication for the user role 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:
For more information about user roles and jBPM installation options, see Installing the KIE Server. Project dependencies The KIE Server Java client API requires the following dependencies on the relevant classpath of your Java project:
The <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-server user
  • 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 KieServicesConfiguration object and a KieServicesClient object, which serve as the entry point for starting the server communication using the Java client API
  • A KieServicesFactory object defining REST protocol and user access
  • Any other client services used, such as RuleServicesClient, ProcessServicesClient, or QueryServicesClient
The following are examples of basic and advanced client configurations with these components:
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-server user role access to KIE Server.
  • You have a Java project with jBPM resources.
Procedure
  1. In your client application, ensure that the following dependencies have been added to the relevant classpath of your Java project:
  2. In the ~/kie/server/client folder of the Java client API in GitHub, identify the relevant Java client for the request you want to send, such as KieServicesClient to access client services for KIE containers and other assets in KIE Server.
  3. In your client application, create a .java class for the API request. The class must contain the necessary imports, KIE Server location and user credentials, a KieServicesClient object, and the client method to execute, such as createContainer and disposeContainer from the KieServicesClient client. Adjust any configuration details according to your use case.
    Creating and disposing a container
    You define service responses using the org.kie.server.api.model.ServiceResponse<T> object, where T represents the type of returned response. The ServiceResponse object has the following attributes:
    • String message: Returns the response message
    • ResponseType type: Returns either SUCCESS or FAILURE
    • T result: Returns the requested object
    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.
    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.
  4. Run the configured .java class 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 the org.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 containers
  • JobServicesClient: Used to schedule, cancel, re-queue, and get job requests
  • RuleServicesClient: Used to send commands to the server to perform rule-related operations, such as executing rules or inserting objects into the KIE session
  • ProcessServicesClient: Used to start, signal, and abort processes or work items
  • QueryServicesClient: Used to query processes, process nodes, and process variables
  • UserTaskServicesClient: 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 ID
  • UIServicesClient: 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)
The getServicesClient method provides access to any of these clients:
For the full list of available KIE Server Java clients, see the Java client API source in GitHub.

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 the org.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
Listing KIE containers in KIE Server KIE containers are represented by the 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
You can optionally filter the KIE container results using an instance of the 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
Creating and disposing KIE containers in KIE Server You can use the 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
Executing runtime commands in KIE Server jBPM supports runtime commands that you can send to KIE Server for asset-related operations, such as inserting or retracting objects in a KIE session or firing all rules. The full list of supported runtime commands is located in the 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.
Listing available business processes in a KIE container You can use the 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
Starting a business process in a KIE container You can use the 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
Running a custom query You can use the 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
In this example, the target instructs the query service to apply default filters. Alternatively, you can set filter parameters manually. The Target class supports the following values: