B.3. REST Task Attributes
The REST task performs REST calls and outputs the response as an object.
RestWorkItemHandler is capable of interacting with the REST service, and supports both types of services:
- Secured: requires authentication.
- Open: does not require authentication.
Authentication methods currently supported are:
-
BASIC -
FORM_BASED
Authentication information can be given on handler initialization and can be overridden using work item parameters. All other configuration options must be given in the work item parameters map:
Input Attributes
- Url
Target URL to be invoked. This attribute is mandatory.
It is often necessary to configure the URL attribute with an expression. This gives you the ability to change the URL dynamically throughout the runtime. For example:
http://DOMAIN:PORT/restService/getCars?brand=CAR_BRAND
In the provided example,
CAR_BRANDwill be replaced by the value of thecarBrandvariable.- Method
- The method of the request, such as GET, POST, or similar. The default method is GET.
- ContentType
- The data type in case of sending data. This attribute is mandatory for POST and PUT requests.
- Content
- The data you want to send. This attribute is mandatory for POST and PUT requests.
- ConnectTimeout
- The connection timeout. The default value is 60 seconds.
- ReadTimeout
The timeout on response. The default value is 60 seconds.
It is possible to modify the default timeout configuration shown below:
Integer connectTimeout = getParamAsInt(params.get("ConnectTimeout")); if (connectTimeout==null) connectTimeout = 60000; Integer readTimeout = getParamAsInt(params.get("ReadTimeout")); if (readTimeout==null) readTimeout = 60000;- Username
- The user name for authentication. This attribute overrides the handler initialization user name.
- Password
- The password for authentication. This attribute overrides the handler initialization password.
User name and password for basic authentication can be passed at construction time using the following:
RESTWorkItemHandler(String username, String password);
- AuthUrl
The URL that is handling authentication when using the
AuthenticationType.FORM_BASEDauthentication method.Use the following constructor for
FORM_BASEDauthentication:public RESTWorkItemHandler(String username, String password, String authUrl, ClassLoader classLoader) { this(); this.username = username; this.password = password; this.type = AuthenticationType.FORM_BASED; this.authUrl = authUrl; this.classLoader = classLoader; }The following is an example of how the constructor must be used in Deployment descriptor:
new org.jbpm.process.workitem.rest.RESTWorkItemHandler("username","password","http://mydomain.com/my-j-security-check-url",classLoader)
AuthUrl configuration requires the typical implementation for FORM_BASED authentication in Java EE servers, and therefore should point to the j_security_check URL. Similarly, inputs for user name and password must be bound to j_username and j_password when using FORM_BASED authentication, otherwise authentication may fail.
- HandleResponseErrors
An optional parameter that instructs the handler to throw errors in case of unsuccessful response codes.
HandleResponseErrorscan be handled in two ways:Process Definition
Status: WhenRESTWorkItemHandlerproduces aStatusoutput variable that includes an HTTP response code. This can be mapped to a process variable and used in a XOR gateway to determine the service outcome.
-
StatusMsg: The output variableStatusMsgincludes additional messages sent by the server, and is filled only when the HTTP Code is not between 200 and 300.
Using a Boundary Event
This can be enabled by setting the REST work item input variable
HandleResponseErrorsto the valuetrue.ImportantThe
HandleResponsemust have a valid boolean expression or be left empty (which will default tofalse), otherwise it will fail.When the REST work item input variable
HandleResponseErrorsis set totrue, theRESTWorkItemHandlerwill, upon receiving an HTTP response code outside of the 200-300 interval, throw the following Java exception:public RESTServiceException(int status, String response, String endpoint) { super("Unsuccessful response from REST server (status " + status +", endpoint " + endoint +", response " + response +"");With the option enabled, this error can be caught using a boundary event:

The provided example includes:
-
A
WorkItemHandlerRuntimeExceptionrestErrorprocess variable. -
A
WorkItemHandlerRuntimeExceptionBoundaryErrorevent-defined output variable that has been mapped to therestErrorprocess variable. A Script task that includes the following code:
org.jbpm.process.workitem.rest.RESTServiceException x = (org.jbpm.process.workitem.rest.RESTServiceException) restError.getCause().getCause();
This code allows
RestServiceExceptionto be extracted fromWorkItemHandlerRuntimeException. UsingRestServiceExceptionprovides access to the following methods:-
getResponse -
getStatus getEndpointThe next line in the Script task is:
System.out.println("response:"+x.getResponse());This provides the full error message as returned by the server.
-
A
Output Attributes
- Result
- The result returned by the REST service.
- ResultClass
-
This attribute determines the class to which the value from the
Resultattribute will be converted. The default value isString. - Status
- This variable will always be filled. It will either have a value from interval 200 to 300 if successful, or an error response code if the request was unsuccessful.
- StatusMsg
- If the service returned an error response, this will contain the error response message.
All output attributes are String by default.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.