diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java index da8b0f9b8..79078f86e 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java @@ -69,6 +69,7 @@ import org.apache.hc.core5.io.CloseMode; import org.apache.hc.core5.util.Args; import org.apache.hc.core5.util.Asserts; import org.apache.hc.core5.util.Deadline; +import org.apache.hc.core5.util.Identifiable; import org.apache.hc.core5.util.TimeValue; import org.apache.hc.core5.util.Timeout; import org.slf4j.Logger; @@ -591,7 +592,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan .build(); } - class InternalConnectionEndpoint extends ConnectionEndpoint { + class InternalConnectionEndpoint extends ConnectionEndpoint implements Identifiable { private final HttpRoute route; private final AtomicReference connRef; @@ -601,6 +602,11 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan this.connRef = new AtomicReference<>(conn); } + @Override + public String getId() { + return id; + } + HttpRoute getRoute() { return route; } @@ -614,8 +620,10 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan } ManagedHttpClientConnection getValidatedConnection() { - final ManagedHttpClientConnection conn = getConnection(); - Asserts.check(conn.isOpen(), "Endpoint is not connected"); + final ManagedHttpClientConnection conn = this.connRef.get(); + if (conn == null || !conn.isOpen()) { + throw new ConnectionShutdownException(); + } return conn; } @@ -625,13 +633,13 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan @Override public boolean isConnected() { - final ManagedHttpClientConnection conn = getConnection(); + final ManagedHttpClientConnection conn = this.connRef.get(); return conn != null && conn.isOpen(); } @Override public void close(final CloseMode closeMode) { - final ManagedHttpClientConnection conn = detach(); + final ManagedHttpClientConnection conn = this.connRef.get(); if (conn != null) { conn.close(closeMode); } @@ -639,7 +647,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan @Override public void close() throws IOException { - final ManagedHttpClientConnection conn = detach(); + final ManagedHttpClientConnection conn = this.connRef.get(); if (conn != null) { conn.close(); }