Classic exec runtime to establish connection automatically if the connection endpoint is disconnected
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1794169 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ConnectExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ConnectExec.java
index 1e83a24..af8daf7 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ConnectExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ConnectExec.java
@@ -202,10 +202,6 @@
this.proxyHttpProcessor.process(connect, null, context);
while (response == null) {
- if (!execRuntime.isConnected()) {
- execRuntime.connect(context);
- }
-
connect.removeHeaders(HttpHeaders.PROXY_AUTHORIZATION);
this.authenticator.addAuthResponse(proxy, ChallengeType.PROXY, connect, proxyAuthExchange, context);
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ExecRuntimeImpl.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ExecRuntimeImpl.java
index 67d5ec0..e80956f 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ExecRuntimeImpl.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ExecRuntimeImpl.java
@@ -141,22 +141,26 @@
return endpoint != null && endpoint.isConnected();
}
+ private void connectEndpoint(final ConnectionEndpoint endpoint, final HttpClientContext context) throws IOException {
+ if (cancellableAware != null) {
+ if (cancellableAware.isCancelled()) {
+ throw new RequestFailedException("Request aborted");
+ }
+ }
+ final RequestConfig requestConfig = context.getRequestConfig();
+ final TimeValue connectTimeout = requestConfig.getConnectTimeout();
+ manager.connect(endpoint, connectTimeout, context);
+ final TimeValue socketTimeout = requestConfig.getSocketTimeout();
+ if (socketTimeout.getDuration() >= 0) {
+ endpoint.setSocketTimeout(socketTimeout.toMillisIntBound());
+ }
+ }
+
@Override
public void connect(final HttpClientContext context) throws IOException {
final ConnectionEndpoint endpoint = ensureValid();
if (!endpoint.isConnected()) {
- if (cancellableAware != null) {
- if (cancellableAware.isCancelled()) {
- throw new RequestFailedException("Request aborted");
- }
- }
- final RequestConfig requestConfig = context.getRequestConfig();
- final TimeValue connectTimeout = requestConfig.getConnectTimeout();
- manager.connect(endpoint, connectTimeout, context);
- final TimeValue socketTimeout = requestConfig.getSocketTimeout();
- if (socketTimeout.getDuration() >= 0) {
- endpoint.setSocketTimeout(socketTimeout.toMillisIntBound());
- }
+ connectEndpoint(endpoint, context);
}
}
@@ -178,6 +182,9 @@
@Override
public ClassicHttpResponse execute(final ClassicHttpRequest request, final HttpClientContext context) throws IOException, HttpException {
final ConnectionEndpoint endpoint = ensureValid();
+ if (!endpoint.isConnected()) {
+ connectEndpoint(endpoint, context);
+ }
return endpoint.execute(request, requestExecutor, context);
}