You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2019/03/07 08:20:48 UTC
[httpcomponents-client] branch bug-fixes created (now 285674e)
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a change to branch bug-fixes
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git.
at 285674e HttpClient should retry requests in case of ConnectionClosedException
This branch includes the following new commits:
new 74ae768 Fixed examples broken by HttpCore upgrade
new 39023df Bug fix: main async request execution handlers to release teh associated response consumer upon exception
new d950fa6 Bug fix: Simple response consumer to discard stored content when releasing resources
new 285674e HttpClient should retry requests in case of ConnectionClosedException
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[httpcomponents-client] 02/04: Bug fix: main async request
execution handlers to release teh associated response consumer upon
exception
Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch bug-fixes
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
commit 39023dfed12a3311efa04c4ef738f0cad50d5b86
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Thu Mar 7 08:41:44 2019 +0100
Bug fix: main async request execution handlers to release teh associated response consumer upon exception
---
.../apache/hc/client5/http/impl/async/Http2AsyncMainClientExec.java | 4 ++++
.../apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/Http2AsyncMainClientExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/Http2AsyncMainClientExec.java
index 4d2b52f..422ce77 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/Http2AsyncMainClientExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/Http2AsyncMainClientExec.java
@@ -100,6 +100,10 @@ public class Http2AsyncMainClientExec implements AsyncExecChainHandler {
@Override
public void failed(final Exception cause) {
+ final AsyncDataConsumer entityConsumer = entityConsumerRef.getAndSet(null);
+ if (entityConsumer != null) {
+ entityConsumer.releaseResources();
+ }
execRuntime.markConnectionNonReusable();
asyncExecCallback.failed(cause);
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java
index 72dbbc4..e558989 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java
@@ -116,6 +116,10 @@ class HttpAsyncMainClientExec implements AsyncExecChainHandler {
@Override
public void failed(final Exception cause) {
+ final AsyncDataConsumer entityConsumer = entityConsumerRef.getAndSet(null);
+ if (entityConsumer != null) {
+ entityConsumer.releaseResources();
+ }
execRuntime.markConnectionNonReusable();
asyncExecCallback.failed(cause);
}
[httpcomponents-client] 03/04: Bug fix: Simple response consumer to
discard stored content when releasing resources
Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch bug-fixes
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
commit d950fa6ed0252cac6c17c4b990172051bdd9bf47
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Thu Mar 7 08:47:29 2019 +0100
Bug fix: Simple response consumer to discard stored content when releasing resources
---
...onsumer.java => SimpleAsyncEntityConsumer.java} | 60 +++++++++++++---------
.../http/async/methods/SimpleResponseConsumer.java | 3 +-
2 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleAsyncEntityConsumer.java
similarity index 52%
copy from httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseConsumer.java
copy to httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleAsyncEntityConsumer.java
index 4af8def..00a94a8 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseConsumer.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleAsyncEntityConsumer.java
@@ -24,47 +24,57 @@
* <http://www.apache.org/>.
*
*/
+
package org.apache.hc.client5.http.async.methods;
import java.io.IOException;
+import java.nio.ByteBuffer;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
-import org.apache.hc.core5.http.nio.entity.BasicAsyncEntityConsumer;
-import org.apache.hc.core5.http.nio.support.AbstractAsyncResponseConsumer;
-import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.http.nio.entity.AbstractBinAsyncEntityConsumer;
+import org.apache.hc.core5.util.ByteArrayBuffer;
-/**
- * HTTP response consumer that generates a {@link SimpleHttpResponse} instance based on events
- * of an incoming data stream.
- *
- * @since 5.0
- *
- * @see SimpleBody
- */
-public final class SimpleResponseConsumer extends AbstractAsyncResponseConsumer<SimpleHttpResponse, byte[]> {
+final class SimpleAsyncEntityConsumer extends AbstractBinAsyncEntityConsumer<byte[]> {
- SimpleResponseConsumer(final AsyncEntityConsumer<byte[]> entityConsumer) {
- super(entityConsumer);
+ private final ByteArrayBuffer buffer;
+
+ public SimpleAsyncEntityConsumer() {
+ super();
+ this.buffer = new ByteArrayBuffer(1024);
}
- public static SimpleResponseConsumer create() {
- return new SimpleResponseConsumer(new BasicAsyncEntityConsumer());
+ @Override
+ protected void streamStart(final ContentType contentType) throws HttpException, IOException {
}
@Override
- public void informationResponse(final HttpResponse response, final HttpContext context) throws HttpException, IOException {
+ protected int capacityIncrement() {
+ return Integer.MAX_VALUE;
}
@Override
- protected SimpleHttpResponse buildResult(final HttpResponse response, final byte[] entity, final ContentType contentType) {
- final SimpleHttpResponse simpleResponse = SimpleHttpResponse.copy(response);
- if (entity != null) {
- simpleResponse.setBodyBytes(entity, contentType);
+ protected void data(final ByteBuffer src, final boolean endOfStream) throws IOException {
+ if (src == null) {
+ return;
+ }
+ if (src.hasArray()) {
+ buffer.append(src.array(), src.arrayOffset() + src.position(), src.remaining());
+ } else {
+ while (src.hasRemaining()) {
+ buffer.append(src.get());
+ }
}
- return simpleResponse;
}
-}
\ No newline at end of file
+ @Override
+ protected byte[] generateContent() throws IOException {
+ return buffer.toByteArray();
+ }
+
+ @Override
+ public void releaseResources() {
+ buffer.clear();
+ }
+
+}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseConsumer.java
index 4af8def..6b51fdc 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseConsumer.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleResponseConsumer.java
@@ -32,7 +32,6 @@ import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
-import org.apache.hc.core5.http.nio.entity.BasicAsyncEntityConsumer;
import org.apache.hc.core5.http.nio.support.AbstractAsyncResponseConsumer;
import org.apache.hc.core5.http.protocol.HttpContext;
@@ -51,7 +50,7 @@ public final class SimpleResponseConsumer extends AbstractAsyncResponseConsumer<
}
public static SimpleResponseConsumer create() {
- return new SimpleResponseConsumer(new BasicAsyncEntityConsumer());
+ return new SimpleResponseConsumer(new SimpleAsyncEntityConsumer());
}
@Override
[httpcomponents-client] 04/04: HttpClient should retry requests in
case of ConnectionClosedException
Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch bug-fixes
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
commit 285674e4ff960c3b7b6614c2ef9cd239a41409bf
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Thu Mar 7 08:50:53 2019 +0100
HttpClient should retry requests in case of ConnectionClosedException
---
.../hc/client5/http/impl/DefaultHttpRequestRetryHandler.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java
index ead786f..fcb4883 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java
@@ -42,6 +42,7 @@ import org.apache.hc.client5.http.StandardMethods;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.concurrent.CancellableDependency;
+import org.apache.hc.core5.http.ConnectionClosedException;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.util.Args;
@@ -87,6 +88,7 @@ public class DefaultHttpRequestRetryHandler implements HttpRequestRetryHandler {
* <li>InterruptedIOException</li>
* <li>UnknownHostException</li>
* <li>ConnectException</li>
+ * <li>ConnectionClosedException</li>
* <li>SSLException</li>
* </ul>
*
@@ -95,7 +97,11 @@ public class DefaultHttpRequestRetryHandler implements HttpRequestRetryHandler {
*/
public DefaultHttpRequestRetryHandler(final int retryCount) {
this(retryCount,
- InterruptedIOException.class, UnknownHostException.class, ConnectException.class, SSLException.class);
+ InterruptedIOException.class,
+ UnknownHostException.class,
+ ConnectException.class,
+ ConnectionClosedException.class,
+ SSLException.class);
}
/**
[httpcomponents-client] 01/04: Fixed examples broken by HttpCore
upgrade
Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch bug-fixes
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
commit 74ae768e0d4a2318470d285c9ffd93bdc00d3b7c
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Thu Mar 7 08:43:28 2019 +0100
Fixed examples broken by HttpCore upgrade
---
.../apache/hc/client5/http/examples/fluent/FluentResponseHandling.java | 3 +--
.../org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java | 1 -
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentResponseHandling.java b/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentResponseHandling.java
index a725091..18f9ab6 100644
--- a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentResponseHandling.java
+++ b/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentResponseHandling.java
@@ -42,7 +42,6 @@ import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.io.HttpClientResponseHandler;
-import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
@@ -69,7 +68,7 @@ public class FluentResponseHandling {
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
- ContentType contentType = EntityUtils.getContentTypeOrDefault(entity);
+ ContentType contentType = ContentType.parseLenient(entity.getContentType());
if (!contentType.equals(ContentType.APPLICATION_XML)) {
throw new ClientProtocolException("Unexpected content type:" + contentType);
}
diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java
index 0706423..d94064c 100644
--- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java
+++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java
@@ -54,7 +54,6 @@ public class ClientChunkEncodedPost {
final InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1, ContentType.APPLICATION_OCTET_STREAM);
- reqEntity.setChunked(true);
// It may be more appropriate to use FileEntity class in this particular
// instance but we are using a more generic InputStreamEntity to demonstrate
// the capability to stream out data from any arbitrary source