Overview
In Etlworks, you can capture the HTTP response code and headers from the most recent HTTP call by enabling specific options when configuring the HTTP Connection.
Process
Capture the HTTP response code
Enable Save HTTP Code into Global Variable in the HTTP connection settings.
Etlworks will store the response code in the thread-safe global variable: http_processor_last_http_code.
You can access this value using JavaScript:
var httpCode = com.toolsverse.config.SystemConfig.instance().getContextProperties().
get("http_processor_last_http_code"));
Note: This value is only valid within the current execution thread and will be overwritten on the next HTTP call. Be sure to capture it immediately after the HTTP operation.
Capture the response headers
To capture the HTTP response headers:
Enable Save Response Header into Global Variable in the HTTP connection settings.
Etlworks will store the response headers as a key=value string in the global variable:
http_processor_last_response_headers.
Access and process the headers using the following JavaScript:
var headers = com.toolsverse.config.SystemConfig.instance().getContextProperties().
get("http_processor_last_response_headers");
// headers is a key=value String
// It must be converted to java.util.Properties
var theHeaders = Utils.getProperties(headers);
// this code just prints available headers
for each (var entry in theHeaders.entrySet()) {
etlConfig.log(entry.getKey() + "=" + entry.getValue());
}
// use theHeaders.getProperty("header name") to access the header value
Note: Like the response code, the headers are only valid within the current execution thread and will be overwritten by the next HTTP call. Access them immediately after the HTTP operation.
Comments
0 comments
Please sign in to leave a comment.