private SimpleHttpResponse sendRequest(HttpUriRequest request)
throws IOException, HttpErrorStatusException {
try (CloseableHttpResponse response = _httpClient.execute(request)) {
String controllerHost = null;
String controllerVersion = null;
if (response.containsHeader(CommonConstants.Controller.HOST_HTTP_HEADER)) {
controllerHost = response.getFirstHeader(CommonConstants.Controller.HOST_HTTP_HEADER).getValue();
controllerVersion = response.getFirstHeader(CommonConstants.Controller.VERSION_HTTP_HEADER).getValue();
}
if (controllerHost != null) {
LOGGER.info(String
.format("Sending request: %s to controller: %s, version: %s", request.getURI(), controllerHost,
controllerVersion));
}
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode >= 300) {
throw new HttpErrorStatusException(getErrorMessage(request, response), statusCode);
}
return new SimpleHttpResponse(statusCode, EntityUtils.toString(response.getEntity()));
}
}