You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Liu Kumai (JIRA)" <ji...@apache.org> on 2014/02/06 12:24:08 UTC
[jira] [Updated] (HTTPCLIENT-1456) ClientProtocolException occurs
when retries after receiving 503
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1456?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Liu Kumai updated HTTPCLIENT-1456:
----------------------------------
Description:
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}
was:
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}
> 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.1, 4.3.2
> 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