HTTPCLIENT-2209: Pass HttpContext to AsyncClientConnectionOperator (#353)
This commit is contained in:
parent
23bb9b89de
commit
6a487ba686
|
@ -47,6 +47,7 @@ import org.apache.hc.core5.http.HttpHost;
|
||||||
import org.apache.hc.core5.http.URIScheme;
|
import org.apache.hc.core5.http.URIScheme;
|
||||||
import org.apache.hc.core5.http.config.Lookup;
|
import org.apache.hc.core5.http.config.Lookup;
|
||||||
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
|
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
|
||||||
|
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||||
import org.apache.hc.core5.reactor.ConnectionInitiator;
|
import org.apache.hc.core5.reactor.ConnectionInitiator;
|
||||||
import org.apache.hc.core5.reactor.IOSession;
|
import org.apache.hc.core5.reactor.IOSession;
|
||||||
import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
|
import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
|
||||||
|
@ -76,6 +77,19 @@ final class DefaultAsyncClientConnectionOperator implements AsyncClientConnectio
|
||||||
final Timeout connectTimeout,
|
final Timeout connectTimeout,
|
||||||
final Object attachment,
|
final Object attachment,
|
||||||
final FutureCallback<ManagedAsyncClientConnection> callback) {
|
final FutureCallback<ManagedAsyncClientConnection> callback) {
|
||||||
|
return connect(connectionInitiator, host, localAddress, connectTimeout,
|
||||||
|
attachment, null, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Future<ManagedAsyncClientConnection> connect(
|
||||||
|
final ConnectionInitiator connectionInitiator,
|
||||||
|
final HttpHost host,
|
||||||
|
final SocketAddress localAddress,
|
||||||
|
final Timeout connectTimeout,
|
||||||
|
final Object attachment,
|
||||||
|
final HttpContext context,
|
||||||
|
final FutureCallback<ManagedAsyncClientConnection> callback) {
|
||||||
Args.notNull(connectionInitiator, "Connection initiator");
|
Args.notNull(connectionInitiator, "Connection initiator");
|
||||||
Args.notNull(host, "Host");
|
Args.notNull(host, "Host");
|
||||||
final ComplexFuture<ManagedAsyncClientConnection> future = new ComplexFuture<>(callback);
|
final ComplexFuture<ManagedAsyncClientConnection> future = new ComplexFuture<>(callback);
|
||||||
|
@ -141,7 +155,7 @@ final class DefaultAsyncClientConnectionOperator implements AsyncClientConnectio
|
||||||
final ManagedAsyncClientConnection connection,
|
final ManagedAsyncClientConnection connection,
|
||||||
final HttpHost host,
|
final HttpHost host,
|
||||||
final Object attachment) {
|
final Object attachment) {
|
||||||
upgrade(connection, host, attachment, null);
|
upgrade(connection, host, attachment, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -149,6 +163,16 @@ final class DefaultAsyncClientConnectionOperator implements AsyncClientConnectio
|
||||||
final ManagedAsyncClientConnection connection,
|
final ManagedAsyncClientConnection connection,
|
||||||
final HttpHost host,
|
final HttpHost host,
|
||||||
final Object attachment,
|
final Object attachment,
|
||||||
|
final HttpContext context) {
|
||||||
|
upgrade(connection, host, attachment, context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void upgrade(
|
||||||
|
final ManagedAsyncClientConnection connection,
|
||||||
|
final HttpHost host,
|
||||||
|
final Object attachment,
|
||||||
|
final HttpContext context,
|
||||||
final FutureCallback<ManagedAsyncClientConnection> callback) {
|
final FutureCallback<ManagedAsyncClientConnection> callback) {
|
||||||
final TlsStrategy tlsStrategy = tlsStrategyLookup != null ? tlsStrategyLookup.lookup(host.getSchemeName()) : null;
|
final TlsStrategy tlsStrategy = tlsStrategyLookup != null ? tlsStrategyLookup.lookup(host.getSchemeName()) : null;
|
||||||
if (tlsStrategy != null) {
|
if (tlsStrategy != null) {
|
||||||
|
|
|
@ -441,6 +441,7 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
|
||||||
route.isTunnelled() ? TlsConfig.copy(tlsConfig)
|
route.isTunnelled() ? TlsConfig.copy(tlsConfig)
|
||||||
.setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_1)
|
.setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_1)
|
||||||
.build() : tlsConfig,
|
.build() : tlsConfig,
|
||||||
|
context,
|
||||||
new FutureCallback<ManagedAsyncClientConnection>() {
|
new FutureCallback<ManagedAsyncClientConnection>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -469,7 +470,6 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
|
||||||
public void cancelled() {
|
public void cancelled() {
|
||||||
resultFuture.cancel();
|
resultFuture.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
resultFuture.setDependency(connectFuture);
|
resultFuture.setDependency(connectFuture);
|
||||||
return resultFuture;
|
return resultFuture;
|
||||||
|
@ -491,6 +491,7 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
|
||||||
poolEntry.getConnection(),
|
poolEntry.getConnection(),
|
||||||
route.getTargetHost(),
|
route.getTargetHost(),
|
||||||
attachment != null ? attachment : tlsConfig,
|
attachment != null ? attachment : tlsConfig,
|
||||||
|
context,
|
||||||
new CallbackContribution<ManagedAsyncClientConnection>(callback) {
|
new CallbackContribution<ManagedAsyncClientConnection>(callback) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -516,7 +517,6 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.apache.hc.core5.annotation.Internal;
|
||||||
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||||
import org.apache.hc.core5.concurrent.FutureCallback;
|
import org.apache.hc.core5.concurrent.FutureCallback;
|
||||||
import org.apache.hc.core5.http.HttpHost;
|
import org.apache.hc.core5.http.HttpHost;
|
||||||
|
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||||
import org.apache.hc.core5.reactor.ConnectionInitiator;
|
import org.apache.hc.core5.reactor.ConnectionInitiator;
|
||||||
import org.apache.hc.core5.util.Timeout;
|
import org.apache.hc.core5.util.Timeout;
|
||||||
|
|
||||||
|
@ -67,6 +68,32 @@ public interface AsyncClientConnectionOperator {
|
||||||
Object attachment,
|
Object attachment,
|
||||||
FutureCallback<ManagedAsyncClientConnection> callback);
|
FutureCallback<ManagedAsyncClientConnection> callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initiates operation to create a connection to the remote endpoint using
|
||||||
|
* the provided {@link ConnectionInitiator}.
|
||||||
|
*
|
||||||
|
* @param connectionInitiator the connection initiator.
|
||||||
|
* @param host the address of the opposite endpoint.
|
||||||
|
* @param localAddress the address of the local endpoint.
|
||||||
|
* @param connectTimeout the timeout of the connect operation.
|
||||||
|
* @param attachment the attachment, which can be any object representing custom parameter
|
||||||
|
* of the operation.
|
||||||
|
* @param context the execution context.
|
||||||
|
* @param callback the future result callback.
|
||||||
|
* @since 5.2
|
||||||
|
*/
|
||||||
|
default Future<ManagedAsyncClientConnection> connect(
|
||||||
|
ConnectionInitiator connectionInitiator,
|
||||||
|
HttpHost host,
|
||||||
|
SocketAddress localAddress,
|
||||||
|
Timeout connectTimeout,
|
||||||
|
Object attachment,
|
||||||
|
HttpContext context,
|
||||||
|
FutureCallback<ManagedAsyncClientConnection> callback) {
|
||||||
|
return connect(connectionInitiator, host, localAddress, connectTimeout,
|
||||||
|
attachment, callback);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upgrades transport security of the given managed connection
|
* Upgrades transport security of the given managed connection
|
||||||
* by using the TLS security protocol.
|
* by using the TLS security protocol.
|
||||||
|
@ -86,18 +113,35 @@ public interface AsyncClientConnectionOperator {
|
||||||
* @param host the address of the opposite endpoint with TLS security.
|
* @param host the address of the opposite endpoint with TLS security.
|
||||||
* @param attachment the attachment, which can be any object representing custom parameter
|
* @param attachment the attachment, which can be any object representing custom parameter
|
||||||
* of the operation.
|
* of the operation.
|
||||||
*
|
* @param context the execution context.
|
||||||
|
* @param callback the future result callback.
|
||||||
* @since 5.2
|
* @since 5.2
|
||||||
*/
|
*/
|
||||||
default void upgrade(
|
default void upgrade(
|
||||||
ManagedAsyncClientConnection conn,
|
ManagedAsyncClientConnection conn,
|
||||||
HttpHost host,
|
HttpHost host,
|
||||||
Object attachment,
|
Object attachment,
|
||||||
|
HttpContext context,
|
||||||
FutureCallback<ManagedAsyncClientConnection> callback) {
|
FutureCallback<ManagedAsyncClientConnection> callback) {
|
||||||
upgrade(conn, host, attachment);
|
upgrade(conn, host, attachment, context);
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback.completed(conn);
|
callback.completed(conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrades transport security of the given managed connection
|
||||||
|
* by using the TLS security protocol.
|
||||||
|
*
|
||||||
|
* @param conn the managed connection.
|
||||||
|
* @param host the address of the opposite endpoint with TLS security.
|
||||||
|
* @param attachment the attachment, which can be any object representing custom parameter
|
||||||
|
* of the operation.
|
||||||
|
* @param context the execution context.
|
||||||
|
* @since 5.2
|
||||||
|
*/
|
||||||
|
default void upgrade(ManagedAsyncClientConnection conn, HttpHost host, Object attachment, HttpContext context) {
|
||||||
|
upgrade(conn, host, attachment);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue