domingo, 26 de julho de 2015

A Parser work item handler for jbpm 6

One usual task we do in a process is to have to parse XML/JSON to objects and vice versa. I always look at sample work item handlers from jbpm and I want to create my own work item handlers because it is fun. Today I will quickly show the first public useful work item handler I have created: The parser.

What is and how to use it?

It is a simple parser task that you can use in your BPM Suite/ jbpm 6 process to parse from XML/JSON to some Java object and vice versa. You can, for example, read XML from a file and convert to your model object. It can be used with the REST Task for previous jbpm version, since recently support to transform was added to the REST Task

It accepts the following parameters:

Input: The input data. If you provide a string, the parser will try to parse the string to an object of type Type and format Format (see below), if not, it will try to parse the object to a String of format Format. It is a required parameter;
Format: It is a required parameter that can have the values JSON or XML;
Result: The result is an output parameter that will be a string if you provide an Input object that is not of String type; and an object of type Type if you provide  an Input object of type String.

Providing these parameters correctly is enough to use the parser task. Please bear in mind that it uses JAXB to parse the object, so it must have the @XmlRootElement annotation.


The steps to install it are similar to the steps we used to install the hello world work item handler. But since we are on BPM Suite 6.1, it will be slight different, see:

* Clone the source code from my github and run mvn clean install to have it in your maven repository (actually in the maven repository used by BPM Suite); Or download the JAR containing this work item handler and upload it as an artifact to your installation;

* Add the GAV information of the WIH(Group: org.jbpm.process.workitem; Artifact ID: parser-task; version: 1.0) as a dependency of your project:

* Now edit the new deployment descriptor to include a declaration of this WIH class. Notice I am sending the Classloader as a parameter. It is needed to load classes defintion to be parsed:

* Finally edit the wid file to include the declaration of the WIH. Now you can open the process and drag it to use in your process.

If you want to see more details about this WIH, please see  the project in github and also the tests for it.


It is easy to extend the jbpm 6 library to include your own custom tasks. The parser task was approved for the Service Repository in BPM Suite! See jbpm github!

3 comentários:

  1. gran post.
    Where I can download the jar of this work item handler?

    1. Hello, I just updated the post with a link to the JAR, I added it to github:

      It is also part of jbpm service repository now!

  2. Great post :) very helpful and made me lots of clarity about workitem handlers.
    One doubt that I have is when we use 'manager.completeWorkItem(workItem.getId(), resultvar);'
    this will return the value of 'resultvar' to 'Results' parameter which we have defined in .wid file

    "results" : [
    "Result" : new ObjectDataType(),

    Correct me if I am wrong.
    Now I would like to use this value if process, how can I do that?