}
private String extractRedirectedUrl(String url, HttpContext localContext) {
// This was triggered by HttpClient with the redirect count was exceeded.
HttpHost host = (HttpHost)localContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
HttpUriRequest finalRequest = (HttpUriRequest)localContext.getAttribute(ExecutionContext.HTTP_REQUEST);
try {
URL hostUrl = new URI(host.toURI()).toURL();
return new URL(hostUrl, finalRequest.getURI().toString()).toExternalForm();
} catch (MalformedURLException e) {
LOGGER.warn("Invalid host/uri specified in final fetch: " + host + finalRequest.getURI());
return url;
} catch (URISyntaxException e) {
LOGGER.warn("Invalid host/uri specified in final fetch: " + host + finalRequest.getURI());
return url;
}
}