Este contenido no está disponible en el idioma seleccionado.
Chapter 23. Process Server capabilities and extensions
The capabilities in Process Server are determined by plug-in extensions that you can enable, disable, or further extend to meet your business needs. Process Server supports the following default capabilities and extensions:
Capability name | Extension name | Description |
---|---|---|
|
| Provides the core capabilities of Process 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 Process Management (BPM) capabilities, such as managing user tasks and executing business processes |
|
| Provides additional user-interface capabilities related to business processes, such as rendering XML forms and SVG images in process diagrams |
|
| Provides the case management capabilities for business processes, such as managing case definitions and milestones |
|
| 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 Process Server REST API |
To view the supported extensions of a running Process 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 Process Server information
http://SERVER:PORT/kie-server/services/rest/server
http://SERVER:PORT/kie-server/services/rest/server
Example JSON response with Process Server information
To enable or disable Process Server extensions, configure the related *.server.ext.disabled
Process Server system property. For example, to disable the BRM
capability, set the system property org.drools.server.ext.disabled=true
. For all Process Server system properties, see Chapter 22, Process Server system properties.
By default, Process Server extensions are exposed through REST or JMS data transports and use predefined client APIs. You can extend existing Process Server capabilities with additional REST endpoints, extend supported transport methods beyond REST or JMS, or extend functionality in the Process Server client.
This flexibility in Process Server functionality enables you to adapt your Process Server instances to your business needs, instead of adapting your business needs to the default Process Server capabilities.
If you extend Process Server functionality, Red Hat does not support the custom code that you use as part of your custom implementations and extensions.
23.1. Extending an existing Process Server capability with a custom REST API endpoint Copiar enlaceEnlace copiado en el portapapeles!
The Process Server REST API enables you to interact with your KIE containers and business assets (such as business rules, processes, and solvers) in Red Hat Process Automation Manager without using the Business Central user interface. The available REST endpoints are determined by the capabilities enabled in your Process Server system properties (for example, org.drools.server.ext.disabled=false
for the BRM
capability). You can extend an existing Process Server capability with a custom REST API endpoint to further adapt the Process Server REST API to your business needs.
As an example, this procedure extends the Drools
Process 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 Process 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 Process 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 Process 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 Process 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 Process 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 Process Server and deploy the built project to the running Process Server. You can deploy the project using either the Business Central interface or the Process Server REST API (a
PUT
request tohttp://SERVER:PORT/kie-server/services/rest/server/containers/{containerId}
).After your project is deployed on a running Process 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:
23.2. Extending Process Server to use a custom data transport Copiar enlaceEnlace copiado en el portapapeles!
By default, Process Server extensions are exposed through REST or JMS data transports. You can extend Process Server to support a custom data transport to adapt Process Server transport protocols to your business needs.
As an example, this procedure adds a custom data transport to Process Server that uses the Drools
extension and that is based on Apache MINA, an open-source Java network-application framework. The example custom MINA transport exchanges string-based data that relies on existing marshalling operations and supports only JSON format.
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.KieServerExtension
interface in a Java class in your project, as shown in the following example:Sample implementation of the
KieServerExtension
interfaceCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
KieServerExtension
interface is the main extension interface that Process Server can use to provide the additional functionality for the new MINA transport. The interface consists of the following components:Overview of the
KieServerExtension
interfaceCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Specifies the capability that is covered by this extension. The capability must be unique within Process Server.
- 2
- Defines a human-readable name for the extension.
- 3
- Determines when the specified extension should be started. For extensions that have dependencies on other extensions, this setting must not conflict with the parent setting. For example, in this case, this custom extension depends on the
Drools
extension, which hasStartOrder
set to0
, so this custom add-on extension must be greater than0
(set to20
in the sample implementation).
In the previous
MinaDroolsKieServerExtension
sample implementation of this interface, theinit
method is the main element for collecting services from theDrools
extension and for bootstrapping the MINA server. All other methods in theKieServerExtension
interface can remain with the standard implementation to fulfill interface requirements.The
TextBasedIoHandlerAdapter
class is the handler on the MINA server that reacts to incoming requests.Implement the
TextBasedIoHandlerAdapter
handler for the MINA server, as shown in the following example:Sample implementation of the
TextBasedIoHandlerAdapter
handlerCopy to Clipboard Copied! Toggle word wrap Toggle overflow In this example, the handler class receives text messages and executes them in the
Drools
service.Consider the following handler requirements and behavior when you use the
TextBasedIoHandlerAdapter
handler implementation:- Anything that you submit to the handler must be a single line because each incoming transport request is a single line.
-
You must pass a KIE container ID in this single line so that the handler expects the format
containerID|payload
. - You can set a response in the way that it is produced by the marshaller. The response can be multiple lines.
-
The handler supports a stream mode that enables you to send commands without disconnecting from a Process Server session. To end a Process Server session in stream mode, send either an
exit
orquit
command to the server.
-
To make the new data transport discoverable for Process Server, create a
META-INF/services/org.kie.server.services.api.KieServerExtension
file in your Maven project and add the fully qualified class name of theKieServerExtension
implementation class within the file. For this example, the file contains the single lineorg.kie.server.ext.mina.MinaDroolsKieServerExtension
. -
Build your project and copy the resulting JAR file and the
mina-core-2.0.9.jar
file (which the extension depends on in this example) 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 Process Server and deploy the built project to the running Process Server. You can deploy the project using either the Business Central interface or the Process Server REST API (a
PUT
request tohttp://SERVER:PORT/kie-server/services/rest/server/containers/{containerId}
).After your project is deployed on a running Process Server, you can view the status of the new data transport in your Process Server log and start using your new data transport:
New data transport in the server log
Drools-Mina KIE Server extension -- Mina server started at localhost and port 9123 Drools-Mina KIE Server extension has been successfully registered as server extension
Drools-Mina KIE Server extension -- Mina server started at localhost and port 9123 Drools-Mina KIE Server extension has been successfully registered as server extension
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For this example, you can use Telnet to interact with the new MINA-based data transport in Process Server:
Starting Telnet and connecting to Process Server on port 9123 in a command terminal
telnet 127.0.0.1 9123
telnet 127.0.0.1 9123
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example interactions with Process Server in a command terminal
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example server log output
16:33:40,206 INFO [stdout] (NioProcessor-2) Hello john 16:34:03,877 INFO [stdout] (NioProcessor-2) Hello mary 16:34:19,800 INFO [stdout] (NioProcessor-2) Hello james
16:33:40,206 INFO [stdout] (NioProcessor-2) Hello john 16:34:03,877 INFO [stdout] (NioProcessor-2) Hello mary 16:34:19,800 INFO [stdout] (NioProcessor-2) Hello james
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
23.3. Extending the Process Server client with a custom client API Copiar enlaceEnlace copiado en el portapapeles!
Process Server uses predefined client APIs that you can interact with to use Process Server services. You can extend the Process Server client with a custom client API to adapt Process Server services to your business needs.
As an example, this procedure adds a custom client API to Process Server to accommodate a custom data transport (configured previously for this scenario) that is based on Apache MINA, an open-source Java network-application framework.
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 relevant
ServicesClient
interface in a Java class in your project, as shown in the following example:Sample
RulesMinaServicesClient
interfacepublic interface RulesMinaServicesClient extends RuleServicesClient { }
public interface RulesMinaServicesClient extends RuleServicesClient { }
Copy to Clipboard Copied! Toggle word wrap Toggle overflow A specific interface is required because you must register client implementations based on the interface, and you can have only one implementation for a given interface.
For this example, the custom MINA-based data transport uses the
Drools
extension, so this exampleRulesMinaServicesClient
interface extends the existingRuleServicesClient
client API from theDrools
extension.Implement the
RulesMinaServicesClient
interface that the Process Server can use to provide the additional client functionality for the new MINA transport, as shown in the following example:Sample implementation of the
RulesMinaServicesClient
interfaceCopy to Clipboard Copied! Toggle word wrap Toggle overflow This example implementation specifies the following data and behavior:
- Uses socket-based communication for simplicity
-
Relies on default configurations from the Process Server client and uses
ServerUrl
for providing the host and port of the MINA server - Specifies JSON as the marshalling format
-
Requires received messages to be JSON objects that start with an open bracket
{
- Uses direct socket communication with a blocking API while waiting for the first line of the response and then reads all lines that are available
- Does not use stream mode and therefore disconnects the Process Server session after invoking a command
Implement the
org.kie.server.client.helper.KieServicesClientBuilder
interface in a Java class in your project, as shown in the following example:Sample implementation of the
KieServicesClientBuilder
interfaceCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Enables you to provide additional client APIs to the generic Process Server client infrastructure
- 2
- Defines the Process Server capability (extension) that the client uses
- 3
- Provides a map of the client implementations, where the key is the interface and the value is the fully initialized implementation
-
To make the new client API discoverable for the Process Server client, create a
META-INF/services/org.kie.server.client.helper.KieServicesClientBuilder
file in your Maven project and add the fully qualified class name of theKieServicesClientBuilder
implementation class within the file. For this example, the file contains the single lineorg.kie.server.ext.mina.client.MinaClientBuilderImpl
. -
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 Process Server and deploy the built project to the running Process Server. You can deploy the project using either the Business Central interface or the Process Server REST API (a
PUT
request tohttp://SERVER:PORT/kie-server/services/rest/server/containers/{containerId}
).After your project is deployed on a running Process Server, you can start interacting with your new Process Server client. You use your new client in the same way as the standard Process Server client, by creating the client configuration and client instance, retrieving the service client by type, and invoking client methods.
For this example, you can create a
RulesMinaServiceClient
client instance and invoke operations on Process Server through the MINA transport:Sample implementation to create the
RulesMinaServiceClient
clientCopy to Clipboard Copied! Toggle word wrap Toggle overflow Sample configuration to invoke operations on Process Server through the MINA transport
Copy to Clipboard Copied! Toggle word wrap Toggle overflow