Chapter 12. Endpoints
Clients can access Realtime Decision Server for OpenShift via multiple endpoints; by default the provided templates include support for REST, HornetQ, and ActiveMQ.
12.1. REST
Clients can use the REST API in various ways:
12.1.1. Browser
- Current server state: http://host/kie-server/services/rest/server
- List of containers: http://host/kie-server/services/rest/server/containers
- Specific container state: http://host/kie-server/services/rest/server/containers/HelloRulesContainer
12.1.2. Java
// HelloRulesClient.java
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(
"http://host/kie-server/services/rest/server", "kieserverUser", "kieserverPassword");
config.setMarshallingFormat(MarshallingFormat.XSTREAM);
RuleServicesClient client =
KieServicesFactory.newKieServicesClient(config).getServicesClient(RuleServicesClient.class);
ServiceResponse<String> response = client.executeCommands("HelloRulesContainer", myCommands);12.1.3. Command Line
# request.sh #!/bin/sh curl -X POST \ -d @request.xml \ -H "Accept:application/xml" \ -H "X-KIE-ContentType:XSTREAM" \ -H "Content-Type:application/xml" \ -H "Authorization:Basic a2llc2VydmVyOmtpZXNlcnZlcjEh" \ -H "X-KIE-ClassType:org.drools.core.command.runtime.BatchExecutionCommandImpl" \ http://host/kie-server/services/rest/server/containers/instances/HelloRulesContainer
<!-- request.xml -->
<batch-execution lookup="HelloRulesSession">
<insert>
<org.openshift.quickstarts.decisionserver.hellorules.Person>
<name>errantepiphany</name>
</org.openshift.quickstarts.decisionserver.hellorules.Person>
</insert>
<fire-all-rules/>
<query out-identifier="greetings" name="get greeting"/>
</batch-execution>12.2. JMS
Client can also use the Java Messaging Service, as demonstrated below:
12.2.1. Java (HornetQ)
// HelloRulesClient.java
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.naming.remote.client.InitialContextFactory");
props.setProperty(Context.PROVIDER_URL, "remote://host:4447");
props.setProperty(Context.SECURITY_PRINCIPAL, "kieserverUser");
props.setProperty(Context.SECURITY_CREDENTIALS, "kieserverPassword");
InitialContext context = new InitialContext(props);
KieServicesConfiguration config =
KieServicesFactory.newJMSConfiguration(context, "hornetqUser", "hornetqPassword");
config.setMarshallingFormat(MarshallingFormat.XSTREAM);
RuleServicesClient client =
KieServicesFactory.newKieServicesClient(config).getServicesClient(RuleServicesClient.class);
ServiceResponse<String> response = client.executeCommands("HelloRulesContainer", myCommands);12.2.2. Java (ActiveMQ)
// HelloRulesClient.java
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
props.setProperty(Context.PROVIDER_URL, "tcp://host:61616");
props.setProperty(Context.SECURITY_PRINCIPAL, "kieserverUser");
props.setProperty(Context.SECURITY_CREDENTIALS, "kieserverPassword");
InitialContext context = new InitialContext(props);
ConnectionFactory connectionFactory = (ConnectionFactory)context.lookup("ConnectionFactory");
Queue requestQueue = (Queue)context.lookup("dynamicQueues/queue/KIE.SERVER.REQUEST");
Queue responseQueue = (Queue)context.lookup("dynamicQueues/queue/KIE.SERVER.RESPONSE");
KieServicesConfiguration config = KieServicesFactory.newJMSConfiguration(
connectionFactory, requestQueue, responseQueue, "activemqUser", "activemqPassword");
config.setMarshallingFormat(MarshallingFormat.XSTREAM);
RuleServicesClient client =
KieServicesFactory.newKieServicesClient(config).getServicesClient(RuleServicesClient.class);
ServiceResponse<String> response = client.executeCommands("HelloRulesContainer", myCommands);
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.