Saturday, July 05, 2008

Drools Smooks Data Loader

Smooks is a powerful open source ETL tool, it can transform variety of data sources.

Drools now supports an internal model, so ideally you want to be able to load different payloads, such as XML, into this model. I've just added support for this and it'll be in M2 :)

Here is an example of the api loading an XML file into a drools session, the xml entries for OrderItem are mapped into the internal class and inserted into the given session. The matching rules simple do a print statement.

declare OrderItem
productId : long
quantity : Integer
price : double

rule someRule
$i : OrderItem()
System.out.println( $i );

PackageBuilder pkgBuilder = new PackageBuilder();
pkgBuilder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test.drl" )) );

RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkgBuilder.getPackage() );

StatefulSession session = ruleBase.newStatefulSession();

// Instantiate Smooks with the config...
Smooks smooks = new Smooks( "smooks-config.xml" );

// set rood id
DroolsSmooksConfiguration conf = new DroolsSmooksConfiguration( "root" );
DroolsSmooks loader = new DroolsSmooks( session, smooks, conf );
loader.insertFilter( new StreamSource( new ByteArrayInputStream( readInputMessage() ) ) );




  1. Hi Mark, nice work!
    How is this internal model implementing equals and hashCode methods? Is it just inheriting them from Object class?
    Thank you.

  2. I think so. We probably need to allow that to be configurable.

  3. What library (jar) are the Smooks dataloaders in? I want to try using Smooks to load my facts from an XML file based on the code you've listed here) but can't resolve the references in my code.


  4. best to ask these things on the drools user mailing list:

    You'll want the binaries zip from here:

    Where you'll find a drools-transformer-smooks.jar and also in lib directory you'll see the smooks dependency itself.

    If you still struggle maybe try using a maven build system, and add the jboss repository from which the smooks dataloader and all it's dependencies will be managed for you

  5. time I'll hit the mailing list ;)

    I did download the M5 binaries from, but I don't see drools-transformer-smooks.jar as one of the jars in the download, nor do I see the Smooks dependency in the lib directory, which is why I was wondering where this stuff was ;)

  6. I just checked in the and you are right, it's not there. I'm guessing our maven assembly needs updating. you can still get it from the maven repository though. I'll make sure that gets fixed for the next release, thanks for bringing it to my attention.

  7. Hi Mark,
    Very helpful info.
    I am having a small problem working with smooks though.
    I uploaded all the reuired dependencies for Smooks from the site But I am unable to resolve DroolsSmooksConfiguration.
    Could you help with all the required dependencies needed to work with smooks?? I am working with JBossDeveloperStudio 3.0.1