segunda-feira, 10 de novembro de 2014

Using the REST Task from jBPM 6

In this post I am going to share my experience using the BPMS 6 REST Task.


jBPM is a JBoss community project to offer an open source and efficient BPM Suite and BPMS is a product created by Red Hat based on jBPM. In this post I will be using BPMS because I have it installed already, but what I am going to described should work for jBPM as well.




 The REST Task is used to invoke a REST resource (or perform an HTTP Request) from your Business Process. You can set the URL, HTTP Method, timeout and credentials from the Process Modeller interface and when the process gets into that task, it will generate a HTTP Request and return the response as String. It is available on the left side pallet under the "Service Tasks" tab:

The Target REST Web Service

The service we are going to access from our process is a really simple one, that's why it is called simple-hello-rs and it is based on JBoss helloworld-rs quickstart.. It has only one simple WEB Service that receives a String parameter called name and returns a greeting. Speaking in Java, here is the code:

The Business Process

Our process could be simpler if didn't have any  parameters to pass to the REST WS, but it would be not fun.
Our process has the following variables, all of type String:

  •  name: When starting the process, the name should be set and it will be sent to the REST WS;
  •  requestBody: It's a variable that contains the HTTP body of the request that will be performed by the REST Task;
  •  requestResponse: This variable has the response of the REST task call.

Here's our process diagram:

So we have two script task and one task used to invoke the WEB Service we described previously. Here is the explanation of each Task:

  • T1: Create Request Body: This script task will take the variable name that the user entered when the process starts and creates the body that will be stored in the requestBody  variable. Here is the script to do this:
kcontext.setVariable("requestBody", "name=" + name);
  •  T2: Perform the REST Request: This is the REST Task and here we have no code, just variables assignment. The requestBody variable will be bound to the Task's Content variable, that is used by the REST Task as the HTTP body. The variable ContentType contains the value of the Content-type HTTP header(in our case it is application/x-www-form-urlencoded), url is the URL of the WS endpoint and Method is the HTTP method of the request:

Parameters assignment
  • T3: Prints the REST response: The last script task will simply print the response of the server
System.out.println("Response from the REST WEB Service: " + requestResponse);


In this quick post we show how to invoke a REST Web Service from your process in BPMS 6 without having to write Java code. The source code is at my github.