Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8164941

java.net.httpclient.redirects.retrylimit should not affect connection retries

XMLWordPrintable

      Currently, property java.net.httpclient.redirects.retrylimit affects not only redirection limit, but also re-connection limit.
      That may be confusing. Redirection and re-connection have different meanings.

      Please consider the below test:

      import java.net.URI;
      import java.net.http.HttpClient;
      import java.net.http.HttpClient.Redirect;
      import java.net.http.HttpRequest;
      import java.net.http.HttpResponse;

      public class SimpleRedirectTest {

          public static void main(String[] args) throws Exception {
              System.setProperty("java.net.httpclient.redirects.retrylimit", "0");
              String url = "...";
              HttpClient client = HttpClient.create().followRedirects(Redirect.ALWAYS).build();
              HttpRequest request = client.request(new URI(url)).GET();
              HttpResponse<String> response = request.response(HttpResponse.BodyHandler.discard("BODY"));
              System.out.println(response.statusCode());
          }
      }

      The test raises the following exception:
      Exception in thread "main" java.io.IOException: Retry limit exceeded
      at java.net.http.MultiExchange.response(java.httpclient@9-internal/MultiExchange.java:170)
      at java.net.http.HttpRequestImpl.response(java.httpclient@9-internal/HttpRequestImpl.java:257)
      at SimpleRedirectTest.main(SimpleRedirectTest.java:17)

      The exception is thrown while connecting the server, but the test only focus on redirection.
      It would be better use two different properties for redirection limit and re-connection limit.

            michaelm Michael McMahon
            jjiang John Jiang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: