Skip navigation

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" />

Here is an example that shows task persistence using H2 database. A simple process that has a couple of human tasks as shown below is considered for this example.

 

processbpmn2.png

 

This example uses the jBPM plugin for Eclipse (jBPM6 - Eclipse BPMN Modeler Installation).

 

 

This examples has a bpmn file (SampleHumanTasks.bpmn), a process test program that starts the process(TaskPersistnecTest.java or TaskPersistenceExample.java), a persistence configuration files (persistence.xml ) and a Bitronix JNDI file ( jndi.properties) .

The persistence configuration file needs to be included in META-INF folder as shown below. Please refer to JPA/Hibernate documents to know more about persistence configuration details.

 

projectexplorer.png

 

This example uses H2 database to show the persistence of process state into various tables.

startH2.png

JBPM6 database persistence involves following categories:

 

1.) Process persistence: This involves persisting runtime state that represents current execution state in a specific context. The runtime state contains the minimal runtime state that is required to continue execution at a later time. This allows restoring the state of execution of all the running processes (e.g., ProcessInstanceInfo)  in the event of a failure.

 

2.) Human task persistence: Task management component, which is treated as a separate component, can persist all the task information (e.g, user, assignment etc) into database.

 

3.) History or Auditlog persistence: All the audit log information(e.g., ProcessInstanceLog, NodeInstanceLog etc)can stored in database for reporting purposes.

 

The database tables can be viewed in Eclipse using one of database plugins such as SQLExplorer, QuantumDB etc.

tables.png

The database mapping of various tables can be seen in the JPA persistence xml file included in META-INF.

persistence1.png

 

 

persistence2.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.

runtimemanager.png

Here is a code snippet that shows how to use the taskservice to start and complete a task.

tasksummarycomplete.png

 

After running the example successfully following results can be seen,

results.png

A SQL client can be used to examine the contents of various process, task and audit tables.

teaskquery.png

 

processinstancelog.png

Filter Blog

By date:
By tag: