第16章 KIE Server capabilities and extensions
The capabilities in KIE Server are determined by plug-in extensions that you can enable, disable, or further extend to meet your business needs. KIE Server supports the following default capabilities and extensions:
Capability name | Extension name | Description |
---|---|---|
|
| Provides the core capabilities of KIE Server, such as creating and disposing KIE containers on your server instance |
|
| Provides the Business Rule Management (BRM) capabilities, such as inserting facts and executing business rules |
|
| Provides the Business Resource Planning (BRP) capabilities, such as implementing solvers |
|
| Provides the Decision Model and Notation (DMN) capabilities, such as managing DMN data types and executing DMN models |
|
| Provides the Swagger web-interface capabilities for interacting with the KIE Server REST API |
To view the supported extensions of a running KIE Server instance, send a GET
request to the following REST API endpoint and review the XML or JSON server response:
Base URL for GET request for KIE Server information
http://SERVER:PORT/kie-server/services/rest/server
http://SERVER:PORT/kie-server/services/rest/server
Example JSON response with KIE Server information
To enable or disable KIE Server extensions, configure the related *.server.ext.disabled
KIE Server system property. For example, to disable the BRM
capability, set the system property org.drools.server.ext.disabled=true
. For all KIE Server system properties, see 15章KIE Server system properties.
By default, KIE Server extensions are exposed through REST or JMS data transports and use predefined client APIs. You can extend existing KIE Server capabilities with additional REST endpoints, extend supported transport methods beyond REST or JMS, or extend functionality in the KIE Server client.
This flexibility in KIE Server functionality enables you to adapt your KIE Server instances to your business needs, instead of adapting your business needs to the default KIE Server capabilities.
If you extend KIE Server functionality, Red Hat does not support the custom code that you use as part of your custom implementations and extensions.
16.1. Extending an existing KIE Server capability with a custom REST API endpoint リンクのコピーリンクがクリップボードにコピーされました!
The KIE Server REST API enables you to interact with your KIE containers and business assets (such as business rules, processes, and solvers) in Red Hat Decision Manager without using the Business Central user interface. The available REST endpoints are determined by the capabilities enabled in your KIE Server system properties (for example, org.drools.server.ext.disabled=false
for the BRM
capability). You can extend an existing KIE Server capability with a custom REST API endpoint to further adapt the KIE Server REST API to your business needs.
As an example, this procedure extends the Drools
KIE Server extension (for the BRM
capability) with the following custom REST API endpoint:
Example custom REST API endpoint
/server/containers/instances/{containerId}/ksession/{ksessionId}
/server/containers/instances/{containerId}/ksession/{ksessionId}
This example custom endpoint accepts a list of facts to be inserted into the working memory of the decision engine, automatically executes all rules, and retrieves all objects from the KIE session in the specified KIE container.
Procedure
Create an empty Maven project and define the following packaging type and dependencies in the
pom.xml
file for the project:Example pom.xml file in the sample project
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Implement the
org.kie.server.services.api.KieServerApplicationComponentsService
interface in a Java class in your project, as shown in the following example:Sample implementation of the
KieServerApplicationComponentsService
interfaceCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Delivers REST endpoints to the KIE Server infrastructure that is deployed when the application starts.
- 2
- Specifies the extension that you are extending, such as the
Drools
extension in this example. - 3
- Returns all resources that the REST container must deploy. Each extension that is enabled in your KIE Server instance calls the
getAppComponents
method, so theif ( !OWNER_EXTENSION.equals(extension) )
call returns an empty collection for any extensions other than the specifiedOWNER_EXTENSION
extension. - 4
- Lists the services from the specified extension that you want to use, such as the
RulesExecutionService
andKieServerRegistry
services from theDrools
extension in this example. - 5
- Specifies the transport type for the extension, either
REST
orJMS
(REST
in this example), and theCustomResource
class that returns the resource as part of thecomponents
list.
Implement the
CustomResource
class that the KIE Server can use to provide the additional functionality for the new REST resource, as shown in the following example:Sample implementation of the
CustomResource
classCopy to Clipboard Copied! Toggle word wrap Toggle overflow In this example, the
CustomResource
class for the custom endpoint specifies the following data and behavior:-
Uses the base endpoint
server/containers/instances/{containerId}/ksession
-
Uses
POST
HTTP method Expects the following data to be given in REST requests:
-
The
containerId
as a path argument -
The
ksessionId
as a path argument - List of facts as a message payload
-
The
Supports all KIE Server data formats:
- XML (JAXB, XStream)
- JSON
-
Unmarshals the payload into a
List<?>
collection and, for each item in the list, creates anInsertCommand
instance followed byFireAllRules
andGetObject
commands. -
Adds all commands to the
BatchExecutionCommand
instance that calls to the decision engine.
-
Uses the base endpoint
-
To make the new endpoint discoverable for KIE Server, create a
META-INF/services/org.kie.server.services.api.KieServerApplicationComponentsService
file in your Maven project and add the fully qualified class name of theKieServerApplicationComponentsService
implementation class within the file. For this example, the file contains the single lineorg.kie.server.ext.drools.rest.CusomtDroolsKieServerApplicationComponentsService
. -
Build your project and copy the resulting JAR file into the
~/kie-server.war/WEB-INF/lib
directory of your project. For example, on Red Hat JBoss EAP, the path to this directory isEAP_HOME/standalone/deployments/kie-server.war/WEB-INF/lib
. Start the KIE Server and deploy the built project to the running KIE Server. You can deploy the project using either the Business Central interface or the KIE Server REST API (a
PUT
request tohttp://SERVER:PORT/kie-server/services/rest/server/containers/{containerId}
).After your project is deployed on a running KIE Server, you can start interacting with your new REST endpoint.
For this example, you can use the following information to invoke the new endpoint:
-
Example request URL:
http://localhost:8080/kie-server/services/rest/server/containers/instances/demo/ksession/defaultKieSession
-
HTTP method:
POST
HTTP headers:
-
Content-Type: application/json
-
Accept: application/json
-
Example message payload:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Example server response:
200
(success) Example server log output:
13:37:20,347 INFO [stdout] (default task-24) Hello mary 13:37:20,348 INFO [stdout] (default task-24) Hello john
13:37:20,347 INFO [stdout] (default task-24) Hello mary 13:37:20,348 INFO [stdout] (default task-24) Hello john
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Example request URL: