Source:
public static String getRedirect(String urlstring, boolean useAuthentication, boolean isGet) throws IOException { HttpRequestBase req; if (isGet) req = new HttpGet(urlstring); else req = new HttpPost(urlstring); req.setConfig(RequestConfig.custom().setRedirectsEnabled(false).build()); req.setHeader("User-Agent", USER_AGENT); CloseableHttpClient httpClient = getCustomClosableHttpClient(useAuthentication); HttpResponse httpResponse = httpClient.execute(req); HttpEntity httpEntity = httpResponse.getEntity(); if (debugLog) Log.getLog().info("[" + (isGet ? "GET": "POST") + "] Status for " + urlstring + ": " + httpResponse.getStatusLine().toString()); if (httpEntity != null) { int httpStatusCode = httpResponse.getStatusLine().getStatusCode(); if (300 <= httpStatusCode && httpStatusCode <= 308) { String location = getLocationHeader(httpResponse); EntityUtils.consumeQuietly(httpEntity); if (location != null) return location; throw new IOException("redirect for " + urlstring+ ": no location attribute found"); } else if (isGet && httpStatusCode != 200) { if (debugLog) Log.getLog().info("GET method failed for " + urlstring + " trying POST"); return getRedirect(urlstring, useAuthentication, false); } else { if (debugLog) Log.getLog().info("Trying to fetch Meta redirect URL for " + urlstring); String metaURL = getMetaRedirectURL(httpEntity); EntityUtils.consumeQuietly(httpEntity); if (metaURL != null) { if (debugLog) Log.getLog().info("Fetched Meta redirect URL for " + urlstring + " : " + metaURL); return metaURL; } return urlstring; } } else { throw new IOException("client connection to " + urlstring + " fail: no connection"); } }

Target:
public static String getRedirect(String urlstring, boolean useAuthentication, boolean isGet) throws IOException { HttpRequestBase req; if (isGet) req = new HttpGet(urlstring); else req = new HttpPost(urlstring); req.setConfig(RequestConfig.custom().setRedirectsEnabled(false).build()); req.setHeader("User-Agent", USER_AGENT); CloseableHttpClient httpClient = getCustomClosableHttpClient(useAuthentication); HttpResponse httpResponse = httpClient.execute(req); HttpEntity httpEntity = httpResponse.getEntity(); if (debugLog) { DAO.log("[" + (isGet ? "GET": "POST") + "] Status for " + urlstring + ": " + httpResponse.getStatusLine().toString()); } if (httpEntity != null) { int httpStatusCode = httpResponse.getStatusLine().getStatusCode(); if (300 <= httpStatusCode && httpStatusCode <= 308) { String location = getLocationHeader(httpResponse); EntityUtils.consumeQuietly(httpEntity); if (location != null) { return location; } throw new IOException("redirect for " + urlstring+ ": no location attribute found"); } else if (isGet && httpStatusCode != 200) { if (debugLog) { DAO.log("GET method failed for " + urlstring + " trying POST"); } return getRedirect(urlstring, useAuthentication, false); } else { if (debugLog) DAO.log("Trying to fetch Meta redirect URL for " + urlstring); String metaURL = getMetaRedirectURL(httpEntity); EntityUtils.consumeQuietly(httpEntity); if (metaURL != null) { if (debugLog) { DAO.log("Fetched Meta redirect URL for " + urlstring + " : " + metaURL); } if (!metaURL.startsWith("http") && !urlstring.endsWith("/")) { return urlstring + "/" + metaURL; } return metaURL; } return urlstring; } } else { throw new IOException("client connection to " + urlstring + " fail: no connection"); } }