use of io.irontest.models.teststep.SOAPTeststepProperties in project irontest by zheng-wang.
the class SOAPTeststepRunner method run.
protected BasicTeststepRun run(Teststep teststep) throws Exception {
BasicTeststepRun basicTeststepRun = new BasicTeststepRun();
Endpoint endpoint = teststep.getEndpoint();
// set request HTTP headers
HttpPost httpPost = new HttpPost(endpoint.getUrl());
SOAPTeststepProperties otherProperties = (SOAPTeststepProperties) teststep.getOtherProperties();
if (otherProperties != null) {
for (HTTPHeader httpHeader : otherProperties.getHttpHeaders()) {
httpPost.setHeader(httpHeader.getName(), httpHeader.getValue());
}
}
// set HTTP basic auth
if (!"".equals(StringUtils.trimToEmpty(endpoint.getUsername()))) {
String auth = endpoint.getUsername() + ":" + getDecryptedEndpointPassword();
String encodedAuth = Base64.encodeBase64String(auth.getBytes());
String authHeader = "Basic " + encodedAuth;
httpPost.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
}
// set request HTTP body
httpPost.setEntity(new StringEntity((String) teststep.getRequest(), "UTF-8"));
final SOAPAPIResponse apiResponse = new SOAPAPIResponse();
ResponseHandler<Void> responseHandler = new ResponseHandler<Void>() {
public Void handleResponse(final HttpResponse httpResponse) throws IOException {
LOGGER.info(httpResponse.toString());
apiResponse.getHttpHeaders().add(new HTTPHeader("*Status-Line*", httpResponse.getStatusLine().toString()));
Header[] headers = httpResponse.getAllHeaders();
for (Header header : headers) {
apiResponse.getHttpHeaders().add(new HTTPHeader(header.getName(), header.getValue()));
}
HttpEntity entity = httpResponse.getEntity();
apiResponse.setHttpBody(entity != null ? EntityUtils.toString(entity) : null);
return null;
}
};
// build HTTP Client instance
// trust all SSL certificates
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(new TrustStrategy() {
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
}).build();
HttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).build();
// invoke the web service
httpClient.execute(httpPost, responseHandler);
basicTeststepRun.setResponse(apiResponse);
return basicTeststepRun;
}
Aggregations