protected HttpToolResponse exec(String path, HttpCall httpCall) {
HttpClient client = Preconditions.checkNotNull(getHttpClientForBrooklynNode(), "No address info for "+entity)
.build();
String baseUri = getEntityUrl();
URI uri = URI.create(Urls.mergePaths(baseUri, path));
HttpToolResponse result;
try {
result = httpCall.call(client, uri);
} catch (Exception e) {
Exceptions.propagateIfFatal(e);
throw new IllegalStateException("Invalid response invoking " + uri + ": " + e, e);
}
Tasks.addTagDynamically(BrooklynTaskTags.tagForStream("http_response", Streams.byteArray(result.getContent())));
if (!responseSuccess.apply(result.getResponseCode())) {
LOG.warn("Invalid response invoking {}: response code {}\n{}: {}",
new Object[]{uri, result.getResponseCode(), result, new String(result.getContent())});
throw new IllegalStateException("Invalid response invoking " + uri + ": response code " + result.getResponseCode());
}
return result;
}