in src/main/java/org/apache/sling/testing/clients/AbstractSlingClient.java [365:398]
public SlingHttpResponse doRawRequest(String method, String uri, List<Header> headers, int... expectedStatus)
throws ClientException {
// create context from config
HttpClientContext context = createHttpClientContextFromConfig();
context.setAttribute(EXPECTED_STATUS, expectedStatus);
HttpHost host = new HttpHost(getUrl().getHost(), getUrl().getPort(), getUrl().getScheme());
HttpRequest request = new BasicHttpRequest(method, uri);
// add headers
if (headers != null) {
request.setHeaders(headers.toArray(new Header[headers.size()]));
}
try {
log.debug("request {} {}", method, uri);
SlingHttpResponse response = new SlingHttpResponse(this.execute(host, request, context));
log.debug("response {}", HttpUtils.getHttpStatus(response));
// Check the status and throw a ClientException if it doesn't match expectedStatus, but close the entity before
if (expectedStatus != null && expectedStatus.length > 0) {
try {
HttpUtils.verifyHttpStatus(response, expectedStatus);
} catch (ClientException e) {
// catch the exception to make sure we close the entity before re-throwing it
response.close();
throw e;
}
}
return response;
} catch (IOException e) {
throw new TestingIOException("Could not execute http request", e);
}
}