[
https://issues.apache.org/jira/browse/HTTPASYNC-144?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16639695#comment-16639695
]
Arkaitz Jimenez edited comment on HTTPASYNC-144 at 10/5/18 11:38 AM:
---------------------------------------------------------------------
Hey, Maybe I have misunderstood something let me go step by step.
# I create a new http client and I set a userTokenHandler that always returns
the same string
# I create a request and submit it without an httpclientcontext to the client
for first time.
# The Exchange Handler takes the userToken directly from the context I
supplied [here |#L375] without using the token handler, since I supplied no
HttpClientContext, thats a null.
# Since there is no available connections a new one gets created in the pool.
# Once the request is completed, the userContext for the connection is stored
[here|https://github.com/apache/httpasyncclient/blob/94b061bae5fe247cf3e69b487a78b457f20ca2e2/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java#L377]
and this time, the userTokenHandler is used, I understand this is the
connection context and whatever came from the userTokenHandler gets stored as
the connections user-token.
# I create a second request and submit it without a httpclientcontext.
# The Exchange handler takes null again as my userToken from [here |#L375].
# The Pool compares the token from all available connections to the request
token(null) in
[here|https://github.com/apache/httpcomponents-core/blob/975b373b6e0431ba8f58abe004039f925703a808/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java#L75]
and none match because all connections have the token supplied by the
userTokenHandler but all requests come with a null userToken extracted directly
from a null HttpClientContext never supplied.
# Connections are never reused.
The above just works if instead of using UserTokenHandler I just set the
user-token in the httpclientcontext and I use a httpclientcontext.
Hope this is clearer.
was (Author: arkaitzj):
Hey, Maybe I have misunderstood something let me go step by step.
# I create a new http client and I set a userTokenHandler that always returns
the same string
# I create a request and submit it without an httpclientcontext to the client
for first time.
# The Exchange Handler takes the userToken directly from the context I
supplied [here |#L375] without using the token handler, since I supplied no
HttpClientContext, thats a null.
# Since there is no available connections a new one gets created in the pool.
# Once the request is completed, the userContext for the connection is stored
[here|https://github.com/apache/httpasyncclient/blob/94b061bae5fe247cf3e69b487a78b457f20ca2e2/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java#L377]
and this time, the userTokenHandler is used, I understand this is the
connection context and whatever came from the userTokenHandler gets stored as
the connections user-token.
# I create a second request and submit it without a httpclientcontext.
# The Exchange handler takes null again as my userToken from [here |#L375].
# The Pool compares the token from all available connections to the request
token(null) in
[here|https://github.com/apache/httpcomponents-core/blob/975b373b6e0431ba8f58abe004039f925703a808/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java#L75]
and none match because all connections have the token supplied by the
userTokenHandler but all requests come with a null userToken extracted directly
# Connections are never reused.
The above just works if instead of using UserTokenHandler I just set the
user-token in the httpclientcontext and I use a httpclientcontext.
Hope this is clearer.
> AbstractClientExchangeHandler does not make use of UserTokenHandler
> -------------------------------------------------------------------
>
> Key: HTTPASYNC-144
> URL: https://issues.apache.org/jira/browse/HTTPASYNC-144
> Project: HttpComponents HttpAsyncClient
> Issue Type: Bug
> Reporter: Arkaitz Jimenez
> Priority: Major
>
> While writing an async client that does make use of SSL, user token handling
> is essential for proper use of pooling.
> I found 2 ways of passing the user token to the client:
> # Create a HttpClientContext and ctx.setUserToken(fixedString); and pass
> that context to execute(request, ctx);
> # Create the AsyncHttpClient via HttpAsyncClients.custom() and setting
> setUserTokenHandler((ctx)->fixedString);
> The first one works no problem.
> The second one fails because AbstractClientExchangeHandler queries the
> context userToken directly without using the UserTokenHandler in
> AbstractClientExchangeHandler::requestConnection.
> That means the userToken for the request will always be null and never match
> the one that is assigned to an open connection.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]