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 2022/10/03 13:24:54 UTC
[httpcomponents-client] branch 5.1.x updated: HTTPCLIENT-2236: MultihomeIOSessionRequester fails to enhance the cause exception in case of connect failure if the remoteAddress argument has been given
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch 5.1.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
The following commit(s) were added to refs/heads/5.1.x by this push:
new 4283132c9 HTTPCLIENT-2236: MultihomeIOSessionRequester fails to enhance the cause exception in case of connect failure if the remoteAddress argument has been given
4283132c9 is described below
commit 4283132c992ececdefc7af2d4cbf89e6eda072cb
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Fri Sep 30 16:34:51 2022 +0200
HTTPCLIENT-2236: MultihomeIOSessionRequester fails to enhance the cause exception in case of connect failure if the remoteAddress argument has been given
---
.../http/impl/nio/MultihomeIOSessionRequester.java | 33 ++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java
index 4d90b8558..35e40726a 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java
@@ -66,18 +66,47 @@ final class MultihomeIOSessionRequester {
final Object attachment,
final FutureCallback<IOSession> callback) {
+ final ComplexFuture<IOSession> future = new ComplexFuture<>(callback);
if (remoteAddress != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("{} connecting {} to {} ({})", remoteEndpoint, localAddress, remoteAddress, connectTimeout);
}
- return connectionInitiator.connect(remoteEndpoint, remoteAddress, localAddress, connectTimeout, attachment, callback);
+ final Future<IOSession> sessionFuture = connectionInitiator.connect(remoteEndpoint, remoteAddress, localAddress, connectTimeout, attachment, new FutureCallback<IOSession>() {
+ @Override
+ public void completed(final IOSession session) {
+ future.completed(session);
+ }
+
+ @Override
+ public void failed(final Exception cause) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("{}:{} connection to {} failed ({}); terminating operation",
+ remoteEndpoint.getHostName(), remoteEndpoint.getPort(), remoteAddress, cause.getClass());
+ }
+ if (cause instanceof IOException) {
+ future.failed(ConnectExceptionSupport.enhance((IOException) cause, remoteEndpoint,
+ (remoteAddress instanceof InetSocketAddress) ?
+ new InetAddress[] { ((InetSocketAddress) remoteAddress).getAddress() } :
+ new InetAddress[] {}));
+ } else {
+ future.failed(cause);
+ }
+ }
+
+ @Override
+ public void cancelled() {
+ future.cancel();
+ }
+
+ });
+ future.setDependency(sessionFuture);
+ return future;
}
if (LOG.isDebugEnabled()) {
LOG.debug("{} resolving remote address", remoteEndpoint);
}
- final ComplexFuture<IOSession> future = new ComplexFuture<>(callback);
final InetAddress[] remoteAddresses;
try {
remoteAddresses = dnsResolver.resolve(remoteEndpoint.getHostName());