HttpGet method = new HttpGet(builder.build());
if (headers != null) {
for (String headerName : headers.keySet())
method.addHeader(headerName, headers.get(headerName));
}
CloseableHttpResponse response = null;
try {
HttpHost targetHost = new HttpHost(builder.getHost(), builder.getPort(), builder.getScheme());
HttpClientContext localcontext = HttpClientContext.create();
if (isAuthConfigured) {
AuthCache authCache = new BasicAuthCache();
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
localcontext.setAuthCache(authCache);
}
response = httpclient.execute(targetHost, method, localcontext);
int statusCode = response.getStatusLine().getStatusCode();
byte[] responseContent = null;
if (response.getEntity() != null) {
responseContent = EntityUtils.toByteArray(response.getEntity());
}
if (statusCode != HttpStatus.SC_OK) {
throw new HttpCallException(url, statusCode, responseContent != null ? new String(responseContent) : "");
}
Header h = response.getFirstHeader("Content-Type");
return new HttpResponseContent(h != null ? h.getValue() : null, responseContent);
} finally {
if (response != null)
response.close();
method.releaseConnection();
}
}