JBPM Maven Plugin 1.0 released

I finally had some time this week to play with maven plugin development that ended with a full release of version 1.0.0 of a Maven plugin for JBPM. Even though JBPM 3.2 Eclipse plugin come with a totally rewritten deployment feature (compared to the old buggy one bundled with version 3.0), it stills an independent task, out of an automated deployment cycle, but the major problem is that  Process deployment is handled by a “servlet” (yes it is) provided with the jbpm-console web-app, which is in my opinion, a little bit constraining as it means for example requiring an application server running somewhere and integrated in the company move-to-production cycle to handle Business process deployment. This plugin, which will be a part of a major project aiming at Maven-JBPM integration (for which I hope I’ll have some free time to develop and promote), aims at including Business process deployment into any of a “proudly” strict clean Maven Build life cycle.

The Maven-JBPM integration experimental project site is available. It also includes an improved version of the JBPM Archetype I’ve already released. Using the plugin in conjunction with the archetype make it really easy to work with JBPM projects. Both are available in my newly experimental public repository : http://maven.khaled-labidi.net/repo

Before making the source code available, I should take few time to fix all those missing javadocs, and make the project’s checkstyle report less ashaming

But beyond the plugin itself, I was particulary marked by two points:

1- The way JBPM deals with resource loading. I started facing this when I set up a dedicated Jboss configuration to deploy and run JBPM applications (like the jbpm-console). I wanted to put the jbpm-jpdl and jbpm-identity jars into $JBOSS_HOME/bpm/lib (bpm is the name of the created configuration) and then freeing any application from carrying these jars in WEB-INF/lib, and making a kind of JBPM run platform with a cut-down version (3.2.3 for instance). The only varying thing should be the configuration files (jbpm.cfg.xml , hibernate.cfg.xml, etc) depending on each particular application needs. That was a nightmare. I solved it using two ways, both of them totally unacceptable for me :

  • The first one was by “pushing” the “break-standard” button of Jboss AS, by changing the flag attribute UseJBossWebLoader to “true” in $JBOSS_HOME\bpm\deploy\jboss-web.deployer\META-INF\jboss-service.xml. I don’t like this solution because it’s driving into an adoption of the Unified Class Loading philosophy and its consequences like loosing isolation, depending on “who’s deployed first”, etc. Norman Richards had already pointed this out.
  • The second way was by hacking the JBPM library itself, and rebuilding my own with a different way of loading resources. In fact, JBPM is using the so called “current” class loader to load resources, that is, the class loader that loaded the JBPM classes. This makes the “current” depending on where the JBPM libraries are, and for my case, it was the “common” class loader (aka “noAnnotationURLClassLoader” in Jboss world)  which is going to be the parent of all application-dedicated classloaders. All in all, JBPM resources (the jbpm.cfg.xml file) will not be visible by the JBPM library because the latter is loaded by a class loader which is the parent of the classloader loading the resource (Parent-blindness principle in Java classloading). For fun, packing the xml file into a Jar and throwing it into $JBOSS_HOME\bpm\lib solves the JBPM ClassLoader problem, but not mine. So, it was all about changing the class org.jbpm.util.ClassLoaderUtil and turns its method getClassLoader() from returning ClassLoaderUtil.class.getClassLoader() to returning Thread.currentThread().getContextClassLoader(). I was not the only one hacking around, some other guys pointed out the problem and they even made a change proposal to JBPM team. The change seems to be planned for 3.3 release, I understand that they worry about things that could be broken, but I don’t understand why making the ClassLoader to be used configurable? I think that when making a sort of library or a framework used by other applications, it should be a good design practice to use the Thread context class loader. This concept introduced by SUN in J2SE 1.2 aimed at having a top-down tunnel through the stratified class loaders hierarchies and resources repositories for higher-level libraries like JNDI allowing them to load other components and resources needed by applications at runtime. One elegant and meaningful way to do and explains this, is the Log4j API via this peace of code:

private static ClassLoader getTCL() throws IllegalAccessException,InvocationTargetException {
// Are we running on a JDK 1.2 or later system?
Method method = null;
try {
method = Thread.class.getMethod("getContextClassLoader", null);
} catch (NoSuchMethodException e) {
// We are running on JDK 1.1
return null;
}
return (ClassLoader) method.invoke(Thread.currentThread(), null);
}

The runtime behaviour of log4j is controlled by the log4j.xml resources which is application-dependent. I’m actually experimenting a changed version of JBPM 3.2 using the same mechanism of classloading.

2- The second point that marked me is the problem of making a maven project’s resources (configuration files, dependencies, etc) available to a particular plugin running inside that project. Once again, JBPM class loading was a problem. Of course, using my modified version of JBPM solved the issue, but I wanted the plugin to run with the standard JBPM library (otherwise I’ll be the only one using it). Googling took me almost to the same idea : trying to control the class loader of the Mojo, creating a new Thread with a newly created and set instance of URLClassloader, etc. All of this stuff is courageous, but for me it’s not elegant and it’s even horrifying as I wanted to write simple and clean Mojos. It was the first time I write Mojos, and I didn’t want to be definitely disgusted. Hopefully, I discovered the power of Plexus component configuration and after hours and hours reading through core Maven source code, I found the way I wanted to solve the problem by writing my own Plexus component configurator coupled to the magic of the @configurator and @requiresDependencyResolution mojo annotation. May be I’ll make a dedicated post about tips and tricks of developing mojos without playing with threads or ClassLoaders.

Logs to kill bogus Jboss logs

As from version 4.2.0, JBoss ships with Apache Tomcat 6, which is supposed to be Bug-43079-free. However, a fresh install & run of Jboss 4.2.3 (with a little tweak of log4j settings) still shows the bogus log :

