Here is a simple web example that shows how to use jBPM6 API to process human tasks. This blog uses the same example show in JBPM5 Web Example - Local Human Task.

 

 

processbpmn2.png

 

This example uses H2 database and it can so be seen that Hibernate persistence dialect is set to H2Dialect in the META-INF/persistence.xml.h2db.PNG

 

This example has the following files as shown below.

TaskProcessServlet performs various actions (such as retrieving and completing the tasks etc) using the JBPM API (JbpmAPIUtil).

 

explore.png

 

jBPM6 introduces a new module called RuntimeManager which simplies the access to KnowledgeSession (KieSession) and taskservice etc.

There are various pre-defined startegies for creating RuntimeManager, such as singleton (one session for all the requests), session per request (a new session for each request) and session per process instance (each process has its own context and all the commands get executed in that context

 

This example uses singleton strategy.

Runtime.PNG

Here is the sample code that shows how to create a task service and complete the task.

 

taskcomplete.PNG

 

How to run and deploy in web container, e.g., Tomcat?


Use maven to create a war file (e.g., mvn package) and copy the war file to TOMCAT_HOME/webapps


A successful deployment shows the following page (e.g., http://localhost:8080/jbpmwebexample/)

mainscreen.png

A process instance can be created selecting 'CreateProcess' button.

createprocess.png

The tasks for the first user can retrieved by selecting the button 'Select User'.

kristask.png

After completing the task as the first user, i.e., krisv, it would wait at the second task that needs to be approved by 'john'.

krisdetail.png

 

johntask.png

 


This example requires a JNDI datasource.
Here are the main steps and refer to http://docs.codehaus.org/display/BTM/Tomcat for more details.

1.) Copy the following libraries to TOMCAT_HOME/lib


btm-2.14.jar

btm-tomcat55-lifecycle-2.1.4.jar

slf4j-api-1.6.4.jar

slf4j-jdk14-1.6.4.jar

geronimo-jta_1.1_spec-1.1.1.jar

h2-1.3.161.jar


a.) Create the following btm-config.properties in TOMCAT_HOME/conf


bitronix.tm.serverId=tomcat-btm-node0

bitronix.tm.journal.disk.logPart1Filename=${btm.root}/work/btm1.tlog

bitronix.tm.journal.disk.logPart2Filename=${btm.root}/work/btm2.tlog

bitronix.tm.resource.configuration=${btm.root}/conf/resources.properties


    b.) Add transaction and Resource information after 'WatchedResource' line in TOMCAT_HOME/conf/context.xml as shown below.

.........

..........

<WatchedResource>WEB-INF/web.xml</WatchedResource>

    <Transaction factory="bitronix.tm.BitronixUserTransactionObjectFactory" />


    <Resource name="jdbc/jbpm-ds" auth="Container" type="javax.sql.DataSource"

               maxActive="15" maxIdle="2" maxWait="10000"

logAbandoned="true"

               username="sa" password=""

driverClassName="org.h2.jdbcx.JdbcDataSource"

               url="jdbc:h2:tcp://localhost/~/test"/>

..........

.........

 

 

c.) Create 'resource.properties' in TOMCAT_HOME/conf as shown below.


resource.ds1.className=bitronix.tm.resource.jdbc.lrc.LrcXADataSource

resource.ds1.uniqueName=jdbc/jbpm-ds

resource.ds1.minPoolSize=0

resource.ds1.maxPoolSize=5

resource.ds1.driverProperties.driverClassName=org.h2.jdbcx.JdbcDataSource


d.) Modify TOMCAT_HOME/conf/server.xml to include BTMLifecycleListener after the line that has GlobalResourcesLifecycleListener as shown below.


.........

<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

  <Listener className="bitronix.tm.integration.tomcat55.BTMLifecycleListener" />