// create request method and configure it
final GetMethod method = new GetMethod(url.toExternalForm());
method.setFollowRedirects(true);
// create cache information object
SystemClock clock = SystemClock.getDefaultInstance();
CachedHttpContentStateBuilder cacheBuilder = new CachedHttpContentStateBuilder();
cacheBuilder.setMethodAccessor(
ResponseHeaderAccessorFactory.getDefaultInstance().
createHttpClientResponseHeaderAccessor(method));
cacheBuilder.setRequestTime(clock.getCurrentTime());
// save request headers to request method
setRequestHeaders(method, headers);
DefaultRepresentation responseInfo = null;
// execute request
try {
httpClient.executeMethod(method);
} catch (IOException e) {
throw new ResourceRetrieverException(exceptionLocalizer.format(
"connection-refused", url.toString()), e);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Requested resource at: " + url.toString());
}
// If the get failed then return immediately.
if (method.getStatusCode() == 200) {
// get response caching information
cacheBuilder.setResponseTime(clock.getCurrentTime());
// read resource stream
InputStream stream = method.getResponseBodyAsStream();
// a custom closer to ensure the method releases its connection