Category Archives: jBPM

Upgrade of jbpm-6-examples to jBPM 6.2 services

In my previous post I described an example implementation of a web application, which demonstrates usage of jBPM business process suite as an embedded workflow library. The focus was on CDI services provided by jBPM libraries and their integration with producers and consumers in the web application itself.

The latest version jBPM 6.2 contains services, which are better designed, provide completely new API and significantly simpler usage. They also provide basic kie-services implementation, which is framework agnostic (now they do not use CDI internally) and other specific services for a particular bean framework – EJB 3.1 or CDI 1.0.

This article is going to describe the current state of jbpm-6-examples demos and the upgrade from version 6.0 to 6.2. The article will be separated to two parts, because both examples are slightly different. The new jbpm-6-examples can be found on current master branch on the github.

rewards-basic web example migration to jBPM 6.2 EJB services

This example application combines jBPM 6.2 EJB services together with servlets and Java Server Pages (JSP). Here is the list of new services used in the example. All of them extend the core service and are already annotated with EJB @Local annotation.

  • DeploymentServiceEJBLocal – used to deploy/undeploy kjar artifacts to/from runtime
  • ProcessServiceEJBLocal – used to start/signal/abort process instance and get their process instance data
  • RuntimeDataServiceEJBLocal – provides information about runtime data, process instances, user tasks, process variables, etc.
  • UserTaskServiceEJBLocal – provides operation to work on a user task

So what has changed? Many things! First of all rewards process with two human tasks is not loaded from the application classpath, but is part of a kjar artifact with maven GAV “org.jbpm.examples:rewards:1.0”. That means that the maven client inside jBPM 6.2 has to be able to resolve this artifact from maven repositories. For this purpose you can just clone and build the rewards project from jbpm-6-examples-assets:

git clone
cd jbpm-6-examples-assets/rewards
mvn clean install

Also you do not have to care of session strategy and runtime manager now. Session strategy can be defined in a deployment descriptor file inside the kjar, or it can be decided at the deployment time.

StartupBean class

EJB annotation @Startup marks this bean for eager initialization, so before the application is ready, we register here our custom UserGroupCallback class and also we use injected deploymentService to deploy a kjar artifact from maven, which contains a business process definition that we want to use.

ProcessServlet class

This is a simple servlet that handles requests coming to /process context. It gets a recipient variable from a POST request and uses injected processService to start a process instance.

TaskServlet class

TaskServlet is bound to handle /task context. It overrides doGet() method to handle GET requests. Based on the command it does two different operations.

  • The first one uses runtimeDataService to retrieve all tasks for a particular user. The rewards process has two human tasks, the first one is for user jiri and the second one for user mary.
  • The second operation is to approve a user task. Operation approve does not exist in the jBPM context, or in userTaskService API in particular, so it is implemented as a single composite operation, consisting of a StartTaskCommand and a CompleteTaskCommand. So the human task is started and immediately completed.

RewardsUserGroupCallback class

UserGroupCallback is necessary not only for mapping between task service users and their membership in groups, but also to just register users in runtime TaskService.


That’s all! Only four classes are now necessary for rewards-basic example, which uses provided jBPM 6.2 EJB services.

rewards-cdi-jsf web example with jBPM 6.2 CDI services

This example combines jBPM 6.2 services together with Context Dependency Injection (CDI) and Java Server Faces (JSF) frameworks. The services share the same API, so the description of the services and their purpose is the same as in the previous example.

CDI is a powerful and very flexible framework how to build Java EE 6 applications, however in the contrary to EJB framework, it does not provide transactions and may have other limitations. In our example, the CDI requires a bit more code to get it properly working using jBPM 6.2 services.

StartupBean class

The purpose is the same as in the previous example, it uses CDI mechanisms to run the initialization code on the application startup.

ProcessBean and TaskBean classes

Again, the purpose is the same as in previous example. Both classes are annotated with a CDI stereotype @Model, which means they are both instantiated for one request (@RequestScoped annotation) and their public methods can be used in the expression language (EL) of the JSF frontend (@Named).

RewardsApplicationScopedProducer class

This class is necessary, because it contains several important producers.

  • The first one produces EntityManagerFactory, which is consumed inside jBPM library and used to setup persistence.
  • The second one produces a deploymentService. The producer class already consumes a qualified injection (using @Kjar qualifier), but it is important also to produce it for StartupBean to be consumed as a default injection.
  • The last instance to produce is a TaskLifeCycleEventListener, which is necessary, because when a human task is completed, it is used to trigger again the process engine and so advance in the process flow.


Since the example does not implement authentication, this is just a placeholder class. However it is necessary for it to be there.


This class is not that important, it serves more as a CDI demonstration, that you can initialize Logger and FacesContext instances in a single place.


Ok, that’s everything for now! In this article you have seen new jBPM 6.2 services in action. These services can reduce much of the code, which was necessary before, like working with RuntimeEnvironment, RuntimeManager, RuntimeEngine and other stuff. Clone the jbpm-6-examples, read the instructions and try the examples. I am looking forward to your comments and feedback!

jBPM 6 at 2014 in Kiev


Two weeks ago I was in Kiev at Colleague of mine recommended me this conference and I applied a talk there. There were many internationally known Java gurus, so it was an honor for me to give a talk there too!

My presentation was called “Streamline your processes with jBPM 6”. I focused on three things:

  • why are business process models useful in information systems
  • what are the most important jBPM 6 features in kie workbench and engine
  • how to embed jBPM into a web application (CDI, EJB, JSF) as a workflow engine library

So the third one was a demonstration of my example application I already blogged about.

The conference was well organized. I really enjoyed its atmosphere. I attended several talks in English:

  • Tooling of a test driven developer by Pawel Lipinski (basically about jParams and AssertJ and some Java 8 hints)
  • Mobile functional testing with Arquillian Droidium by Stefan Miklosovic (how you can create complex testing scenarios which may include several application servers and Android devices)
  • Holding down your Technical Debt with SonarQube by Patroklos Papapetrou (code quality management tool)

I also ‘tried to attend’ a presentation in Russian, but my very basic level of this language prevented me to understand it. Majority of the talks were in Russian, so this is the only drawback of this conference.

To sum it up, despite the current crisis, Kiev was safe to visit and I really enjoyed the city and the conference! Kudos to the organizers team.

jBPM 6 presentation at 2014

Hello all those who are interested in jBPM 6! I had a presentation called ‘Integration with jBPM 6’ at Developer Conference organized by Red Hat Czech Republic in Brno.

Main focus of the presentation was to shortly describe new major features in jBPM 6 business process suite and also to demonstrate its capabilities when it comes to embedding jBPM as a library into a web application.

The presented web application was rewards-jsf example, which demonstrates usage of new RuntimeManager API and CDI interfaces used together with Java Server Faces web framework.

My talk was recorded and you can see it on youtube:

jBPM 6 web application examples

After a long time, let’s see new technology in action. jBPM 6 was released in the end of the last year, so it’s quite fresh and still lacks good examples to easily start with. I’ll focus on my recent example projects, which demonstrate jBPM 6 in use as a workflow engine embedded inside a web application.

rewards-basic application

So far the git repo contains just two projects. The first one is called rewards-basic. It was developed by Toshiya Kobayashi, who created the original application using jBPM 5 and Java Enterprise Editon (EE) 5. I’ve rewritten his application to work with new jBPM 6 and also later standard Java EE 6. There are many useful improvements in the new engine. For example now you can use runtime managers with advanced session strategies to better separate process contexts or to gain a better performance, especially in concurrent environment. Seamless integration with Java EE world is done by Context and Dependency Injection (CDI). Many people still don’t like CDI, but once you learn it, you may realize its advantages. You may even continue to use jBPM without CDI and initialize your environment using ordinary Java constructors or factories.

Both applications are build around one simple business process. After start it creates a task for user John and after he approves his task, the process creates a second task for user Mary. After she approves her task, the process finishes. Example applications provide web interfaces to these operations – in particular to start a business process, to list human tasks available and to approve them. More information including steps how to run the programs can be found on Github link above.

ProcessBean class

This article focuses on internal structure suitable to software developers. Let’s start and take a look on a code snippet from a process service Enterprise Java Bean (EJB):

private RuntimeManager singletonManager;

This demostrates CDI and how it can be used. You can just inject an object of defined class to your bean and you don’t have to care about how and where it is initialized. Don’t worry, we’ll get to that! The second annotation is interesting as well. You may choose also others for advanced session strategies like @PerProcessInstance and @PerRequest. Their names are self-explanatory, just to be sure – the first one keeps session (context) for a process instance and the second one is just stateless, no state is kept. What can be done with the runtime manager then?

RuntimeEngine runtime = singletonManager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
ProcessInstance processInstance = ksession.startProcess("com.sample.rewards-basic", params);

Keep in mind that runtime manager usually follows singleton design pattern in your application. For each request you should get an instance of runtime engine from it based on the context. Note that runtime engine is just an encapsulation of a kie session and a task service. The session can be used to start a process instance. The task service is automatically linked to this session and can be used for human task related queries and commands. The last command just starts a process instance, so the business process is finally running.

The last thing that can be noted are user transactions. You don’t have to use user transactions, but they are useful in many cases. For example you may want to save some information into a corporate database at the same time with the execution of the process engine. This way you ensure that all operations are either committed or rolled back together.

TaskBean class

Similarly you can just simply inject a task service. Do you remember jBPM 5? The task service was decoupled from the process engine and had to be connected to the engine for each process run in order to support human tasks. jBPM 6 integrated the task service back to the engine.

TaskService taskService;
List list = taskService.getTasksAssignedAsPotentialOwner(actorId, "en-UK");

As you can see in TaskBean, you can easily run an arbitrary task service method.

CDI producer classes

In order to get CDI working you have to provide producers for injected class instance where necessary. One of the CDI advantages is the loose coupling. For example you may use a service in your beans, which functionality is dependent on running application server. This is ok, but how to easily unit test your application without setting up awkward application server? For example you can easily write a mock service for unit testing and don’t even have to modify a Java code. All you would have to do is just to change an alternative class in CDI configuration file beans.xml.

On the other hand debugging a CDI application may be difficult as the errors of unsatisfied dependencies are thrown mostly during run time, which slows the development process. If you know how to cope with this, please leave me a comment, thanks!

Application scoped producers

These producers can be found in ApplicationScopedProducer class. @ApplicationScoped annotation tells the application server (or more precisely the CDI container), that instances produced here should be instantiated for the whole life cycle of this web application deployment. It’s logical – for example the persistence unit (database connection) won’t change during the runtime of the web application.

Very important is also the RuntimeEnvironment producer, which provides whole setup for runtime manager, for example including our “com.sample.rewards-basic” process definition to be used. Runtime manager is injected from a jBPM library, but this same library also internally injects RuntimeEnvironment instance to get our environment that it doesn’t know.

You may also notice RewardsUserGroupCallback class. It is a simple user group callback and is defined as an alternative. This demonstrates that by using alternatives you may use your own classes, if you are not satisfied with prepared implementations coming from jBPM libraries.

Presentation layer

Web presentation layer is really simple. It uses Java Server Pages (JSP) technology and Java Servlets to handle presentation logic. Web user interface is just plain HTML, because the focus was put on demonstrating the internal service logic.


The second example application stays internally mostly the same, based on the same concepts. However Java Server Faces (JSF) technology including CDI is used for presentation layer.


I have described briefly two simple web applications demonstrating together jBPM 6 and Java EE 6. Please write a comment if you’ve liked them or if you have some feedback, I would be happy to hear your opinion. Thanks.

jBPM 5 Developer Guide – review

In this article I am going to describe my impressions from the book jBPM 5 Developer Guide by Packt Publishing. I think I should start with introducing myself. Of course, you can check my About page, but I’ll go a little bit deeper. I work as a jBPM quality engineer. I started with quality engineering of rule engine Drools, but later I’ve moved my attention towards jBPM 5, which had to be productized. I’ve started to learn jBPM in the end of 2011 and also I’ve registered my master project at school, where I focused on using jBPM to control Jenkins jobs, for example to execute test plans on Jenkins. So I know the jBPM only from the technical perspective, I have no experience with adopting Business Process Management (BPM) solutions at customers.

Why to use business processes?

After reading the book I have learned many new things, which I missed before. The book clearly describes motivation for learning and reasons for adopting BPM techniques. What I found most useful were the tips given by the authors, how to convince the employees of the target company to deploy such BPM solution instead of their traditional paperwork. I can imagine how hard this task may be as I have also some experience from developing and deploying a network management information system. The book is written from the developer’s perspective and gives you hints how to deal with these early problems, which you will surely face (as the IT experts).

Business process basics

From the start the book is not limited only to jBPM, but business processes are described in general. The same applies for the general description of the whole business process management system. jBPM 5 uses Business Process Management and Notation (BPMN) 2.0 standard and that’s one of the biggest differences from the last widely used version jBPM 3. The chapter about BPMN 2.0 could have also contained references to other books, which describe business process modeling more in depth, because one chapter cannot cover everything. In later chapter the jBPM 5 components are described, including differences from jBPM 3. Unfortunately sometimes I found some parts of the text describing too obvious things, which were easily visible from the many pictures. From these jBPM 5 components only the Designer is described in depth in its own chapter. The steps how to draft a business process are described from simple processes to complex ones, with advanced concepts like for example swimlanes,  messages, events and subprocesses.

Features important for everyone

If you were already familiar with some of the business process suites you could have skipped the previous chapters without severe complications, but chapters describing service tasks, human tasks, persistence and transactions are a must to read. The stress is put on the features, which can be implemented by a developer on its own on the top of the existing APIs. Author explains that you are not tied to the offered tooling, for example proposes you a way how to define your own frontends to your human tasks. These chapters also contain description of the services which are not present in the current jBPM 5.4 yet, but can be implemented in the future versions, so you can be prepared for these future features as well. Or which you can implement just now on your own.

Benefit of business rules and complex event processing

Next two chapters are more advanced topics, which you may or don’t have to use. It’s up to you and your use cases. They describe how to take advantage of the well working integration of jBPM with the rule engine Drools Expert and Drools Fusion (complex event processing). Rule engine is useful for evaluating complex business logic which may often change (for example mortgage calculations, complex discount logic, …) and event processing agent can be used to detect a complex event from an event stream and based on that start a business process (for example detecting a fraud and launching business process for its investigation).


To sum it up – it’s definitely a very good book for everyone who is new to the jBPM 5 and its ecosystem. The information, guides and problem solutions are often scattered from documentation, wiki pages, blogs to user forum and this book gives you all important information nicely put together in one place.


  • All important information nicely put together, currently there is nothing better to start learning jBPM 5 from
  • Developer’s perspective and hints
  • Not only about jBPM, but also describes business rules, complex events and integration options to give a complete picture


  • Sometimes there are empty sentences telling nothing new
  • Some Java code examples are not obvious and easy to understand
  • Lack of clustering topics, steps how to scale jBPM