use of com.axway.ats.action.ActionLibraryConfigurator in project ats-framework by Axway.
the class FileSystemSnapshot method loadConfiguration.
/**
* Extract all the configuration information we are interested in.
* It will be send to the local or remote instance.
*/
private void loadConfiguration() {
ActionLibraryConfigurator configurator = ActionLibraryConfigurator.getInstance();
configuration = new SnapshotConfiguration();
configuration.setCheckModificationTime(configurator.getFileSnapshotCheckModificationTime());
configuration.setCheckSize(configurator.getFileSnapshotCheckFileSize());
configuration.setCheckMD5(configurator.getFileSnapshotCheckFileMd5());
configuration.setCheckPermissions(configurator.getFileSnapshotCheckFilePermissions());
configuration.setSupportHidden(configurator.getFileSnapshotSupportHiddenFiles());
}
use of com.axway.ats.action.ActionLibraryConfigurator in project ats-framework by Axway.
the class HttpClient method execute.
/**
* Main execute method that sends request and receives response.
*
* @param method The POST/PUT etc. method
* @return The response
* @throws HttpException
*/
private HttpResponse execute(HttpRequestBase httpMethod) throws HttpException {
HttpClientContext localContext = null;
if (httpClient == null) {
HttpClientBuilder httpClientBuilder = HttpClients.custom();
// Add this interceptor to get the values of all HTTP headers in the request.
// Some of them are provided by the user while others are generated by Apache HTTP Components.
httpClientBuilder.addInterceptorLast(new HttpRequestInterceptor() {
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
Header[] requestHeaders = request.getAllHeaders();
actualRequestHeaders = new ArrayList<HttpHeader>();
for (Header header : requestHeaders) {
addHeaderToList(actualRequestHeaders, header.getName(), header.getValue());
}
if (debugLevel != HttpDebugLevel.NONE) {
logHTTPRequest(requestHeaders, request);
}
}
});
// Setup authentication
if (!StringUtils.isNullOrEmpty(username)) {
localContext = setupAuthentication(httpClientBuilder);
}
// Setup SSL
if (url.toLowerCase().startsWith("https")) {
setupSSL(httpClientBuilder);
}
// all important options are set, now build the HTTP client
if (AtsSystemProperties.SYSTEM_HTTP_PROXY_HOST != null && AtsSystemProperties.SYSTEM_HTTP_PROXY_PORT != null) {
HttpHost proxy = new HttpHost(AtsSystemProperties.SYSTEM_HTTP_PROXY_HOST, Integer.parseInt(AtsSystemProperties.SYSTEM_HTTP_PROXY_PORT));
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
httpClient = httpClientBuilder.setRoutePlanner(routePlanner).build();
} else {
httpClient = httpClientBuilder.build();
}
}
// Setup read and connect timeouts
httpMethod.setConfig(RequestConfig.custom().setSocketTimeout(readTimeoutSeconds * 1000).setConnectTimeout(connectTimeoutSeconds * 1000).build());
// Add HTTP headers
addHeadersToHttpMethod(httpMethod);
// Create response handler
ResponseHandler<HttpResponse> responseHandler = new ResponseHandler<HttpResponse>() {
@Override
public HttpResponse handleResponse(final org.apache.http.HttpResponse response) throws ClientProtocolException, IOException {
int status = response.getStatusLine().getStatusCode();
Header[] responseHeaders = response.getAllHeaders();
List<HttpHeader> responseHeadersList = new ArrayList<HttpHeader>();
for (Header header : responseHeaders) {
addHeaderToList(responseHeadersList, header.getName(), header.getValue());
}
if ((debugLevel & HttpDebugLevel.HEADERS) == HttpDebugLevel.HEADERS) {
logHTTPResponse(responseHeaders, response);
}
try {
HttpEntity entity = response.getEntity();
if (entity == null) {
// No response body, generally have '204 No content' status
return new HttpResponse(status, response.getStatusLine().getReasonPhrase(), responseHeadersList);
} else {
if (responseBodyFilePath != null) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File(responseBodyFilePath), false);
entity.writeTo(fos);
} finally {
IoUtils.closeStream(fos);
}
return new HttpResponse(status, response.getStatusLine().getReasonPhrase(), responseHeadersList);
} else {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
entity.writeTo(bos);
return new HttpResponse(status, response.getStatusLine().getReasonPhrase(), responseHeadersList, bos.toByteArray());
}
}
} finally {
if (response instanceof CloseableHttpResponse) {
IoUtils.closeStream((CloseableHttpResponse) response, "Failed to close HttpResponse");
}
}
}
};
// Send the request as POST/GET etc. and return response.
try {
return httpClient.execute(httpMethod, responseHandler, localContext);
} catch (IOException e) {
throw new HttpException("Exception occurred sending message to URL '" + actualUrl + "' with a read timeout of " + readTimeoutSeconds + " seconds and a connect timeout of " + connectTimeoutSeconds + " seconds.", e);
} finally {
// clear internal variables
ActionLibraryConfigurator actionLibraryConfigurator = ActionLibraryConfigurator.getInstance();
if (!actionLibraryConfigurator.getHttpKeepRequestHeaders()) {
this.requestHeaders.clear();
}
if (!actionLibraryConfigurator.getHttpKeepRequestParameters()) {
this.requestParameters.clear();
}
if (!actionLibraryConfigurator.getHttpKeepRequestBody()) {
this.requestBody = null;
}
this.responseBodyFilePath = null;
}
}
Aggregations