Getting the REST Adapter Response
In addition to the response parameter, each REST Adapter call also provides the complete adapter response as an output object. The adapter response contains the following:
Attribute | Type | Description | Allowed Values / Examples |
---|---|---|---|
httpStatus | Integer | HTTP status code of the adapter call. | 500 |
headers | Array of HeaderField |
This attribute is deprecated. It is only present for compatibility reasons. Please use httpHeaderMap for new implementations. The implementation of httpHeaderMap complies to the HTTP specification and supports multiple headers having the same name. | |
body | Blob | HTTP body of HTTP response. Among others, the body contains
| |
responseObject | Any | Response Object of the REST adapter call if the endpoint returns one (response output parameter). The response object is only returned for successful calls. | |
httpHeaderMap | Map of Entry | Header information as a map. The map contains arrays of header value strings whereas the header name is the key of the map.
Refer to HTTP Header Support for more information on the standard xUML HTTP headers. |
You can get the adapter response from the adapterResponse pin of the adapter.
Example
The following example shows how to get the REST error object in case of error and log it to the service log.
The adapter response is taken from the corresponding pin and transferred to a local object. The object does not necessarily need to be called adapterResponse - you can name it as you like.
Next, in case of error, the response is provided to an operation (logRESTError) that logs the error.
This operation takes the the adapter response from the response body and transforms it using action script (getResponseObjectFromBody). Parameter return is of type RESTError, a type that has been imported with the OpenAPI descriptor.
Using transcodeToString() and jsonToClass(), the body content is transformed to the error object.
set return = adapterResponse.body.transcodeToString("ISO-8859-1").jsonToClass();
This error object is provided as details parameter to the logger.
The error code to be logged is taken from the HTTP status code of the adapter response as described on Transforming Data on an Object Flow, using the following action script snippet:
adapterResponse.httpStatus.convertToString()
Related Pages: