org.jbpm.process.workitem.rest

## Class RESTWorkItemHandler

- java.lang.Object
- - org.jbpm.process.workitem.AbstractLogOrThrowWorkItemHandler
  - - org.jbpm.process.workitem.rest.RESTWorkItemHandler

- All Implemented Interfaces:
    org.kie.api.runtime.process.WorkItemHandler

      public class RESTWorkItemHandler
      extends AbstractLogOrThrowWorkItemHandler

  WorkItemHandler that is capable of interacting with REST service. Supports both types of services secured (that requires authentication) and open (no authentication). Authentication methods currently supported:
  - BASIC
  - FORM BASED
  Authentication information can be given on handler initialization and can be overridden via work item parameters. All other configuration options must be given via work item parameters map:
  - Url - resource location to be invoked - mandatory
  - Method - HTTP method that will be executed - defaults to GET
  - ContentType - data type in case of sending data - mandatory for POST,PUT
  - Content - actual data to be sent - mandatory for POST,PUT
  - ConnectTimeout - connection time out - default to 60 seconds
  - ReadTimeout - read time out - default to 60 seconds
  - Username - user name for authentication - overrides one given on handler initialization)
  - Password - password for authentication - overrides one given on handler initialization)
  - AuthUrl - url that is handling authentication (usually j_security_check url)
  - HandleResponseErrors - optional parameter that instructs handler to throw errors in case of non successful response codes (other than 2XX)
  - ResultClass - fully qualified class name of the class that response should be transformed to, if not given string format will be returned

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `RESTWorkItemHandler.AuthenticationType`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static boolean` | `HTTP_CLIENT_API_43`

    - ### Fields inherited from class org.jbpm.process.workitem.AbstractLogOrThrowWorkItemHandler

      `logThrownException`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RESTWorkItemHandler()` Used when no authentication is required
    `RESTWorkItemHandler(ClassLoader classLoader)` Used when no authentication is required
    `RESTWorkItemHandler(String username, String password)` Dedicated constructor when BASIC authentication method shall be used
    `RESTWorkItemHandler(String username, String password, ClassLoader classLoader)` Dedicated constructor when BASIC authentication method shall be used
    `RESTWorkItemHandler(String username, String password, String authUrl)` Dedicated constructor when FORM BASED authentication method shall be used
    `RESTWorkItemHandler(String username, String password, String authUrl, ClassLoader classLoader)` Dedicated constructor when FORM BASED authentication method shall be used

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `abortWorkItem(org.kie.api.runtime.process.WorkItem workItem, org.kie.api.runtime.process.WorkItemManager manager)`
    `protected void` | `close(org.apache.http.client.HttpClient httpClient, Object httpMethod)`
    `protected Object` | `configureRequest(String method, String urlStr, Map<String,Object> params)`
    `protected org.apache.http.HttpResponse` | `doRequestWithAuthorization(org.apache.http.client.HttpClient httpclient, org.apache.http.client.methods.HttpRequestBase httpMethod, Map<String,Object> params, RESTWorkItemHandler.AuthenticationType type)`
    `protected org.apache.http.HttpResponse` | `doRequestWithAuthorization(org.apache.http.client.HttpClient httpclient, Object method, Map<String,Object> params, RESTWorkItemHandler.AuthenticationType authType)`
    `protected org.apache.http.HttpResponse` | `doRequestWithAuthorization(org.apache.http.client.HttpClient httpclient, org.apache.http.client.methods.RequestBuilder requestBuilder, Map<String,Object> params, RESTWorkItemHandler.AuthenticationType type)` This method does the actual request, including the setup for authorization.
    `void` | `executeWorkItem(org.kie.api.runtime.process.WorkItem workItem, org.kie.api.runtime.process.WorkItemManager manager)`
    `String` | `getAuthUrl()`
    `protected org.apache.http.client.HttpClient` | `getHttpClient(Integer readTimeout, Integer connectTimeout)`
    `protected Integer` | `getParamAsInt(Object param)`
    `protected void` | `postProcessResult(String result, String resultClass, String contentType, Map<String,Object> results)`
    `protected void` | `setBody(org.apache.http.client.methods.HttpRequestBase theMethod, Map<String,Object> params)`
    `protected void` | `setBody(org.apache.http.client.methods.RequestBuilder builder, Map<String,Object> params)`
    `protected String` | `transformRequest(Object data, String contentType)`
    `protected Object` | `transformResult(Class<?> clazz, String contentType, String content)`

    - ### Methods inherited from class org.jbpm.process.workitem.AbstractLogOrThrowWorkItemHandler

      `handleException, handleException, setLogThrownException`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### HTTP_CLIENT_API_43

          protected static boolean HTTP_CLIENT_API_43

  - ### Constructor Detail

    - #### RESTWorkItemHandler

          public RESTWorkItemHandler()

      Used when no authentication is required

    - #### RESTWorkItemHandler

          public RESTWorkItemHandler(String username,
                                     String password)

      Dedicated constructor when BASIC authentication method shall be used
      Parameters:
        `username` - - user name to be used for authentication
        `password` - - password to be used for authentication

    - #### RESTWorkItemHandler

          public RESTWorkItemHandler(String username,
                                     String password,
                                     String authUrl)

      Dedicated constructor when FORM BASED authentication method shall be used
      Parameters:
        `username` - - user name to be used for authentication
        `password` - - password to be used for authentication
        `authUrl` -

    - #### RESTWorkItemHandler

          public RESTWorkItemHandler(ClassLoader classLoader)

      Used when no authentication is required

    - #### RESTWorkItemHandler

          public RESTWorkItemHandler(String username,
                                     String password,
                                     ClassLoader classLoader)

      Dedicated constructor when BASIC authentication method shall be used
      Parameters:
        `username` - - user name to be used for authentication
        `password` - - password to be used for authentication

    - #### RESTWorkItemHandler

          public RESTWorkItemHandler(String username,
                                     String password,
                                     String authUrl,
                                     ClassLoader classLoader)

      Dedicated constructor when FORM BASED authentication method shall be used
      Parameters:
        `username` - - user name to be used for authentication
        `password` - - password to be used for authentication
        `authUrl` -

  - ### Method Detail

    - #### getAuthUrl

          public String getAuthUrl()

    - #### executeWorkItem

          public void executeWorkItem(org.kie.api.runtime.process.WorkItem workItem,
                                      org.kie.api.runtime.process.WorkItemManager manager)

    - #### getParamAsInt

          protected Integer getParamAsInt(Object param)

    - #### setBody

          protected void setBody(org.apache.http.client.methods.RequestBuilder builder,
                                 Map<String,Object> params)

    - #### setBody

          protected void setBody(org.apache.http.client.methods.HttpRequestBase theMethod,
                                 Map<String,Object> params)

    - #### postProcessResult

          protected void postProcessResult(String result,
                                           String resultClass,
                                           String contentType,
                                           Map<String,Object> results)

    - #### transformRequest

          protected String transformRequest(Object data,
                                            String contentType)

    - #### transformResult

          protected Object transformResult(Class<?> clazz,
                                           String contentType,
                                           String content)
                                    throws Exception

      Throws:
        `Exception`

    - #### doRequestWithAuthorization

          protected org.apache.http.HttpResponse doRequestWithAuthorization(org.apache.http.client.HttpClient httpclient,
                                                                            Object method,
                                                                            Map<String,Object> params,
                                                                            RESTWorkItemHandler.AuthenticationType authType)

    - #### doRequestWithAuthorization

          protected org.apache.http.HttpResponse doRequestWithAuthorization(org.apache.http.client.HttpClient httpclient,
                                                                            org.apache.http.client.methods.RequestBuilder requestBuilder,
                                                                            Map<String,Object> params,
                                                                            RESTWorkItemHandler.AuthenticationType type)

      This method does the actual request, including the setup for authorization. It is not responsible for cleaning up after the last request that it does. It is responsible for cleaning up after all previous request, such as for form-based authentication, that happen.
      Parameters:
        `httpclient` - The `HttpClient` instance
        `requestBuilder` - The `RequestBuilder` instance
        `params` - The parameters that may be needed for authentication
      Returns:
        A `HttpResponse` instance from which we can extract the content

    - #### doRequestWithAuthorization

          protected org.apache.http.HttpResponse doRequestWithAuthorization(org.apache.http.client.HttpClient httpclient,
                                                                            org.apache.http.client.methods.HttpRequestBase httpMethod,
                                                                            Map<String,Object> params,
                                                                            RESTWorkItemHandler.AuthenticationType type)

    - #### abortWorkItem

          public void abortWorkItem(org.kie.api.runtime.process.WorkItem workItem,
                                    org.kie.api.runtime.process.WorkItemManager manager)

    - #### getHttpClient

          protected org.apache.http.client.HttpClient getHttpClient(Integer readTimeout,
                                                                    Integer connectTimeout)

    - #### close

          protected void close(org.apache.http.client.HttpClient httpClient,
                               Object httpMethod)
                        throws IOException

      Throws:
        `IOException`

    - #### configureRequest

          protected Object configureRequest(String method,
                                            String urlStr,
                                            Map<String,Object> params)

Copyright © 2001–2016 JBoss by Red Hat. All rights reserved.