private String executeHttpCall(final HttpRequestBase httpRequest, final String body, final String identityToken) throws RESTClientException {
try {
LOGGER.info("Executing http call to: {} ", httpRequest.toString());
if (StringUtils.hasText(body)) {
((HttpEntityEnclosingRequestBase) httpRequest).setEntity(new StringEntity(body, ContentType.APPLICATION_JSON));
}
if (StringUtils.hasText(identityToken)) {
httpRequest.addHeader(RESTUtils.buildIdentityHeader(identityToken));
}
if (StringUtils.hasText(secretKey)) {
addSignedHeader(httpRequest, body);
}
final HttpResponse response = httpClient.execute(httpRequest);
validateResponse(response);
if (response.getEntity() != null) {
return EntityUtils.toString(response.getEntity());
} else {
return "";
}
} catch (final RESTClientException e) {
LOGGER.error("Error executing http call: {} ", httpRequest.toString(), e);
throw e;
} catch (final Exception e) {
LOGGER.error("Error executing http call: {} ", httpRequest.toString(), e);
final String msg = String.format("Error executing http call: %s ", httpRequest.toString());
throw new RESTClientException(msg, e);
}
}