Overview
In Etlworks, you can capture the response code and response headers from the last HTTP call just by enabling a configuration option when configuring the HTTP Connection.
Process
Capture the HTTP response code
If you enable the option Save HTTP Code into Global Variable
when configuring the HTTP Connection, the system will capture the HTTP response code and store it in the thread-safe global variable http_processor_last_http_code
.
To access this global variable, use the following JavaScript code:
var httpCode = com.toolsverse.config.SystemConfig.instance().getContextProperties().
get("http_processor_last_http_code"));
The last HTTP response code is valid only within the current execution thread. It will override it on the next HTTP call, so if you do want to capture it, you must execute the JavaScript code above right after the HTTP call.
Capture the response headers
If you enable the option Save Response Header into Global Variable
when configuring the HTTP Connection, the system will capture the HTTP response code and store it in the thread-safe global variable http_processor_last_last_response_headers
.
To access this global variable, use the following JavaScript code:
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
The value of this variable is valid only within the current execution thread. It will override it on the next HTTP call, so if you want to capture the response headers, you must execute the JavaScript code above right after the HTTP call.
Comments
0 comments
Please sign in to leave a comment.