Tag Archives: guvnor

JBoss Drools Developer‘s Cookbook released

Maybe you noticed, or not, that this blog hasn’t had too much activity lately (but hey, I wasn’t blooging much before, right?). Well, one of the reasons was the Drools Developer Cookbook, a book that I was writing and that after a few months of hard work is finally finished and released by Packt Publishing.

Drools Developer's Cookbook cover

Inside this book you will find lots of recipes to apply in your Drools projects, in order to take advantage of the latest features released in JBoss Drools 5.2 and 5.3. It covers all the main modules, Expert, Fusion, Guvnor, Planner and even jBPM5.

I would like to thank Packt Publishing & crew, Edson Tirelli, Geoffrey De Smet, Toni Rikkola and everyone else that in any way helped me.

The chapters 2 & 7 are available to read in the next links:

Expert: behind the rules (Full chapter)
Integration: How to connect Drools (Article)

As always, for further details you can take a look in the book website

Have fun


New Drools Execution Server

Update: drools-server features/configuration were changed, please read the updated post here

Hi everyone,  last week I was working on a new version of the Drools Execution Server. The goal of this new version was to get the new XStream/JAXB Drools Camel integration to execute commands using a simple service that can be accessed using the RestWS and SOAP protocols. Similar to the previous version, the Drools Execution Server is a simple WAR file that can be deployed on a JBoss AS or any other servlet container.

But the big new feature is the ability to use both stateful and stateless knowledge sessions that can be accessed throught REST and SOAP at the same time.

You must note that in the past, the old drools-server saved the following information in order to create only stateless knowledge session:


This information was stored in a file called <session>.properties, where <session> is the name of the stateless session that was used in the request to reference a specific state knowledge session, that in the previous version can only contain a single rule file.

This approach was extended with the concept of Knowledge Context Profiles. Each Knowledge Context Profile let us define more complex execution scenarios. Now we can define Stateful and Stateless sessions with more that one Knowledge resource, using different marshallers to send and recieve the information that we will use to interact with this remote sessions.

Profiles can be configured through a simple profiles.xml file, which resides inside the WAR file, and can contain multiple Knowledge Context Profiles definitions, as in the following XML example:

<?xml version="1.0" encoding="UTF-8" ?>
	<knowledge-context-profile id="ksession1">
			<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
			<batch-execution lookup="ksession1" xmlns:ns2="http://drools.org/model">
			    <insert out-identifier="santa">
			        <object xsi:type="ns2:person" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

	<knowledge-context-profile id="ksession2">


As you can see to configure each knowledge-context-profiles you need to set up the following information:

  • id: the session identifier (required)
  • session-type: stateless/stateful (required)
  • change-sets: here you can add the changesets that contains references to the rules to be used on the session
  • jaxb-models: this is only if you wanted to use jaxb-commands and define the model with an XSD model definition (required only when using jaxb)
  • classes-names:  classes that you could include on jaxb context (required on jaxb)
  • startup-commands: here you can add xml commands to be executed on the session  startup.

Actually the drools server was tested on JBoss AS 5.X and JBoss AS 4.2.3, but should work on any servlet container. Just copy the .war file on the deploy folder and configure the profiles.xml file inside the /WEB-INF/classes directory.

Note: to deploy in JBoss AS 4.X (and probably another servlet containter) you need to modify the cxf.xml server configuration file located inside /WEB-INF/. You need to replace the next lines

<bean id="knowledgeService" class="org.drools.server.KnowledgeService" >
        <property name="packageScanClassResolver">
            <ref local="jbossResolver" />

<bean id="jbossResolver" />


<bean id="knowledgeService"  class="org.drools.server.KnowledgeService" /> to make it work.

This will change how Apache Camel will interact with the JBoss AS5 classloader, pretty simple.


On this new version we are using the Drools Commands API in XML form. Take a look at the following example:

BatchExecutionCommand executionCommand = new BatchExecutionCommand();

InsertObjectCommand insertCommand = new InsertObjectCommand();
insertCommand.setObject(new Person("lucaz"));


String xml = BatchExecutionHelper.newXStreamMarshaller().toXML(executionCommand);

With this lines you will get the xml command representation, using xstream marshaller, that you can use to interact with the drools execution server:

<batch-execution lookup="ksession1">
  <insert out-identifier="person1" return-object="true">

RestWS integration

Let’s test the RestWS service by following this steps:

1) Create an Apache HttpClient instance and configure it with the drools-server ip address and port:

HttpClient httpClient = new HttpClient();
httpClient.getHostConfiguration().setHost("", 8080);

2) Create a PosthMethod and send the xml command to the URI /drools-server/services/rest/execute

PostMethod postMethod = new PostMethod("/drools-server/services/rest/execute");
postMethod.addParameter("command", xmlCommand);

3) Execute the method. If the execution was succesfull you will got a HTTP Response Code OK (200) otherwise a BAD_REQUEST (400) response code will be thrown to the client.

assertEquals(200, postMethod.getStatusCode());

4) And finally, get the execution response

String response = postMethod.getResponseBodyAsString();

SOAP integration

Here’s one way to use the SOAP interface with Apache CXF:

1) Create a JaxWsProxyFactoryBean, set the KnowledgeServiceSoap (that could be generated with the WSDL exposed at ) as the Service Class and the URL

JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();

2) Create the KnowledgeServiceSoap client and execute the xml command

<span style="font-size: x-small;">KnowledgeServiceSoap client = (KnowledgeServiceSoap) clientFactory.create();
String response = client.execute(xmlCommand);</span>

Future Steps (in development)

Currently I’m working on a new Guvnor module that will let us define the Knowledge Context Profile with a guided editor (without write XML!), and with a similar change-sets structure. Also you could add drools-server instance and do simple operations, as send commands to execute, check the server status and others features.

Note: Drools Execution Server is not merged into the trunk, but we are working to merge it as soon as possible and include this features in the M2 release. Please, let me kwow what do you think when M2 is ready!

Google Summer of Code 2009


Hace unos pocos días fuí seleccionado para participar en el Google Summer of Code 2009, más precisamente con el proyecto Refactoring Rules de JBoss Drools.

El objetivo de este proyecto es realizar la integración de refactorización de reglas en los IDEs, tanto en el IDE para Eclipse como en Guvnor. Este módulo tiene que ser reutilizable para ambas partes, y tener un nivel de abstracción que permita realizar la refactorización en todos los tipos de formatos de reglas conocidos, no solamente DRL sino que también en DSL, BRL, TableDecision (aunque en este momento no se implemente), RuleFlow, etc.

En la application presentada se propusieron varias features, que en teoría todas son implementables pero todavia no hay nada concreto.

  • Asignación de variable
  • Renombrar variable
  • Cambio de parámetros para aumentar la performance
  • Detección de producto cruzado
  • Sugerencia de join/linking variable
  • Organizar imports

Se habrán dado cuenta que algunas features van más allá de lo que denominamos refactorización, pero son un buen agregado que pueden proporcionarles nuevas funcionalidades a los IDE’s, y seguramente se agregarán o modificarán algunos requerimientos según los pedidos de mi mentor asignado aparte de algunas ideas que puedan surguir cuando empieze el coding madness.

Toda esta locura empieza el 23 de mayo, cuando es la fecha fijada para el inicio formal de GSoC, sin embargo en estas semanas restantes son los momentos para empezar a coordinar con los mentores y completar wikis como Refactoring Rules , que como verán todavía no tiene ningún contenido de implementación más allá de los requerimientos y donde podrán seguir los avances que vayan sucediendo.

Supongo que si hay alguna novedad útil para comentar sobre los progresos lo haré en otro post, por ahora no hay mucho más que contar… eso si, el 26 de agosto les comento como terminó todo esto.

Post original de lucazamador.wordpress.com