Rest Mapping
The RestMapping is a mapping for performing RESTful HTTP requests. It can make requests using different HTTP methods: GET, PUT, POST and PATCH.
The HTTP calls are made through Apache HTTP client, thanks to the ApacheHttpClientRequestHandler class, as follows:
HTTPRequestHandler request = HTTPRequestHandlerFactory.getRequestHandler("apache", true);
This class implements the HTTPRequestHandler interface, so if at any point we want to replace the HTTP calls with another client (such as WebClient), we simply need to change this line to obtain an object of the corresponding class that implements the interface, such as the WebClientRequestHandler class (note that this class is not fully developed or tested).
Usage
To use the RestMapping in a mapper, you should first prepare the different parts of the request:
- Create a body if necessary: Make the transformations to get the body needed for the REST call. For example:
ticket/subject
ticket/description - Transform the parts of the request: Once you have the body, you can make the following transformations:
Note: In the URL, you can use placeholders such as
ticket --> restcall/request/body
--> restcall/request/url
restcall/request/headers/Content-Type{{endpoint:ticketurl}}(if you have configured an endpoint) or{{msg:ticket/id}} - Apply the corresponding mapping:
restcall/request ---> RestMapping ---> restcall/response - File Upload Structure: If we want to upload a file, we must create a specific structure for files:
And apart from the attachment, the fields that the multipart/form-data POST/PUT request needs, for example:
request/body/attachment/content (The file content as a base64 string)
request/body/attachment/filename (The name of the file)
request/body/attachment/contentType (The MIME type of the file, e.g., application/pdf, image/png)
request/body/attachment/key: Form data key name (name of the file field in the post/put request)A valid example would be:request/body/descriptionrequest/body/attachment/content: "ACDdkasdjfdfadfsd...."
request/body/attachment/filename: "printer.png"
request/body/attachment/contentType: "image/png"
request/body/attachment/key: "uploaded_data"
request/body/description: "This is a printer"
These steps ensure that all necessary parts of the request are properly formatted and mapped, allowing for successful RESTful HTTP calls using the RestMapping.
HTTP Output Handling
The output of the HTTP call is displayed in the field specified by the to parameter. If an error occurs during the HTTP request, the last node of the message will be removed, and an error node will be added instead. For example, if to is specified as createticket/response and an error occurs, a new node will be generated as createticket/error.
RestMapping configuration
| Field | Description | Example |
|---|---|---|
| From | Defines the field to which the mapping will be applied | createticket/request |
| To | Defines the field to which the mapping will be applied | createticket/response |
| Function type | Defines the function type. Needs to be "REST Mapping". | |
| Function | Defines the HTTP method | POST, PUT, DELETE, PATCH, GET |
| condition | ||
| regex | ||
| audit | Enables auditing of HTTP calls | true/false/nothing |