public RequestResult executeGet(String spec) throws IOException {
    try (CloseableHttpClient httpClient = buildHttpClient()) {
      HttpGet httpGet = new HttpGet(spec);

      RequestConfig requestConfig = RequestConfig.custom()
        .setConnectionRequestTimeout(connTimeout)
        .setSocketTimeout(readTimeout).build();
      httpGet.setConfig(requestConfig);

      try (CloseableHttpResponse response = httpClient.execute(httpGet);) {
        final HttpEntity entity = response.getEntity();
        final InputStream is = entity.getContent();

        final int statusCode = response.getStatusLine().getStatusCode();
        final RequestResult result = new RequestResult(IOUtils.toString(is, StandardCharsets.UTF_8), statusCode);

        if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_NOT_FOUND
          || statusCode == HttpStatus.SC_FORBIDDEN) {
          LOG.error(String.format("Received HTTP '%s' response from URL: '%s'", statusCode,
                                  URLCredentialsHider.hideCredentials(spec)));
        }
        return result;
      }
    }
  }
Class that provides support to work with URLs behind redirects.
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLRedirectProvider.java