diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java index c9001b2fd..70d7a47ae 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java @@ -656,6 +656,7 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler try { final SimpleHttpResponse cacheResponse = generateCachedResponse(request, context, entry, now); final String exchangeId = ExecSupport.getNextExchangeId(); + context.setExchangeId(exchangeId); final AsyncExecChain.Scope fork = new AsyncExecChain.Scope( exchangeId, scope.route, diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java index 801f5a739..3f756fe84 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java @@ -278,6 +278,7 @@ class CachingExec extends CachingExecBase implements ExecChainHandler { && validityPolicy.mayReturnStaleWhileRevalidating(entry, now)) { LOG.debug("Serving stale with asynchronous revalidation"); final String exchangeId = ExecSupport.getNextExchangeId(); + context.setExchangeId(exchangeId); final ExecChain.Scope fork = new ExecChain.Scope( exchangeId, scope.route, diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalAbstractHttpAsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalAbstractHttpAsyncClient.java index c4fd29401..9496a32f5 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalAbstractHttpAsyncClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalAbstractHttpAsyncClient.java @@ -188,12 +188,12 @@ abstract class InternalAbstractHttpAsyncClient extends AbstractHttpAsyncClientBa httpHost != null ? httpHost : RoutingSupport.determineHost(request), clientContext); final String exchangeId = ExecSupport.getNextExchangeId(); + clientContext.setExchangeId(exchangeId); if (LOG.isDebugEnabled()) { LOG.debug("{} preparing request execution", exchangeId); } final AsyncExecRuntime execRuntime = createAsyncExecRuntime(pushHandlerFactory); - clientContext.setExchangeId(exchangeId); setupContext(clientContext); final AsyncExecChain.Scheduler scheduler = this::executeScheduled; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalH2AsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalH2AsyncClient.java index a88b26e53..a4bbee659 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalH2AsyncClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalH2AsyncClient.java @@ -213,7 +213,10 @@ public final class MinimalH2AsyncClient extends AbstractMinimalHttpAsyncClientBa }; if (LOG.isDebugEnabled()) { final String exchangeId = ExecSupport.getNextExchangeId(); - LOG.debug("{} executing message exchange {}", exchangeId, ConnPoolSupport.getId(session)); + clientContext.setExchangeId(exchangeId); + if (LOG.isDebugEnabled()) { + LOG.debug("{} executing message exchange {}", exchangeId, ConnPoolSupport.getId(session)); + } session.enqueue( new RequestExecutionCommand( new LoggingAsyncClientExchangeHandler(LOG, exchangeId, internalExchangeHandler), diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java index 0363c8669..6a7bb4e94 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java @@ -136,6 +136,7 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient final HttpRoute route = new HttpRoute(RoutingSupport.normalize(host, schemePortResolver)); final ComplexFuture resultFuture = new ComplexFuture<>(callback); final String exchangeId = ExecSupport.getNextExchangeId(); + clientContext.setExchangeId(exchangeId); final Future leaseFuture = manager.lease( exchangeId, route, @@ -445,16 +446,18 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient final HttpContext context) { Asserts.check(!released.get(), "Endpoint has already been released"); + final HttpClientContext clientContext = context != null ? HttpClientContext.adapt(context) : HttpClientContext.create(); final String exchangeId = ExecSupport.getNextExchangeId(); + clientContext.setExchangeId(exchangeId); if (LOG.isDebugEnabled()) { LOG.debug("{} executing message exchange {}", exchangeId, ConnPoolSupport.getId(connectionEndpoint)); connectionEndpoint.execute( exchangeId, new LoggingAsyncClientExchangeHandler(LOG, exchangeId, exchangeHandler), pushHandlerFactory, - context); + clientContext); } else { - connectionEndpoint.execute(exchangeId, exchangeHandler, context); + connectionEndpoint.execute(exchangeId, exchangeHandler, clientContext); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalHttpClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalHttpClient.java index da5a1886e..699784d28 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalHttpClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalHttpClient.java @@ -159,6 +159,7 @@ class InternalHttpClient extends CloseableHttpClient implements Configurable { target != null ? target : RoutingSupport.determineHost(request), localcontext); final String exchangeId = ExecSupport.getNextExchangeId(); + localcontext.setExchangeId(exchangeId); if (LOG.isDebugEnabled()) { LOG.debug("{} preparing request execution", exchangeId); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/MinimalHttpClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/MinimalHttpClient.java index b6f423021..24f8b9def 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/MinimalHttpClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/MinimalHttpClient.java @@ -132,6 +132,7 @@ public class MinimalHttpClient extends CloseableHttpClient { final HttpRoute route = new HttpRoute(RoutingSupport.normalize(target, schemePortResolver)); final String exchangeId = ExecSupport.getNextExchangeId(); + clientContext.setExchangeId(exchangeId); final ExecRuntime execRuntime = new InternalExecRuntime(LOG, connManager, requestExecutor, request instanceof CancellableDependency ? (CancellableDependency) request : null); try {