WARN  [org.apache.catalina.deploy.SecurityCollection] Suspicious url pattern: “/restricted/*” - see http://java.sun.com/aboutJava/communityprocess/first/jsr053/servlet23_PFD.pdf  section 11.2

After decompiling the SecurityCollection.class file within jbossweb.jar under $JBOSS_HOME\server\bpm\deploy\jboss-web.deployer, I noticed that the bug stil there


if(pattern.endsWith("*") && pattern.charAt(pattern.length() - 1) != '/' && log.isDebugEnabled())

Not having mauch time to fix, recompile and repackage, here ’s a little workaround using particular log4j setting to send this log to a “/dev/null”-like planet:


<appender name="NULL" class="org.apache.log4j.varia.NullAppender" />
<logger name="org.apache.catalina.deploy.SecurityCollection" additivity="false">
<appender-ref ref="NULL" />
</logger>

Of course, we loose no extra logs information from SecurityCollection class as it only has one (and undesired) logging statement.

Syntaxhighlighter made XHTML compliant

Syntaxhighlighter is a powerful Wordpress plugin, based on the the google-hosted highlighter project, and it’s what I’ve chose for posted code snippets. However, there still an issue not yet solved: the generated markup is not XHTML valid. Surely, this could be insignificant for some users, but a plugin for a bloging system whose motto is “Code is Poetry”, shall, in my opinion, never break this rule. This issue seems not to be under consideration by the plugin developers, and that’s why I’ve quickly made this Hack on the plugin code to make it XHTML compliant. The W3C validator is complaining as follows: there is no attribute “name”. So one most possible solution is to used the (highly recommended) “id” attribute, and as the “id” attribute value shall be unique along the DOM, a special pattern of the value could be defined by the server-side, allowing the client side javascript code to find the target element to highlight. In a nutshell :

In syntaxhighlighter.php, change line 297 :


$content = str_replace( $match[0], '<pre name="code" class="'

to


$content = str_replace( $match[0], '<pre id="code__'.rand() . '" class="'

In shCore.js, add the following prototype at the beginning of the script:


String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}

and change line 146


if(tags[i].getAttribute('name')==name)

to


if( ((x = tags[i].getAttribute('id'))!=null) && (x.startsWith(name + '__')))

Basically, instead of looking for elements with name = “code”, it will look for elements whith id attribute starting with “code__”. That’s it. It’s working and XHTML compliant above all!

PS : The probability that few consecutive calls to PHP rand() function give 2 equal values is really infinitesimal and this guarantee to never get two id with the same value.

My Maven site skin

I’ve finished writing my online cuuriculum vitae, and as I’ve used maven to build the site (building for instance is just parsing my plain APT text file), I didn’t find a suitable skin for it among those publicly available. So I made my own skin consisting of small tuning of the well known stylus maven skin. It can be downloaded from here, and one unzipped somewhere, it can be installed by issuing the command:

D:\workspace\net.labidi.skin>mvn install
[INFO] Scanning for projects…
[INFO] ————————————————————————
[INFO] Building Unnamed - net.labidi:net.labidi.skin:jar:1.0.0-SNAPSHOT
[INFO]    task-segment: [install]
[INFO] ————————————————————————

Once the skin installed, it can be used in a site  descriptor (site.xml) like this:


<skin>
<groupId>net.labidi</groupId>
<artifactId>net.labidi.skin</artifactId>
<version>1.0.0-SNAPSHOT</version>
</skin>

Jbpm archetype for Maven

Update:

The archetype is updated and available from this dedicated site.

Working with Jboss JBPM in conjunction with maven could be made simpler and easier when using this little useful maven archetype to generate starting-block jbpm projects. I built this artifact on top of the skeleton project generate under Eclipse by the Jboss JBPM Eclipse plugin, but with much more enhancement.

Features

  • Junit tests are upgraded to junit 4, and use the hamcrest assertions
  • All required configuration files are included and default DataBase is MySQL 5
  • There are 2 junit tests : one for testing the process from a local process definition XML, and one for making the same test but loading the process from a Database (this means the process should be deployed in prior)
  • Maven dependencies are included, even a C3PO pool connection manager
  • No more “default” package. The desired package name for java classes could be chosen when generating the project and the filtering mechanism will applied to java classes packages declarations as well as “class” attribute for Action elements in the process definition.
  • It works smoothely with JBPM 3.2.3 (latest stable release) and integrates seamlessly with M2Eclipse maven plugin under Eclipse Ganymede.
  • Generated projects are targeting jdk 1.5

prerequisites

  • Maven 2.0.9
  • Jboss JBPM 3.2.3 Eclipse plugin
  • M2Eclipse maven plugin for Eclipse (Optional)

Download

The archetype can be downloaded from here.

Installation

The installation is a straight-forward one line maven command

D:\workspace\archetype-jbpm>mvn clean package install archetype:update-local-catalog
[INFO] Scanning for projects…
[INFO] Searching repository for plugin with prefix: ‘archetype’.
[INFO] ————————————————————————
[INFO] Building Archetype-JBPM
[INFO] task-segment: [clean, package, install, archetype:update-local-catalog]
[INFO] ————————————————————————
etc

Usage

The archetype can be used either naturally from the command line, and it goes like this:

mvn archetype:create -DarchetypeGroupId=net.labidi -DarchetypeArtifactId=archetype-jbpm -DarchetypeVersion=1.0.0 -DgroupId=mycompany -DartifactId=myjbpmproject

or it can be used from M2Eclipse plugin, which is the way I prfer to use (How many people are out there coding JBPM process from outsides IDEs ?)

Creating from local archetype catalog with M2Eclipse

Creating from local archetype catalog with M2Eclipse

choosing project coordinates. Package name is auto-filled

choosing project coordinates. Package name is auto-filled

Generated JBPM Maven project under eclipse

Generated JBPM Maven project under eclipse

Maven Dependencies under M2Eclipse

Maven Dependencies under M2Eclipse

Exept Junit, all other dependencies are provided-scoped. This because JBPM project are basically aimed to be deployed under an application server whose container provides almost of theses packages (except jbpm-jpdl, jbpm-identity and c3po, they need to be deloyed once for all into the aplication server)

Java source highlighting

Here is a simple practical solution for highlighting source code served from an Apache web server. The motivation behind this was when I wondered how to allow syntax highlight for my SVN hosted source code when viwed with a browser. I came across a very useful tool written in python, pygmentize. Once this python module downloaded and installed, the following settings should be put in Apache httpd.conf file:

Action highlight /cgi-bin/highlight.py
AddHandler highlight .java

the highlight.py is a python script using pygmentise, and here’s the simplicity :


#!/bin/python
import cgi
import cgitb; cgitb.enable()
import os
from pygments import highlight
from pygments.lexers import JavaLexer
from pygments.formatters import HtmlFormatter

def main():
   print "Content-type: text/html\n"
   print highlight(open(os.environ['PATH_TRANSLATED']).read(), JavaLexer(), HtmlFormatter(full=True))

main()

Obviously, this will hilight java or whatever source code, but will not touch files served via WebDAV/SVN (Hopefully!)

Default storage engine (InnoDB) is not available

That’s the big issue I was facing this morning when starting the MySQL service version 5.0.67/Win32. The first step I took is to simply look for a google-looked-up page that deals with this issue, and it was the mysql forums. However, I found the diffrent exposed solutions a lot radical as almost of them tend to a backup-delete-reinstall strategy, and it does not really suit my needs. So the first thing I’ve done is to try starting the mysql service in the console  debug mode :

D:\mysql\bin>mysqld-debug.exe –console

and the output was very explicit about the possible roots of the innoDB issue :

InnoDB: Error: log file .\ib_logfile0 is of different size 0 25165824 bytes
InnoDB: than specified in the .cnf file 0 10485760 bytes!
080913 13:24:24 [ERROR] Default storage engine (InnoDB) is not available
080913 13:24:24 [ERROR] Aborting
080913 13:24:24 [Note] mysqld-nt.exe: Shutdown complete

So basically, the MySQL service is complaining about a mismatch between the effective innoDB log file size on the disk (24MB), and the defined size (10MB) within the my.ini file. So changing the my.ini property would help solving the issue :

innodb_log_file_size=24M

A little attenion should be paid to another property in my.ini file which is innodb_buffer_pool_size as its value is impacted by the innodb_log_file_size setting. After this simple setting, the service was correctly started. No data/log backup, deletion required, nor service reinstallation. Nevertheless, I still not understand the real issue behind this file size mismatch…

Subversion with Apache

One of the greatest featurse with nowodays SVC systems, in particular Subversion, is its accessibility through a banch of network protocols, as HTTP, when SVN is coupled with Apache web server. When making my own install on my lapotop, and as I’m very sensitive to keep each peace of software in it’s own containing folder, I came to these points :

- It was impossible for me to avoid copying required SVN dlls to Apache bin folder. That’s the most annoying part of the installation especially when the 2 official tutorials are not really explicit. In fact, including the bin directory of SVN installation into the PATH system variable is not working. And copying only intl3_svn.dll and libdb44.dll is not working eather. I finally come across the solution consisting of copying intl3_svn.dll as well as all the lib*.dll to the Apache/bin folder, without overrwiting the existing ones. It’s about 12 dll files.
- The SVN official documentation states that the stylesheet files (necessary if we want to visualize a well-presented web page when accessing to the repository URL) shall be put in the DocumentRoot of the Apache server. That’s also an annoying point for me as I always want to avoid putting any extra document or file in the standard Apache installation. This time, I found a little hack to avoid this, without even playing with VirtualHosts configuration. The main part to add to httpd.conf is the following :

<Location /svn>
DAV svn
SVNListParentPath on
SVNParentPath D:\svnrepo
SVNIndexXSLT /svnindex.xsl
AuthType Basic
AuthName "Subversion repositories"
AuthUserFile "auth/__users.txt"
Require valid-user
</Location>

wich makes the SVN repository accessible at http://localhost/svn. Now we want the SVN stylesheets material to be placed outside the Apache DocumentRoot, for example in the folder D:/www/svn-web-content/, we have just to add the following configuration to httpd.conf :

Alias /svn-web "D:/www/svn-web-content/"
<Directory "D:/www/svn-web-content/">
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>

And then change the directive SVNIndexXSLT to point at /svn-web/svnindex.xsl instead of /svnindex.xsl. Now if we open the page http://localhost/svn, we unfortunately see the same unformatted basic page. However, after looking to the Apache acess log file, we can understand the trick :

”GET /svn-web/svnindex.xsl HTTP/1.1″ 200 3558
”GET /svnindex.css HTTP/1.1″ 404 1950
”GET /menucheckout.ico HTTP/1.1″ 404 1950

So XSL file is correctly found and sent by the server, but not the CSS/ICO file. The solution is really simple by editing the XSL file and replacing each occurrence of href=”/svnindex.css with href=”/svn-web/svnindex.css, and the same for the file menucheckout.ico. It’s up and running.

The fastest upgrade

After donwloading and installing wordpress version 2.6.1, and as soon as I went through its consol, it told me that version 2.6.2 is already available for upgrade. I didn’t wait to grab it and upgrade. However, I found it funny to see that the readme file in the 2.6.2 archive still mentionning version 2.6.1. Anyway, wordpress is a great peace of software, with a greate ease-of-use (surely, after one knows how to correctly set the “uploads” folder path and rights). And by the way, Hello Wolrd !

Hacking (?) mod_autoindex

When browsing several Internet sites, we certainly have come across some commonly-formatted web pages. Lots of them are automatically generated by the Web server. Apache web server has a dedicated module to generate directory indexes. theses indexes are often “ugly” simple pages.

Here’s some steps to get around this starchy formattin, and don’t worry, I’m not gonne advice you to edit the module’s source code and recompile it. The hack is based on CSS and DOM manipulation using JavaScript, and some tips when configuring the server. First, we have to enhance the default settings of the directive IndexOptions of the httpd-autoindex.conf file as follows :

IndexOptions FancyIndexing HTMLTable FoldersFirst IgnoreCase IgnoreClient XHTML Type=text/html NameWidth=* SuppressDescription SuppressLastModified SuppressHTMLPreamble

Then, within the same file, we set the directive ReadmeName to /README.html (which is the default setting). This way, the README.html file wich is appended by Apache after each directory indexing will be used to host the CSS/JavaScript code used to impropuve the index formatting. This is the CSS dirctives I’ve included in my README.html file :


H1 {font-size:18px;font-family:Arial;font-weight:normal;color:#EEEEEE;text-align:center;background-color:#777777;margin-bottom:30px;}
BODY {margin-top:0px;margin-left:0px;margin-right:0px;background-color:#d8d8d8}
A {color:#3300cc; font-family:Arial; font-size:13px;text-decoration:none;}
A:hover {color:#330000; font-family:Arial; font-size:13px;text-decoration:underline;}
TD {font-family:Arial; font-size:12px;}
SPAN.GT {
color:orange;
font-weight:bold;
position:relative;
top:1px;
}

then, just after the <style> bloc, I’ve added the following JavaScript code :


<script langage="javascript">
if(document.getElementsByTagName)
{
t=document.getElementsByTagName("table").item(0)
t.setAttribute("align","center")
t.setAttribute("cellpadding","2")
t.setAttribute("border","0")
t.setAttribute("style","border-width:0px;border-style:solid;border-color:black;")
}
d=document.createElement("div");
d.setAttribute("style","width:500px;border-style:solid;border-width:1px;border-color:black;margin-top:20px;padding:20px");
d.appendChild(t)
h=document.getElementsByTagName("h1").item(0);
d.insertBefore(h,t)
c=document.createElement("center");
c.appendChild(d);
s=document.getElementsByTagName("script").item(0);
s.parentNode.insertBefore(c,s);
document.getElementsByTagName("h1").item(0).innerHTML=document.getElementsByTagName("h1").item(0).innerHTML.replace("Index of /" , "").replace(/\//g , " <span class=\"GT\">&amp;amp;gt;</span> ");
document.getElementsByTagName("tr").item(0).setAttribute("style","display:none;");
document.getElementsByTagName("tr").item(1).setAttribute("style","display:none;");
document.getElementsByTagName("tr").item(document.getElementsByTagName("tr").length-1).setAttribute("style","display:none;");
_tds=document.getElementsByTagName("td");
for(i=0,__loop=_tds.length;i<__loop;i++){
if( _tds.item(i).innerHTML == "  - "  )
document.getElementsByTagName("td").item(i).innerHTML="&amp;amp;nbsp;";
}
</script>

The above script basically creates an empty centered div tag inside of wich it places the generated html table, the index title and removes unwanted others hedares or tables headers (some <tr> elements). The final result looks much more pretty: