hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Liu Kumai (JIRA)" <j...@apache.org>
Subject [jira] [Created] (HTTPCLIENT-1456) ClientProtocolException occurs when retries after receiving 503
Date Thu, 06 Feb 2014 11:20:09 GMT
Liu Kumai created HTTPCLIENT-1456:
-------------------------------------

             Summary: ClientProtocolException occurs when retries after receiving 503
                 Key: HTTPCLIENT-1456
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1456
             Project: HttpComponents HttpClient
          Issue Type: Improvement
          Components: HttpClient
    Affects Versions: 4.3.2, 4.3.1
            Reporter: Liu Kumai
            Priority: Minor


When HttpClient retries a POST request after receiving 503 (service temporary unavailable),
ClientProtocolException occurs. On second request, Content-Length header is already set and
the RequestContent created by HttpClientBuilder doesn't allow overriding it.

There's a workaround:

{code}
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setServiceUnavailableRetryStrategy(new DefaultServiceUnavailableRetryStrategy(2, 100));
builder.addInterceptorFirst(new HttpRequestInterceptor() {
    @Override
    public void process(HttpRequest request, HttpContext context) throws HttpException, IOException
{
      if (request.containsHeader(HTTP.CONTENT_LEN)) {
        request.removeHeaders(HTTP.CONTENT_LEN);
      }
    }
});
{code}

I think HttpClientBuilder should provide an option like this:
{code}
Index: httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
===================================================================
--- httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java (revision
1565153)
+++ httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java (working copy)
@@ -193,6 +193,7 @@
     private boolean cookieManagementDisabled;
     private boolean authCachingDisabled;
     private boolean connectionStateDisabled;
+    private boolean overrideContentLength;

     private int maxConnTotal = 0;
     private int maxConnPerRoute = 0;
@@ -568,6 +569,11 @@
         return this;
     }

+    public final HttpClientBuilder enableOverrideContentLength() {
+       overrideContentLength = true;
+       return this;
+    }
+
     /**
      * Assigns {@link ConnectionBackoffStrategy} instance.
      */
@@ -821,7 +827,7 @@
             }
             b.addAll(
                     new RequestDefaultHeaders(defaultHeaders),
-                    new RequestContent(),
+                    new RequestContent(overrideContentLength),
                     new RequestTargetHost(),
                     new RequestClientConnControl(),
                     new RequestUserAgent(userAgent),
{code}



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message