<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Red Hat Magazine &#187; JBoss</title>
	<atom:link href="http://magazine.redhat.com/category/jboss/feed/" rel="self" type="application/rss+xml" />
	<link>http://magazine.redhat.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Tue, 15 Sep 2009 20:14:47 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='magazine.redhat.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/43e95982d87da9fb7c7b9a74b524335f?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Red Hat Magazine &#187; JBoss</title>
		<link>http://magazine.redhat.com</link>
	</image>
			<item>
		<title>The JBoss Virtual Experience</title>
		<link>http://magazine.redhat.com/2009/02/10/the-jboss-virtual-experience/</link>
		<comments>http://magazine.redhat.com/2009/02/10/the-jboss-virtual-experience/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 23:10:12 +0000</pubDate>
		<dc:creator>The editorial team</dc:creator>
				<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[multimedia]]></category>

		<guid isPermaLink="false">http://magazine.redhat.com/?p=1128</guid>
		<description><![CDATA[Do you know what&#8217;s happening in middleware? Budget crunch keeping you from attending industry gatherings? Bring the conference to your desktop.  Take a minute (or a few hours) and attend the JBoss Virtual Experience.
Wednesday, February 11th, 2009 LIVE online
(on-demand February 16th &#8211; May 11th, 2009)
Find out more or register now.

Join our executives, key developers, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1128&subd=rhredhatmagazine&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Do you know what&#8217;s happening in middleware? Budget crunch keeping you from attending industry gatherings? Bring the conference to your desktop.  Take a minute (or a few hours) and attend the JBoss Virtual Experience.</p>
<p><strong>Wednesday, February 11th, 2009 LIVE online</strong><br />
(on-demand February 16th &#8211; May 11th, 2009)</p>
<p><span style="font-size:larger;font-weight:heavy;"><a href="http://www.jboss.com/virtualexperience">Find out more</a> or <a href="http://www-2.virtualevents365.com/jboss_experience/register.php">register now.</a></span></p>
<p><a href="http://www.jboss.com/virtualexperience" title="JBVE_map by redhatmag, on Flickr"><img src="http://farm2.static.flickr.com/1080/3270677136_f0d5f888b9_o.png" width="300" height="181" alt="JBVE_map" /></a></p>
<p>Join our executives, key developers, and your business peers. Attend keynote sessions for executive insight into the future of open source and the middleware roadmap for 2009 and beyond. Visit the Exhibit Hall and chat live with booth representatives. Come to the Networking Cafe for in-depth technical and business discussions, birds-of-a-feather chats, and live Q&amp;A with our speakers.<br />
<span id="more-1128"></span><br />
Whether you&#8217;re a developer, enterprise architect, or senior IT manager, this one-day event will show you how JBoss can help you build, integrate, deploy, and manage mission-critical applications and services while lowering your costs without sacrificing performance, security, or functionality.</p>
<p>For updates, <a href="http://twitter.com/jbossvirtexp">follow us on Twitter</a>.</p>
<p>Here&#8217;s a few more details:</p>
<p>Keynotes with live Q&amp;A:</p>
<ul>
<li>Business keynote by Jim Whitehurst (live event only) and Craig Muzilla</li>
<li>technical keynote by Rob Cardwell and Sacha Labourey</li>
</ul>
<p>Sessions with live Q&amp;A: </p>
<ul>
<li>business, technical and government</li>
<li>2 panel discussions: Customer viewpoint and Developer panel</li>
</ul>
<p>Exhibit Hall:<br />
Red Hat booths, including: </p>
<ul>
<li>JBoss Enterprise Middleware</li>
<li>JBoss Operations Network</li>
<li>JBoss.org</li>
<li>Customer Reference</li>
<li>MRG (Messaging, Realtime, and Grid)</li>
<li>Cloud Computing</li>
</ul>
<p>Partner booths include: </p>
<ul>
<li>Alfresco</li>
<li>Carahsoft</li>
<li>CityTech</li>
<li>Consilium1</li>
<li>DLT</li>
<li>Dell</li>
<li>EnterpriseDB</li>
<li>Exadel</li>
<li>Freedom OSS</li>
<li>Ingres</li>
<li>Jaspersoft</li>
<li>USolutions</li>
<li>Vizuri</li>
</ul>
<p>Media sponsor: </p>
<ul>
<li>DZone</li>
</ul>
<p>Networking cafe:</p>
<ul>
<li>Birds-of-a-Feather sessions with JBoss Rock Stars</li>
</ul>
<p><strong><a href="http://www.jboss.com/virtualexperience">Find out more</a> or <a href="http://www-2.virtualevents365.com/jboss_experience/register.php">register now.</a></strong></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rhredhatmagazine.wordpress.com/1128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rhredhatmagazine.wordpress.com/1128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rhredhatmagazine.wordpress.com/1128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rhredhatmagazine.wordpress.com/1128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rhredhatmagazine.wordpress.com/1128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rhredhatmagazine.wordpress.com/1128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rhredhatmagazine.wordpress.com/1128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rhredhatmagazine.wordpress.com/1128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rhredhatmagazine.wordpress.com/1128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rhredhatmagazine.wordpress.com/1128/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1128&subd=rhredhatmagazine&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://magazine.redhat.com/2009/02/10/the-jboss-virtual-experience/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">The editorial team</media:title>
		</media:content>

		<media:content url="http://farm2.static.flickr.com/1080/3270677136_f0d5f888b9_o.png" medium="image">
			<media:title type="html">JBVE_map</media:title>
		</media:content>
	</item>
		<item>
		<title>Interview: Chris Morgan on Jopr</title>
		<link>http://magazine.redhat.com/2008/10/31/interview-chris-morgan-on-jopr/</link>
		<comments>http://magazine.redhat.com/2008/10/31/interview-chris-morgan-on-jopr/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 20:18:50 +0000</pubDate>
		<dc:creator>Ruth Suehle</dc:creator>
				<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://www.redhatmagazine.com/2008/10/31/interview-chris-morgan-on-jopr/</guid>
		<description><![CDATA[JBoss Operations Network (JON) recently became available as an open source solution through the Jopr project. (That&#8217;s pronounced &#8220;jopper.&#8221;) We interviewed Chris Morgan from Red Hat&#8217;s JON group to learn more.
1.  What does Jopr do?
Jopr is an open source project that provides an integrated  management platform that simplifies the development, testing, deployment, and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1069&subd=rhredhatmagazine&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>JBoss Operations Network (JON) recently became available as an open source solution through the Jopr project. (That&#8217;s pronounced &#8220;jopper.&#8221;) We interviewed Chris Morgan from Red Hat&#8217;s JON group to learn more.</p>
<p><b>1.  What does Jopr do?</b><br />
<a href="http://www.jboss.org/jopr/">Jopr</a> is an open source project that provides an integrated  management platform that simplifies the development, testing, deployment, and monitoring of your JBoss technologies. From a single console you can inventory and monitor resources from the operating system to deployed applications. It also lets users control and audit application configurations to standardize deployments. It&#8217;s a robust solution to manage, monitor, and tune your applications for improved visibility, performance, and availability.</p>
<p><span id="more-1069"></span></p>
<p><b>2.  What about Embedded Jopr?</b><br />
Embedded Jopr provides many of the same features as Jopr, but only for a single instance or (in the near future) a cluster of JBoss technologies. It&#8217;s essentially an administration console to manage JBoss  products&#8211;users don&#8217;t have to rely so much on command line and XML configuration to set up their JBoss environment and applications.</p>
<p>It doesn&#8217;t offer the extensive monitoring and historical auditing capabilities of Jopr, but it is perfect for an individual developer or administrator to use. In contrast, Jopr is what you use to manage the entire enterprise or multiple instances and clusters from one location.</p>
<p><b>3.  How does Jopr fit in with JON and RHQ?</b><br />
RHQ is the platform on which Jopr is written. RHQ provides a very extensible plug-in technology that allows for many other technologies to be managed. Jopr includes all of the existing RHQ plugins, plus JBoss-specific ones. In turn, Jopr is the true upstream to commercial JBoss Operations Network (JON).</p>
<p>So you could think of it this way: RHQ is upstream to Jopr, which is upstream to JBoss Operations Network.</p>
<p><b>4. How did the project get started?</b><br />
The project has really been in the works for a while, starting when it was becoming clear that JBoss needed a tool to help enable solutions for &#8220;non-developers&#8221; as the JBoss footprint continued to grow.</p>
<p>Typically, the groups responsible for operations in an environment are not the developers, so they need a different set of tools.  Most operations staff are concerned  with uptime and making sure the environment is compliant and ready to use for the customers they support. Jopr is the open source solution to provide that for JBoss technologies.</p>
<p><b>5. Tell us about the name.</b><br />
Well, the team actually went through what seemed like hundreds of names, but almost every one we were close to choosing had some sort of issue where it was taken, trademarked, or just not &#8220;sticky&#8221; enough. So legend has it that a 1983 Matthew Broderick and Ally Sheedy flick called <em>War Games</em> was the eventual inspiration.</p>
<p>The real star of the movie was an artificial intelligence computer the military used called W.O.P.R.  (pronounced whopper). From this, Jopr was born (it&#8217;s not a acronym as in the movie&#8211;that would have opened an entire other set of issues for getting a trademark). So it met the criteria of not being taken, it could be trademarked. And it was definitely &#8220;sticky,&#8221; as there is really no project, especially not in the Java space, that is even close.</p>
<p><b>6. So how is Embedded Jopr different from the consoles that have shipped with JBoss Application Server in the past?</b><br />
Previous consoles for the application server were designed with a &#8220;developer&#8221; in mind, so they required some JBoss and Java expertise to use. With Embedded Jopr (and really, Jopr, too), it&#8217;s all about enabling JBoss for operations by making administrative and management tasks easier. We hope that with the open source community helping us, we can continue to push that goal forward.</p>
<p><b>7. Can anyone contribute? How would they get involved?</b><br />
Absolutely!  Just go to <a href="http://www.jboss.org/jopr">http://www.jboss.org/jopr</a> or <a href="http://www.jboss.org/embjopr">http://www.jboss.org/embjopr</a> and join us!</p>
<p><b>Related links</b><br />
<a href="http://www.jboss.org/jopr">http://www.jboss.org/jopr</a><br />
<a href="http://www.jboss.org/embjopr">http://www.jboss.org/embjopr</a><br />
<a href="http://www.jboss.org/feeds/">http://www.jboss.org/feeds/</a><br />
(scroll down to JBoss ON section for many of the development team blogs)<br />
<a href="http://www.rhq-project.org">http://www.rhq-project.org</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rhredhatmagazine.wordpress.com/1069/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rhredhatmagazine.wordpress.com/1069/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rhredhatmagazine.wordpress.com/1069/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rhredhatmagazine.wordpress.com/1069/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rhredhatmagazine.wordpress.com/1069/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rhredhatmagazine.wordpress.com/1069/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rhredhatmagazine.wordpress.com/1069/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rhredhatmagazine.wordpress.com/1069/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rhredhatmagazine.wordpress.com/1069/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rhredhatmagazine.wordpress.com/1069/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1069&subd=rhredhatmagazine&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://magazine.redhat.com/2008/10/31/interview-chris-morgan-on-jopr/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ruthsuehle</media:title>
		</media:content>
	</item>
		<item>
		<title>JBoss Drools how-to: Tuning Guvnor, part 2</title>
		<link>http://magazine.redhat.com/2008/08/14/jboss-drools-how-to-tuning-guvnor-part-2/</link>
		<comments>http://magazine.redhat.com/2008/08/14/jboss-drools-how-to-tuning-guvnor-part-2/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 22:34:10 +0000</pubDate>
		<dc:creator>kijanowski</dc:creator>
				<category><![CDATA[JBoss]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://www.redhatmagazine.com/2008/08/14/jboss-drools-how-to-tuning-guvnor-part-2/</guid>
		<description><![CDATA[Guvnor is the business rules management system in Drools 5. When you deploy it out of the box, you get an unsecured web application that stores data in Jackrabbit&#8217;s embedded Derby database.
This two-part article explains how to tune Guvnor deployed on JBoss Application Server 4.2.3. (If you missed the first half of the series, catch [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1021&subd=rhredhatmagazine&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Guvnor is the business rules management system in Drools 5. When you deploy it out of the box, you get an unsecured web application that stores data in Jackrabbit&#8217;s embedded Derby database.</p>
<p>This two-part article explains how to tune Guvnor deployed on JBoss Application Server 4.2.3. (If you missed the first half of the series, <a href="http://www.redhatmagazine.com/2008/08/12/jboss-drools-how-to-tuning-guvnor-part-1/">catch up</a> in our archives.)This means that we will use the container&#8217;s configuration files and security infrastructure. This installment covers enabling password validation based on an OpenLDAP server, moving from the default data repository, and enabling SSL for better security.<span id="more-1021"></span></p>
<ol>
<li><a href="#ldap">Use OpenLDAP as a user repository</a></li>
<li><a href="#mysql">Use MySQL as a data repository</a></li>
<li><a href="#ssl">Enable SSL</a></li>
<li><a href="#secured">How to use a secured Guvnor package</a></li>
<li><a href="#summary">Summary</a></li>
</ol>
<p><a name="ldap"></a></p>
<h2>Use OpenLDAP as a user repository</h2>
<p>There are several reasons why you would want to use an LDAP directory instead of a clear text file &#8212; security, provisioning,  and reuseability are just a few. First of all, we need a directory. OpenLDAP will do for this example. Download and extract the bits from the OpenLDAP <a href="http://www.openldap.org/">home page</a>. In this example, I&#8217;ve used <a href="ftp://ftp.openldap.org/pub/OpenLDAP/openldap-stable/openldap-stable-20071118.tgz">openldap-2.3.39.tgz</a>. Next, go to the directory where you&#8217;ve extracted the installation files and perform following steps:</p>
<pre>
$ mkdir -p /data/openldap-2.3.39
$ ./configure --prefix=/data/openldap-2.3.39
$ make depend
$ make
$ make install
</pre>
<p>For more detailed instructions, look at the INSTALL file or the <a href="http://www.openldap.org/doc/admin23/">OpenLDAP Administrator&#8217;s Guide</a>.</p>
<p>The next instructions will configure our directory and create a tree which looks like this:</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2744228157/" title="Fig 2.1  tree by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3093/2744228157_6ccd75dac5.jpg" width="500" height="334" alt="Fig 2.1  tree" /></a></p>
<div class="caption">Fig 2.1 tree</div>
<p>We need to initialize the LDAP server and provide data like the root suffix, directory manager, and password. We also want to enable SSL like so:</p>
<pre>
$ mkdir /data/openldap-2.3.39/ssl
$ openssl req -newkey rsa:1024 -x509 -nodes -out /data/openldap-2.3.39/ssl/server.pem -keyout /data/openldap-2.3.39/ssl/server.pem -days 365
Generating a 1024 bit RSA private key
....++++++
................++++++
writing new private key to 'server.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:EU
State or Province Name (full name) [Berkshire]:Mazovia
Locality Name (eg, city) [Newbury]:Warsaw
Organization Name (eg, company) [My Company Ltd]:Kijanowski
Organizational Unit Name (eg, section) []:Guvnor
Common Name (eg, your name or your server's hostname) []:localhost
Email Address []:a@a.a
</pre>
<p>Since this is a self-signed certificate we will need to add it to the client&#8217;s (JBoss AS) truststore.</p>
<pre>
$ openssl
OpenSSL&gt; x509 -inform PEM -outform DER -in /data/openldap-2.3.39/ssl/server.pem -out /data/openldap-2.3.39/ssl/server.der
OpenSSL&gt; exit

$ keytool -import -file /data/openldap-2.3.39/ssl/server.der -keystore $JBOSS_SERVER/conf/ldap.truststore

Enter keystore password:  qwerty
Owner: EMAILADDRESS=a@a.a, CN=localhost, OU=Guvnor, O=Kijanowski, L=Warsaw, ST=Mazovia, C=EU
Issuer: EMAILADDRESS=a@a.a, CN=localhost, OU=Guvnor, O=Kijanowski, L=Warsaw, ST=Mazovia, C=EU
Serial number: d8537a079c5eed59
Valid from: Wed Jul 16 18:35:50 CEST 2008 until: Thu Jul 16 18:35:50 CEST 2009
Certificate fingerprints:
         MD5:  25:C5:88:7B:D4:88:02:46:F1:EF:0D:6B:D6:EE:1F:A7
         SHA1: 57:B8:F4:25:77:F0:12:BD:B2:2E:DD:7D:CE:09:D2:D4:96:56:BC:26
Trust this certificate? [no]:  yes
Certificate was added to keystore
</pre>
<p>To enable the new truststore, edit <code>$JBOSS_SERVER/deploy/properties-service.xml</code> and add following lines:</p>
<pre>

    javax.net.ssl.trustStore=/data/jboss-4.2.3.GA/server//conf/ldap.truststore
    javax.net.ssl.trustStorePassword=qwerty
</pre>
<p>Now edit the file <code>/data/openldap-2.3.39/etc/openldap/slapd.conf</code>:</p>
<pre>
include         /data/openldap-2.3.39/etc/openldap/schema/core.schema
include         /data/openldap-2.3.39/etc/openldap/schema/cosine.schema
include         /data/openldap-2.3.39/etc/openldap/schema/inetorgperson.schema

pidfile         /data/openldap-2.3.39/var/run/slapd.pid
argsfile        /data/openldap-2.3.39/var/run/slapd.args

database        bdb
suffix          "dc=kijanowski,dc=eu"
rootdn          "cn=DirManager,dc=kijanowski,dc=eu"
rootpw          secret
directory       /data/openldap-2.3.39/var/openldap-data
index   objectClass     eq

TLSCipherSuite HIGH:MEDIUM:-SSLv2
TLSCACertificateFile /data/openldap-2.3.39/ssl/server.pem
TLSCertificateFile /data/openldap-2.3.39/ssl/server.pem
TLSCertificateKeyFile /data/openldap-2.3.39/ssl/server.pem
TLSVerifyClient never
</pre>
<p>The rootpw attribute should be changed from &#8217;secret&#8217; to:</p>
<pre>
$ /data/openldap-2.3.39/sbin/slappasswd -s admin123
</pre>
<p>where &#8216;admin123&#8242; is the new directory manager&#8217;s password. For better performance, you can create a config file for the backend database or copy the sample configuration file like so:</p>
<pre>
$ cp /data/openldap-2.3.39/var/openldap-data/DB_CONFIG.example /data/openldap-2.3.39/var/openldap-data/DB_CONFIG
</pre>
<p>To start the server with a customized listener, run:</p>
<pre>
$ /data/openldap-2.3.39/libexec/slapd -h ldaps://localhost:16636
</pre>
<p>You can make sure your LDAP server is up and running (listening) by running:</p>
<pre>
$ netstat -an|grep 16636
tcp        0      0 127.0.0.1:16636             0.0.0.0:*                   LISTEN
</pre>
<p>To create tree like the one shown above, we need to add the following myorg.ldif file:</p>
<pre>
dn: dc=kijanowski,dc=eu
objectclass: top
objectclass: dcObject
objectclass: organization
dc: kijanowski
o: kijanowski

dn: o=guvnor,dc=kijanowski,dc=eu
objectclass: top
objectclass: organization
o: guvnor

dn: ou=People,o=guvnor,dc=kijanowski,dc=eu
objectclass: top
objectclass: organizationalUnit
ou: People

dn: uid=admin,ou=People,o=guvnor,dc=kijanowski,dc=eu
objectclass: top
objectclass: uidObject
objectclass: person
objectClass: inetOrgPerson
uid: admin
cn: Guvnor Admin
sn: Administrator
userPassword: {SSHA}ZGUjbzh0wN0JoWxIAcZfFXpV5MIu/gZw

dn: uid=user1,ou=People,o=guvnor,dc=kijanowski,dc=eu
objectclass: top
objectclass: uidObject
objectclass: person
objectClass: inetOrgPerson
uid: user1
cn: Regular User
sn: Regular
userPassword: {SSHA}Gcif1SlGPu2vHrtoLGYlKXbKBytJiVVF

dn: ou=Roles,o=guvnor,dc=kijanowski,dc=eu
objectClass: top
objectClass: organizationalUnit
ou: Roles

dn: cn=admin,ou=Roles,o=guvnor,dc=kijanowski,dc=eu
objectClass: top
objectClass: groupOfNames
cn: admin
description: the GuvnorAdmin group
member: uid=admin,ou=People,o=guvnor,dc=kijanowski,dc=eu

dn: cn=regular,ou=Roles,o=guvnor,dc=kijanowski,dc=eu
objectClass: top
objectClass: groupOfNames
cn: regular
description: the Guvnor Regular group
member: uid=user1,ou=People,o=guvnor,dc=kijanowski,dc=eu
</pre>
<p>The passwords for admin and user1 are &#8216;9uvn04&#8242; and &#8216;user1&#8242; (respectively) and were generated with slappasswd. To add this ldif to our directory, we will use an ldap client application called ldapadd. First we need to update its configuration to be able to talk over SSL. Edit the file <code>/data/openldap-2.3.39/etc/openldap/ldap.conf</code> and add following line:</p>
<pre>
TLS_REQCERT allow
</pre>
<p>This will prevent us from getting errors like these:</p>
<pre>
client side:
ldap_initialize( ldaps://localhost:16636 )
ldap_bind: Can't contact LDAP server (-1)
        additional info: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

server side:
TLS trace: SSL3 alert read:fatal:unknown CA
TLS trace: SSL_accept:failed in SSLv3 read client certificate A
TLS: can't accept.
TLS: error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown ca s3_pkt.c:1057
connection_read(11): TLS accept failure error=-1 id=4, closing
connection_closing: readying conn=4 sd=11 for close
connection_close: conn=4 sd=11
</pre>
<p>Now we can add the ldif file to our directory:</p>
<pre>
$ /data/openldap-2.3.39/bin/ldapadd -x -D "cn=DirManager,dc=kijanowski,dc=eu" -H ldaps://localhost:16636 -w admin123 -f myorg.ldif

adding new entry "dc=kijanowski,dc=eu"
adding new entry "o=guvnor,dc=kijanowski,dc=eu"
adding new entry "ou=People,o=guvnor,dc=kijanowski,dc=eu"
adding new entry "uid=admin,ou=People,o=guvnor,dc=kijanowski,dc=eu"
adding new entry "uid=user1,ou=People,o=guvnor,dc=kijanowski,dc=eu"
adding new entry "ou=Roles,o=guvnor,dc=kijanowski,dc=eu"
adding new entry "cn=admin,ou=Roles,o=guvnor,dc=kijanowski,dc=eu"
adding new entry "cn=regular,ou=Roles,o=guvnor,dc=kijanowski,dc=eu"
</pre>
<p>The last step is to configure JAAS in <code>$JBOSS_SERVER/conf/login-config.xml</code>. Replace the previous file based login module with this one:</p>
<pre>

            ldaps://localhost:16636
            ssl
            cn=DirManager,dc=kijanowski,dc=eu
            admin123

            ou=People,o=guvnor,dc=kijanowski,dc=eu
            (uid={0})

            ou=Roles,o=guvnor,dc=kijanowski,dc=eu
            (member={1})
            cn

            -1
            ONELEVEL_SCOPE
</pre>
<p>Now restart JBoss AS and try to login as admin with password 9uvn04. The application server will talk with the OpenLDAP server over SSL. If you want to shutdown the OpenLDAP server you need to determine its PID and interrupt it by sending the process a SIGINT signal:</p>
<pre>
$ kill -INT `cat /data/openldap-2.3.39/var/run/slapd.pid`
</pre>
<p><a name="mysql"></a></p>
<h2>Use MySQL as a data repository</h2>
<p>Jackrabbit has been chosen as a Java Content Repository (JCR) implementation. By default, it uses the Derby database as a backend. You may want to switch to a database you are more familiar with, and can regularly back up and properly tune. If you have already used the file-based repository and don&#8217;t want to loose all your assets, export them. After MySQL is up and running, import them back. To export your current repository, go to the &#8216;Administration&#8217; menu on the left side, expand &#8216;Admin,&#8217; choose &#8216;Import/Export,&#8217; and click on &#8216;Export&#8217;:</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2745062730/" title="Fig 2.2  export by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3255/2745062730_9186be390d.jpg" width="500" height="188" alt="Fig 2.2  export" /></a></p>
<div class="caption">Fig 2.2 export</div>
<p>Shut down the server and set up MySQL as your new repository. First, download <a href="http://dev.mysql.com/">MySQL</a> and extract it. I will use the <a href="http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.51a-linux-i686.tar.gz/from/http://mysql.linux.cz/">community server 5.0.51a standard</a>,  extracted to /data/mysql-5.0.51. As root, perform the following steps. (For more details, have a look at the INSTALL-BINARY file):</p>
<pre>
$ /usr/sbin/groupadd mysql5
$ /usr/sbin/useradd -g mysql5 mysql5
$ cd /data/mysql-5.0.51
$ chown -R mysql5 .
$ chgrp -R mysql5 .
$ /data/mysql-5.0.51/scripts/mysql_install_db --user=mysql5

$ chown -R root .
$ chown -R mysql5 data

# now start MySQL
$ /data/mysql-5.0.51/bin/mysqld_safe --user=mysql5 &amp;

# and create a password for root
$ /data/mysql-5.0.51/bin/mysqladmin -u root password mysqladminpwd
To shutdown the MySQL server run:
$ /data/mysql-5.0.51/bin/mysqladmin -u root shutdown -p
Logout as root and log in to MySQL to create a user and database for Guvnor:
$ /data/mysql-5.0.51/bin/mysql -u root -p
mysql&gt; create database guvnor;
Query OK, 1 row affected (0.00 sec)

mysql&gt; grant all privileges on guvnor.* to 'guvnor-user'@'localhost' identified by 'guvnor-pwd';
Query OK, 0 rows affected (0.00 sec)

mysql&gt; flush privileges;
Query OK, 0 rows affected (0.00 sec)
</pre>
<p>Now the DB side is complete.</p>
<p>Edit the <code>$GUVNOR/WEB-INF/components.xml</code> file and provide a path to where you would like to keep the repository configuration files. You can leave the default value&#8211;which is the JBoss Application Server&#8217;s bin directory&#8211;however it is recommended to provide a location that is regularly backed up. Under the &#8216;repositoryConfiguration&#8217; component add:</p>
<pre>
/data/GuvnorRepo/
</pre>
<p>This last step creates a repository.xml file. It is created by default when running Guvnor the first time and is placed into the AS bin directory. This file configures the data repository. We would like to use MySQL, so we will create <code>/data/GuvnorRepo/repository.xml</code>:</p>
<pre>

        <!-- Define where to store global data -->

                        <!-- param name="externalBLOBs" value="false" /-->
</pre>
<p>As you see we&#8217;re using the com.mysql.jdbc.Driver, so we need to provide it. Download the mysql java connector from <a href="http://dev.mysql.com/">MySQL</a>, unzip it, and copy the JAR file to $JBOSS_SERVER/lib. (I&#8217;m using <a href="http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.6.zip/from/http://mysql.linux.cz/">mysql-connector-java-5.1.6</a>.)</p>
<p>Now you can start the app server. If you have exported your assets, just go to the &#8216;Administration&#8217; menu, expand &#8216;Admin,&#8217; choose &#8216;Import/Export,&#8217; and import your xml file. Please note that you have to unzip your exported xml file before you can upload it.</p>
<p><a name="ssl"></a></p>
<h2>Enable SSL</h2>
<p>The last tweak is enabling SSL. It not only provides security, but also ensures the transmitted data hasn&#8217;t been modified. This is strictly a server-side task.</p>
<p>First, we need a certificate. Please note that as the &#8220;first and last name&#8221; you have to provide the <strong>fully qualified domain name</strong> of the host. For testing purposes you can use localhost like so:</p>
<pre>
$ keytool -genkey -alias guvnor -keyalg RSA -keystore $JBOSS_SERVER/conf/guvnor.keystore -validity 365

Enter keystore password:  guvnorkspwd
What is your first and last name?
  [Unknown]:  localhost
What is the name of your organizational unit?
  [Unknown]:  My Department
What is the name of your organization?
  [Unknown]:  My Company
What is the name of your City or Locality?
  [Unknown]:  My City
What is the name of your State or Province?
  [Unknown]:  My State
What is the two-letter country code for this unit?
  [Unknown]:  US
Is CN=My Name, OU=My Department, O=My Company, L=My City, ST=My State, C=US correct?
  [no]:  yes

Enter key password for
        (RETURN if same as keystore password):
</pre>
<p>Now we can enable an SSL connector. Edit the file $JBOSS_SERVER/deploy/jboss-web.deployer/server.xml like so:</p>
<pre>
</pre>
<p>Restart your JBoss Application Server. Guvnor should be available at <a href="https://localhost:8443/drools-guvnor">https://localhost:8443/drools-guvnor</a>.</p>
<p><a name="secured"></a></p>
<h2>How to use a secured Guvnor package</h2>
<p>The last part of this article shows how you can access a drools package from Guvnor in a secure way. This is very straight forward if you use certificates signed by trusted authorities. In our test environment, it&#8217;s a little bit more complicated since we use self-signed certificates.</p>
<p>First create a package and deploy it. I&#8217;ll use the package we made during the quick introduction. This package is available under <a href="https://localhost:8443/drools-guvnor/org.drools.guvnor.Guvnor/package/myNewPackage/LATEST">https://localhost:8443/drools-guvnor/org.drools.guvnor.Guvnor/package/myNewPackage/LATEST</a>. Replace the url attribute with the new value in Guvnor.properties:</p>
<pre>
url=https://localhost:8443/drools-guvnor/org.drools.guvnor.Guvnor/package/myNewPackage/LATEST
</pre>
<p>One would expect that running the Drools application should end successfully, however this is not the case:</p>
<pre>
RuleAgent(default) INFO (Wed Jul 23 20:38:03 CEST 2008): Configuring with newInstance=false, secondsToRefresh=-1
RuleAgent(default) INFO (Wed Jul 23 20:38:03 CEST 2008): Configuring package provider : URLScanner monitoring URLs:  https://localhost:8443/drools-guvnor/org.drools.guvnor.Guvnor/package/myNewPackage/LATEST
RuleAgent(default) WARNING (Wed Jul 23 20:38:04 CEST 2008): Was an error contacting https://localhost:8443/drools-guvnor/org.drools.guvnor.Guvnor/package/myNewPackage/LATEST. Reponse header: {}
RuleAgent(default) EXCEPTION (Wed Jul 23 20:38:04 CEST 2008): Was unable to reach server.. Stack trace should follow.
java.io.IOException: Was unable to reach server.
        at org.drools.agent.URLScanner.hasChanged(URLScanner.java:149)
        at org.drools.agent.URLScanner.getChangeSet(URLScanner.java:113)
        at org.drools.agent.URLScanner.loadPackageChanges(URLScanner.java:90)
        at org.drools.agent.RuleAgent.checkForChanges(RuleAgent.java:341)
        at org.drools.agent.RuleAgent.refreshRuleBase(RuleAgent.java:300)
        at org.drools.agent.RuleAgent.configure(RuleAgent.java:285)
        at org.drools.agent.RuleAgent.init(RuleAgent.java:209)
        at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:177)
        at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:149)
        at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:217)
        at kijanowski.eu.GuvnorTest.main(GuvnorTest.java:12)
Exception in thread "main" java.lang.NullPointerException
        at org.drools.agent.RuleAgent.refreshRuleBase(RuleAgent.java:301)
        at org.drools.agent.RuleAgent.configure(RuleAgent.java:285)
        at org.drools.agent.RuleAgent.init(RuleAgent.java:209)
        at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:177)
        at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:149)
        at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:217)
        at kijanowski.eu.GuvnorTest.main(GuvnorTest.java:12)
</pre>
<p>If you navigate with your browser to this URL, you will be asked to accept the non-signed certificate. In case of our test application, we need to trust the server by importing its public key to our (temporary) local keystore:</p>
<pre>
$ mkdir /data/ssl

# export the public key
$ keytool -export -alias guvnor -keystore $JBOSS_SERVER/conf/guvnor.keystore -file /data/ssl/out.cert

# you don't have to provide a password
Enter keystore password:

*****************  WARNING WARNING WARNING  *****************
* The integrity of the information stored in your keystore  *
* has NOT been verified!  In order to verify its integrity, *
* you must provide your keystore password.                  *
*****************  WARNING WARNING WARNING  *****************

Certificate stored in file 

# import this key to a local truststore
$ keytool -import -alias guvnor -file /data/ssl/out.cert -keystore /data/ssl/myKS

Enter keystore password:  qwerty
Owner: CN=localhost, OU=My Department, O=My Company, L=My City, ST=My State, C=US
Issuer: CN=localhost, OU=My Department, O=My Company, L=My City, ST=My State, C=US
Serial number: 48862cb6
Valid from: Tue Jul 22 20:53:42 CEST 2008 until: Wed Jul 22 20:53:42 CEST 2009
Certificate fingerprints:
         MD5:  81:FD:97:97:12:E7:2B:94:DA:62:35:11:2C:2B:4E:2B
         SHA1: 7E:B1:36:F4:C9:F9:45:5A:98:F2:F1:46:F6:58:E6:0D:81:46:EC:B5
Trust this certificate? [no]:  yes
Certificate was added to keystore
</pre>
<p>Now we have a keystore with a server&#8217;s key that we trust. To use this keystore, just start the drools application with the following property:</p>
<pre>
-Djavax.net.ssl.trustStore=/data/ssl/myKS
</pre>
<p>In Eclipse, click on GuvnorTest.java. From the menu Run -&gt; Open Run Dialog and then add this property to the VM arguments:</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2745062728/" title="Fig 2.3  eclipse by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3075/2745062728_7bac4326aa.jpg" width="500" height="443" alt="Fig 2.3  eclipse" /></a></p>
<div class="caption">Fig 2.3 eclipse</div>
<p>Now your Drools application runs in a secure environment.</p>
<p><a name="summary"></a></p>
<h2>Summary</h2>
<p>This article has shown how you can upgrade your BRMS, which should only be deployed out-of-the-box for testing purposes. For a multiuser environment with mission-critical applications, Guvnor should be tuned. Have a look at this <a href="http://blogs.sun.com/andreas/entry/no_more_unable_to_find">blog post</a>, the <a href="http://java.sun.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html">JSSE Reference Guide</a> or the <a href="http://java.sun.com/javase/6/docs/technotes/tools/solaris/keytool.html">key tool docs page</a> for more details about the tools we used. For LDAP browsing I recommend this <a href="http://www-unix.mcs.anl.gov/~gawor/ldap/index.html">user-friendly and light-weight tool</a>.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rhredhatmagazine.wordpress.com/1021/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rhredhatmagazine.wordpress.com/1021/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rhredhatmagazine.wordpress.com/1021/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rhredhatmagazine.wordpress.com/1021/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rhredhatmagazine.wordpress.com/1021/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rhredhatmagazine.wordpress.com/1021/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rhredhatmagazine.wordpress.com/1021/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rhredhatmagazine.wordpress.com/1021/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rhredhatmagazine.wordpress.com/1021/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rhredhatmagazine.wordpress.com/1021/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rhredhatmagazine.wordpress.com/1021/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rhredhatmagazine.wordpress.com/1021/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1021&subd=rhredhatmagazine&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://magazine.redhat.com/2008/08/14/jboss-drools-how-to-tuning-guvnor-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kijanowski</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3093/2744228157_6ccd75dac5.jpg" medium="image">
			<media:title type="html">Fig 2.1  tree</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3255/2745062730_9186be390d.jpg" medium="image">
			<media:title type="html">Fig 2.2  export</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3075/2745062728_7bac4326aa.jpg" medium="image">
			<media:title type="html">Fig 2.3  eclipse</media:title>
		</media:content>
	</item>
		<item>
		<title>JBoss Drools how-to: Tuning Guvnor, part 1</title>
		<link>http://magazine.redhat.com/2008/08/12/jboss-drools-how-to-tuning-guvnor-part-1/</link>
		<comments>http://magazine.redhat.com/2008/08/12/jboss-drools-how-to-tuning-guvnor-part-1/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 20:58:02 +0000</pubDate>
		<dc:creator>kijanowski</dc:creator>
				<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://www.redhatmagazine.com/2008/08/12/jboss-drools-how-to-tuning-guvnor-part-1/</guid>
		<description><![CDATA[Guvnor is the business rules management system in Drools 5. When you deploy it out of the box, you get an unsecured web application that stores data in Jackrabbit&#8217;s embedded Derby database.
The first half of this series explains how to tune Guvnor deployed on JBoss Application Server 4.2.3. This means that we will use the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1002&subd=rhredhatmagazine&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Guvnor is the business rules management system in Drools 5. When you deploy it out of the box, you get an unsecured web application that stores data in Jackrabbit&#8217;s embedded Derby database.</p>
<p>The first half of this series explains how to tune Guvnor deployed on JBoss Application Server 4.2.3. This means that we will use the container&#8217;s configuration files and security infrastructure. We will cover enabling password validation based on an OpenLDAP server, moving from the default data repository, and enabling SSL for better security in part 2.<span id="more-1002"></span></p>
<ol>
<li><a href="#install">Installation</a></li>
<li><a href="#intro">Quick introduction</a></li>
<li><a href="#password">Enable user/password validation</a></li>
</ol>
<p><a name="install"></a></p>
<h2>Installation </h2>
<p>We will deploy Guvnor as an exploded archive on the JBoss Application Server.</p>
<ol>
<li><a href="http://www.jboss.org/jbossas/downloads/">Download JBoss AS 4.2.3.GA</a> and extract it to:
<pre>
 /data/jboss-4.2.3.GA
</pre>
</li>
<li><a href="http://download.jboss.org/drools/release/5.0.0.20899M1/drools-5.0.0.M1-guvnor.zip">Download Guvnor M1</a> and extract it to the deploy directory under:
<pre>
 /data/jboss-4.2.3.GA/server//deploy/drools-guvnor.war
</pre>
</li>
<li>From now on we&#8217;ll use:
<pre>
$JBOSS_SERVER as /data/jboss-4.2.3.GA/server/
$GUVNOR as /data/jboss-4.2.3.GA/server//deploy/drools-guvnor.war
</pre>
</li>
<li>To verify a successful deployment, start the server:
<pre>
$ /data/jboss-4.2.3.GA/bin/run.sh -c
</pre>
<p>You should see the response below:</p>
<pre>
JBoss Bootstrap Environment

JBOSS_HOME: /data/jboss-4.2.3.GA

JAVA: /usr/local/jdk1.5.0_11/bin/java

JAVA_OPTS: -Dprogram.name=run.sh -server -Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000-Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.net.preferIPv4Stack=true

CLASSPATH: /data/jboss-4.2.3.GA/bin/run.jar:/usr/local/jdk1.5.0_11/lib/tools.jar

=========================================================================

17:13:53,732 INFO  [Server] Starting JBoss (MX MicroKernel)...
17:13:53,734 INFO  [Server] Release ID: JBoss [Trinity] 4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)
17:13:53,736 INFO  [Server] Home Dir: /data/jboss-4.2.3.GA
.
.
.
17:14:38,366 INFO  [TomcatDeployer] deploy, ctxPath=/drools-guvnor, warUrl=.../deploy/drools-guvnor.war/.
.
.
</pre>
</li>
</ol>
<p>Navigate to <a href="http://localhost:8080/drools-guvnor">http://localhost:8080/drools-guvnor</a> and login as &#8216;admin&#8217; without any password.</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2745062734/" title="Fig 1. Guvnor by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3296/2745062734_ee5fe0e12d.jpg" width="500" height="239" alt="Fig 1. Guvnor" /></a></p>
<div class="caption">Fig 1. Guvnor</div>
<p>Guvnor is now up and running. Let&#8217;s see how we can get started quickly.</p>
<p><a name="intro"></a></p>
<h2>Quick introduction</h2>
<p>Before you can start using Guvnor for rule authoring, you need to perform some basic setup. We will need to create a category, make a package, and upload your facts. Let&#8217;s log in.</p>
<p><strong>Categories</strong><br />
You will need to create at least one category, under which you will store your rules. Categories are for classification purposes. You will normally want to provide meaningful names like &#8216;Insurance&#8217; or &#8216;Discount,&#8217; but for this test instance, we&#8217;ll just create &#8216;MyNewCategory.&#8217; On the left side click on the &#8216;Administration&#8217; tab, expand the &#8216;Admin&#8217; list, and then click on &#8216;Categories&#8217;:</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2745062726/" title="cat by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3214/2745062726_10ecbbd489.jpg" width="500" height="227" alt="cat" /></a></p>
<div class="caption">Fig 2. cat</div>
<p>Create a category by clicking on &#8216;New category&#8217; and providing a name.</p>
<p><strong>Packages</strong><br />
A package is a place where rules are stored. It also includes globals and imports of all the facts and other classes we would like to use in our rules&#8211;for example,  ArrayLists or Iterators. To create a package, expand the &#8216;Package&#8217; tab and click on &#8216;Create New&#8217; -&gt; &#8216;New Package&#8217;</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2745062736/" title="Fig 3. pack by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3266/2745062736_1e2b7ed7e1.jpg" width="500" height="228" alt="Fig 3. pack" /></a></p>
<div class="caption">Fig 3. pack</div>
<p>You can create a new package by providing its name (our example is myNewPackage) or by importing one from a drl file. In either case, you will need to provide the facts you&#8217;re going to use in your rules.</p>
<p><strong>Facts</strong><br />
Next, you will create classes you would like to use in your rules. For this example, I&#8217;ll use a Driver and a Car class:</p>
<pre>
<em>Driver.java</em>
package kijanowski.eu;

public class Driver {

        private String name;
        private int age;
        private Car car;

        public Driver() {}

        public Driver(String name, int age, Car car) {
                this.name = name;
                this.age = age;
                this.car = car;
        }

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        public int getAge() {
                return age;
        }

        public void setAge(int age) {
                this.age = age;
        }

        public Car getCar() {
                return car;
        }

        public void setCar(Car car) {
                this.car = car;
        }

}

<em>Car.java</em>
package kijanowski.eu;

public class Car {

        private String color;
        private double value;

        public Car() {}

        public Car(String color, double value) {
                this.color = color;
                this.value = value;
        }

        public String getColor() {
                return color;
        }

        public void setColor(String color) {
                this.color = color;
        }

        public double getValue() {
                return value;
        }

        public void setValue(double value) {
                this.value = value;
        }

}
</pre>
<p>Compile these java files (if not already done by your IDE) and create an java archive:</p>
<pre>
$ javac -d . *.java
$ jar cf model.jar kijanowski
</pre>
<p>Import the new model to your package. From the &#8216;Packages&#8217; tab click on &#8216;Create New&#8217; -&gt; &#8216;Upload new Model jar&#8217;:</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2745062738/" title="Fig 4. pack2 by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3267/2745062738_7a50463f3d.jpg" width="500" height="228" alt="Fig 4. pack2" /></a></p>
<div class="caption">Fig 4. pack2</div>
<p>Provide a name and select myNewPackage as the destination package. Provide a path (or click on Browse and navigate) to your facts archive. Finally, click on Upload.</p>
<p>When you choose myNewPackage from the &#8216;Packages&#8217; tab, you should see the imported facts:</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2744228149/" title="Fig 5. pack3 by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3153/2744228149_bd02c1c11b.jpg" width="500" height="228" alt="Fig 5. pack3" /></a></p>
<div class="caption">Fig 5. pack3</div>
<p>Before these facts are available in rules, you need to save this package. Click on &#8216;Save and validate configuration&#8217;.</p>
<p><strong>Rules</strong><br />
Now you can create rules. From the &#8216;Package&#8217; tab select &#8216;Create New&#8217; -&gt; &#8216;New Rule&#8217;. Provide a name, choose a category, and select your favorite rule format with myNewPakage as the destination package:</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2744228153/" title="Fig 6. pack4 by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3230/2744228153_e6b7d15a65.jpg" width="500" height="228" alt="Fig 6. pack4" /></a></p>
<div class="caption">Fig 6. pack4</div>
<p>A simple example is shown below:</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2744228155/" title="Fig 7. pack5 by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3168/2744228155_f5cd7375d2.jpg" width="500" height="324" alt="Fig 7. pack5" /></a></p>
<div class="caption">Fig 7. pack5</div>
<p>Validate and save your rule by first choosing &#8216;Validate&#8217; and&#8211;if all is ok&#8211;then &#8216;Save changes&#8217;. Now you can make this package and all its rules available to your applications.<br />
Choose your package and click on &#8216;Save and validate configuration.&#8217; Before building it, click on &#8216;Show package source&#8217; to have a look at the whole package. When you&#8217;re done looking at the source, choose &#8216;Build package&#8217;. You should be able to access the package under <a href="http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/myNewPackage/LATEST">http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/myNewPackage/LATEST</a> and in drl format at <a href="http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/myNewPackage/LATEST.drl">http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/myNewPackage/LATEST.drl</a>.</p>
<p>Now let&#8217;s create a simple Drools application that will use a package served by Guvnor.</p>
<p>Open Eclipse and create a new Drools project (as described in <a href="http://www.kijanowski.eu/index.php?site=articles&amp;article=introduction&amp;lang=en#start">Introduction into Rule Engines</a>) or use your favorite IDE (don&#8217;t forget to add drools-core.jar and mvel.jar to your classpath). Add model.jar to your classpath and create a test class:</p>
<pre>
package kijanowski.eu;

import org.drools.RuleBase;
import org.drools.WorkingMemory;
import org.drools.agent.RuleAgent;
import java.util.Iterator;

public class GuvnorTest {

        public static final void main(String[] args) {

                RuleAgent agent = RuleAgent.newRuleAgent("/Guvnor.properties");
                RuleBase ruleBase = agent.getRuleBase();

                WorkingMemory workingMemory = ruleBase.newStatefulSession();

                Driver d = new Driver("Jarek", 20, null);
                workingMemory.insert(d);

                workingMemory.fireAllRules();

                for (Iterator i = workingMemory.iterateObjects(); i.hasNext();) {
                        System.out.println(i.next().getClass().getCanonicalName());
                }
        }

}
</pre>
<p>This time we don&#8217;t read a package from the filesystem, but are configuring our rule agent with a properties file. One fact is inserted, rules are fired, and, in the end, we iterate over all facts in the working memory to make sure a Car fact has been inserted. We expect this will happen, don&#8217;t we? Check the rule if you&#8217;re in doubt. Let&#8217;s have a look at the properties file:</p>
<pre>
url=http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/myNewPackage/LATEST
</pre>
<p>We provide the url that points to our package. There are a lot more attributes you can provide (read the  <a href="http://download.jboss.org/drools/release/5.0.0.20899M1/drools-5.0.0.M1-docs.zip">Guvnor docs</a> for details). When the application is run, you should get following output:</p>
<pre>
RuleAgent(default) INFO (Wed Jul 23 20:31:28 CEST 2008): Configuring with newInstance=false, secondsToRefresh=-1
RuleAgent(default) INFO (Wed Jul 23 20:31:28 CEST 2008): Configuring package provider : URLScanner monitoring URLs:  http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/myNewPackage/LATEST
RuleAgent(default) INFO (Wed Jul 23 20:31:29 CEST 2008): Applying changes to the rulebase.
RuleAgent(default) INFO (Wed Jul 23 20:31:29 CEST 2008): Adding package called myNewPackage
kijanowski.eu.Driver
kijanowski.eu.Car
</pre>
<p>This was just a quick introduction into Guvnor. A much more exhaustive description can be found in the <a href="http://download.jboss.org/drools/release/5.0.0.20899M1/drools-5.0.0.M1-docs.zip">Guvnor documentation</a>.</p>
<p><a name="password"></a></p>
<h2>Enable user/password validation</h2>
<p>When deploying Guvnor, everyone can access it using the admin username–a password isn&#8217;t verified. However, Guvnor is designed to allow access to different users, who may have different skills and rights. Controlling access may be critical. To enable username/password validation, we need to edit Guvnor&#8217;s security configuration. This is located in:</p>
<pre>
$GUVNOR/WEB-INF/components.xml
</pre>
<p>We will want to set JAAS as the new authorization and authentication service. Comment out:</p>
<pre>
</pre>
<p>and add:</p>
<pre>
</pre>
<p>That&#8217;s all from the apps side. To configure JBoss AS, add the following to $JBOSS_SERVER/conf/login-config.xml:</p>
<pre>

          &lt;login-module code="<strong>org.jboss.security.auth.spi.UsersRolesLoginModule</strong>" flag = "required"&gt;
           <strong>props/guvnor-users.properties</strong>
           <strong>props/guvnor-roles.properties</strong>
</pre>
<p>We have chosen the file-based login module. We now need to create two files, where we will provide the admin username, password, and role:</p>
<pre>
$JBOSS_SERVER/conf/props/guvnor-users.properties
admin=admin123
$JBOSS_SERVER/conf/props/guvnor-roles.properties
admin=admin
</pre>
<p>We have now created an &#8216;admin&#8217; user with the password &#8216;admin123&#8242; and its role is &#8216;admin&#8217;.</p>
<p>You may want to have all your users in a database or directory. For all available login modules, have a look at this <a href="http://wiki.jboss.org/wiki/LoginModule">wiki</a>.</p>
<p>In the current Drools 5M1 release, only the admin role is supported. You may want to have a look at <code>drools-guvnor/src/main/java/org/drools/guvnor/server/security/RoleTypes.java</code> for other roles implemented in future releases.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rhredhatmagazine.wordpress.com/1002/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rhredhatmagazine.wordpress.com/1002/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rhredhatmagazine.wordpress.com/1002/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rhredhatmagazine.wordpress.com/1002/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rhredhatmagazine.wordpress.com/1002/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rhredhatmagazine.wordpress.com/1002/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rhredhatmagazine.wordpress.com/1002/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rhredhatmagazine.wordpress.com/1002/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rhredhatmagazine.wordpress.com/1002/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rhredhatmagazine.wordpress.com/1002/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rhredhatmagazine.wordpress.com/1002/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rhredhatmagazine.wordpress.com/1002/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1002&subd=rhredhatmagazine&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://magazine.redhat.com/2008/08/12/jboss-drools-how-to-tuning-guvnor-part-1/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kijanowski</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3296/2745062734_ee5fe0e12d.jpg" medium="image">
			<media:title type="html">Fig 1. Guvnor</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3214/2745062726_10ecbbd489.jpg" medium="image">
			<media:title type="html">cat</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3266/2745062736_1e2b7ed7e1.jpg" medium="image">
			<media:title type="html">Fig 3. pack</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3267/2745062738_7a50463f3d.jpg" medium="image">
			<media:title type="html">Fig 4. pack2</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3153/2744228149_bd02c1c11b.jpg" medium="image">
			<media:title type="html">Fig 5. pack3</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3230/2744228153_e6b7d15a65.jpg" medium="image">
			<media:title type="html">Fig 6. pack4</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3168/2744228155_f5cd7375d2.jpg" medium="image">
			<media:title type="html">Fig 7. pack5</media:title>
		</media:content>
	</item>
		<item>
		<title>Rules and Drools Rundown</title>
		<link>http://magazine.redhat.com/2008/07/17/rules-and-drools-rundown/</link>
		<comments>http://magazine.redhat.com/2008/07/17/rules-and-drools-rundown/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 11:20:50 +0000</pubDate>
		<dc:creator>Karsten 'quaid' Wade</dc:creator>
				<category><![CDATA[Dev Fu]]></category>
		<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://magazine.redhat.com/?p=1372</guid>
		<description><![CDATA[It&#8217;s been a good few weeks for stories and information about JBoss Rules and Drools, the open source project upstream of the JBoss subscription offering.  Here is a quick summary of the recent stories.  Post a comment if you know of any others we all should pay attention to.

Pierre Fricke, JBoss product manager, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1372&subd=rhredhatmagazine&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>It&#8217;s been a good few weeks for stories and information about <a href="http://jboss.com/products/rules">JBoss Rules</a> and <a href="http://www.jboss.org/drools/">Drools</a>, the open source project upstream of the JBoss subscription offering.  Here is a quick summary of the recent stories.  Post a comment if you know of any others we all should pay attention to.</p>
<ul>
<li>Pierre Fricke, JBoss product manager, writes about <a href="http://blogs.jboss.com/blog/pfricke/2008/07/16/Daiwa_Securities_America_Improves_Performance_and_Reduces_Costs_with_JBoss_Enterprise_Portal_Platform">Daiwa Securities America Improves Performance and Reduces Costs with JBoss Enterprise Portal Platform</a>.  The <a href="http://www.redhat.com/about/news/prarchive/2008/daiwa.html">Red Hat press release</a> says, &#8220;In addition to the (JBoss) Portal Platform, Daiwa also uses the JBoss Rules framework to embed alerts into portal applications.&#8221;</li>
<li>Two articles on Drools were published in Red Hat Magazine, <a href="http://www.redhatmagazine.com/2008/07/10/introduction-to-drools-rules-fall-from-your-eyes/">Introduction to Drools: Rules fall from your eyes</a> and <a href="http://www.redhatmagazine.com/2008/07/11/jboss-drools-meets-hibernate/">JBoss Drools meets Hibernate</a>.  Both pieces are a good introduction to working with Drools.</li>
<li>Drools continues to grow its library of widgets for the <a href="http://blog.athico.com/2008/04/brms-for-drools-5.html">Guv&#8217;nor</a>, which is the web tool and rules repository of Drools, formerly known just as the &#8220;Drools BRMS.&#8221;  This <a href="http://blog.athico.com/2008/07/integrating-rolodex-to-guvnor-for-image.html">new widget, rolodex</a>, adds a flipping slideshow of photos pulled using Google Web Toolkit.</li>
<li>A beta implementation of <a href="http://en.wikipedia.org/wiki/WordNet">WordNet</a> for Drools is being <a href="http://blog.athico.com/2008/07/drools-and-wordnet.html">talked up by project lead Mark Proctor</a>; they are seeking comments from users/testers in the Drools mailing list.</li>
<li>Mark Proctor also <a href="http://blog.athico.com/2008/07/drools-scalability.html">writes</a>, &#8220;We often get asked about Drools scalability in complex apps, so I thought I would <a href="http://www.mail-archive.com/rules-users@lists.jboss.org/msg05922.html">link to this posting just done</a>, where someone has Drools scaling to 900K facts on a 64bit JVM with reasonable performance.&#8221;</li>
<li>More tools and features are being included in Drools all the time, such as <a href="http://blog.athico.com/2008/07/drools-smooks-data-loader.html">adding Smooks as a data loader</a>.</li>
</ul>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rhredhatmagazine.wordpress.com/1372/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rhredhatmagazine.wordpress.com/1372/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rhredhatmagazine.wordpress.com/1372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rhredhatmagazine.wordpress.com/1372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rhredhatmagazine.wordpress.com/1372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rhredhatmagazine.wordpress.com/1372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rhredhatmagazine.wordpress.com/1372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rhredhatmagazine.wordpress.com/1372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rhredhatmagazine.wordpress.com/1372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rhredhatmagazine.wordpress.com/1372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rhredhatmagazine.wordpress.com/1372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rhredhatmagazine.wordpress.com/1372/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1372&subd=rhredhatmagazine&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://magazine.redhat.com/2008/07/17/rules-and-drools-rundown/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Karsten 'quaid' Wade</media:title>
		</media:content>
	</item>
		<item>
		<title>JBoss Drools meets Hibernate</title>
		<link>http://magazine.redhat.com/2008/07/11/jboss-drools-meets-hibernate/</link>
		<comments>http://magazine.redhat.com/2008/07/11/jboss-drools-meets-hibernate/#comments</comments>
		<pubDate>Fri, 11 Jul 2008 20:31:36 +0000</pubDate>
		<dc:creator>kijanowski</dc:creator>
				<category><![CDATA[JBoss]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://www.redhatmagazine.com/2008/07/11/jboss-drools-meets-hibernate/</guid>
		<description><![CDATA[Jaroslaw is a JBoss QA Engineer based in Poland, and recently published an introduction to Drools that he kindly shared with us. This second piece covers Drools (or JBoss Rules), the open source business rules engine&#8230; in this case combining it with Hibernate.
This article is presented here in its entirety (with a trackback).  The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=966&subd=rhredhatmagazine&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><em>Jaroslaw is a JBoss QA Engineer based in Poland, and recently published an <a href="http://www.kijanowski.eu/index.php?site=articles&amp;article=introduction&amp;lang=en">introduction to Drools</a> that he kindly shared with us. This second piece covers <a href="http://en.wikipedia.org/wiki/Drools">Drools (or JBoss Rules)</a>, the open source business rules engine&#8230; in this case combining it with <a href="http://en.wikipedia.org/wiki/Hibernate_%28Java%29">Hibernate</a>.</p>
<p>This article is presented here in its entirety (with a trackback).  The original can be found on <a href="http://www.kijanowski.eu/index.php?site=articles&amp;article=drools_hibernate&amp;lang=en">Jaroslaw&#8217;s site</a>.  This article is also available in <a href="http://www.kijanowski.eu/index.php?site=articles&amp;article=drools_hibernate&amp;lang=de">German</a> and <a href="http://www.kijanowski.eu/index.php?site=articles&amp;article=drools_hibernate&amp;lang=pl">Polish</a>.</em></p>
<h2>Justification:</h2>
<p>Drools evaluates facts which are present in the working memory. But could it also reason over data stored in a relational database? This feature would extend Drools&#8217; range of applicability and since this is an often asked question in the mailing list, it&#8217;s worth to know the answer which sounds: &#8220;of course Drools can!&#8221;</p>
<h2>Abstract:</h2>
<p>Hibernate, one of the most favorite <a href="http://en.wikipedia.org/wiki/Object-relational_mapping">ORM</a> tools, allows to handle data stored in a relational database. This article will describe how one can access a Hibernate session from inside the rule engine. I will use PostgreSQL as a data source. Besides that I will create two classes, Game and Player, having a many-to-many relationship.<span id="more-966"></span></p>
<ol>
<li><a href="#newproject">Creating a new Drools project</a></li>
<li><a href="#classes">Class files</a></li>
<li><a href="#hibernate">Hibernate</a></li>
<li><a href="#drools">Drools</a></li>
<li><a href="#howdoesitwork">How does it work?</a></li>
<li><a href="#final">Results</a>
<li><a href="#summary">Summary</a></li>
</ol>
<h2><a name="newproject">Creating a new Drools project</a></h2>
<p><i>You still don&#8217;t have installed the Drools 4.0.7 Eclipse Workbench? Just have a look at this article: <a href="http://www.kijanowski.eu/index.php?site=articles&amp;article=introduction&amp;lang=en">&#8220;Rules fall from your eyes&#8221;</a>.</i></p>
<p>Menu File -&gt; New -&gt; Project -&gt; Drools &#8211; &gt; Rule Project -&gt; Next. Provide the project&#8217;s name, drools-hibernate-demo, and click on Next, to <b>uncheck</b> the example files</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2658892369/" title="fig2-1_step1 by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3096/2658892369_0eea61eb8e.jpg" width="500" height="458" alt="fig2-1_step1" /></a></p>
<h2><a name="classes">Class files</a></h2>
<p>Create a package &#8220;eu.kijanowski.drools.hibernate&#8221; in the src/main/java directory. We will use two class files, Player.java and Game.java. They have a many-to-many relationship, since one player can own many games and one game can be owned by many players <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><i>Class Game.java</i></p>
<pre>
package eu.kijanowski.drools.hibernate;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

public class Game implements Serializable {
	private static final long serialVersionUID = 1L;
	private Long id = null;
	private String name;
	private double price;
	private int levels;
	private Set players = new HashSet();

	public Game() {
	}

	public Game(String name, double price, int levels) {
		this.name = name;
		this.price = price;
		this.levels = levels;
	}

	public Long getId() {
		return id;
	}

	@SuppressWarnings("unused")
	private void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public int getLevels() {
		return levels;
	}

	public void setLevels(int levels) {
		this.levels = levels;
	}

	public Set getPlayers() {
		return players;
	}

	public void setPlayers(Set players) {
		this.players = players;
	}

	public String toString() {
		return name + " with " + levels + " levels for " + price;
	}
}
</pre>
<p><i>Class Player.java</i></p>
<pre>
package eu.kijanowski.drools.hibernate;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

public class Player implements Serializable {
	private static final long serialVersionUID = 1L;
	private Long id;
	private String name;
	private int age;
	private Set games = new HashSet();

	public Player() {
	}

	public Player(String name, int age, HashSet games) {
		this.name = name;
		this.age = age;
		this.games = games;
	}

	public Long getId() {
		return id;
	}

	@SuppressWarnings("unused")
	private void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public Set getGames() {
		return games;
	}

	public void setGames(Set games) {
		this.games = games;
	}

	public String toString() {
		return name;
	}
}
</pre>
<h2><a name="hibernate">Hibernate</a></h2>
<p>Without going into details, <a href="http://www.hibernate.org/6.html">download the binaries</a>, Hibernate Core 3.2.6 and extract the archive.</p>
<p>In our project create a directory called lib and copy over following files:</p>
<ul>
<li>hibernate-3.2.6.GA/lib/antlr-2.7.6.jar</li>
<li>hibernate-3.2.6.GA/lib/asm.jar</li>
<li>hibernate-3.2.6.GA/lib/cglib-2.1.3.jar</li>
<li>hibernate-3.2.6.GA/lib/commons-collections-2.1.1.jar</li>
<li>hibernate-3.2.6.GA/lib/commons-logging-1.0.4.jar</li>
<li>hibernate-3.2.6.GA/lib/dom4j-1.6.1.jar</li>
<li>hibernate-3.2.6.GA/hibernate3.jar</li>
<li>hibernate-3.2.6.GA/lib/jta.jar</li>
</ul>
<p>Now we have to add these libraries to the &#8220;build path&#8221;: from the menu choose Project -&gt; Properties -&gt; Java Build Path -&gt; Libraries and	then Add External JARs and navigate to the project&#8217;s lib directory.	Mark all files and click OK.</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2658892523/" title="fig2-2_libs by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3276/2658892523_dd6937c6a2.jpg" width="470" height="500" alt="fig2-2_libs" /></a></p>
<p>It&#8217;s time to configure Hibernate. In the src/main/java directory create a file called hibernate.cfg.xml:</p>
<pre>

         org.postgresql.Driver
         jdbc:postgresql://localhost/droolsdb
         droolsuser

         1
         org.hibernate.dialect.PostgreSQLDialect
         org.hibernate.transaction.JDBCTransactionFactory

         thread
         org.hibernate.cache.NoCacheProvider
         true
         create
</pre>
<p>As you see, we&#8217;re going to use the org.postgresql.Driver class,	hence we need to add another library to our project. From the <a href="http://jdbc.postgresql.org/download.html">PostgreSQL home	page</a> we can download the required driver. I&#8217;m using <a href="http://jdbc.postgresql.org/download/postgresql-8.2-508.jdbc3.jar">8.2-508	JDBC 3</a>. Don&#8217;t forget to add it to the Java Build Path, like we did with the hibernate library.</p>
<p>It&#8217;s time to <a href="http://www.postgresql.org/ftp/source/v8.2.9/">download</a> and start PostgreSQL and create a user and schema.</p>
<pre>
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data&gt;logfile 2&gt;&amp;1 &amp;
/usr/local/pgsql/bin/createuser -h 127.0.0.1 -p 5432 -U postgres -s -d -R droolsuser
/usr/local/pgsql/bin/createdb -h 127.0.0.1 -p 5432 -U postgres -O droolsuser droolsdb
</pre>
<p>The last step is mapping &#8211; this is connecting the world of Java	objects with the world of relations (tabels). Create model.hbm.xml in the eu.kijanowski.drools.hibernate package:</p>
<pre>

				player_id_seq

				game_id_seq
</pre>
<h2><a name="drools">Drools</a></h2>
<p>We&#8217;re almost there. We olny have to create the rule file and a testing class which will start our example. But how are we going to use Hibernate in our application? Well, in our testing class we will create a Hibernate session and provide it to the rule engine&#8217;s working memory as a constant global value. This allows us to access the database from inside the rule file. Next we will create a query and access the result&#8217;s objects using the keyword &#8220;from&#8221;. Let&#8217;s do this:</p>
<p><i>Class DroolsHibernateTest.java</i></p>
<pre>
package eu.kijanowski.drools.hibernate;

import java.io.InputStreamReader;
import java.io.Reader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class DroolsHibernateTest {

	private final static SessionFactory factory;
	static {
		Configuration cfg = new Configuration().configure();
		factory = cfg.buildSessionFactory();
	}

	public static final void main(String[] args) {
		try {

			Game g1 = new Game("BF2", 39.99, 5);
			Game g2 = new Game("AoE3", 129.99, 45);
			Game g3 = new Game("BF3", 139.99, 15);

			HashSet games1 = new HashSet();
			games1.add(g1);
			games1.add(g2);
			games1.add(g3);
			HashSet games2 = new HashSet();
			games2.add(g1);
			games2.add(g3);

			Player p1 = new Player("jarek", 26, games1);
			Player p2 = new Player("ewelina", 25, games2);

			System.out.println(p1.getGames());
			System.out.println(p2.getGames());

			/* open a Hibernate session and persist data */
			Session session = factory.openSession();
			Transaction tx = session.beginTransaction();
			session.save(p1);
			session.save(p2);
			tx.commit();
			session.close();

			/* Let's verify the persisted data */
			session = factory.openSession();
			tx = session.beginTransaction();

			List players = session.createCriteria(Player.class).list();
			System.out.println(players.size() + " player(s) found:");
			for (Iterator iter = players.iterator(); iter.hasNext();) {
				Player player = (Player) iter.next();
				System.out.println(player.getName() + " has following games: "
						+ player.getGames());
			}
			tx.commit();
			session.close();

			// load up the rulebase
			RuleBase ruleBase = readRule();
			WorkingMemory workingMemory = ruleBase.newStatefulSession();

			/* pass a hibernate session to the working memory as a global */
			session = factory.openSession();
			workingMemory.setGlobal("hibernateSession", session);

			workingMemory.fireAllRules();
			session.close();

		} catch (Throwable t) {
			t.printStackTrace();
		}
	}

	private static RuleBase readRule() throws Exception {
		// read in the source
		Reader source = new InputStreamReader(DroolsHibernateTest.class
				.getResourceAsStream("/Demo.drl"));

		PackageBuilder builder = new PackageBuilder();

		// this will parse and compile in one step
		builder.addPackageFromDrl(source);

		// get the compiled package (which is serializable)
		Package pkg = builder.getPackage();

		// add the package to a rulebase (deploy the rule package).
		RuleBase ruleBase = RuleBaseFactory.newRuleBase();
		ruleBase.addPackage(pkg);
		return ruleBase;
	}

}
</pre>
<p>The rule file can be created using the drools plug-in. Just click on the src/main/rules directory and from the menu File -&gt; New -&gt; Other&#8230; click Drools -&gt; Rule Resource:</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2658892635/" title="fig2-3_demodrl by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3189/2658892635_58deebe2a6.jpg" width="414" height="500" alt="fig2-3_demodrl" /></a></p>
<p><i>Demo.drl</i></p>
<pre>
package eu.kijanowski.drools.hibernate

global org.hibernate.Session hibernateSession;

rule "hibernate_from"
	when
		game:Game() from hibernateSession.createQuery("select games from Player p where p.age &gt;= :age").setProperties( {"age" : 18 }).list()
	then
		System.out.println("The game "+game.getName() +"is owned by "+game.getPlayers());
end
</pre>
<h2><a name="howdoesitwork">How does it work?</a></h2>
<p>Let&#8217;s have a look at the <b>global</b> keyword in the rule file. This allows us to provide the rule engine with constants and variables from outside. Potential usecases are:</p>
<ul>
<li>return results back to the application
<li>
<li>access services, like Hibernate, JMS, file writers, email senders, etc.</li>
</ul>
<p>What&#8217;s worth to know is that you should <b>never change a global</b>, when you use it in the condition part (LHS) of a rule. Moreover globals are <b>not designed to share any data</b> between rules, this can be done via facts living in the working memory.</p>
<p>The condition element <b>from</b> allows to access data from other sources than the working memory. These can be Collectins, Maps and results coming from called methods. In our scenario we&#8217;ve created a query and received a list of games.</p>
<h2><a name="final">Results</a></h2>
<p>After running our example (Run as -&gt; Java Application) the console will show:</p>
<pre>
Jun 14, 2008 8:58:11 AM org.hibernate.cfg.Environment 

INFO: Hibernate 3.2.6
Jun 14, 2008 8:58:11 AM org.hibernate.cfg.Environment
INFO: hibernate.properties not found
Jun 14, 2008 8:58:11 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Jun 14, 2008 8:58:11 AM org.hibernate.cfg.Environment 

INFO: using JDK 1.4 java.sql.Timestamp handling
Jun 14, 2008 8:58:11 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Jun 14, 2008 8:58:11 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : eu/kijanowski/drools/hibernate/model.hbm.xml
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: eu.kijanowski.drools.hibernate.Player -&gt; PLAYERS
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.HbmBinder bindCollection
INFO: Mapping collection: eu.kijanowski.drools.hibernate.Player.games -&gt; PLAYERS_GAMES
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: eu.kijanowski.drools.hibernate.Game -&gt; GAMES
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.HbmBinder bindCollection
INFO: Mapping collection: eu.kijanowski.drools.hibernate.Game.players -&gt; PLAYERS_GAMES
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Jun 14, 2008 8:58:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Jun 14, 2008 8:58:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 1
Jun 14, 2008 8:58:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Jun 14, 2008 8:58:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost/droolsdb
Jun 14, 2008 8:58:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=droolsuser, password=****}
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: PostgreSQL, version: 8.2.5
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.2 JDBC3 with SSL (build 508)
Jun 14, 2008 8:58:12 AM org.hibernate.dialect.Dialect 

INFO: Using dialect: org.hibernate.dialect.PostgreSQLDialect
Jun 14, 2008 8:58:12 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
Jun 14, 2008 8:58:12 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Jun 14, 2008 8:58:12 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO: Using ASTQueryTranslatorFactory
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Jun 14, 2008 8:58:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Jun 14, 2008 8:58:12 AM org.hibernate.impl.SessionFactoryImpl
INFO: building session factory
Jun 14, 2008 8:58:12 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Jun 14, 2008 8:58:12 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: Running hbm2ddl schema export
Jun 14, 2008 8:58:12 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: exporting generated schema to database
Jun 14, 2008 8:58:13 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: schema export complete
[BF3 with 15 levels for 139.99, BF2 with 5 levels for 39.99, AoE3 with 45 levels for 129.99]
[BF3 with 15 levels for 139.99, BF2 with 5 levels for 39.99]
Hibernate: select nextval ('player_id_seq')
Hibernate: select nextval ('game_id_seq')
Hibernate: select nextval ('game_id_seq')
Hibernate: select nextval ('game_id_seq')
Hibernate: select nextval ('player_id_seq')
Hibernate: insert into PLAYERS (NAME, AGE, PLAYER_ID) values (?, ?, ?)
Hibernate: insert into GAMES (NAME, PRICE, LEVELS, GAME_ID) values (?, ?, ?, ?)
Hibernate: insert into GAMES (NAME, PRICE, LEVELS, GAME_ID) values (?, ?, ?, ?)
Hibernate: insert into GAMES (NAME, PRICE, LEVELS, GAME_ID) values (?, ?, ?, ?)
Hibernate: insert into PLAYERS (NAME, AGE, PLAYER_ID) values (?, ?, ?)
Hibernate: insert into PLAYERS_GAMES (PLAYER_ID, GAME_ID) values (?, ?)
Hibernate: insert into PLAYERS_GAMES (PLAYER_ID, GAME_ID) values (?, ?)
Hibernate: insert into PLAYERS_GAMES (PLAYER_ID, GAME_ID) values (?, ?)
Hibernate: insert into PLAYERS_GAMES (PLAYER_ID, GAME_ID) values (?, ?)
Hibernate: insert into PLAYERS_GAMES (PLAYER_ID, GAME_ID) values (?, ?)
Hibernate: select this_.PLAYER_ID as PLAYER1_0_0_, this_.NAME as NAME0_0_, this_.AGE as AGE0_0_ from PLAYERS this_
2 player(s) found:
Hibernate: select games0_.PLAYER_ID as PLAYER1_1_, games0_.GAME_ID as GAME2_1_, game1_.GAME_ID as GAME1_2_0_, game1_.NAME as NAME2_0_, game1_.PRICE as PRICE2_0_, game1_.LEVELS as LEVELS2_0_ from PLAYERS_GAMES games0_ left outer join GAMES game1_ on games0_.GAME_ID=game1_.GAME_ID where games0_.PLAYER_ID=?
jarek has following games: [AoE3 with 45 levels for 129.99, BF3 with 15 levels for 139.99, BF2 with 5 levels for 39.99]
Hibernate: select games0_.PLAYER_ID as PLAYER1_1_, games0_.GAME_ID as GAME2_1_, game1_.GAME_ID as GAME1_2_0_, game1_.NAME as NAME2_0_, game1_.PRICE as PRICE2_0_, game1_.LEVELS as LEVELS2_0_ from PLAYERS_GAMES games0_ left outer join GAMES game1_ on games0_.GAME_ID=game1_.GAME_ID where games0_.PLAYER_ID=?
ewelina has following games: [BF3 with 15 levels for 139.99, BF2 with 5 levels for 39.99]
Hibernate: select game2_.GAME_ID as GAME1_2_, game2_.NAME as NAME2_, game2_.PRICE as PRICE2_, game2_.LEVELS as LEVELS2_ from PLAYERS player0_ inner join PLAYERS_GAMES games1_ on player0_.PLAYER_ID=games1_.PLAYER_ID inner join GAMES game2_ on games1_.GAME_ID=game2_.GAME_ID where player0_.AGE&gt;=?
Hibernate: select players0_.GAME_ID as GAME2_1_, players0_.PLAYER_ID as PLAYER1_1_, player1_.PLAYER_ID as PLAYER1_0_0_, player1_.NAME as NAME0_0_, player1_.AGE as AGE0_0_ from PLAYERS_GAMES players0_ left outer join PLAYERS player1_ on players0_.PLAYER_ID=player1_.PLAYER_ID where players0_.GAME_ID=?
The game BF2is owned by [jarek, ewelina]
Hibernate: select players0_.GAME_ID as GAME2_1_, players0_.PLAYER_ID as PLAYER1_1_, player1_.PLAYER_ID as PLAYER1_0_0_, player1_.NAME as NAME0_0_, player1_.AGE as AGE0_0_ from PLAYERS_GAMES players0_ left outer join PLAYERS player1_ on players0_.PLAYER_ID=player1_.PLAYER_ID where players0_.GAME_ID=?
The game BF3is owned by [jarek, ewelina]
Hibernate: select players0_.GAME_ID as GAME2_1_, players0_.PLAYER_ID as PLAYER1_1_, player1_.PLAYER_ID as PLAYER1_0_0_, player1_.NAME as NAME0_0_, player1_.AGE as AGE0_0_ from PLAYERS_GAMES players0_ left outer join PLAYERS player1_ on players0_.PLAYER_ID=player1_.PLAYER_ID where players0_.GAME_ID=?
The game AoE3is owned by [jarek]
The game BF2is owned by [jarek, ewelina]
The game BF3is owned by [jarek, ewelina]
</pre>
<h2><a name="summary">Summary</a></h2>
<p>This article shows how you can easily integrate Hibernate with the Drools rule engine. This allows you to reason over data, which does not only live in the working memory, but also in an external database.</p>
<div class="caption">All images and content copyright © 2008 Jaroslaw Kianowski. All rights reserved. Used with permission.</div>
<h2>Related articles</h2>
<ul>
<li><a href="http://www.redhatmagazine.com/2008/03/27/video-mark-proctor/">Video: Mark Proctor and JBoss Drools</a></li>
<li><a href="http://www.redhatmagazine.com/2008/05/01/video-mark-proctor-part-2-origins-and-uses-of-jboss-drools/">Video: Mark Proctor, part 2: Origins and uses of JBoss Drools</a></li>
</ul>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rhredhatmagazine.wordpress.com/966/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rhredhatmagazine.wordpress.com/966/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rhredhatmagazine.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rhredhatmagazine.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rhredhatmagazine.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rhredhatmagazine.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rhredhatmagazine.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rhredhatmagazine.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rhredhatmagazine.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rhredhatmagazine.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rhredhatmagazine.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rhredhatmagazine.wordpress.com/966/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=966&subd=rhredhatmagazine&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://magazine.redhat.com/2008/07/11/jboss-drools-meets-hibernate/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kijanowski</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3096/2658892369_0eea61eb8e.jpg" medium="image">
			<media:title type="html">fig2-1_step1</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3276/2658892523_dd6937c6a2.jpg" medium="image">
			<media:title type="html">fig2-2_libs</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3189/2658892635_58deebe2a6.jpg" medium="image">
			<media:title type="html">fig2-3_demodrl</media:title>
		</media:content>
	</item>
		<item>
		<title>Introduction to Drools:  Rules fall from your eyes</title>
		<link>http://magazine.redhat.com/2008/07/10/introduction-to-drools-rules-fall-from-your-eyes/</link>
		<comments>http://magazine.redhat.com/2008/07/10/introduction-to-drools-rules-fall-from-your-eyes/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 22:25:55 +0000</pubDate>
		<dc:creator>kijanowski</dc:creator>
				<category><![CDATA[JBoss]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://www.redhatmagazine.com/2008/07/10/introduction-to-drools-rules-fall-from-your-eyes/</guid>
		<description><![CDATA[One of our long-time writers introduced us to Jaroslaw, a JBoss QA Engineer based in Poland, and mentioned that he&#8217;d been working on some documentation we might find interesting.  And, boy, do we!  This first piece de-mystifies the complex world of rules engines.  Whether you call it Drools, or JBoss Rules, or [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=968&subd=rhredhatmagazine&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><em>One of our long-time writers introduced us to Jaroslaw, a JBoss QA Engineer based in Poland, and mentioned that he&#8217;d been working on some documentation we might find interesting.  And, boy, do we!  This first piece de-mystifies the complex world of rules engines.  Whether you call it <a href="http://en.wikipedia.org/wiki/Drools">Drools</a>, or <a href="http://www.jboss.com/products/rules">JBoss Rules</a>, or JBoss Drools&#8230;  you still might want to know what it does and how it functions in your technical environment. (Not to mention that it&#8217;s just all kinds of logical and interesting&#8211;if you like brainteaser word puzzles or abstract math questions, this qualifies as pleasure reading.)</p>
<p>This article is presented here in its entirety (with a trackback).  The original can be found on <a href="http://www.kijanowski.eu/index.php?site=articles&amp;article=introduction&amp;lang=en">Jaroslaw&#8217;s site</a>.  This article is also available in <a href="http://www.kijanowski.eu/index.php?site=articles&amp;article=introduction&amp;lang=de">German</a> and <a href="http://www.kijanowski.eu/index.php?site=articles&amp;article=introduction&amp;lang=pl">Polish</a>.</em></em></p>
<h2>Justification:</h2>
<p>Either you&#8217;re a developer, architect or a business analyst, it&#8217;s worth to get familiar at least with the first chapter of this article. It contains an introduction into the world of rule engines, which increase the readability of certain applications and make them easier to manage and to maintain. It applies to apps that take decisions, which depend on events or a state of some objects.</p>
<h2>Abstract:</h2>
<p>This article contains an introduction to rule engines, a description of an installation of Eclipse IDE and a guide how to configure Eclipse with the Drools Workbench plug-in.<span id="more-968"></span></p>
<ol>
<li><a href="#ruleengine">A Rule Engine</a></li>
<li><a href="#drools">Drools</a></li>
<li><a href="#advantages">Advantages of the Drools rule engine</a></li>
<li><a href="#brms">BRMS</a></li>
<li><a href="#productionsvsevents">Production rules vs. events</a></li>
<li><a href="#start">Let&#8217;s get started!</a>
<li><a href="#howdoesitwork">What happened?</a></li>
<li><a href="#summary">Summary</a></li>
</ol>
<h2><a name="ruleengine">A Rule Engine</a></h2>
<p>A <a href="http://en.wikipedia.org/wiki/Rules_engine" target="_blank">rule engine</a> is a piece of software, which having some knowledge is able to perform conclusions. Knowledge and inferences are stored in rules, which are called <a href="http://en.wikipedia.org/wiki/Production_rule_system" target="_blank">production rules</a>. In other words, production rules consist of conditions and actions, which are executed when their	conditions are true. Besides that there&#8217;s a <a href="http://en.wikipedia.org/wiki/Working_memory" target="_blank">working memory</a>, which stores all objects we may want to use while making a decision. The state of this memory can vary, because actions can add,	delete or change existing objects. Moreover rules can get into a conflict. This happens when there are more than one rule which are true, at the same time. Then conflict resolution is provided by the agenda. It arranges the order of actions, which has been selected to be run. The agenda is an important part of a rule engine, because the execution of an action may invalidate a rule and in consequence cancel another action. To sum it up, a rule engine can be presented as follows:</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2658891787/" title="fig1-1_rule_engine_en by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3268/2658891787_bb60abfca1.jpg" width="346" height="500" alt="fig1-1_rule_engine_en" /></a></p>
<p>Rule engines perfectly fits to:</p>
<ul>
<li>calculate a discount of orders based on the amount or price</li>
<li>determine an insurance policy dependent on the age of the driver and the value of the car</li>
<li>make a diagnosis</li>
<li>detect imminence of failure</li>
<li>solve riddles</li>
</ul>
<h2><a name="drools">Drools</a></h2>
<p>One of the open source implementations of a rule engine is <a href="http://www.jboss.org/drools/" target="_blank">Drools</a>. It&#8217;s a Java library distributed under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">Apache license</a>. It&#8217;s available as as a binary and a source download. You can get it and use in your applications for free.</p>
<p>The heart of a rule engine is an <a href="http://en.wikipedia.org/wiki/Inference_engine" target="_blank">inference engine</a>. Its job is to match facts and rules (pattern matching) to make conclusions which ends in running actions. This matching is done by the <a href="http://en.wikipedia.org/wiki/Rete_algorithm" target="_blank">RETE</a> algorithm, which has been extended by object oriented concepts.</p>
<p>As I already mentioned, <b>knowledge</b> is presented in form of production rules. <a href="http://en.wikipedia.org/wiki/Knowledge_representation" target="_blank">Knowledge representation</a>, which is a way to provide the rule engine with data, is based on <a href="http://en.wikipedia.org/wiki/First-order_logic" target="_blank">FOL &#8211; first order logic</a>. FOL allows to evaluate expressions like 2 + 3 == 5 or customer.age &gt; 17.</p>
<p>The two main parts of a production rule are its condition(s) and action(s):</p>
<pre>
when
	Customer (age &gt; 17)
	then
	System.out.println("Customer is full age");
</pre>
<p>The rule above is going to evaluated as true for all those facts, which represents full age customers. A similar sql query would look as follows:</p>
<p><code>SELECT * from Customers c WHERE c.age &gt; 17</code></p>
<p>There are two ways to determine the truth of a rule (condition)	and run its action in consequence. <a href="http://en.wikipedia.org/wiki/Forward_chaining" target="_blank">Forward chaining</a> is driven with facts. Rules are checked, which <b>conditions</b> are true for facts being in the working memory. The process of pattern matching finishes, when there are no more rules left, whose conditions are true. <a href="http://en.wikipedia.org/wiki/Backward_chaining" target="_blank">Backward chaining</a> on the other hand is a goal<br />
driven approach. Only those rules are checked, whose <b>actions</b> can be matched with a goal. If that is the case, conditions of that rule are evaluated.</p>
<h2><a name="advantages">Advantages of the Drools rule engine</a></h2>
<ul>
<li>separates your <b>application</b> from <b>conditions</b> which control the flow
<ul>
<li>rules are stored in separate files</li>
<li>rules can be modified by different groups of people</li>
<li>changing rules does not require to recompile or to redeploy	the whole application</li>
<li>putting all rules into one place makes it easier to control or manage the flow of the application</li>
</ul>
</li>
<li>rules can replace <b>complex</b> if &#8211; then statements in an <b>easy	and readable</b> way
<ul>
<li>the rule language is not very difficult to learn</li>
<li>a plug-in for Eclipse IDE makes it easier to write rules and allows to have a look at the RETE tree</li>
</ul>
</li>
<li>problems are not solved using a <b>complicated algorithm</b>, but via rules, which are <b>easier to read and understand</b> than<br />
		code</p>
<ul>
<li>with <a href="http://en.wikipedia.org/wiki/Declarative_programming" target="_blank">declarative programming</a> you are focused on <b>WHAT</b> you are solving, and not <b>HOW</b></li>
<li>a group of problems can be easily solved with rules, where the algorithmic approach may be unusable (too complex, too time consuming, etc)</li>
</ul>
</li>
<li>access to the reasoning process allows you to <b>understand	why</b> a particular decisions has been made</li>
</ul>
<p>Summing up a rule engine should be considered when the solution	of a problem seems complex or simply the algorithm contains a lot of it &#8211; then or switch statements. Rules should be also taken into account, when logic that drives your application often changes or has to be	managed by people who don&#8217;t (or shouldn&#8217;t) have access to the application itself (to recompile/redeploy it).</p>
<h2><a name="brms">BRMS</a></h2>
<p>Drools is not just a rule engine. It provides also an application for managing rules, called Business Rules Management System. It allows to create, modify, delete, branch and persist rules. Moreover it&#8217;s possible to assign roles to users and a login mechanism	and LDAP integration makes it easy to introduce security. So for example, a business analyst may have access to modify a rule, a developer on the other hand may be able only to read it. A BRMS is a single point of truth.</p>
<h2><a name="productionsvsevents">Production rules vs. events</h2>
<p>Production rules consists mainly of conditions (when) and actions (then), e.g. when there&#8217;s a customer, who has a driving license for less than 5 years, then offer her an expensive insurance. Other type of rules are events (<a href="http://en.wikipedia.org/wiki/Event_Condition_Action" target="_blank">event condition action</a>). In that case a rule engine looks for event patterns to match registered events. An event may be selling the last item or a breakdown of traffic lights. Another	difference is the moment, when actions are executed. In the production rules environment, it&#8217;s the developer, who decides, when the rule engine is going to fire all actions. However, when working with events, an action is fired, when the associated event did happen.</p>
<h2><a name="start">Let&#8217;s get started!</a></h2>
<p>&#8230; and install an IDE. I&#8217;ve chosen Eclipse, because it&#8217;s good enough and Drools provides a plug-in for writing rules.</p>
<p><a href="http://www.eclipse.org/downloads/" target="_blank">Eclipse IDE</a>, Eclipse IDE for Java EE Developers (eclipse-jee-europa-winter-linux-gtk.tar.gz)</p>
<p>After you&#8217;ve downloaded it, extract and start Eclipse. From the	menu click on Help -&gt; Software Updates -&gt; Find and install&#8230; -&gt; Search for new features to install -&gt; New Remote Site&#8230;</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2658891901/" title="fig1-2_install1 by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3018/2658891901_a13a162530.jpg" width="470" height="500" alt="fig1-2_install1" /></a></p>
<p>You can find the URL on the Drools <a href="http://www.jboss.org/drools/downloads.html" target="_blank">downloads page</a> under &#8220;Drools IDE Update Site&#8221;. It&#8217;s a link to the plug-in. For Drools 4.0.7 Eclipse Workbench for Europa 3.3 it is <a href="http://downloads.jboss.com/drools/updatesite3.3/">http://downloads.jboss.com/drools/updatesite3.3/</a></p>
<p>We choose OK and Finish. Eclipse will show the search results:</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2658891991/" title="fig1-3_install2 by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3109/2658891991_1a0376f6a1.jpg" width="500" height="454" alt="fig1-3_install2" /></a></p>
<p>Click on Next, accept the license and choose Finish, to start to download the plug-in. After that Eclipse will show another window, where we click on &#8220;Install all&#8221;. When asked for a restart we click on &#8220;Yes&#8221;. To verify a successful installation of the plug-in, make sure a new Drools icon showed up in the toolbar.</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2658892115/" title="fig1-4_symbol by redhatmag, on Flickr"><img src="http://farm4.static.flickr.com/3097/2658892115_560094df70_o.png" width="275" height="81" alt="fig1-4_symbol" /></a></p>
<p>Let&#8217;s have a look at our first Drools application. Click on the Drools &#8220;head&#8221; and choose &#8220;New Rule Project&#8221;.</p>
<p><a href="http://www.flickr.com/photos/redhatmagazine/2658892229/" title="fig1-6_step0 by redhatmag, on Flickr"><img src="http://farm3.static.flickr.com/2312/2658892229_9e1f9cec61_o.png" width="358" height="203" alt="fig1-6_step0" /></a></p>
<p>Type a name for the project and click Finish. The Drools plug-in creates a standard layout and provides all the necessary libraries to get started. To run this application click on com.sample.DroolsTest and	press &#8220;Shift + Alt + X&#8221; and then &#8220;J&#8221;. The console will show th following:</p>
<pre>
Hello World
	Goodbye cruel world
</pre>
<h2><a name="howdoesitwork">What happened?</a></h2>
<p>This example has been described in the <a href="http://downloads.jboss.com/drools/docs/4.0.7.19894.GA/html_single/index.html#d0e5986" target="_blank">Drools documentation</a>. I&#8217;m not going into detail what&#8217;s happening in DroolsTest.java, where the rule engine is initialized and rules are read. The more interesting part is the rule file itself, Sample.drl.</p>
<p>This file has two rules. At the beginning, the working memory contains one object of the class Message, whose fields message and status are set to &#8220;Hello World&#8221; and &#8220;0&#8243;. When fireAllRules() is called, all actions are going to be executed. It&#8217;s worth to note that conditions of rules are evaluated <b>when an object is added into the working memory</b>. The condition of the rule called &#8220;Hello World&#8221; is true, because there is an object in the working memory, which is a Message and has a status equal to &#8220;0&#8243;. Hence actions of this rule are going to be run. As a result, the status and message fields of that Message object are going to be modified. The <b>update()</b> command forces the rule engine to evaluate its rules again. This time the second rule&#8217;s condition is true and appropriate actions are executed.</p>
<h2><a name="summary">Summary</a></h2>
<p>This short introduction into the world of rule engines and the chosen implementation Drools showed their main characteristics and some potential fields of use. To get more familiar with this software I would suggest to read the <a href="http://www.jboss.org/drools/documentation.html" target="_blank">Drools documentation</a>.</p>
<div class="caption">All images and content copyright © 2008 Jaroslaw Kianowski. All rights reserved. Used with permission.</div>
<h2>Related articles</h2>
<ul>
<li><a href="http://www.redhatmagazine.com/2008/03/27/video-mark-proctor/">Video: Mark Proctor and JBoss Drools</a></li>
<li><a href="http://www.redhatmagazine.com/2008/05/01/video-mark-proctor-part-2-origins-and-uses-of-jboss-drools/">Video: Mark Proctor, part 2: Origins and uses of JBoss Drools</a></li>
</ul>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rhredhatmagazine.wordpress.com/968/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rhredhatmagazine.wordpress.com/968/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rhredhatmagazine.wordpress.com/968/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rhredhatmagazine.wordpress.com/968/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rhredhatmagazine.wordpress.com/968/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rhredhatmagazine.wordpress.com/968/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rhredhatmagazine.wordpress.com/968/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rhredhatmagazine.wordpress.com/968/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rhredhatmagazine.wordpress.com/968/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rhredhatmagazine.wordpress.com/968/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rhredhatmagazine.wordpress.com/968/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rhredhatmagazine.wordpress.com/968/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=968&subd=rhredhatmagazine&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://magazine.redhat.com/2008/07/10/introduction-to-drools-rules-fall-from-your-eyes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kijanowski</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3268/2658891787_bb60abfca1.jpg" medium="image">
			<media:title type="html">fig1-1_rule_engine_en</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3018/2658891901_a13a162530.jpg" medium="image">
			<media:title type="html">fig1-2_install1</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3109/2658891991_1a0376f6a1.jpg" medium="image">
			<media:title type="html">fig1-3_install2</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3097/2658892115_560094df70_o.png" medium="image">
			<media:title type="html">fig1-4_symbol</media:title>
		</media:content>

		<media:content url="http://farm3.static.flickr.com/2312/2658892229_9e1f9cec61_o.png" medium="image">
			<media:title type="html">fig1-6_step0</media:title>
		</media:content>
	</item>
		<item>
		<title>JBoss Application Server 5 CR1 available</title>
		<link>http://magazine.redhat.com/2008/07/07/jboss-application-server-5-cr1-available/</link>
		<comments>http://magazine.redhat.com/2008/07/07/jboss-application-server-5-cr1-available/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 09:35:35 +0000</pubDate>
		<dc:creator>Karsten 'quaid' Wade</dc:creator>
				<category><![CDATA[Dev Fu]]></category>
		<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://magazine.redhat.com/?p=1366</guid>
		<description><![CDATA[The first candidate release (CR1) for JBoss Application Server 5 has been released.  There is a lot of good background from Sacha Labourey and feature details from project lead Dimitris Andreadis.  Now that version 5 of the new application server has been through alpha and beta stages, this candidate release is a great [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1366&subd=rhredhatmagazine&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The first candidate release (CR1) for JBoss Application Server 5 has been <a href="https://sourceforge.net/project/showfiles.php?group_id=22866&amp;package_id=16942&amp;release_id=610469">released</a>.  There is a lot of <a href="http://sacha.labourey.com/2008/06/28/jboss-as-50-status/">good background from Sacha Labourey</a> and <a href="http://www.infoq.com/news/2008/06/jboss-as5-rc1">feature details from project lead Dimitris Andreadis</a>.  Now that version 5 of the new application server has been through alpha and beta stages, this candidate release is a great opportunity for developers to get knowledge and practice on the next gen app server.</p>
<p>(Tip of the hat for <a href="http://blogs.jboss.com/blog/alesj/?permalink=JBoss5_CR1_SpringDeployer_and_VFS.txt">Ales Justin&#8217;s post</a> about the CR1.  Ales also posts new information about <a href="https://sourceforge.net/project/showfiles.php?group_id=22866&amp;package_id=161914&amp;release_id=611416">SpringDeployer</a> and VFS .)</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rhredhatmagazine.wordpress.com/1366/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rhredhatmagazine.wordpress.com/1366/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rhredhatmagazine.wordpress.com/1366/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rhredhatmagazine.wordpress.com/1366/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rhredhatmagazine.wordpress.com/1366/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rhredhatmagazine.wordpress.com/1366/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rhredhatmagazine.wordpress.com/1366/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rhredhatmagazine.wordpress.com/1366/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rhredhatmagazine.wordpress.com/1366/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rhredhatmagazine.wordpress.com/1366/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rhredhatmagazine.wordpress.com/1366/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rhredhatmagazine.wordpress.com/1366/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1366&subd=rhredhatmagazine&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://magazine.redhat.com/2008/07/07/jboss-application-server-5-cr1-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Karsten 'quaid' Wade</media:title>
		</media:content>
	</item>
		<item>
		<title>Adapters for an ESB</title>
		<link>http://magazine.redhat.com/2008/05/22/adapters-for-an-esb/</link>
		<comments>http://magazine.redhat.com/2008/05/22/adapters-for-an-esb/#comments</comments>
		<pubDate>Thu, 22 May 2008 21:53:37 +0000</pubDate>
		<dc:creator>Len DiMaggio</dc:creator>
				<category><![CDATA[JBoss]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://www.redhatmagazine.com/2008/05/22/adapters-for-an-esb/</guid>
		<description><![CDATA[One of the joys of software development is the ease with which you can create complex stuff out of thin air&#8211;or your own imagination.  Creating new software may fulfill a need that could not otherwise be met. However, you can take advantage of a standardized way of doing things, so that you don&#8217;t have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=901&subd=rhredhatmagazine&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>One of the joys of software development is the ease with which you can create complex stuff out of thin air&#8211;or your own imagination.  Creating new software may fulfill a need that could not otherwise be met. However, you can take advantage of a standardized way of doing things, so that you don&#8217;t have to start from scratch every single time. In the case of infrastructure software, using an established standard enables you to concentrate on your specific business needs, and not the supporting systems.</p>
<p>The seed of this article is actually a comment on the first article<a href="#one"><sup>[1]</sup></a> in this series. In that first article, I described middleware as though it were plumbing. I chose to use this analogy as the term &#8220;middleware&#8221; is often misunderstood. My rationale for the plumbing analogy was that plumbing and middleware share these characteristics:</p>
<p>First, it&#8217;s mostly invisible. Second, it provides a standard way of doing things. Third, it ties together parts of complex systems. Fourth, and finally, it lets you worry about other things.<span id="more-901"></span></p>
<p>What I was getting at with the fourth characteristic is this: With middleware,  application developers don&#8217;t have to re-invent the software infrastructure needed to support their applications. Instead, they can concentrate on the business logic of the application. In the article, I said, &#8220;When you put an addition onto a house, what do you worry about? Bathroom fixtures, kitchen appliances, flooring, colors, and how to pay for it all. It&#8217;s a very stressful process. The last thing you want to worry about is whether you want 3/4-inch or half-inch pipe, copper or PVC connectors, #9 or #17 solder, etc. With middleware taking care of all the invisible functions, you (as a software developer or a business owner) can concentrate on building software to solve your business problems and fulfill your customers&#8217; needs.&#8221;</p>
<p>That article has received several responses from readers. One response included this comment:</p>
<p>&#8220;&#8230;Except that when you do build your addition, you will need to worry about those exact issues. You&#8217;ll need adapters for attaching new metric pipes to old Imperial sizes; you&#8217;ll probably have couplers that are designed to connect plastic to copper; and you&#8217;ll also need to know the current regulations about when to use copper, plastic, or (heaven forbid) steel. In this sense, your analogy that middleware is like plumbing is surprisingly accurate. Just when you aquire all the materials and expertise in working with one standard, a new standard replaces it, and you start all over again, with the added headache of making the two work together during the transition period&#8230;At least that has been my experience over the past twenty years as a developer.&#8221;</p>
<p>Now, I hadn&#8217;t planned on writing a series of articles on middleware, but that reader&#8217;s comment got me thinking about adapters. Not the kind of adapter that you use to tie together different generations of water pipes in your house, but the kind of connections that the adapters in an ESB make possible.</p>
<h2>JBoss ESB</h2>
<p>Just like &#8220;middleware,&#8221; the term &#8220;ESB&#8221; can cause confusion.</p>
<p>An Enterprise Service Bus (ESB) is not a single program or technology. It&#8217;s really a matter of software architecture or design. Let&#8217;s take a step back from all the jargon and keep it simple. In hardware terms, a &#8220;bus&#8221; is a physical connector  that ties together multiple systems or subsystems. Instead of having a large number of point-to-point connectors between pairs of systems, you connect each system to the bus once.</p>
<p>An ESB does the same thing, logically, in software. Instead of passing electric current or data over the bus to and from the connections (or &#8220;endpoints&#8221;) on the ESB, the ESB logically sits in the architectural layer above a messaging system. The messaging system allows for asynchronous communications between services over the ESB. In fact, when you are working with an ESB, everything is either a service (which in this context is your application software) or a message being sent between services. It&#8217;s important to note that a &#8220;service&#8221; is not automatically a web service. Other types of applications, using transports such as FTP or JMS, can also be services.</p>
<h3>Is an ESB the same thing as SOA? (Service Oriented Architecture)</h3>
<p>Not exactly. An ESB does not provide a Service Oriented Architecture, but it does provide the tools than can be used to build one&#8211;especially loose-coupling and asynchronous message passing. SOA is a series of principles, patterns, and best practices. The key initial &#8220;A&#8221; is for “architecture.” In this article, we&#8217;ll discuss JBossESB<a href="#two"><sup>[2]</sup></a>.</p>
<h2>Raising Your (ESB) Awareness</h2>
<p>We just talked about considering everything in an ESB as either a message or a service. That&#8217;s fine for inside the ESB. How does a client or service&#8211;especially legacy applications&#8211;connect to an ESB?</p>
<p>To answer that question, we have to think about awareness.</p>
<p>No, I&#8217;m not talking about getting in touch with your inner child. I&#8217;m talking about whether or not your application clients and services are &#8220;ESB-aware&#8221; or, in other words, whether they can understand the message formats and transport protocols used by the ESB. If you (as a programmer) are ESB-aware, then you can simply code any new clients and services that you write to also be ESB-aware. ESB-aware clients and services communicate with each other using messages. ESB-aware services are identified using Endpoint References (EPRs). The messages take the form defined by the <code>org.jboss.soa.esb.message</code> interface. As the javadocs<a href="#four"><sup>[4]</sup></a> for message says:</p>
<p>A message consists of the following components:</p>
<ul>
<li><strong>Header:</strong> the header information contains information such as the destination EPR, the sender EPR, and where the reply goes&#8211;general message-level functional information.</li>
<li><strong>Context:</strong> additional information that further explains the message; for example, transaction or security data, the identity of the ultimate receiver, or HTTP-cookie-like information.</li>
<li><strong>Body:</strong> the actual payload of the message.</li>
<li><strong>Fault:</strong> any error information associated with the message.</li>
<li><strong>Attachment:</strong> any attachments (additional files) associated with the message.</li>
<li><strong>Properties:</strong> any message-specific properties (for example the <code>jbossesb.message.id</code> property is a unique value for each message.</li>
</ul>
<p>What about cases where legacy clients and services that are not ESB-aware need to be able to communicate over the ESB? What about cases where legacy clients and services need to be able to communicate with newer ESB-aware clients and services? Oh, and how about ESB-aware clients that we need to be able to use with ESB-unaware services?</p>
<p>This is suddenly getting complicated. It sounds like you will have to build lots of custom plumbing adapters to get all these combinations of clients and services to talk to each other. But don&#8217;t panic and don&#8217;t start building home-grown infrastructure. Supporting interoperability between different clients and services is one of the goals of JbossESB.</p>
<h2>Interoperability through ESB adapters</h2>
<p>One of the ways that JBossESB makes this interoperability possible is though gateway adapters.</p>
<p>Remember how I said that in an ESB, everything is either a message or a service? Well, a gateway (<code>org.jboss.soa.esb.listeners.gateway</code>) is a service that acts as a bridge between an ESB-aware and an ESB-unaware client and service. Gateways translate information between ESB and non-ESB message formats and EPRs. (And EPR stands for endpoint reference.) Gateways are listener processes in that they &#8220;listen&#8221; for incoming communications. They are different from ESB-aware listeners in that they accept data in different formats such as objects in files or SQL tables. ESB-aware listeners can only accept messages in the <code>org.jboss.soa.esb.message</code> format.</p>
<p>JBossESB supports these gateways:</p>
<ul>
<li>file gateways: local filesystem, ftp, sftp and ftps</li>
<li>JMS</li>
<li>HTTP/HTTPS</li>
<li>email (POP3)</li>
<li>SQL table</li>
<li>Hibernate</li>
</ul>
<p>When a gateway listener hears something, it converts the non-JBossESB messages that it receives to the <code>org.jboss.soa.esb.message</code> format. How this conversion happens depends on the gateway type. For example, the file gateway takes the contents of the file and puts it into the location named <code>BytesBody.BYTES_LOCATION</code> within the message body.</p>
<p>Let&#8217;s look at an example.</p>
<h2>A quick start (with a quickstart)</h2>
<p>One of the helpful features included in JBossESB is the set of &#8220;quickstart&#8221; sample applications. The quickstarts demonstrate JBossESB functions and integrations. The goals of the quickstarts are to serve as learning tools and as a starting point for your own application coding. We&#8217;ll examine one of these quickstarts to view the operation of a gateway.</p>
<p>Let&#8217;s assume that you have a legacy application that stores data in text files. What you want to do is to create an ESB-aware service to read these files and process them as they are created. You could write infrastructure code that periodically polls a target directory to determine when a new file is deposited there. With JBossESB, however, you can simply use a file gateway.</p>
<p>First, let&#8217;s install and start up a JBossESB server. Before you start, you will need to install Java (1.4 or 1.5) and ant (1.6.5 or later).</p>
<p>Next, download the JBossESB server from <a href="http://www.jboss.org/jbossesb/downloads/">http://www.jboss.org/jbossesb/downloads/</a>. For this illustration, download the <a href="http://www.jboss.org/downloading/?projectId=jbossesb&amp;url=/jbossesb/downloads/4.2.1GA/binary/jbossesb-server-4.2.1GA.zip">JBossESB 4.2.1 GA Binary</a> and unzip it:</p>
<pre>
unzip jbossesb-server-4.2.1GA.zip
</pre>
<p>Then, configure the quickstarts to know about the install directory for the JBossESb server by editing <code>jbossesb-server-4.2.1GA/samples/quickstarts/conf</code>, and setting <code>org.jboss.esb.server.home</code> to the directory into which you installed the JBossESB server</p>
<p>Now start the server:</p>
<pre>
sh jbossesb-server-4.2.1GA/bin/run.sh -c default
</pre>
<p>The quickstarts are distributed under the samples/quickstarts directory. Let&#8217;s take a look at <code>helloworld_file_action</code>.</p>
<pre>
cd jbossesb-server-4.2.1GA/samples/quickstartshelloworld_file_action
</pre>
<p>Deploy the test to the server and run it  with these simple commands:</p>
<pre>
ant deploy
ant runtest
</pre>
<p>The server output should look something like this:</p>
<pre>
16:42:22,744 INFO [STDOUT] Message structure:
16:42:22,744 INFO [STDOUT] [Hello World In A File].
16:42:22,746 INFO [STDOUT]
&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;
16:42:22,746 INFO [STDOUT] Body: Hello World In A File
16:42:22,746 INFO [STDOUT] &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;
16:42:22,747 INFO [STDOUT] Message structure:
16:42:22,747 INFO [STDOUT] [ message: [ JBOSS_XML ]
</pre>
<p>What just happened here? Let&#8217;s take a look. The &#8220;runtest&#8221; and target invokes <code>CreateTestFile.java</code> program. As its name implies, this program creates a test file. The file contains this text: Hello World In A File</p>
<p>For what happens next, we need to look at how the test application is configured in the ESB. A JBossESB application&#8217;s primary configuration file is named <code>jboss-esb.xml</code>. In the case of this quickstart, that file is generated at run time so that the JBossESB install directory can be determined. So, we need to look at the source of the generated file, <code>jboss-esb-unfiltered.xml</code>.</p>
<p>The first part of the file that we&#8217;re interested in looks like this:</p>
<pre>
</pre>
<p>This is the definition of the file gateway that we&#8217;ll use. Note the directory names. In this example, they are filled in at run time from values determined by the directory in which you installed JBossESB.</p>
<p>Now, remember how we said that everything in the ESB is either a message or a service? Scroll down in the file and we&#8217;ll see our service.</p>
<pre>
</pre>
<p>Let&#8217;s look at this service description.</p>
<p>First, the listeners. Note the definition of the file system (fs) listener. This is our gateway. The &#8220;busidref&#8221; field references the &#8220;fs-provider&#8221; that we discussed a minute ago. Did you notice a second listener? This is an ESB-aware JMS listener. It is there because JBossESB requires that each gateway have a corresponding ESB listener defined.</p>
<p>Let&#8217;s look at the actions. The &#8220;mep&#8221; definition of &#8220;OneWay&#8221; refers to the action pipeline (the sequence of actions) explicitly not sending a response. (You can find more detail about these definitions in the ESB Programmers&#8217; Guide <a href="#seven"><sup>[7]</sup></a>.)</p>
<p>The actions named &#8220;testAction&#8221; and &#8220;dump&#8221; write the message to the server log. The action that we&#8217;re most interested in is &#8220;action1.&#8221; The methods (displayMessage, playWithMessage) in the class referred to by this action (org.jboss.soa.esb.samples.quickstart.helloworldfileaction.MyAction) receive the data in the input file as an ESB-Aware message, extract that information, and process it. In the case of your application, you would replace “MyAction” with your own business logic code.</p>
<p>So, in summary, what happens when this quickstart is run?</p>
<ol>
<li>The file system gateway is initialized.</li>
<li>A file is created in the input directory defined in its fs-provider definition.</li>
<li>The gateway reads the file, transforms it into an ESB-aware message, and passes the message to the methods in the action class defined in the action definition.</li>
<li>These methods process the message (in the case of the quickstart, they write the message contents to the server log).5. The gateway moves the file to the output directory defined in its fs-provider definition.</li>
</ol>
<p>It&#8217;s important to note that the only new code that had to be written is the action class. The infrastructure code to listen for and transform the file into a message in the format that the ESB can process is all part of the gateway.</p>
<p>From the perspective of an application developer, this is a plus as you can concentrate on writing code to fulfill the business process requirements of your application.</p>
<p>From the perspective of a QE engineer, this is a real plus as it means that less code has to be written. And, the less code, the fewer opportunities for bugs!</p>
<h2>What&#8217;s next?</h2>
<p>In the next article in this series, we&#8217;ll take a look at the counterpart to listeners: the notifiers. The listeners enable you to get information into the ESB. Notifiers provide one way to get information out.</p>
<h2>Resources</h2>
<p><a name="one"></a><sup>[1]</sup> Read the first article in this series &#8211; <a href="http://www.redhatmagazine.com/2008/03/11/what-is-middleware-in-plain-english-please/">What is middleware?  (In plain english, please.)</a><br />
<a name="two"></a><sup>[2]</sup> JBossESB &#8211; <a href="http://labs.jboss.com/jbossesb/">http://labs.jboss.com/jbossesb/</a><br />
<a name="three"></a><sup>[3]</sup> JBossESB Connectors and Adapters Guide<br />
<a name="four"></a><sup>[4]</sup> JBossESB javadoc: jboss/soa/esb/message/Message.html<br />
<a name="five"></a><sup>[5]</sup> <a href="http://wiki.jboss.org/wiki/JBossESBQuickStart">JBossESB quick start</a><br />
<a name="six"></a><sup>[6]</sup> <a href="http://www.jboss.org/file-access/default/members/jbossesb/freezone/docs/4.2.1GA/manuals/html/GettingStarted.html">JBossESB getting started guide (4.2.1GA)</a><br />
<a name="seven"></a><sup>[7]</sup> JBossESB Programmers Guide</p>
<h2>Acknowledgments</h2>
<p>The author would like to thank the members of the <a href="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/Contributors.txt">JBossESB project and community</a> (especially Burr Sutter and Mark Little) and the SOA Platform project for their help and timely review comments. This article relies heavily on the excellent JBossESB user documents and the quickstarts.</p>
<h2>About the author</h2>
<p>Len DiMaggio is a senior QE engineer for JBoss middleware at Red Hat. When he&#8217;s not building tests and generally breaking things, he likes writing, photography, and chauffeuring the kids to their many sports activities.  Len is a frequent contributor to Red Hat Magazine (this is Len&#8217;s 10th article in the magazine), and has also written for Dr. Dobbs&#8217; Journal, STQE, Software Development, IBM DeveloperWorks, and other publications. Len also recently launched <a href="http://swqetesting.blogspot.com">a blog dedicated to software testing</a>.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rhredhatmagazine.wordpress.com/901/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rhredhatmagazine.wordpress.com/901/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rhredhatmagazine.wordpress.com/901/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rhredhatmagazine.wordpress.com/901/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rhredhatmagazine.wordpress.com/901/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rhredhatmagazine.wordpress.com/901/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rhredhatmagazine.wordpress.com/901/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rhredhatmagazine.wordpress.com/901/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rhredhatmagazine.wordpress.com/901/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rhredhatmagazine.wordpress.com/901/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rhredhatmagazine.wordpress.com/901/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rhredhatmagazine.wordpress.com/901/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=901&subd=rhredhatmagazine&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://magazine.redhat.com/2008/05/22/adapters-for-an-esb/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">ldimaggi</media:title>
		</media:content>
	</item>
		<item>
		<title>More how to get OpenJDK</title>
		<link>http://magazine.redhat.com/2008/05/19/more-how-to-get-openjdk/</link>
		<comments>http://magazine.redhat.com/2008/05/19/more-how-to-get-openjdk/#comments</comments>
		<pubDate>Mon, 19 May 2008 18:45:39 +0000</pubDate>
		<dc:creator>Karsten 'quaid' Wade</dc:creator>
				<category><![CDATA[Dev Fu]]></category>
		<category><![CDATA[Fedora]]></category>
		<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://magazine.redhat.com/?p=1364</guid>
		<description><![CDATA[A previous post, How to get OpenJDK 6 for Red Hat Enterprise Linux 5, covered how to install OpenJDK for Fedora Extra Packages for Enterprise Linux (EPEL) 5.  Now these instructions are at an even easier URL to remember:
http://openjdk.java.net/install/#fedora
These instructions cover installing OpenJDK 6 for Fedora 9 and EPEL 5, as well as IcedTea [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1364&subd=rhredhatmagazine&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>A previous post, <a href="http://developer.redhatmagazine.com/2008/05/06/how-to-get-openjdk-6-for-red-hat-enterprise-linux-5/">How to get OpenJDK 6 for Red Hat Enterprise Linux 5</a>, covered how to install <a href="http://openjdk.java.net">OpenJDK</a> for <a href="http://fedoraproject.org/wiki/EPEL">Fedora Extra Packages for Enterprise Linux (EPEL) 5</a>.  Now these instructions are at an even easier URL to remember:</p>
<p><a href="http://openjdk.java.net/install/#fedora">http://openjdk.java.net/install/#fedora</a></p>
<p>These instructions cover installing OpenJDK 6 for Fedora 9 and EPEL 5, as well as <a href="http://fedoraproject.org/wiki/Features/IcedTea">IcedTea</a> 7 for Fedora 8.  IcedTea 7 provides the OpenJDK 7 development branch with IcedTea components to make it build under Fedora using entirely open source components.  The package name remains the same in the repository, despite the <a href="http://www.redhatmagazine.com/2008/05/16/open-source-project-openjdk/">trademark agreement allowing the OpenJDK mark to be used by Fedora</a>, because it is considered too disruptive to rename it now.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/rhredhatmagazine.wordpress.com/1364/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/rhredhatmagazine.wordpress.com/1364/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rhredhatmagazine.wordpress.com/1364/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rhredhatmagazine.wordpress.com/1364/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rhredhatmagazine.wordpress.com/1364/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rhredhatmagazine.wordpress.com/1364/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rhredhatmagazine.wordpress.com/1364/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rhredhatmagazine.wordpress.com/1364/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rhredhatmagazine.wordpress.com/1364/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rhredhatmagazine.wordpress.com/1364/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rhredhatmagazine.wordpress.com/1364/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rhredhatmagazine.wordpress.com/1364/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magazine.redhat.com&blog=5816259&post=1364&subd=rhredhatmagazine&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://magazine.redhat.com/2008/05/19/more-how-to-get-openjdk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Karsten 'quaid' Wade</media:title>
		</media:content>
	</item>
	</channel>
</rss>