You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Oleg Kalnichevski <ol...@apache.org> on 2022/02/01 08:49:08 UTC

[ANNOUNCEMENT] HttpComponents Client 5.1.3 GA Released

The Apache HttpComponents project is pleased to announce 5.1.3 GA
release of HttpComponents HttpClient.

This release upgrades HttpCore to the latest 5.1 version and fixes a
number of issues found since release 5.1.2.

Please note that 5.1 is going to be the last release series compatible
with Java 1.7. HttpClient will require Java 8 as of 5.2.


Download - <http://hc.apache.org/downloads.cgi>
Release notes - <
https://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-5.1.x.txt
HttpComponents site - <http://hc.apache.org/>

About HttpComponents HttpClient

The Hyper-Text Transfer Protocol (HTTP) is perhaps the most
significantprotocol used on the Internet today. Web services, network-
enabled appliances and the growth of network computing continue to
expand the role of the HTTP protocol beyond user-driven web browsers,
while increasing the number of applications that require HTTP support.

Although the java.net package provides basic functionality for
accessing resources via HTTP, it doesn't provide the full flexibility
or functionality needed by many applications. HttpClient seeks to fill
this voidby providing an efficient, up-to-date, and feature-rich
package implementing the client side of the most recent HTTP standards
and recommendations.

Designed for extension while providing robust support for the base HTTP
protocol, HttpClient may be of interest to anyone building HTTP-aware
client applications such as web browsers, web service clients, or
systems that leverage or extend the HTTP protocol for distributed
communication.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: AW: Preemptive authentication in Http Client 5 Async

Posted by Oleg Kalnichevski <ol...@apache.org>.

On 2/9/2022 5:15 PM, Naber, Peter wrote:
> Hi,
> 
> I use the HttpCacheContext but I think with the httpclient5 the preemtive authentication is implemented the same way.
> 
> 
> 	public HttpCacheContext getHttpCacheContext(final URL aURL) throws Exception {
> 		final HttpHost targetHost = new HttpHost(aURL.getProtocol(), aURL.getHost(), aURL.getPort()==-1?aURL.getDefaultPort():aURL.getPort());
> 		final HttpCacheContext context = HttpCacheContext.create();
> 		final AuthCache authCache = new BasicAuthCache();
> 		if (this.getPreAuth() && this.getUser()!= null && this.getPassword()!=null ) {
> 			if (this.getAuthScheme() == AuthScheme.BASIC) {
> 				final BasicScheme basicAuth = new BasicScheme();
> 				basicAuth.initPreemptive(
> 						new UsernamePasswordCredentials(this.getUser(), this.getPassword().toCharArray()));
> 				authCache.put(targetHost, basicAuth);
> 			} else if (this.getAuthScheme() == AuthScheme.DIGEST) {
> 				final DigestScheme digestScheme = new DigestScheme();
> 				final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(this.replace(this.getUser()),
> 						this.replace(this.getPassword()).toCharArray());
> 				digestScheme.initPreemptive(creds, UUID.randomUUID().toString().replaceAll("-", ""), "vectorius");
> 				authCache.put(targetHost, digestScheme);
> 			}
> 			context.setAuthCache(authCache);
> 		}
> 		context.setCredentialsProvider(this.getCredentialsProvider(aURL));
> 		return context;
> 	}
> 
> regards,
> 
> Peter
> 

Christophe

If you still think there is a problem with authentication state caching 
in HttpClient 5, please produce two wire / context logs, one generated 
with HttpClient 4 and another one with HttpClient 5. Please do redact 
security sensitive bits but please keep the logs complete.

Oleg


> -----Ursprüngliche Nachricht-----
> Von: Christophe Darville <cd...@internetvista.com>
> Gesendet: Mittwoch, 9. Februar 2022 17:00
> An: HttpClient User Discussion <ht...@hc.apache.org>
> Betreff: Preemptive authentication in Http Client 5 Async
> 
> Hi,
> 
> I am trying to make preemptive authentication in HttpClient 5 Async mode using the following code, but I does not work, first request is still without authentication and the authentication is done on the second request :
> 
> 	HttpClientContext httpContext = HttpClientContext.create();
> 	CredentialsProvider credentialsProvider = getCredentialsProvider();
> 	if (preemptive) {
> 		URI uri = URI.create(url);
> 		HttpHost targetHost = new HttpHost(uri.getScheme(), uri.getHost(), uri.getPort());
> 		AuthCache authCache = new BasicAuthCache();
> 		BasicScheme basicAuth = new BasicScheme();
> 		authCache.put(targetHost, basicAuth);
> 		httpContext.setAuthCache(authCache);
> 	}
> 	httpContext.setCredentialsProvider(credentialsProvider);
> 
> This code was working in httpClient 4. Any suggestion on how to make preemptive authentication work in HttpClient5 Async ?
> 
> Thank you,
> Christophe
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


AW: Preemptive authentication in Http Client 5 Async

Posted by "Naber, Peter" <pe...@alfa.de>.
Damn,

That's right, there was something else. It took me days to figure it out.
Sorry, I had already completely forgotten about it.

Regards,

Peter
-----Ursprüngliche Nachricht-----
Von: Christophe Darville <cd...@internetvista.com> 
Gesendet: Donnerstag, 10. Februar 2022 16:02
An: HttpClient User Discussion <ht...@hc.apache.org>
Betreff: Re: Preemptive authentication in Http Client 5 Async

Thank you Oleg, it works for me with your code

Regards,
Christophe

> On 10 Feb 2022, at 15:18, Oleg Kalnichevski <ol...@apache.org> wrote:
> 
> 
> 
> On 2/10/2022 2:16 PM, Oleg Kalnichevski wrote:
>> On 2/10/2022 10:43 AM, Christophe Darville wrote:
>>> Thank you very much Peter. I missed the point that HttpCacheContext was extending HttpClientContext.
>>> 
>>> Unfortunately, httpClient5 Async (CloseableHttpAsyncClient) is not sending credentials at first request even with your code (the same as mine except using HttpCacheContext in place of HttpClientContext).
>>> 
>>> I will check with Oleg on the way to produce logs.
>>> 
>> The issue you are having may be the defect just reported as HTTPCLIENT-2203. I am looking into it. There is no need for wire logs anymore, because I have a local reproducer.
>> https://issues.apache.org/jira/browse/HTTPCLIENT-2203
>> Oleg
> 
> What is broken is the target host port normalization. When using explicitly defined ports the preemptive authentication works just fine. Please note the request URI contains a port in it.
> 
> This example works just fine for me:
> 
> ----
> public class AsyncPreemptiveBasicClientAuthentication {
> 
>    public static void main(final String[] args) throws Exception {
>        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
>        credsProvider.setCredentials(
>                new AuthScope("httpbin.org", 80),
>                new UsernamePasswordCredentials("user", "passwd".toCharArray()));
>        final CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
>                .setDefaultCredentialsProvider(credsProvider)
>                .build();
>        httpclient.start();
> 
>        // Generate Basic scheme object and add it to the local auth cache
>        final BasicScheme basicAuth = new BasicScheme();
>        basicAuth.initPreemptive(new 
> UsernamePasswordCredentials("user", "passwd".toCharArray()));
> 
>        final HttpHost target = new HttpHost("http", "httpbin.org", 
> 80);
> 
>        // Add AuthCache to the execution context
>        final HttpClientContext localContext = HttpClientContext.create();
>        localContext.resetAuthExchange(target, basicAuth);
> 
>        final SimpleHttpRequest request = SimpleRequestBuilder.get("http://httpbin.org:80/basic-auth/user/passwd")
>                .build();
> 
>        System.out.println("Executing request " + request);
>        for (int i = 0; i < 3; i++) {
>            final Future<SimpleHttpResponse> future = httpclient.execute(
>                    SimpleRequestProducer.create(request),
>                    SimpleResponseConsumer.create(),
>                    localContext,
>                    new FutureCallback<SimpleHttpResponse>() {
> 
>                        @Override
>                        public void completed(final SimpleHttpResponse response) {
>                            System.out.println(request + "->" + new StatusLine(response));
>                            System.out.println(response.getBody());
>                        }
> 
>                        @Override
>                        public void failed(final Exception ex) {
>                            System.out.println(request + "->" + ex);
>                        }
> 
>                        @Override
>                        public void cancelled() {
>                            System.out.println(request + " cancelled");
>                        }
> 
>                    });
>            future.get();
>        }
> 
>        System.out.println("Shutting down");
>        httpclient.close(CloseMode.GRACEFUL);
>    }
> }
> 
> ---
> Executing request GET http://httpbin.org:80/basic-auth/user/passwd
> 2022-02-10 15:10:47,511 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsync
> Client] ex-0000000001 preparing request execution
> 2022-02-10 15:10:47,520 DEBUG 
> [main][org.apache.hc.client5.http.protocol.RequestAddCookies] 
> ex-0000000001 Cookie spec selected: strict
> 2022-02-10 15:10:47,524 DEBUG 
> [main][org.apache.hc.client5.http.protocol.RequestAuthCache] 
> ex-0000000001 Auth cache not set in the context
> 2022-02-10 15:10:47,524 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] 
> ex-0000000001 target auth state: UNCHALLENGED
> 2022-02-10 15:10:47,530 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] 
> ex-0000000001 proxy auth state: UNCHALLENGED
> 2022-02-10 15:10:47,532 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.AsyncConnectExec] 
> ex-0000000001 acquiring connection with route 
> {}->http://httpbin.org:80
> 2022-02-10 15:10:47,533 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
> ex-0000000001 acquiring endpoint (3 MINUTES)
> 2022-02-10 15:10:47,534 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] ex-0000000001 endpoint lease request (3 MINUTES) [route: 
> {}->http://httpbin.org:80][total available: 0; route allocated: 0 of 
> 5; total allocated: 0 of 25]
> 2022-02-10 15:10:47,538 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] ex-0000000001 endpoint leased [route: 
> {}->http://httpbin.org:80][total available: 0; route allocated: 1 of 
> 5; total allocated: 1 of 25]
> 2022-02-10 15:10:47,538 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] ex-0000000001 acquired ep-0000000000
> 2022-02-10 15:10:47,539 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
> ex-0000000001 acquired endpoint ep-0000000000
> 2022-02-10 15:10:47,539 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
> ep-0000000000 connecting endpoint (3 MINUTES)
> 2022-02-10 15:10:47,539 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] ep-0000000000 connecting endpoint to http://httpbin.org:80 
> (3 MINUTES)
> 2022-02-10 15:10:47,541 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester
> ] http://httpbin.org:80 resolving remote address
> 2022-02-10 15:10:47,541 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester
> ] http://httpbin.org:80 resolved to [httpbin.org/54.221.78.73, 
> httpbin.org/3.209.99.235, httpbin.org/52.55.211.119, 
> httpbin.org/35.171.190.227]
> 2022-02-10 15:10:47,542 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester
> ] http://httpbin.org:80 connecting null to httpbin.org/54.221.78.73:80 
> (3 MINUTES)
> 2022-02-10 15:10:47,755 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.MultihomeI
> OSessionRequester] http://httpbin.org:80 connected c-0000000000 
> /192.168.8.102:49873->httpbin.org/54.221.78.73:80
> 2022-02-10 15:10:47,765 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsy
> ncClientConnectionManager] ep-0000000000 connected c-0000000000
> 2022-02-10 15:10:47,765 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.Internal
> HttpAsyncClient] ep-0000000000 endpoint connected
> 2022-02-10 15:10:47,765 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.AsyncCon
> nectExec] ex-0000000001 connected to target
> 2022-02-10 15:10:47,765 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.AsyncCon
> nectExec] ex-0000000001 route fully established
> 2022-02-10 15:10:47,766 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyn
> cMainClientExec] ex-0000000001 executing GET /basic-auth/user/passwd 
> HTTP/1.1
> 2022-02-10 15:10:47,769 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.Internal
> HttpAsyncClient] ep-0000000000 start execution ex-0000000001
> 2022-02-10 15:10:47,769 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsy
> ncClientConnectionManager] ep-0000000000 executing exchange 
> ex-0000000001 over c-0000000000
> 2022-02-10 15:10:47,771 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.DefaultMan
> agedAsyncClientConnection] c-0000000000 RequestExecutionCommand with 
> NORMAL priority
> 2022-02-10 15:10:47,792 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyn
> cMainClientExec] ex-0000000001 send request GET 
> /basic-auth/user/passwd HTTP/1.1, null entity
> 2022-02-10 15:10:47,792 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> GET /basic-auth/user/passwd HTTP/1.1
> 2022-02-10 15:10:47,792 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> User-Agent: Apache-HttpAsyncClient/5.1.4-SNAPSHOT 
> (Java/1.8.0_272)
> 2022-02-10 15:10:47,792 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> Authorization: Basic dXNlcjpwYXNzd2Q=
> 2022-02-10 15:10:47,792 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> Host: httpbin.org:80
> 2022-02-10 15:10:47,793 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> Connection: keep-alive
> 2022-02-10 15:10:47,946 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << HTTP/1.1 200 OK
> 2022-02-10 15:10:47,946 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Date: Thu, 10 Feb 2022 14:10:48 GMT
> 2022-02-10 15:10:47,946 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Content-Type: application/json
> 2022-02-10 15:10:47,946 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Content-Length: 47
> 2022-02-10 15:10:47,946 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Connection: keep-alive
> 2022-02-10 15:10:47,947 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Server: gunicorn/19.9.0
> 2022-02-10 15:10:47,947 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Access-Control-Allow-Origin: *
> 2022-02-10 15:10:47,947 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Access-Control-Allow-Credentials: true
> 2022-02-10 15:10:47,949 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyn
> cMainClientExec] ex-0000000001 consume response HTTP/1.1 200 OK, 
> entity len 47
> 2022-02-10 15:10:47,959 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyn
> cMainClientExec] ex-0000000001 consume response data, len 47 bytes
> 2022-02-10 15:10:47,959 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyn
> cMainClientExec] ex-0000000001 end of response data GET 
> http://httpbin.org:80/basic-auth/user/passwd->HTTP/1.1 200 OK 
> SimpleBody{content length=47, content type=application/json}
> 2022-02-10 15:10:47,962 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsync
> Client] ex-0000000002 preparing request execution
> 2022-02-10 15:10:47,962 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.Internal
> AbstractHttpAsyncClient] ex-0000000001 message exchange successfully 
> completed
> 2022-02-10 15:10:47,962 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.Internal
> HttpAsyncClient] ep-0000000000 releasing valid endpoint
> 2022-02-10 15:10:47,962 DEBUG 
> [main][org.apache.hc.client5.http.protocol.RequestAddCookies] 
> ex-0000000002 Cookie spec selected: strict
> 2022-02-10 15:10:47,962 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsy
> ncClientConnectionManager] ep-0000000000 releasing endpoint
> 2022-02-10 15:10:47,962 DEBUG 
> [main][org.apache.hc.client5.http.protocol.RequestAuthCache] 
> ex-0000000002 Auth cache not set in the context
> 2022-02-10 15:10:47,962 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] 
> ex-0000000002 target auth state: UNCHALLENGED
> 2022-02-10 15:10:47,962 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsy
> ncClientConnectionManager] ep-0000000000 connection c-0000000000 can 
> be kept alive for 3 MINUTES
> 2022-02-10 15:10:47,962 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] 
> ex-0000000002 proxy auth state: UNCHALLENGED
> 2022-02-10 15:10:47,962 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.AsyncConnectExec] 
> ex-0000000002 acquiring connection with route 
> {}->http://httpbin.org:80
> 2022-02-10 15:10:47,962 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
> ex-0000000002 acquiring endpoint (3 MINUTES)
> 2022-02-10 15:10:47,963 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsy
> ncClientConnectionManager] ep-0000000000 connection released [route: 
> {}->http://httpbin.org:80][total available: 1; route allocated: 1 of 
> 5; total allocated: 1 of 25]
> 2022-02-10 15:10:47,963 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] ex-0000000002 endpoint lease request (3 MINUTES) [route: 
> {}->http://httpbin.org:80][total available: 1; route allocated: 1 of 
> 5; total allocated: 1 of 25]
> 2022-02-10 15:10:47,963 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.Internal
> HttpAsyncClient] c-0000000000 Connection is kept alive
> 2022-02-10 15:10:47,963 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] ex-0000000002 endpoint leased [route: 
> {}->http://httpbin.org:80][total available: 0; route allocated: 1 of 
> 5; total allocated: 1 of 25]
> 2022-02-10 15:10:47,963 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] ex-0000000002 acquired ep-0000000001
> 2022-02-10 15:10:47,963 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
> ex-0000000002 acquired endpoint ep-0000000001
> 2022-02-10 15:10:47,963 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
> ex-0000000002 executing GET /basic-auth/user/passwd HTTP/1.1
> 2022-02-10 15:10:47,964 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
> ep-0000000001 start execution ex-0000000002
> 2022-02-10 15:10:47,964 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] ep-0000000001 executing exchange ex-0000000002 over 
> c-0000000000
> 2022-02-10 15:10:47,964 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.DefaultManagedAsyncClientCo
> nnection] c-0000000000 RequestExecutionCommand with NORMAL priority
> 2022-02-10 15:10:47,964 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyn
> cMainClientExec] ex-0000000002 send request GET 
> /basic-auth/user/passwd HTTP/1.1, null entity
> 2022-02-10 15:10:47,964 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> GET /basic-auth/user/passwd HTTP/1.1
> 2022-02-10 15:10:47,964 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> User-Agent: Apache-HttpAsyncClient/5.1.4-SNAPSHOT 
> (Java/1.8.0_272)
> 2022-02-10 15:10:47,964 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> Authorization: Basic dXNlcjpwYXNzd2Q=
> 2022-02-10 15:10:47,965 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> Host: httpbin.org:80
> 2022-02-10 15:10:47,965 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> Connection: keep-alive
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << HTTP/1.1 200 OK
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Date: Thu, 10 Feb 2022 14:10:48 GMT
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Content-Type: application/json
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Content-Length: 47
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Connection: keep-alive
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Server: gunicorn/19.9.0
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Access-Control-Allow-Origin: *
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Access-Control-Allow-Credentials: true
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyn
> cMainClientExec] ex-0000000002 consume response HTTP/1.1 200 OK, 
> entity len 47
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyn
> cMainClientExec] ex-0000000002 consume response data, len 47 bytes
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyn
> cMainClientExec] ex-0000000002 end of response data GET 
> http://httpbin.org:80/basic-auth/user/passwd->HTTP/1.1 200 OK 
> SimpleBody{content length=47, content type=application/json}
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.Internal
> AbstractHttpAsyncClient] ex-0000000002 message exchange successfully 
> completed
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.Internal
> HttpAsyncClient] ep-0000000001 releasing valid endpoint
> 2022-02-10 15:10:48,099 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsync
> Client] ex-0000000003 preparing request execution
> 2022-02-10 15:10:48,099 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsy
> ncClientConnectionManager] ep-0000000001 releasing endpoint
> 2022-02-10 15:10:48,100 DEBUG 
> [main][org.apache.hc.client5.http.protocol.RequestAddCookies] 
> ex-0000000003 Cookie spec selected: strict
> 2022-02-10 15:10:48,100 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsy
> ncClientConnectionManager] ep-0000000001 connection c-0000000000 can 
> be kept alive for 3 MINUTES
> 2022-02-10 15:10:48,100 DEBUG 
> [main][org.apache.hc.client5.http.protocol.RequestAuthCache] 
> ex-0000000003 Auth cache not set in the context
> 2022-02-10 15:10:48,100 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsy
> ncClientConnectionManager] ep-0000000001 connection released [route: 
> {}->http://httpbin.org:80][total available: 1; route allocated: 1 of 
> 5; total allocated: 1 of 25]
> 2022-02-10 15:10:48,100 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] 
> ex-0000000003 target auth state: UNCHALLENGED
> 2022-02-10 15:10:48,100 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.Internal
> HttpAsyncClient] c-0000000000 Connection is kept alive
> 2022-02-10 15:10:48,100 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] 
> ex-0000000003 proxy auth state: UNCHALLENGED
> 2022-02-10 15:10:48,100 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.AsyncConnectExec] 
> ex-0000000003 acquiring connection with route 
> {}->http://httpbin.org:80
> 2022-02-10 15:10:48,100 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
> ex-0000000003 acquiring endpoint (3 MINUTES)
> 2022-02-10 15:10:48,100 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] ex-0000000003 endpoint lease request (3 MINUTES) [route: 
> {}->http://httpbin.org:80][total available: 1; route allocated: 1 of 
> 5; total allocated: 1 of 25]
> 2022-02-10 15:10:48,101 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] ex-0000000003 endpoint leased [route: 
> {}->http://httpbin.org:80][total available: 0; route allocated: 1 of 
> 5; total allocated: 1 of 25]
> 2022-02-10 15:10:48,101 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] ex-0000000003 acquired ep-0000000002
> 2022-02-10 15:10:48,101 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
> ex-0000000003 acquired endpoint ep-0000000002
> 2022-02-10 15:10:48,101 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
> ex-0000000003 executing GET /basic-auth/user/passwd HTTP/1.1
> 2022-02-10 15:10:48,101 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
> ep-0000000002 start execution ex-0000000003
> 2022-02-10 15:10:48,101 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] ep-0000000002 executing exchange ex-0000000003 over 
> c-0000000000
> 2022-02-10 15:10:48,101 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.DefaultManagedAsyncClientCo
> nnection] c-0000000000 RequestExecutionCommand with NORMAL priority
> 2022-02-10 15:10:48,102 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyn
> cMainClientExec] ex-0000000003 send request GET 
> /basic-auth/user/passwd HTTP/1.1, null entity
> 2022-02-10 15:10:48,102 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> GET /basic-auth/user/passwd HTTP/1.1
> 2022-02-10 15:10:48,102 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> User-Agent: Apache-HttpAsyncClient/5.1.4-SNAPSHOT 
> (Java/1.8.0_272)
> 2022-02-10 15:10:48,102 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> Authorization: Basic dXNlcjpwYXNzd2Q=
> 2022-02-10 15:10:48,102 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> Host: httpbin.org:80
> 2022-02-10 15:10:48,102 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 >> Connection: keep-alive
> 2022-02-10 15:10:48,257 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << HTTP/1.1 200 OK
> 2022-02-10 15:10:48,257 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Date: Thu, 10 Feb 2022 14:10:48 GMT
> 2022-02-10 15:10:48,257 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Content-Type: application/json
> 2022-02-10 15:10:48,257 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Content-Length: 47
> 2022-02-10 15:10:48,257 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Connection: keep-alive
> 2022-02-10 15:10:48,258 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Server: gunicorn/19.9.0
> 2022-02-10 15:10:48,258 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Access-Control-Allow-Origin: *
> 2022-02-10 15:10:48,258 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.headers] 
> c-0000000000 << Access-Control-Allow-Credentials: true
> 2022-02-10 15:10:48,258 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyn
> cMainClientExec] ex-0000000003 consume response HTTP/1.1 200 OK, 
> entity len 47
> 2022-02-10 15:10:48,258 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyn
> cMainClientExec] ex-0000000003 consume response data, len 47 bytes
> 2022-02-10 15:10:48,258 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyn
> cMainClientExec] ex-0000000003 end of response data GET 
> http://httpbin.org:80/basic-auth/user/passwd->HTTP/1.1 200 OK Shutting 
> down SimpleBody{content length=47, content type=application/json}
> 2022-02-10 15:10:48,258 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.Internal
> AbstractHttpAsyncClient] ex-0000000003 message exchange successfully 
> completed
> 2022-02-10 15:10:48,258 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.Internal
> HttpAsyncClient] ep-0000000002 releasing valid endpoint
> 2022-02-10 15:10:48,258 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsy
> ncClientConnectionManager] ep-0000000002 releasing endpoint
> 2022-02-10 15:10:48,258 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsy
> ncClientConnectionManager] ep-0000000002 connection c-0000000000 can 
> be kept alive for 3 MINUTES
> 2022-02-10 15:10:48,259 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsy
> ncClientConnectionManager] ep-0000000002 connection released [route: 
> {}->http://httpbin.org:80][total available: 1; route allocated: 1 of 
> 5; total allocated: 1 of 25]
> 2022-02-10 15:10:48,259 DEBUG 
> [main][org.apache.hc.client5.http.impl.async.AbstractHttpAsyncClientBa
> se] Shutdown GRACEFUL
> 2022-02-10 15:10:48,259 DEBUG 
> [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.Internal
> HttpAsyncClient] c-0000000000 Connection is kept alive
> 2022-02-10 15:10:48,262 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] Shutdown connection pool GRACEFUL
> 2022-02-10 15:10:48,262 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.DefaultManagedAsyncClientCo
> nnection] c-0000000000 Shutdown connection GRACEFUL
> 2022-02-10 15:10:48,263 DEBUG 
> [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectio
> nManager] Connection pool shut down
> 
> 
> 
> 
> 
> 
>>> Regards,
>>> Christophe
>>> 
>>>> On 10 Feb 2022, at 10:26, Naber, Peter <pe...@alfa.de> wrote:
>>>> 
>>>> Hi,
>>>> 
>>>> ok, than a little bit more code 😊
>>>> 
>>>> 
>>>>     public CloseableHttpClient getHttpClient() throws IOException, NoSuchAlgorithmException {
>>>>         final SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).build();
>>>>         String tlsString = System.getProperty("https.protocols");
>>>>         if ((tlsString == null) || tlsString.isEmpty()) {
>>>>             tlsString = "";
>>>>             final String[] protocols = SSLContext.getDefault().getSupportedSSLParameters().getProtocols();
>>>>             for (final String protocol : protocols) {
>>>>                 if (protocol.startsWith("TLS")) {
>>>>                     tlsString = tlsString.length() == 0 ? tlsString + protocol : tlsString + "," + protocol;
>>>>                 }
>>>>             }
>>>>         }
>>>>         final PoolingHttpClientConnectionManager connManager = PoolingHttpClientConnectionManagerBuilder.create()
>>>>                .setConnectionFactory(this.connFactory).setDnsResolver(new SystemDefaultDnsResolver())
>>>>                .setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create().setSslContext(this.sslContext) 
>>>>                         .setTlsVersions(tlsString.split(",")).build())
>>>>                
>>>> .setDefaultSocketConfig(socketConfig).setValidateAfterInactivity(Ti
>>>> meValue.ofSeconds(10L)).build();
>>>> 
>>>>         this.defaultRequestConfig = RequestConfig.custom().setCookieSpec(StandardCookieSpec.RELAXED)
>>>>                .setAuthenticationEnabled(true).setExpectContinueEnabled(false).setContentCompressionEnabled(true) 
>>>>                .setConnectionRequestTimeout(Timeout.ofMilliseconds(this.getConnectionRequestTimeout())) 
>>>>                .setConnectTimeout(Timeout.ofMilliseconds(this.getConnectTimeout()))
>>>>                .setResponseTimeout(Timeout.ofMilliseconds(this.getSocketTimeout()))
>>>>                .setRedirectsEnabled(this.getRedirect()).setCircularRedirectsAllowed(false) 
>>>>                 .setTargetPreferredAuthSchemes(
>>>>                         Arrays.asList(StandardAuthScheme.DIGEST, StandardAuthScheme.BASIC, StandardAuthScheme.NTLM))
>>>>                
>>>> .setProxyPreferredAuthSchemes(Arrays.asList(StandardAuthScheme.BASI
>>>> C, StandardAuthScheme.NTLM)).build();
>>>> 
>>>>         final RedirectStrategy redirectStrategy = new 
>>>> DefaultRedirectStrategy();
>>>> 
>>>>         final CachingHttpClientBuilder cachingHttpClients = CachingHttpClients.custom();
>>>>        cachingHttpClients.setCacheConfig(this.getHttpCacheConfig().getCacheConfig()).setConnectionManager(connManager) 
>>>>                .setRedirectStrategy(redirectStrategy).setDefaultCookieStore(this.getCookieStore()) 
>>>>                 .setDefaultRequestConfig(this.defaultRequestConfig);
>>>>         if (this.getHttpCacheConfig().getCacheFileName() != null) {
>>>>             cachingHttpClients.setCacheDir(new File(this.getHttpCacheConfig().getCacheFileName()));
>>>>         }
>>>> 
>>>>         final HttpClientBuilder httpBuild = cachingHttpClients;
>>>>         httpBuild.addExecInterceptorBefore("test", "compress", new ContentCompressionExec());
>>>>         if (this.getHttpProxy() != null) {
>>>>             final HttpProxy hproxy = this.getHttpProxy();
>>>>             this.proxy = new HttpHost(hproxy.getHost(), hproxy.getPort());
>>>>             httpBuild.setProxy(this.proxy);
>>>>             httpBuild.setRoutePlanner(new DefaultProxyRoutePlanner(this.proxy) {
>>>>                 @Override
>>>>                 protected HttpHost determineProxy(final HttpHost target, final HttpContext context)
>>>>                         throws HttpException {
>>>> 
>>>>                     if (ExecuteHttp.this.httpProxy == null) {
>>>>                         return null;
>>>>                     }
>>>>                     if (ExecuteHttp.this.httpProxy.getProxyNonHosts() != null) {
>>>>                         for (final String proxy1 : ExecuteHttp.this.httpProxy.getProxyNonHosts()) {
>>>>                             try {
>>>>                                 if (target.getHostName().matches(proxy1)) {
>>>>                                     return null;
>>>>                                 }
>>>>                             } catch (final Exception e) {
>>>>                                 e.printStackTrace();
>>>>                             }
>>>>                         }
>>>>                     }
>>>>                     return super.determineProxy(target, context);
>>>>                 }
>>>>             });
>>>>         }
>>>>         final CloseableHttpClient httpClient = httpBuild.build();
>>>> 
>>>>         return httpClient;
>>>>     }
>>>> 
>>>> 
>>>>     private void basicRequest(final String basicCommand, final String urls1) throws Exception {
>>>>         int status = 0;
>>>>         String returnString = "";
>>>>         try (CloseableHttpClient httpClient = this.getHttpClient()) {
>>>>             for (final String url : this.getURL(this.replace(urls1))) {
>>>>                 final HttpUriRequestBase basicRequest = new HttpUriRequestBase(basicCommand, new URI(url));
>>>>                 final URL aURL = new URL(url);
>>>> 
>>>>                 this.setHeaders(basicRequest);
>>>>                 final HttpCacheContext context = this.getHttpCacheContext(aURL);
>>>>                 this.log.info("[basicRequest]  " + basicRequest.getRequestUri());
>>>>                 final CloseableHttpResponse response = 
>>>> httpClient.execute(basicRequest, context);
>>>> 
>>>>                 try {
>>>>                     status = response.getCode();
>>>>                     ...
>>>> 
>>>> Regards,
>>>> 
>>>> Peter
>>>> 
>>>> -----Ursprüngliche Nachricht-----
>>>> Von: Christophe Darville <cd...@internetvista.com>
>>>> Gesendet: Donnerstag, 10. Februar 2022 08:42
>>>> An: HttpClient User Discussion <ht...@hc.apache.org>
>>>> Betreff: Re: Preemptive authentication in Http Client 5 Async
>>>> 
>>>> Hi Peter,
>>>> 
>>>> Thank you for your answer. Once you get an HttpCacheContext instance, how do you link it with the request ? I see no setter on the HttpClient nor on the RequestConfig.
>>>> 
>>>> Regards,
>>>> Christophe
>>>> 
>>>>> On 9 Feb 2022, at 17:15, Naber, Peter <pe...@alfa.de> wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> I use the HttpCacheContext but I think with the httpclient5 the preemtive authentication is implemented the same way.
>>>>> 
>>>>> 
>>>>>     public HttpCacheContext getHttpCacheContext(final URL aURL) throws Exception {
>>>>>         final HttpHost targetHost = new HttpHost(aURL.getProtocol(), aURL.getHost(), aURL.getPort()==-1?aURL.getDefaultPort():aURL.getPort());
>>>>>         final HttpCacheContext context = HttpCacheContext.create();
>>>>>         final AuthCache authCache = new BasicAuthCache();
>>>>>         if (this.getPreAuth() && this.getUser()!= null && this.getPassword()!=null ) {
>>>>>             if (this.getAuthScheme() == AuthScheme.BASIC) {
>>>>>                 final BasicScheme basicAuth = new BasicScheme();
>>>>>                 basicAuth.initPreemptive(
>>>>>                         new UsernamePasswordCredentials(this.getUser(), this.getPassword().toCharArray()));
>>>>>                 authCache.put(targetHost, basicAuth);
>>>>>             } else if (this.getAuthScheme() == AuthScheme.DIGEST) {
>>>>>                 final DigestScheme digestScheme = new DigestScheme();
>>>>>                 final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(this.replace(this.getUser()),
>>>>>                        this.replace(this.getPassword()).toCharArray());
>>>>>                 digestScheme.initPreemptive(creds, UUID.randomUUID().toString().replaceAll("-", ""), "vectorius");
>>>>>                 authCache.put(targetHost, digestScheme);
>>>>>             }
>>>>>             context.setAuthCache(authCache);
>>>>>         }
>>>>>        context.setCredentialsProvider(this.getCredentialsProvider(aURL));
>>>>>         return context;
>>>>>     }
>>>>> 
>>>>> regards,
>>>>> 
>>>>> Peter
>>>>> 
>>>>> -----Ursprüngliche Nachricht-----
>>>>> Von: Christophe Darville <cd...@internetvista.com>
>>>>> Gesendet: Mittwoch, 9. Februar 2022 17:00
>>>>> An: HttpClient User Discussion <ht...@hc.apache.org>
>>>>> Betreff: Preemptive authentication in Http Client 5 Async
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> I am trying to make preemptive authentication in HttpClient 5 Async mode using the following code, but I does not work, first request is still without authentication and the authentication is done on the second request :
>>>>> 
>>>>>     HttpClientContext httpContext = HttpClientContext.create();
>>>>>     CredentialsProvider credentialsProvider = getCredentialsProvider();
>>>>>     if (preemptive) {
>>>>>         URI uri = URI.create(url);
>>>>>         HttpHost targetHost = new HttpHost(uri.getScheme(), uri.getHost(), uri.getPort());
>>>>>         AuthCache authCache = new BasicAuthCache();
>>>>>         BasicScheme basicAuth = new BasicScheme();
>>>>>         authCache.put(targetHost, basicAuth);
>>>>>         httpContext.setAuthCache(authCache);
>>>>>     }
>>>>>     httpContext.setCredentialsProvider(credentialsProvider);
>>>>> 
>>>>> This code was working in httpClient 4. Any suggestion on how to make preemptive authentication work in HttpClient5 Async ?
>>>>> 
>>>>> Thank you,
>>>>> Christophe
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> ------------------------------------------------------------------
>>>>> --- To unsubscribe, e-mail: 
>>>>> httpclient-users-unsubscribe@hc.apache.org
>>>>> For additional commands, e-mail: 
>>>>> httpclient-users-help@hc.apache.org
>>>>> 
>>>> 
>>>> 
>>>> -------------------------------------------------------------------
>>>> -- To unsubscribe, e-mail: 
>>>> httpclient-users-unsubscribe@hc.apache.org
>>>> For additional commands, e-mail: 
>>>> httpclient-users-help@hc.apache.org
>>>> 
>>>> 
>>>> -------------------------------------------------------------------
>>>> -- To unsubscribe, e-mail: 
>>>> httpclient-users-unsubscribe@hc.apache.org
>>>> For additional commands, e-mail: 
>>>> httpclient-users-help@hc.apache.org
>>>> 
>>> 
>>> 
>>> --------------------------------------------------------------------
>>> - To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Preemptive authentication in Http Client 5 Async

Posted by Christophe Darville <cd...@internetvista.com>.
Thank you Oleg, it works for me with your code

Regards,
Christophe

> On 10 Feb 2022, at 15:18, Oleg Kalnichevski <ol...@apache.org> wrote:
> 
> 
> 
> On 2/10/2022 2:16 PM, Oleg Kalnichevski wrote:
>> On 2/10/2022 10:43 AM, Christophe Darville wrote:
>>> Thank you very much Peter. I missed the point that HttpCacheContext was extending HttpClientContext.
>>> 
>>> Unfortunately, httpClient5 Async (CloseableHttpAsyncClient) is not sending credentials at first request even with your code (the same as mine except using HttpCacheContext in place of HttpClientContext).
>>> 
>>> I will check with Oleg on the way to produce logs.
>>> 
>> The issue you are having may be the defect just reported as HTTPCLIENT-2203. I am looking into it. There is no need for wire logs anymore, because I have a local reproducer.
>> https://issues.apache.org/jira/browse/HTTPCLIENT-2203
>> Oleg
> 
> What is broken is the target host port normalization. When using explicitly defined ports the preemptive authentication works just fine. Please note the request URI contains a port in it.
> 
> This example works just fine for me:
> 
> ----
> public class AsyncPreemptiveBasicClientAuthentication {
> 
>    public static void main(final String[] args) throws Exception {
>        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
>        credsProvider.setCredentials(
>                new AuthScope("httpbin.org", 80),
>                new UsernamePasswordCredentials("user", "passwd".toCharArray()));
>        final CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
>                .setDefaultCredentialsProvider(credsProvider)
>                .build();
>        httpclient.start();
> 
>        // Generate Basic scheme object and add it to the local auth cache
>        final BasicScheme basicAuth = new BasicScheme();
>        basicAuth.initPreemptive(new UsernamePasswordCredentials("user", "passwd".toCharArray()));
> 
>        final HttpHost target = new HttpHost("http", "httpbin.org", 80);
> 
>        // Add AuthCache to the execution context
>        final HttpClientContext localContext = HttpClientContext.create();
>        localContext.resetAuthExchange(target, basicAuth);
> 
>        final SimpleHttpRequest request = SimpleRequestBuilder.get("http://httpbin.org:80/basic-auth/user/passwd")
>                .build();
> 
>        System.out.println("Executing request " + request);
>        for (int i = 0; i < 3; i++) {
>            final Future<SimpleHttpResponse> future = httpclient.execute(
>                    SimpleRequestProducer.create(request),
>                    SimpleResponseConsumer.create(),
>                    localContext,
>                    new FutureCallback<SimpleHttpResponse>() {
> 
>                        @Override
>                        public void completed(final SimpleHttpResponse response) {
>                            System.out.println(request + "->" + new StatusLine(response));
>                            System.out.println(response.getBody());
>                        }
> 
>                        @Override
>                        public void failed(final Exception ex) {
>                            System.out.println(request + "->" + ex);
>                        }
> 
>                        @Override
>                        public void cancelled() {
>                            System.out.println(request + " cancelled");
>                        }
> 
>                    });
>            future.get();
>        }
> 
>        System.out.println("Shutting down");
>        httpclient.close(CloseMode.GRACEFUL);
>    }
> }
> 
> ---
> Executing request GET http://httpbin.org:80/basic-auth/user/passwd
> 2022-02-10 15:10:47,511 DEBUG [main][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] ex-0000000001 preparing request execution
> 2022-02-10 15:10:47,520 DEBUG [main][org.apache.hc.client5.http.protocol.RequestAddCookies] ex-0000000001 Cookie spec selected: strict
> 2022-02-10 15:10:47,524 DEBUG [main][org.apache.hc.client5.http.protocol.RequestAuthCache] ex-0000000001 Auth cache not set in the context
> 2022-02-10 15:10:47,524 DEBUG [main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] ex-0000000001 target auth state: UNCHALLENGED
> 2022-02-10 15:10:47,530 DEBUG [main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] ex-0000000001 proxy auth state: UNCHALLENGED
> 2022-02-10 15:10:47,532 DEBUG [main][org.apache.hc.client5.http.impl.async.AsyncConnectExec] ex-0000000001 acquiring connection with route {}->http://httpbin.org:80
> 2022-02-10 15:10:47,533 DEBUG [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ex-0000000001 acquiring endpoint (3 MINUTES)
> 2022-02-10 15:10:47,534 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ex-0000000001 endpoint lease request (3 MINUTES) [route: {}->http://httpbin.org:80][total available: 0; route allocated: 0 of 5; total allocated: 0 of 25]
> 2022-02-10 15:10:47,538 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ex-0000000001 endpoint leased [route: {}->http://httpbin.org:80][total available: 0; route allocated: 1 of 5; total allocated: 1 of 25]
> 2022-02-10 15:10:47,538 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ex-0000000001 acquired ep-0000000000
> 2022-02-10 15:10:47,539 DEBUG [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ex-0000000001 acquired endpoint ep-0000000000
> 2022-02-10 15:10:47,539 DEBUG [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ep-0000000000 connecting endpoint (3 MINUTES)
> 2022-02-10 15:10:47,539 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000000 connecting endpoint to http://httpbin.org:80 (3 MINUTES)
> 2022-02-10 15:10:47,541 DEBUG [main][org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] http://httpbin.org:80 resolving remote address
> 2022-02-10 15:10:47,541 DEBUG [main][org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] http://httpbin.org:80 resolved to [httpbin.org/54.221.78.73, httpbin.org/3.209.99.235, httpbin.org/52.55.211.119, httpbin.org/35.171.190.227]
> 2022-02-10 15:10:47,542 DEBUG [main][org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] http://httpbin.org:80 connecting null to httpbin.org/54.221.78.73:80 (3 MINUTES)
> 2022-02-10 15:10:47,755 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] http://httpbin.org:80 connected c-0000000000 /192.168.8.102:49873->httpbin.org/54.221.78.73:80
> 2022-02-10 15:10:47,765 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000000 connected c-0000000000
> 2022-02-10 15:10:47,765 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ep-0000000000 endpoint connected
> 2022-02-10 15:10:47,765 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.AsyncConnectExec] ex-0000000001 connected to target
> 2022-02-10 15:10:47,765 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.AsyncConnectExec] ex-0000000001 route fully established
> 2022-02-10 15:10:47,766 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000001 executing GET /basic-auth/user/passwd HTTP/1.1
> 2022-02-10 15:10:47,769 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ep-0000000000 start execution ex-0000000001
> 2022-02-10 15:10:47,769 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000000 executing exchange ex-0000000001 over c-0000000000
> 2022-02-10 15:10:47,771 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.DefaultManagedAsyncClientConnection] c-0000000000 RequestExecutionCommand with NORMAL priority
> 2022-02-10 15:10:47,792 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000001 send request GET /basic-auth/user/passwd HTTP/1.1, null entity
> 2022-02-10 15:10:47,792 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> GET /basic-auth/user/passwd HTTP/1.1
> 2022-02-10 15:10:47,792 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> User-Agent: Apache-HttpAsyncClient/5.1.4-SNAPSHOT (Java/1.8.0_272)
> 2022-02-10 15:10:47,792 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> Authorization: Basic dXNlcjpwYXNzd2Q=
> 2022-02-10 15:10:47,792 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> Host: httpbin.org:80
> 2022-02-10 15:10:47,793 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> Connection: keep-alive
> 2022-02-10 15:10:47,946 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << HTTP/1.1 200 OK
> 2022-02-10 15:10:47,946 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Date: Thu, 10 Feb 2022 14:10:48 GMT
> 2022-02-10 15:10:47,946 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Content-Type: application/json
> 2022-02-10 15:10:47,946 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Content-Length: 47
> 2022-02-10 15:10:47,946 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Connection: keep-alive
> 2022-02-10 15:10:47,947 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Server: gunicorn/19.9.0
> 2022-02-10 15:10:47,947 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Access-Control-Allow-Origin: *
> 2022-02-10 15:10:47,947 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Access-Control-Allow-Credentials: true
> 2022-02-10 15:10:47,949 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000001 consume response HTTP/1.1 200 OK, entity len 47
> 2022-02-10 15:10:47,959 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000001 consume response data, len 47 bytes
> 2022-02-10 15:10:47,959 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000001 end of response data
> GET http://httpbin.org:80/basic-auth/user/passwd->HTTP/1.1 200 OK
> SimpleBody{content length=47, content type=application/json}
> 2022-02-10 15:10:47,962 DEBUG [main][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] ex-0000000002 preparing request execution
> 2022-02-10 15:10:47,962 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] ex-0000000001 message exchange successfully completed
> 2022-02-10 15:10:47,962 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ep-0000000000 releasing valid endpoint
> 2022-02-10 15:10:47,962 DEBUG [main][org.apache.hc.client5.http.protocol.RequestAddCookies] ex-0000000002 Cookie spec selected: strict
> 2022-02-10 15:10:47,962 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000000 releasing endpoint
> 2022-02-10 15:10:47,962 DEBUG [main][org.apache.hc.client5.http.protocol.RequestAuthCache] ex-0000000002 Auth cache not set in the context
> 2022-02-10 15:10:47,962 DEBUG [main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] ex-0000000002 target auth state: UNCHALLENGED
> 2022-02-10 15:10:47,962 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000000 connection c-0000000000 can be kept alive for 3 MINUTES
> 2022-02-10 15:10:47,962 DEBUG [main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] ex-0000000002 proxy auth state: UNCHALLENGED
> 2022-02-10 15:10:47,962 DEBUG [main][org.apache.hc.client5.http.impl.async.AsyncConnectExec] ex-0000000002 acquiring connection with route {}->http://httpbin.org:80
> 2022-02-10 15:10:47,962 DEBUG [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ex-0000000002 acquiring endpoint (3 MINUTES)
> 2022-02-10 15:10:47,963 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000000 connection released [route: {}->http://httpbin.org:80][total available: 1; route allocated: 1 of 5; total allocated: 1 of 25]
> 2022-02-10 15:10:47,963 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ex-0000000002 endpoint lease request (3 MINUTES) [route: {}->http://httpbin.org:80][total available: 1; route allocated: 1 of 5; total allocated: 1 of 25]
> 2022-02-10 15:10:47,963 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] c-0000000000 Connection is kept alive
> 2022-02-10 15:10:47,963 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ex-0000000002 endpoint leased [route: {}->http://httpbin.org:80][total available: 0; route allocated: 1 of 5; total allocated: 1 of 25]
> 2022-02-10 15:10:47,963 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ex-0000000002 acquired ep-0000000001
> 2022-02-10 15:10:47,963 DEBUG [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ex-0000000002 acquired endpoint ep-0000000001
> 2022-02-10 15:10:47,963 DEBUG [main][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000002 executing GET /basic-auth/user/passwd HTTP/1.1
> 2022-02-10 15:10:47,964 DEBUG [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ep-0000000001 start execution ex-0000000002
> 2022-02-10 15:10:47,964 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000001 executing exchange ex-0000000002 over c-0000000000
> 2022-02-10 15:10:47,964 DEBUG [main][org.apache.hc.client5.http.impl.nio.DefaultManagedAsyncClientConnection] c-0000000000 RequestExecutionCommand with NORMAL priority
> 2022-02-10 15:10:47,964 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000002 send request GET /basic-auth/user/passwd HTTP/1.1, null entity
> 2022-02-10 15:10:47,964 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> GET /basic-auth/user/passwd HTTP/1.1
> 2022-02-10 15:10:47,964 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> User-Agent: Apache-HttpAsyncClient/5.1.4-SNAPSHOT (Java/1.8.0_272)
> 2022-02-10 15:10:47,964 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> Authorization: Basic dXNlcjpwYXNzd2Q=
> 2022-02-10 15:10:47,965 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> Host: httpbin.org:80
> 2022-02-10 15:10:47,965 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> Connection: keep-alive
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << HTTP/1.1 200 OK
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Date: Thu, 10 Feb 2022 14:10:48 GMT
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Content-Type: application/json
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Content-Length: 47
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Connection: keep-alive
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Server: gunicorn/19.9.0
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Access-Control-Allow-Origin: *
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Access-Control-Allow-Credentials: true
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000002 consume response HTTP/1.1 200 OK, entity len 47
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000002 consume response data, len 47 bytes
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000002 end of response data
> GET http://httpbin.org:80/basic-auth/user/passwd->HTTP/1.1 200 OK
> SimpleBody{content length=47, content type=application/json}
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] ex-0000000002 message exchange successfully completed
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ep-0000000001 releasing valid endpoint
> 2022-02-10 15:10:48,099 DEBUG [main][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] ex-0000000003 preparing request execution
> 2022-02-10 15:10:48,099 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000001 releasing endpoint
> 2022-02-10 15:10:48,100 DEBUG [main][org.apache.hc.client5.http.protocol.RequestAddCookies] ex-0000000003 Cookie spec selected: strict
> 2022-02-10 15:10:48,100 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000001 connection c-0000000000 can be kept alive for 3 MINUTES
> 2022-02-10 15:10:48,100 DEBUG [main][org.apache.hc.client5.http.protocol.RequestAuthCache] ex-0000000003 Auth cache not set in the context
> 2022-02-10 15:10:48,100 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000001 connection released [route: {}->http://httpbin.org:80][total available: 1; route allocated: 1 of 5; total allocated: 1 of 25]
> 2022-02-10 15:10:48,100 DEBUG [main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] ex-0000000003 target auth state: UNCHALLENGED
> 2022-02-10 15:10:48,100 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] c-0000000000 Connection is kept alive
> 2022-02-10 15:10:48,100 DEBUG [main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] ex-0000000003 proxy auth state: UNCHALLENGED
> 2022-02-10 15:10:48,100 DEBUG [main][org.apache.hc.client5.http.impl.async.AsyncConnectExec] ex-0000000003 acquiring connection with route {}->http://httpbin.org:80
> 2022-02-10 15:10:48,100 DEBUG [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ex-0000000003 acquiring endpoint (3 MINUTES)
> 2022-02-10 15:10:48,100 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ex-0000000003 endpoint lease request (3 MINUTES) [route: {}->http://httpbin.org:80][total available: 1; route allocated: 1 of 5; total allocated: 1 of 25]
> 2022-02-10 15:10:48,101 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ex-0000000003 endpoint leased [route: {}->http://httpbin.org:80][total available: 0; route allocated: 1 of 5; total allocated: 1 of 25]
> 2022-02-10 15:10:48,101 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ex-0000000003 acquired ep-0000000002
> 2022-02-10 15:10:48,101 DEBUG [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ex-0000000003 acquired endpoint ep-0000000002
> 2022-02-10 15:10:48,101 DEBUG [main][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000003 executing GET /basic-auth/user/passwd HTTP/1.1
> 2022-02-10 15:10:48,101 DEBUG [main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ep-0000000002 start execution ex-0000000003
> 2022-02-10 15:10:48,101 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000002 executing exchange ex-0000000003 over c-0000000000
> 2022-02-10 15:10:48,101 DEBUG [main][org.apache.hc.client5.http.impl.nio.DefaultManagedAsyncClientConnection] c-0000000000 RequestExecutionCommand with NORMAL priority
> 2022-02-10 15:10:48,102 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000003 send request GET /basic-auth/user/passwd HTTP/1.1, null entity
> 2022-02-10 15:10:48,102 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> GET /basic-auth/user/passwd HTTP/1.1
> 2022-02-10 15:10:48,102 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> User-Agent: Apache-HttpAsyncClient/5.1.4-SNAPSHOT (Java/1.8.0_272)
> 2022-02-10 15:10:48,102 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> Authorization: Basic dXNlcjpwYXNzd2Q=
> 2022-02-10 15:10:48,102 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> Host: httpbin.org:80
> 2022-02-10 15:10:48,102 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 >> Connection: keep-alive
> 2022-02-10 15:10:48,257 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << HTTP/1.1 200 OK
> 2022-02-10 15:10:48,257 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Date: Thu, 10 Feb 2022 14:10:48 GMT
> 2022-02-10 15:10:48,257 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Content-Type: application/json
> 2022-02-10 15:10:48,257 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Content-Length: 47
> 2022-02-10 15:10:48,257 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Connection: keep-alive
> 2022-02-10 15:10:48,258 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Server: gunicorn/19.9.0
> 2022-02-10 15:10:48,258 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Access-Control-Allow-Origin: *
> 2022-02-10 15:10:48,258 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 << Access-Control-Allow-Credentials: true
> 2022-02-10 15:10:48,258 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000003 consume response HTTP/1.1 200 OK, entity len 47
> 2022-02-10 15:10:48,258 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000003 consume response data, len 47 bytes
> 2022-02-10 15:10:48,258 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] ex-0000000003 end of response data
> GET http://httpbin.org:80/basic-auth/user/passwd->HTTP/1.1 200 OK
> Shutting down
> SimpleBody{content length=47, content type=application/json}
> 2022-02-10 15:10:48,258 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] ex-0000000003 message exchange successfully completed
> 2022-02-10 15:10:48,258 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] ep-0000000002 releasing valid endpoint
> 2022-02-10 15:10:48,258 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000002 releasing endpoint
> 2022-02-10 15:10:48,258 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000002 connection c-0000000000 can be kept alive for 3 MINUTES
> 2022-02-10 15:10:48,259 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] ep-0000000002 connection released [route: {}->http://httpbin.org:80][total available: 1; route allocated: 1 of 5; total allocated: 1 of 25]
> 2022-02-10 15:10:48,259 DEBUG [main][org.apache.hc.client5.http.impl.async.AbstractHttpAsyncClientBase] Shutdown GRACEFUL
> 2022-02-10 15:10:48,259 DEBUG [httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] c-0000000000 Connection is kept alive
> 2022-02-10 15:10:48,262 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] Shutdown connection pool GRACEFUL
> 2022-02-10 15:10:48,262 DEBUG [main][org.apache.hc.client5.http.impl.nio.DefaultManagedAsyncClientConnection] c-0000000000 Shutdown connection GRACEFUL
> 2022-02-10 15:10:48,263 DEBUG [main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] Connection pool shut down
> 
> 
> 
> 
> 
> 
>>> Regards,
>>> Christophe
>>> 
>>>> On 10 Feb 2022, at 10:26, Naber, Peter <pe...@alfa.de> wrote:
>>>> 
>>>> Hi,
>>>> 
>>>> ok, than a little bit more code 😊
>>>> 
>>>> 
>>>>     public CloseableHttpClient getHttpClient() throws IOException, NoSuchAlgorithmException {
>>>>         final SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).build();
>>>>         String tlsString = System.getProperty("https.protocols");
>>>>         if ((tlsString == null) || tlsString.isEmpty()) {
>>>>             tlsString = "";
>>>>             final String[] protocols = SSLContext.getDefault().getSupportedSSLParameters().getProtocols();
>>>>             for (final String protocol : protocols) {
>>>>                 if (protocol.startsWith("TLS")) {
>>>>                     tlsString = tlsString.length() == 0 ? tlsString + protocol : tlsString + "," + protocol;
>>>>                 }
>>>>             }
>>>>         }
>>>>         final PoolingHttpClientConnectionManager connManager = PoolingHttpClientConnectionManagerBuilder.create()
>>>>                .setConnectionFactory(this.connFactory).setDnsResolver(new SystemDefaultDnsResolver())
>>>>                .setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create().setSslContext(this.sslContext) 
>>>>                         .setTlsVersions(tlsString.split(",")).build())
>>>>                .setDefaultSocketConfig(socketConfig).setValidateAfterInactivity(TimeValue.ofSeconds(10L)).build(); 
>>>> 
>>>>         this.defaultRequestConfig = RequestConfig.custom().setCookieSpec(StandardCookieSpec.RELAXED)
>>>>                .setAuthenticationEnabled(true).setExpectContinueEnabled(false).setContentCompressionEnabled(true) 
>>>>                .setConnectionRequestTimeout(Timeout.ofMilliseconds(this.getConnectionRequestTimeout())) 
>>>>                .setConnectTimeout(Timeout.ofMilliseconds(this.getConnectTimeout()))
>>>>                .setResponseTimeout(Timeout.ofMilliseconds(this.getSocketTimeout()))
>>>>                .setRedirectsEnabled(this.getRedirect()).setCircularRedirectsAllowed(false) 
>>>>                 .setTargetPreferredAuthSchemes(
>>>>                         Arrays.asList(StandardAuthScheme.DIGEST, StandardAuthScheme.BASIC, StandardAuthScheme.NTLM))
>>>>                .setProxyPreferredAuthSchemes(Arrays.asList(StandardAuthScheme.BASIC, StandardAuthScheme.NTLM)).build();
>>>> 
>>>>         final RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
>>>> 
>>>>         final CachingHttpClientBuilder cachingHttpClients = CachingHttpClients.custom();
>>>>        cachingHttpClients.setCacheConfig(this.getHttpCacheConfig().getCacheConfig()).setConnectionManager(connManager) 
>>>>                .setRedirectStrategy(redirectStrategy).setDefaultCookieStore(this.getCookieStore()) 
>>>>                 .setDefaultRequestConfig(this.defaultRequestConfig);
>>>>         if (this.getHttpCacheConfig().getCacheFileName() != null) {
>>>>             cachingHttpClients.setCacheDir(new File(this.getHttpCacheConfig().getCacheFileName()));
>>>>         }
>>>> 
>>>>         final HttpClientBuilder httpBuild = cachingHttpClients;
>>>>         httpBuild.addExecInterceptorBefore("test", "compress", new ContentCompressionExec());
>>>>         if (this.getHttpProxy() != null) {
>>>>             final HttpProxy hproxy = this.getHttpProxy();
>>>>             this.proxy = new HttpHost(hproxy.getHost(), hproxy.getPort());
>>>>             httpBuild.setProxy(this.proxy);
>>>>             httpBuild.setRoutePlanner(new DefaultProxyRoutePlanner(this.proxy) {
>>>>                 @Override
>>>>                 protected HttpHost determineProxy(final HttpHost target, final HttpContext context)
>>>>                         throws HttpException {
>>>> 
>>>>                     if (ExecuteHttp.this.httpProxy == null) {
>>>>                         return null;
>>>>                     }
>>>>                     if (ExecuteHttp.this.httpProxy.getProxyNonHosts() != null) {
>>>>                         for (final String proxy1 : ExecuteHttp.this.httpProxy.getProxyNonHosts()) {
>>>>                             try {
>>>>                                 if (target.getHostName().matches(proxy1)) {
>>>>                                     return null;
>>>>                                 }
>>>>                             } catch (final Exception e) {
>>>>                                 e.printStackTrace();
>>>>                             }
>>>>                         }
>>>>                     }
>>>>                     return super.determineProxy(target, context);
>>>>                 }
>>>>             });
>>>>         }
>>>>         final CloseableHttpClient httpClient = httpBuild.build();
>>>> 
>>>>         return httpClient;
>>>>     }
>>>> 
>>>> 
>>>>     private void basicRequest(final String basicCommand, final String urls1) throws Exception {
>>>>         int status = 0;
>>>>         String returnString = "";
>>>>         try (CloseableHttpClient httpClient = this.getHttpClient()) {
>>>>             for (final String url : this.getURL(this.replace(urls1))) {
>>>>                 final HttpUriRequestBase basicRequest = new HttpUriRequestBase(basicCommand, new URI(url));
>>>>                 final URL aURL = new URL(url);
>>>> 
>>>>                 this.setHeaders(basicRequest);
>>>>                 final HttpCacheContext context = this.getHttpCacheContext(aURL);
>>>>                 this.log.info("[basicRequest]  " + basicRequest.getRequestUri());
>>>>                 final CloseableHttpResponse response = httpClient.execute(basicRequest, context);
>>>> 
>>>>                 try {
>>>>                     status = response.getCode();
>>>>                     ...
>>>> 
>>>> Regards,
>>>> 
>>>> Peter
>>>> 
>>>> -----Ursprüngliche Nachricht-----
>>>> Von: Christophe Darville <cd...@internetvista.com>
>>>> Gesendet: Donnerstag, 10. Februar 2022 08:42
>>>> An: HttpClient User Discussion <ht...@hc.apache.org>
>>>> Betreff: Re: Preemptive authentication in Http Client 5 Async
>>>> 
>>>> Hi Peter,
>>>> 
>>>> Thank you for your answer. Once you get an HttpCacheContext instance, how do you link it with the request ? I see no setter on the HttpClient nor on the RequestConfig.
>>>> 
>>>> Regards,
>>>> Christophe
>>>> 
>>>>> On 9 Feb 2022, at 17:15, Naber, Peter <pe...@alfa.de> wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> I use the HttpCacheContext but I think with the httpclient5 the preemtive authentication is implemented the same way.
>>>>> 
>>>>> 
>>>>>     public HttpCacheContext getHttpCacheContext(final URL aURL) throws Exception {
>>>>>         final HttpHost targetHost = new HttpHost(aURL.getProtocol(), aURL.getHost(), aURL.getPort()==-1?aURL.getDefaultPort():aURL.getPort());
>>>>>         final HttpCacheContext context = HttpCacheContext.create();
>>>>>         final AuthCache authCache = new BasicAuthCache();
>>>>>         if (this.getPreAuth() && this.getUser()!= null && this.getPassword()!=null ) {
>>>>>             if (this.getAuthScheme() == AuthScheme.BASIC) {
>>>>>                 final BasicScheme basicAuth = new BasicScheme();
>>>>>                 basicAuth.initPreemptive(
>>>>>                         new UsernamePasswordCredentials(this.getUser(), this.getPassword().toCharArray()));
>>>>>                 authCache.put(targetHost, basicAuth);
>>>>>             } else if (this.getAuthScheme() == AuthScheme.DIGEST) {
>>>>>                 final DigestScheme digestScheme = new DigestScheme();
>>>>>                 final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(this.replace(this.getUser()),
>>>>>                        this.replace(this.getPassword()).toCharArray());
>>>>>                 digestScheme.initPreemptive(creds, UUID.randomUUID().toString().replaceAll("-", ""), "vectorius");
>>>>>                 authCache.put(targetHost, digestScheme);
>>>>>             }
>>>>>             context.setAuthCache(authCache);
>>>>>         }
>>>>>        context.setCredentialsProvider(this.getCredentialsProvider(aURL));
>>>>>         return context;
>>>>>     }
>>>>> 
>>>>> regards,
>>>>> 
>>>>> Peter
>>>>> 
>>>>> -----Ursprüngliche Nachricht-----
>>>>> Von: Christophe Darville <cd...@internetvista.com>
>>>>> Gesendet: Mittwoch, 9. Februar 2022 17:00
>>>>> An: HttpClient User Discussion <ht...@hc.apache.org>
>>>>> Betreff: Preemptive authentication in Http Client 5 Async
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> I am trying to make preemptive authentication in HttpClient 5 Async mode using the following code, but I does not work, first request is still without authentication and the authentication is done on the second request :
>>>>> 
>>>>>     HttpClientContext httpContext = HttpClientContext.create();
>>>>>     CredentialsProvider credentialsProvider = getCredentialsProvider();
>>>>>     if (preemptive) {
>>>>>         URI uri = URI.create(url);
>>>>>         HttpHost targetHost = new HttpHost(uri.getScheme(), uri.getHost(), uri.getPort());
>>>>>         AuthCache authCache = new BasicAuthCache();
>>>>>         BasicScheme basicAuth = new BasicScheme();
>>>>>         authCache.put(targetHost, basicAuth);
>>>>>         httpContext.setAuthCache(authCache);
>>>>>     }
>>>>>     httpContext.setCredentialsProvider(credentialsProvider);
>>>>> 
>>>>> This code was working in httpClient 4. Any suggestion on how to make preemptive authentication work in HttpClient5 Async ?
>>>>> 
>>>>> Thank you,
>>>>> Christophe
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>>>> 
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Preemptive authentication in Http Client 5 Async

Posted by Oleg Kalnichevski <ol...@apache.org>.

On 2/10/2022 2:16 PM, Oleg Kalnichevski wrote:
> 
> 
> On 2/10/2022 10:43 AM, Christophe Darville wrote:
>> Thank you very much Peter. I missed the point that HttpCacheContext 
>> was extending HttpClientContext.
>>
>> Unfortunately, httpClient5 Async (CloseableHttpAsyncClient) is not 
>> sending credentials at first request even with your code (the same as 
>> mine except using HttpCacheContext in place of HttpClientContext).
>>
>> I will check with Oleg on the way to produce logs.
>>
> 
> The issue you are having may be the defect just reported as 
> HTTPCLIENT-2203. I am looking into it. There is no need for wire logs 
> anymore, because I have a local reproducer.
> 
> https://issues.apache.org/jira/browse/HTTPCLIENT-2203
> 
> Oleg
> 

What is broken is the target host port normalization. When using 
explicitly defined ports the preemptive authentication works just fine. 
Please note the request URI contains a port in it.

This example works just fine for me:

----
public class AsyncPreemptiveBasicClientAuthentication {

     public static void main(final String[] args) throws Exception {
         final BasicCredentialsProvider credsProvider = new 
BasicCredentialsProvider();
         credsProvider.setCredentials(
                 new AuthScope("httpbin.org", 80),
                 new UsernamePasswordCredentials("user", 
"passwd".toCharArray()));
         final CloseableHttpAsyncClient httpclient = 
HttpAsyncClients.custom()
                 .setDefaultCredentialsProvider(credsProvider)
                 .build();
         httpclient.start();

         // Generate Basic scheme object and add it to the local auth cache
         final BasicScheme basicAuth = new BasicScheme();
         basicAuth.initPreemptive(new 
UsernamePasswordCredentials("user", "passwd".toCharArray()));

         final HttpHost target = new HttpHost("http", "httpbin.org", 80);

         // Add AuthCache to the execution context
         final HttpClientContext localContext = HttpClientContext.create();
         localContext.resetAuthExchange(target, basicAuth);

         final SimpleHttpRequest request = 
SimpleRequestBuilder.get("http://httpbin.org:80/basic-auth/user/passwd")
                 .build();

         System.out.println("Executing request " + request);
         for (int i = 0; i < 3; i++) {
             final Future<SimpleHttpResponse> future = httpclient.execute(
                     SimpleRequestProducer.create(request),
                     SimpleResponseConsumer.create(),
                     localContext,
                     new FutureCallback<SimpleHttpResponse>() {

                         @Override
                         public void completed(final SimpleHttpResponse 
response) {
                             System.out.println(request + "->" + new 
StatusLine(response));
                             System.out.println(response.getBody());
                         }

                         @Override
                         public void failed(final Exception ex) {
                             System.out.println(request + "->" + ex);
                         }

                         @Override
                         public void cancelled() {
                             System.out.println(request + " cancelled");
                         }

                     });
             future.get();
         }

         System.out.println("Shutting down");
         httpclient.close(CloseMode.GRACEFUL);
     }
}

---
Executing request GET http://httpbin.org:80/basic-auth/user/passwd
2022-02-10 15:10:47,511 DEBUG 
[main][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] 
ex-0000000001 preparing request execution
2022-02-10 15:10:47,520 DEBUG 
[main][org.apache.hc.client5.http.protocol.RequestAddCookies] 
ex-0000000001 Cookie spec selected: strict
2022-02-10 15:10:47,524 DEBUG 
[main][org.apache.hc.client5.http.protocol.RequestAuthCache] 
ex-0000000001 Auth cache not set in the context
2022-02-10 15:10:47,524 DEBUG 
[main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] 
ex-0000000001 target auth state: UNCHALLENGED
2022-02-10 15:10:47,530 DEBUG 
[main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] 
ex-0000000001 proxy auth state: UNCHALLENGED
2022-02-10 15:10:47,532 DEBUG 
[main][org.apache.hc.client5.http.impl.async.AsyncConnectExec] 
ex-0000000001 acquiring connection with route {}->http://httpbin.org:80
2022-02-10 15:10:47,533 DEBUG 
[main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ex-0000000001 acquiring endpoint (3 MINUTES)
2022-02-10 15:10:47,534 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ex-0000000001 endpoint lease request (3 MINUTES) [route: 
{}->http://httpbin.org:80][total available: 0; route allocated: 0 of 5; 
total allocated: 0 of 25]
2022-02-10 15:10:47,538 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ex-0000000001 endpoint leased [route: {}->http://httpbin.org:80][total 
available: 0; route allocated: 1 of 5; total allocated: 1 of 25]
2022-02-10 15:10:47,538 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ex-0000000001 acquired ep-0000000000
2022-02-10 15:10:47,539 DEBUG 
[main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ex-0000000001 acquired endpoint ep-0000000000
2022-02-10 15:10:47,539 DEBUG 
[main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ep-0000000000 connecting endpoint (3 MINUTES)
2022-02-10 15:10:47,539 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000000 connecting endpoint to http://httpbin.org:80 (3 MINUTES)
2022-02-10 15:10:47,541 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] 
http://httpbin.org:80 resolving remote address
2022-02-10 15:10:47,541 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] 
http://httpbin.org:80 resolved to [httpbin.org/54.221.78.73, 
httpbin.org/3.209.99.235, httpbin.org/52.55.211.119, 
httpbin.org/35.171.190.227]
2022-02-10 15:10:47,542 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] 
http://httpbin.org:80 connecting null to httpbin.org/54.221.78.73:80 (3 
MINUTES)
2022-02-10 15:10:47,755 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] 
http://httpbin.org:80 connected c-0000000000 
/192.168.8.102:49873->httpbin.org/54.221.78.73:80
2022-02-10 15:10:47,765 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000000 connected c-0000000000
2022-02-10 15:10:47,765 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ep-0000000000 endpoint connected
2022-02-10 15:10:47,765 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.AsyncConnectExec] 
ex-0000000001 connected to target
2022-02-10 15:10:47,765 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.AsyncConnectExec] 
ex-0000000001 route fully established
2022-02-10 15:10:47,766 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000001 executing GET /basic-auth/user/passwd HTTP/1.1
2022-02-10 15:10:47,769 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ep-0000000000 start execution ex-0000000001
2022-02-10 15:10:47,769 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000000 executing exchange ex-0000000001 over c-0000000000
2022-02-10 15:10:47,771 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.DefaultManagedAsyncClientConnection] 
c-0000000000 RequestExecutionCommand with NORMAL priority
2022-02-10 15:10:47,792 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000001 send request GET /basic-auth/user/passwd HTTP/1.1, null entity
2022-02-10 15:10:47,792 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> GET /basic-auth/user/passwd HTTP/1.1
2022-02-10 15:10:47,792 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> User-Agent: Apache-HttpAsyncClient/5.1.4-SNAPSHOT (Java/1.8.0_272)
2022-02-10 15:10:47,792 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> Authorization: Basic dXNlcjpwYXNzd2Q=
2022-02-10 15:10:47,792 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> Host: httpbin.org:80
2022-02-10 15:10:47,793 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> Connection: keep-alive
2022-02-10 15:10:47,946 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< HTTP/1.1 200 OK
2022-02-10 15:10:47,946 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Date: Thu, 10 Feb 2022 14:10:48 GMT
2022-02-10 15:10:47,946 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Content-Type: application/json
2022-02-10 15:10:47,946 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Content-Length: 47
2022-02-10 15:10:47,946 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Connection: keep-alive
2022-02-10 15:10:47,947 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Server: gunicorn/19.9.0
2022-02-10 15:10:47,947 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Access-Control-Allow-Origin: *
2022-02-10 15:10:47,947 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Access-Control-Allow-Credentials: true
2022-02-10 15:10:47,949 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000001 consume response HTTP/1.1 200 OK, entity len 47
2022-02-10 15:10:47,959 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000001 consume response data, len 47 bytes
2022-02-10 15:10:47,959 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000001 end of response data
GET http://httpbin.org:80/basic-auth/user/passwd->HTTP/1.1 200 OK
SimpleBody{content length=47, content type=application/json}
2022-02-10 15:10:47,962 DEBUG 
[main][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] 
ex-0000000002 preparing request execution
2022-02-10 15:10:47,962 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] 
ex-0000000001 message exchange successfully completed
2022-02-10 15:10:47,962 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ep-0000000000 releasing valid endpoint
2022-02-10 15:10:47,962 DEBUG 
[main][org.apache.hc.client5.http.protocol.RequestAddCookies] 
ex-0000000002 Cookie spec selected: strict
2022-02-10 15:10:47,962 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000000 releasing endpoint
2022-02-10 15:10:47,962 DEBUG 
[main][org.apache.hc.client5.http.protocol.RequestAuthCache] 
ex-0000000002 Auth cache not set in the context
2022-02-10 15:10:47,962 DEBUG 
[main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] 
ex-0000000002 target auth state: UNCHALLENGED
2022-02-10 15:10:47,962 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000000 connection c-0000000000 can be kept alive for 3 MINUTES
2022-02-10 15:10:47,962 DEBUG 
[main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] 
ex-0000000002 proxy auth state: UNCHALLENGED
2022-02-10 15:10:47,962 DEBUG 
[main][org.apache.hc.client5.http.impl.async.AsyncConnectExec] 
ex-0000000002 acquiring connection with route {}->http://httpbin.org:80
2022-02-10 15:10:47,962 DEBUG 
[main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ex-0000000002 acquiring endpoint (3 MINUTES)
2022-02-10 15:10:47,963 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000000 connection released [route: 
{}->http://httpbin.org:80][total available: 1; route allocated: 1 of 5; 
total allocated: 1 of 25]
2022-02-10 15:10:47,963 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ex-0000000002 endpoint lease request (3 MINUTES) [route: 
{}->http://httpbin.org:80][total available: 1; route allocated: 1 of 5; 
total allocated: 1 of 25]
2022-02-10 15:10:47,963 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
c-0000000000 Connection is kept alive
2022-02-10 15:10:47,963 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ex-0000000002 endpoint leased [route: {}->http://httpbin.org:80][total 
available: 0; route allocated: 1 of 5; total allocated: 1 of 25]
2022-02-10 15:10:47,963 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ex-0000000002 acquired ep-0000000001
2022-02-10 15:10:47,963 DEBUG 
[main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ex-0000000002 acquired endpoint ep-0000000001
2022-02-10 15:10:47,963 DEBUG 
[main][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000002 executing GET /basic-auth/user/passwd HTTP/1.1
2022-02-10 15:10:47,964 DEBUG 
[main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ep-0000000001 start execution ex-0000000002
2022-02-10 15:10:47,964 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000001 executing exchange ex-0000000002 over c-0000000000
2022-02-10 15:10:47,964 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.DefaultManagedAsyncClientConnection] 
c-0000000000 RequestExecutionCommand with NORMAL priority
2022-02-10 15:10:47,964 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000002 send request GET /basic-auth/user/passwd HTTP/1.1, null entity
2022-02-10 15:10:47,964 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> GET /basic-auth/user/passwd HTTP/1.1
2022-02-10 15:10:47,964 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> User-Agent: Apache-HttpAsyncClient/5.1.4-SNAPSHOT (Java/1.8.0_272)
2022-02-10 15:10:47,964 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> Authorization: Basic dXNlcjpwYXNzd2Q=
2022-02-10 15:10:47,965 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> Host: httpbin.org:80
2022-02-10 15:10:47,965 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> Connection: keep-alive
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< HTTP/1.1 200 OK
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Date: Thu, 10 Feb 2022 14:10:48 GMT
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Content-Type: application/json
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Content-Length: 47
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Connection: keep-alive
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Server: gunicorn/19.9.0
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Access-Control-Allow-Origin: *
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Access-Control-Allow-Credentials: true
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000002 consume response HTTP/1.1 200 OK, entity len 47
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000002 consume response data, len 47 bytes
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000002 end of response data
GET http://httpbin.org:80/basic-auth/user/passwd->HTTP/1.1 200 OK
SimpleBody{content length=47, content type=application/json}
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] 
ex-0000000002 message exchange successfully completed
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ep-0000000001 releasing valid endpoint
2022-02-10 15:10:48,099 DEBUG 
[main][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] 
ex-0000000003 preparing request execution
2022-02-10 15:10:48,099 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000001 releasing endpoint
2022-02-10 15:10:48,100 DEBUG 
[main][org.apache.hc.client5.http.protocol.RequestAddCookies] 
ex-0000000003 Cookie spec selected: strict
2022-02-10 15:10:48,100 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000001 connection c-0000000000 can be kept alive for 3 MINUTES
2022-02-10 15:10:48,100 DEBUG 
[main][org.apache.hc.client5.http.protocol.RequestAuthCache] 
ex-0000000003 Auth cache not set in the context
2022-02-10 15:10:48,100 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000001 connection released [route: 
{}->http://httpbin.org:80][total available: 1; route allocated: 1 of 5; 
total allocated: 1 of 25]
2022-02-10 15:10:48,100 DEBUG 
[main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] 
ex-0000000003 target auth state: UNCHALLENGED
2022-02-10 15:10:48,100 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
c-0000000000 Connection is kept alive
2022-02-10 15:10:48,100 DEBUG 
[main][org.apache.hc.client5.http.impl.async.AsyncProtocolExec] 
ex-0000000003 proxy auth state: UNCHALLENGED
2022-02-10 15:10:48,100 DEBUG 
[main][org.apache.hc.client5.http.impl.async.AsyncConnectExec] 
ex-0000000003 acquiring connection with route {}->http://httpbin.org:80
2022-02-10 15:10:48,100 DEBUG 
[main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ex-0000000003 acquiring endpoint (3 MINUTES)
2022-02-10 15:10:48,100 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ex-0000000003 endpoint lease request (3 MINUTES) [route: 
{}->http://httpbin.org:80][total available: 1; route allocated: 1 of 5; 
total allocated: 1 of 25]
2022-02-10 15:10:48,101 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ex-0000000003 endpoint leased [route: {}->http://httpbin.org:80][total 
available: 0; route allocated: 1 of 5; total allocated: 1 of 25]
2022-02-10 15:10:48,101 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ex-0000000003 acquired ep-0000000002
2022-02-10 15:10:48,101 DEBUG 
[main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ex-0000000003 acquired endpoint ep-0000000002
2022-02-10 15:10:48,101 DEBUG 
[main][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000003 executing GET /basic-auth/user/passwd HTTP/1.1
2022-02-10 15:10:48,101 DEBUG 
[main][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ep-0000000002 start execution ex-0000000003
2022-02-10 15:10:48,101 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000002 executing exchange ex-0000000003 over c-0000000000
2022-02-10 15:10:48,101 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.DefaultManagedAsyncClientConnection] 
c-0000000000 RequestExecutionCommand with NORMAL priority
2022-02-10 15:10:48,102 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000003 send request GET /basic-auth/user/passwd HTTP/1.1, null entity
2022-02-10 15:10:48,102 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> GET /basic-auth/user/passwd HTTP/1.1
2022-02-10 15:10:48,102 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> User-Agent: Apache-HttpAsyncClient/5.1.4-SNAPSHOT (Java/1.8.0_272)
2022-02-10 15:10:48,102 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> Authorization: Basic dXNlcjpwYXNzd2Q=
2022-02-10 15:10:48,102 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> Host: httpbin.org:80
2022-02-10 15:10:48,102 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
 >> Connection: keep-alive
2022-02-10 15:10:48,257 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< HTTP/1.1 200 OK
2022-02-10 15:10:48,257 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Date: Thu, 10 Feb 2022 14:10:48 GMT
2022-02-10 15:10:48,257 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Content-Type: application/json
2022-02-10 15:10:48,257 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Content-Length: 47
2022-02-10 15:10:48,257 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Connection: keep-alive
2022-02-10 15:10:48,258 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Server: gunicorn/19.9.0
2022-02-10 15:10:48,258 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Access-Control-Allow-Origin: *
2022-02-10 15:10:48,258 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.headers] c-0000000000 
<< Access-Control-Allow-Credentials: true
2022-02-10 15:10:48,258 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000003 consume response HTTP/1.1 200 OK, entity len 47
2022-02-10 15:10:48,258 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000003 consume response data, len 47 bytes
2022-02-10 15:10:48,258 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec] 
ex-0000000003 end of response data
GET http://httpbin.org:80/basic-auth/user/passwd->HTTP/1.1 200 OK
Shutting down
SimpleBody{content length=47, content type=application/json}
2022-02-10 15:10:48,258 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] 
ex-0000000003 message exchange successfully completed
2022-02-10 15:10:48,258 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
ep-0000000002 releasing valid endpoint
2022-02-10 15:10:48,258 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000002 releasing endpoint
2022-02-10 15:10:48,258 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000002 connection c-0000000000 can be kept alive for 3 MINUTES
2022-02-10 15:10:48,259 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
ep-0000000002 connection released [route: 
{}->http://httpbin.org:80][total available: 1; route allocated: 1 of 5; 
total allocated: 1 of 25]
2022-02-10 15:10:48,259 DEBUG 
[main][org.apache.hc.client5.http.impl.async.AbstractHttpAsyncClientBase] Shutdown 
GRACEFUL
2022-02-10 15:10:48,259 DEBUG 
[httpclient-dispatch-1][org.apache.hc.client5.http.impl.async.InternalHttpAsyncClient] 
c-0000000000 Connection is kept alive
2022-02-10 15:10:48,262 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
Shutdown connection pool GRACEFUL
2022-02-10 15:10:48,262 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.DefaultManagedAsyncClientConnection] 
c-0000000000 Shutdown connection GRACEFUL
2022-02-10 15:10:48,263 DEBUG 
[main][org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager] 
Connection pool shut down






>> Regards,
>> Christophe
>>
>>> On 10 Feb 2022, at 10:26, Naber, Peter <pe...@alfa.de> wrote:
>>>
>>> Hi,
>>>
>>> ok, than a little bit more code 😊
>>>
>>>
>>>     public CloseableHttpClient getHttpClient() throws IOException, 
>>> NoSuchAlgorithmException {
>>>         final SocketConfig socketConfig = 
>>> SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).build();
>>>         String tlsString = System.getProperty("https.protocols");
>>>         if ((tlsString == null) || tlsString.isEmpty()) {
>>>             tlsString = "";
>>>             final String[] protocols = 
>>> SSLContext.getDefault().getSupportedSSLParameters().getProtocols();
>>>             for (final String protocol : protocols) {
>>>                 if (protocol.startsWith("TLS")) {
>>>                     tlsString = tlsString.length() == 0 ? tlsString + 
>>> protocol : tlsString + "," + protocol;
>>>                 }
>>>             }
>>>         }
>>>         final PoolingHttpClientConnectionManager connManager = 
>>> PoolingHttpClientConnectionManagerBuilder.create()
>>>                 
>>> .setConnectionFactory(this.connFactory).setDnsResolver(new 
>>> SystemDefaultDnsResolver())
>>>                 
>>> .setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create().setSslContext(this.sslContext) 
>>>
>>>                         .setTlsVersions(tlsString.split(",")).build())
>>>                 
>>> .setDefaultSocketConfig(socketConfig).setValidateAfterInactivity(TimeValue.ofSeconds(10L)).build(); 
>>>
>>>
>>>         this.defaultRequestConfig = 
>>> RequestConfig.custom().setCookieSpec(StandardCookieSpec.RELAXED)
>>>                 
>>> .setAuthenticationEnabled(true).setExpectContinueEnabled(false).setContentCompressionEnabled(true) 
>>>
>>>                 
>>> .setConnectionRequestTimeout(Timeout.ofMilliseconds(this.getConnectionRequestTimeout())) 
>>>
>>>                 
>>> .setConnectTimeout(Timeout.ofMilliseconds(this.getConnectTimeout()))
>>>                 
>>> .setResponseTimeout(Timeout.ofMilliseconds(this.getSocketTimeout()))
>>>                 
>>> .setRedirectsEnabled(this.getRedirect()).setCircularRedirectsAllowed(false) 
>>>
>>>                 .setTargetPreferredAuthSchemes(
>>>                         Arrays.asList(StandardAuthScheme.DIGEST, 
>>> StandardAuthScheme.BASIC, StandardAuthScheme.NTLM))
>>>                 
>>> .setProxyPreferredAuthSchemes(Arrays.asList(StandardAuthScheme.BASIC, 
>>> StandardAuthScheme.NTLM)).build();
>>>
>>>         final RedirectStrategy redirectStrategy = new 
>>> DefaultRedirectStrategy();
>>>
>>>         final CachingHttpClientBuilder cachingHttpClients = 
>>> CachingHttpClients.custom();
>>>         
>>> cachingHttpClients.setCacheConfig(this.getHttpCacheConfig().getCacheConfig()).setConnectionManager(connManager) 
>>>
>>>                 
>>> .setRedirectStrategy(redirectStrategy).setDefaultCookieStore(this.getCookieStore()) 
>>>
>>>                 .setDefaultRequestConfig(this.defaultRequestConfig);
>>>         if (this.getHttpCacheConfig().getCacheFileName() != null) {
>>>             cachingHttpClients.setCacheDir(new 
>>> File(this.getHttpCacheConfig().getCacheFileName()));
>>>         }
>>>
>>>         final HttpClientBuilder httpBuild = cachingHttpClients;
>>>         httpBuild.addExecInterceptorBefore("test", "compress", new 
>>> ContentCompressionExec());
>>>         if (this.getHttpProxy() != null) {
>>>             final HttpProxy hproxy = this.getHttpProxy();
>>>             this.proxy = new HttpHost(hproxy.getHost(), 
>>> hproxy.getPort());
>>>             httpBuild.setProxy(this.proxy);
>>>             httpBuild.setRoutePlanner(new 
>>> DefaultProxyRoutePlanner(this.proxy) {
>>>                 @Override
>>>                 protected HttpHost determineProxy(final HttpHost 
>>> target, final HttpContext context)
>>>                         throws HttpException {
>>>
>>>                     if (ExecuteHttp.this.httpProxy == null) {
>>>                         return null;
>>>                     }
>>>                     if (ExecuteHttp.this.httpProxy.getProxyNonHosts() 
>>> != null) {
>>>                         for (final String proxy1 : 
>>> ExecuteHttp.this.httpProxy.getProxyNonHosts()) {
>>>                             try {
>>>                                 if 
>>> (target.getHostName().matches(proxy1)) {
>>>                                     return null;
>>>                                 }
>>>                             } catch (final Exception e) {
>>>                                 e.printStackTrace();
>>>                             }
>>>                         }
>>>                     }
>>>                     return super.determineProxy(target, context);
>>>                 }
>>>             });
>>>         }
>>>         final CloseableHttpClient httpClient = httpBuild.build();
>>>
>>>         return httpClient;
>>>     }
>>>
>>>
>>>     private void basicRequest(final String basicCommand, final String 
>>> urls1) throws Exception {
>>>         int status = 0;
>>>         String returnString = "";
>>>         try (CloseableHttpClient httpClient = this.getHttpClient()) {
>>>             for (final String url : this.getURL(this.replace(urls1))) {
>>>                 final HttpUriRequestBase basicRequest = new 
>>> HttpUriRequestBase(basicCommand, new URI(url));
>>>                 final URL aURL = new URL(url);
>>>
>>>                 this.setHeaders(basicRequest);
>>>                 final HttpCacheContext context = 
>>> this.getHttpCacheContext(aURL);
>>>                 this.log.info("[basicRequest]  " + 
>>> basicRequest.getRequestUri());
>>>                 final CloseableHttpResponse response = 
>>> httpClient.execute(basicRequest, context);
>>>
>>>                 try {
>>>                     status = response.getCode();
>>>                     ...
>>>
>>> Regards,
>>>
>>> Peter
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: Christophe Darville <cd...@internetvista.com>
>>> Gesendet: Donnerstag, 10. Februar 2022 08:42
>>> An: HttpClient User Discussion <ht...@hc.apache.org>
>>> Betreff: Re: Preemptive authentication in Http Client 5 Async
>>>
>>> Hi Peter,
>>>
>>> Thank you for your answer. Once you get an HttpCacheContext instance, 
>>> how do you link it with the request ? I see no setter on the 
>>> HttpClient nor on the RequestConfig.
>>>
>>> Regards,
>>> Christophe
>>>
>>>> On 9 Feb 2022, at 17:15, Naber, Peter <pe...@alfa.de> wrote:
>>>>
>>>> Hi,
>>>>
>>>> I use the HttpCacheContext but I think with the httpclient5 the 
>>>> preemtive authentication is implemented the same way.
>>>>
>>>>
>>>>     public HttpCacheContext getHttpCacheContext(final URL aURL) 
>>>> throws Exception {
>>>>         final HttpHost targetHost = new HttpHost(aURL.getProtocol(), 
>>>> aURL.getHost(), 
>>>> aURL.getPort()==-1?aURL.getDefaultPort():aURL.getPort());
>>>>         final HttpCacheContext context = HttpCacheContext.create();
>>>>         final AuthCache authCache = new BasicAuthCache();
>>>>         if (this.getPreAuth() && this.getUser()!= null && 
>>>> this.getPassword()!=null ) {
>>>>             if (this.getAuthScheme() == AuthScheme.BASIC) {
>>>>                 final BasicScheme basicAuth = new BasicScheme();
>>>>                 basicAuth.initPreemptive(
>>>>                         new 
>>>> UsernamePasswordCredentials(this.getUser(), 
>>>> this.getPassword().toCharArray()));
>>>>                 authCache.put(targetHost, basicAuth);
>>>>             } else if (this.getAuthScheme() == AuthScheme.DIGEST) {
>>>>                 final DigestScheme digestScheme = new DigestScheme();
>>>>                 final UsernamePasswordCredentials creds = new 
>>>> UsernamePasswordCredentials(this.replace(this.getUser()),
>>>>                         
>>>> this.replace(this.getPassword()).toCharArray());
>>>>                 digestScheme.initPreemptive(creds, 
>>>> UUID.randomUUID().toString().replaceAll("-", ""), "vectorius");
>>>>                 authCache.put(targetHost, digestScheme);
>>>>             }
>>>>             context.setAuthCache(authCache);
>>>>         }
>>>>         
>>>> context.setCredentialsProvider(this.getCredentialsProvider(aURL));
>>>>         return context;
>>>>     }
>>>>
>>>> regards,
>>>>
>>>> Peter
>>>>
>>>> -----Ursprüngliche Nachricht-----
>>>> Von: Christophe Darville <cd...@internetvista.com>
>>>> Gesendet: Mittwoch, 9. Februar 2022 17:00
>>>> An: HttpClient User Discussion <ht...@hc.apache.org>
>>>> Betreff: Preemptive authentication in Http Client 5 Async
>>>>
>>>> Hi,
>>>>
>>>> I am trying to make preemptive authentication in HttpClient 5 Async 
>>>> mode using the following code, but I does not work, first request is 
>>>> still without authentication and the authentication is done on the 
>>>> second request :
>>>>
>>>>     HttpClientContext httpContext = HttpClientContext.create();
>>>>     CredentialsProvider credentialsProvider = getCredentialsProvider();
>>>>     if (preemptive) {
>>>>         URI uri = URI.create(url);
>>>>         HttpHost targetHost = new HttpHost(uri.getScheme(), 
>>>> uri.getHost(), uri.getPort());
>>>>         AuthCache authCache = new BasicAuthCache();
>>>>         BasicScheme basicAuth = new BasicScheme();
>>>>         authCache.put(targetHost, basicAuth);
>>>>         httpContext.setAuthCache(authCache);
>>>>     }
>>>>     httpContext.setCredentialsProvider(credentialsProvider);
>>>>
>>>> This code was working in httpClient 4. Any suggestion on how to make 
>>>> preemptive authentication work in HttpClient5 Async ?
>>>>
>>>> Thank you,
>>>> Christophe
>>>>
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Preemptive authentication in Http Client 5 Async

Posted by Oleg Kalnichevski <ol...@apache.org>.

On 2/10/2022 10:43 AM, Christophe Darville wrote:
> Thank you very much Peter. I missed the point that HttpCacheContext was extending HttpClientContext.
> 
> Unfortunately, httpClient5 Async (CloseableHttpAsyncClient) is not sending credentials at first request even with your code (the same as mine except using HttpCacheContext in place of HttpClientContext).
> 
> I will check with Oleg on the way to produce logs.
> 

The issue you are having may be the defect just reported as 
HTTPCLIENT-2203. I am looking into it. There is no need for wire logs 
anymore, because I have a local reproducer.

https://issues.apache.org/jira/browse/HTTPCLIENT-2203

Oleg

> Regards,
> Christophe
> 
>> On 10 Feb 2022, at 10:26, Naber, Peter <pe...@alfa.de> wrote:
>>
>> Hi,
>>
>> ok, than a little bit more code 😊
>>
>>
>> 	public CloseableHttpClient getHttpClient() throws IOException, NoSuchAlgorithmException {
>> 		final SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).build();
>> 		String tlsString = System.getProperty("https.protocols");
>> 		if ((tlsString == null) || tlsString.isEmpty()) {
>> 			tlsString = "";
>> 			final String[] protocols = SSLContext.getDefault().getSupportedSSLParameters().getProtocols();
>> 			for (final String protocol : protocols) {
>> 				if (protocol.startsWith("TLS")) {
>> 					tlsString = tlsString.length() == 0 ? tlsString + protocol : tlsString + "," + protocol;
>> 				}
>> 			}
>> 		}
>> 		final PoolingHttpClientConnectionManager connManager = PoolingHttpClientConnectionManagerBuilder.create()
>> 				.setConnectionFactory(this.connFactory).setDnsResolver(new SystemDefaultDnsResolver())
>> 				.setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create().setSslContext(this.sslContext)
>> 						.setTlsVersions(tlsString.split(",")).build())
>> 				.setDefaultSocketConfig(socketConfig).setValidateAfterInactivity(TimeValue.ofSeconds(10L)).build();
>>
>> 		this.defaultRequestConfig = RequestConfig.custom().setCookieSpec(StandardCookieSpec.RELAXED)
>> 				.setAuthenticationEnabled(true).setExpectContinueEnabled(false).setContentCompressionEnabled(true)
>> 				.setConnectionRequestTimeout(Timeout.ofMilliseconds(this.getConnectionRequestTimeout()))
>> 				.setConnectTimeout(Timeout.ofMilliseconds(this.getConnectTimeout()))
>> 				.setResponseTimeout(Timeout.ofMilliseconds(this.getSocketTimeout()))
>> 				.setRedirectsEnabled(this.getRedirect()).setCircularRedirectsAllowed(false)
>> 				.setTargetPreferredAuthSchemes(
>> 						Arrays.asList(StandardAuthScheme.DIGEST, StandardAuthScheme.BASIC, StandardAuthScheme.NTLM))
>> 				.setProxyPreferredAuthSchemes(Arrays.asList(StandardAuthScheme.BASIC, StandardAuthScheme.NTLM)).build();
>>
>> 		final RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
>>
>> 		final CachingHttpClientBuilder cachingHttpClients = CachingHttpClients.custom();
>> 		cachingHttpClients.setCacheConfig(this.getHttpCacheConfig().getCacheConfig()).setConnectionManager(connManager)
>> 				.setRedirectStrategy(redirectStrategy).setDefaultCookieStore(this.getCookieStore())
>> 				.setDefaultRequestConfig(this.defaultRequestConfig);
>> 		if (this.getHttpCacheConfig().getCacheFileName() != null) {
>> 			cachingHttpClients.setCacheDir(new File(this.getHttpCacheConfig().getCacheFileName()));
>> 		}
>>
>> 		final HttpClientBuilder httpBuild = cachingHttpClients;
>> 		httpBuild.addExecInterceptorBefore("test", "compress", new ContentCompressionExec());
>> 		if (this.getHttpProxy() != null) {
>> 			final HttpProxy hproxy = this.getHttpProxy();
>> 			this.proxy = new HttpHost(hproxy.getHost(), hproxy.getPort());
>> 			httpBuild.setProxy(this.proxy);
>> 			httpBuild.setRoutePlanner(new DefaultProxyRoutePlanner(this.proxy) {
>> 				@Override
>> 				protected HttpHost determineProxy(final HttpHost target, final HttpContext context)
>> 						throws HttpException {
>>
>> 					if (ExecuteHttp.this.httpProxy == null) {
>> 						return null;
>> 					}
>> 					if (ExecuteHttp.this.httpProxy.getProxyNonHosts() != null) {
>> 						for (final String proxy1 : ExecuteHttp.this.httpProxy.getProxyNonHosts()) {
>> 							try {
>> 								if (target.getHostName().matches(proxy1)) {
>> 									return null;
>> 								}
>> 							} catch (final Exception e) {
>> 								e.printStackTrace();
>> 							}
>> 						}
>> 					}
>> 					return super.determineProxy(target, context);
>> 				}
>> 			});
>> 		}
>> 		final CloseableHttpClient httpClient = httpBuild.build();
>>
>> 		return httpClient;
>> 	}
>>
>>
>> 	private void basicRequest(final String basicCommand, final String urls1) throws Exception {
>> 		int status = 0;
>> 		String returnString = "";
>> 		try (CloseableHttpClient httpClient = this.getHttpClient()) {
>> 			for (final String url : this.getURL(this.replace(urls1))) {
>> 				final HttpUriRequestBase basicRequest = new HttpUriRequestBase(basicCommand, new URI(url));
>> 				final URL aURL = new URL(url);
>>
>> 				this.setHeaders(basicRequest);
>> 				final HttpCacheContext context = this.getHttpCacheContext(aURL);
>> 				this.log.info("[basicRequest]  " + basicRequest.getRequestUri());
>> 				final CloseableHttpResponse response = httpClient.execute(basicRequest, context);
>>
>> 				try {
>> 					status = response.getCode();
>> 					...
>>
>> Regards,
>>
>> Peter
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Christophe Darville <cd...@internetvista.com>
>> Gesendet: Donnerstag, 10. Februar 2022 08:42
>> An: HttpClient User Discussion <ht...@hc.apache.org>
>> Betreff: Re: Preemptive authentication in Http Client 5 Async
>>
>> Hi Peter,
>>
>> Thank you for your answer. Once you get an HttpCacheContext instance, how do you link it with the request ? I see no setter on the HttpClient nor on the RequestConfig.
>>
>> Regards,
>> Christophe
>>
>>> On 9 Feb 2022, at 17:15, Naber, Peter <pe...@alfa.de> wrote:
>>>
>>> Hi,
>>>
>>> I use the HttpCacheContext but I think with the httpclient5 the preemtive authentication is implemented the same way.
>>>
>>>
>>> 	public HttpCacheContext getHttpCacheContext(final URL aURL) throws Exception {
>>> 		final HttpHost targetHost = new HttpHost(aURL.getProtocol(), aURL.getHost(), aURL.getPort()==-1?aURL.getDefaultPort():aURL.getPort());
>>> 		final HttpCacheContext context = HttpCacheContext.create();
>>> 		final AuthCache authCache = new BasicAuthCache();
>>> 		if (this.getPreAuth() && this.getUser()!= null && this.getPassword()!=null ) {
>>> 			if (this.getAuthScheme() == AuthScheme.BASIC) {
>>> 				final BasicScheme basicAuth = new BasicScheme();
>>> 				basicAuth.initPreemptive(
>>> 						new UsernamePasswordCredentials(this.getUser(), this.getPassword().toCharArray()));
>>> 				authCache.put(targetHost, basicAuth);
>>> 			} else if (this.getAuthScheme() == AuthScheme.DIGEST) {
>>> 				final DigestScheme digestScheme = new DigestScheme();
>>> 				final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(this.replace(this.getUser()),
>>> 						this.replace(this.getPassword()).toCharArray());
>>> 				digestScheme.initPreemptive(creds, UUID.randomUUID().toString().replaceAll("-", ""), "vectorius");
>>> 				authCache.put(targetHost, digestScheme);
>>> 			}
>>> 			context.setAuthCache(authCache);
>>> 		}
>>> 		context.setCredentialsProvider(this.getCredentialsProvider(aURL));
>>> 		return context;
>>> 	}
>>>
>>> regards,
>>>
>>> Peter
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: Christophe Darville <cd...@internetvista.com>
>>> Gesendet: Mittwoch, 9. Februar 2022 17:00
>>> An: HttpClient User Discussion <ht...@hc.apache.org>
>>> Betreff: Preemptive authentication in Http Client 5 Async
>>>
>>> Hi,
>>>
>>> I am trying to make preemptive authentication in HttpClient 5 Async mode using the following code, but I does not work, first request is still without authentication and the authentication is done on the second request :
>>>
>>> 	HttpClientContext httpContext = HttpClientContext.create();
>>> 	CredentialsProvider credentialsProvider = getCredentialsProvider();
>>> 	if (preemptive) {
>>> 		URI uri = URI.create(url);
>>> 		HttpHost targetHost = new HttpHost(uri.getScheme(), uri.getHost(), uri.getPort());
>>> 		AuthCache authCache = new BasicAuthCache();
>>> 		BasicScheme basicAuth = new BasicScheme();
>>> 		authCache.put(targetHost, basicAuth);
>>> 		httpContext.setAuthCache(authCache);
>>> 	}
>>> 	httpContext.setCredentialsProvider(credentialsProvider);
>>>
>>> This code was working in httpClient 4. Any suggestion on how to make preemptive authentication work in HttpClient5 Async ?
>>>
>>> Thank you,
>>> Christophe
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Post Multipart request using CloseableHttpAsyncClient (HC5)

Posted by Christophe Darville <cd...@internetvista.com>.
Ok, so today it is not possible to upload a file through a CloseableHttpAsyncClient or I missed something ?

> On 11 Feb 2022, at 18:50, Oleg Kalnichevski <ol...@apache.org> wrote:
> 
> 
> 
> On 2/11/2022 9:28 AM, Christophe Darville wrote:
>> Hi,
>> Do you have some sample code or some hints on how to post a multipart request through an async client in httpClient 5 ?
>> Javadoc about SimpleHttpRequest says  "It is generally recommended to use AsyncRequestBuilder and streaming AsyncEntityProducers.” but I cannot find traces of those classes in javadoc.
>> Any help would be appreciated.
> 
> As soon as someone contributes support for non-blocking multipart entity producers to the project there will be traces of those classes in javadocs.
> 
> Oleg
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Setting IOSessionListener on an HttpAsyncClientBuilder

Posted by Gary Gregory <ga...@gmail.com>.
A test would be nice ;-)

Gary

On Fri, Feb 18, 2022, 05:35 Christophe Darville <cd...@internetvista.com>
wrote:

> Hi Oleh,
>
> I have created a PR at Github with this feature. I hope I did it the right
> way.
>
> Regards,
> Christophe
>
> > On 17 Feb 2022, at 12:19, Oleg Kalnichevski <ol...@apache.org> wrote:
> >
> > On Thu, 2022-02-17 at 10:48 +0100, Christophe Darville wrote:
> >> Hi,
> >>
> >> It would be a nice feature to be able to set an IOSessionListener on
> >> an HttpAsyncClientBuilder in the same way we can set an
> >> IOReactorConfig. This IOSessionListener would be passed in the
> >> constructor of DefaultConnectingIOReactor like the IOReactorConfig
> >> (currently set to null).
> >>
> >> Regards,
> >> Christophe
> >>
> >>
> >
> > Christophe,
> >
> > Feel free to raise a change request JIRA for this feature or, better
> > yet, contribute it as a PR at GitHub.
> >
> > Oleg
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

Re: Setting IOSessionListener on an HttpAsyncClientBuilder

Posted by Christophe Darville <cd...@internetvista.com>.
Hi Oleh,

I have created a PR at Github with this feature. I hope I did it the right way.

Regards,
Christophe

> On 17 Feb 2022, at 12:19, Oleg Kalnichevski <ol...@apache.org> wrote:
> 
> On Thu, 2022-02-17 at 10:48 +0100, Christophe Darville wrote:
>> Hi,
>> 
>> It would be a nice feature to be able to set an IOSessionListener on
>> an HttpAsyncClientBuilder in the same way we can set an
>> IOReactorConfig. This IOSessionListener would be passed in the
>> constructor of DefaultConnectingIOReactor like the IOReactorConfig
>> (currently set to null). 
>> 
>> Regards,
>> Christophe 
>> 
>> 
> 
> Christophe,
> 
> Feel free to raise a change request JIRA for this feature or, better
> yet, contribute it as a PR at GitHub.
> 
> Oleg
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Setting IOSessionListener on an HttpAsyncClientBuilder

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2022-02-17 at 10:48 +0100, Christophe Darville wrote:
> Hi,
> 
> It would be a nice feature to be able to set an IOSessionListener on
> an HttpAsyncClientBuilder in the same way we can set an
> IOReactorConfig. This IOSessionListener would be passed in the
> constructor of DefaultConnectingIOReactor like the IOReactorConfig
> (currently set to null). 
> 
> Regards,
> Christophe 
> 
> 

Christophe,

Feel free to raise a change request JIRA for this feature or, better
yet, contribute it as a PR at GitHub.

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Setting IOSessionListener on an HttpAsyncClientBuilder

Posted by Christophe Darville <cd...@internetvista.com>.
Hi,

It would be a nice feature to be able to set an IOSessionListener on an HttpAsyncClientBuilder in the same way we can set an IOReactorConfig. This IOSessionListener would be passed in the constructor of DefaultConnectingIOReactor like the IOReactorConfig (currently set to null). 

Regards,
Christophe 



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Post Multipart request using CloseableHttpAsyncClient (HC5)

Posted by Oleg Kalnichevski <ol...@apache.org>.

On 2/11/2022 9:28 AM, Christophe Darville wrote:
> Hi,
> 
> Do you have some sample code or some hints on how to post a multipart request through an async client in httpClient 5 ?
> 
> Javadoc about SimpleHttpRequest says  "It is generally recommended to use AsyncRequestBuilder and streaming AsyncEntityProducers.” but I cannot find traces of those classes in javadoc.
> 
> Any help would be appreciated.
> 

As soon as someone contributes support for non-blocking multipart entity 
producers to the project there will be traces of those classes in javadocs.

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Post Multipart request using CloseableHttpAsyncClient (HC5)

Posted by Christophe Darville <cd...@internetvista.com>.
Hi,

Do you have some sample code or some hints on how to post a multipart request through an async client in httpClient 5 ? 

Javadoc about SimpleHttpRequest says  "It is generally recommended to use AsyncRequestBuilder and streaming AsyncEntityProducers.” but I cannot find traces of those classes in javadoc. 

Any help would be appreciated.

Regards,
Christophe
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


AW: Preemptive authentication in Http Client 5 Async

Posted by "Naber, Peter" <pe...@alfa.de>.
It was worth a try 😊

-----Ursprüngliche Nachricht-----
Von: Christophe Darville <cd...@internetvista.com> 
Gesendet: Donnerstag, 10. Februar 2022 10:44
An: HttpClient User Discussion <ht...@hc.apache.org>
Betreff: Re: Preemptive authentication in Http Client 5 Async

Thank you very much Peter. I missed the point that HttpCacheContext was extending HttpClientContext.

Unfortunately, httpClient5 Async (CloseableHttpAsyncClient) is not sending credentials at first request even with your code (the same as mine except using HttpCacheContext in place of HttpClientContext).

I will check with Oleg on the way to produce logs.

Regards,
Christophe

> On 10 Feb 2022, at 10:26, Naber, Peter <pe...@alfa.de> wrote:
> 
> Hi,
> 
> ok, than a little bit more code 😊
> 
> 
> 	public CloseableHttpClient getHttpClient() throws IOException, NoSuchAlgorithmException {
> 		final SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).build();
> 		String tlsString = System.getProperty("https.protocols");
> 		if ((tlsString == null) || tlsString.isEmpty()) {
> 			tlsString = "";
> 			final String[] protocols = SSLContext.getDefault().getSupportedSSLParameters().getProtocols();
> 			for (final String protocol : protocols) {
> 				if (protocol.startsWith("TLS")) {
> 					tlsString = tlsString.length() == 0 ? tlsString + protocol : tlsString + "," + protocol;
> 				}
> 			}
> 		}
> 		final PoolingHttpClientConnectionManager connManager = PoolingHttpClientConnectionManagerBuilder.create()
> 				.setConnectionFactory(this.connFactory).setDnsResolver(new SystemDefaultDnsResolver())
> 				.setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create().setSslContext(this.sslContext)
> 						.setTlsVersions(tlsString.split(",")).build())
> 				.setDefaultSocketConfig(socketConfig).setValidateAfterInactivity(TimeValue.ofSeconds(10L)).build();
> 
> 		this.defaultRequestConfig = RequestConfig.custom().setCookieSpec(StandardCookieSpec.RELAXED)
> 				.setAuthenticationEnabled(true).setExpectContinueEnabled(false).setContentCompressionEnabled(true)
> 				.setConnectionRequestTimeout(Timeout.ofMilliseconds(this.getConnectionRequestTimeout()))
> 				.setConnectTimeout(Timeout.ofMilliseconds(this.getConnectTimeout()))
> 				.setResponseTimeout(Timeout.ofMilliseconds(this.getSocketTimeout()))
> 				.setRedirectsEnabled(this.getRedirect()).setCircularRedirectsAllowed(false)
> 				.setTargetPreferredAuthSchemes(
> 						Arrays.asList(StandardAuthScheme.DIGEST, StandardAuthScheme.BASIC, StandardAuthScheme.NTLM))
> 				.setProxyPreferredAuthSchemes(Arrays.asList(StandardAuthScheme.BASIC, StandardAuthScheme.NTLM)).build();
> 
> 		final RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
> 
> 		final CachingHttpClientBuilder cachingHttpClients = CachingHttpClients.custom();
> 		cachingHttpClients.setCacheConfig(this.getHttpCacheConfig().getCacheConfig()).setConnectionManager(connManager)
> 				.setRedirectStrategy(redirectStrategy).setDefaultCookieStore(this.getCookieStore())
> 				.setDefaultRequestConfig(this.defaultRequestConfig);
> 		if (this.getHttpCacheConfig().getCacheFileName() != null) {
> 			cachingHttpClients.setCacheDir(new File(this.getHttpCacheConfig().getCacheFileName()));
> 		}
> 
> 		final HttpClientBuilder httpBuild = cachingHttpClients;
> 		httpBuild.addExecInterceptorBefore("test", "compress", new ContentCompressionExec());
> 		if (this.getHttpProxy() != null) {
> 			final HttpProxy hproxy = this.getHttpProxy();
> 			this.proxy = new HttpHost(hproxy.getHost(), hproxy.getPort());
> 			httpBuild.setProxy(this.proxy);
> 			httpBuild.setRoutePlanner(new DefaultProxyRoutePlanner(this.proxy) {
> 				@Override
> 				protected HttpHost determineProxy(final HttpHost target, final HttpContext context)
> 						throws HttpException {
> 
> 					if (ExecuteHttp.this.httpProxy == null) {
> 						return null;
> 					}
> 					if (ExecuteHttp.this.httpProxy.getProxyNonHosts() != null) {
> 						for (final String proxy1 : ExecuteHttp.this.httpProxy.getProxyNonHosts()) {
> 							try {
> 								if (target.getHostName().matches(proxy1)) {
> 									return null;
> 								}
> 							} catch (final Exception e) {
> 								e.printStackTrace();
> 							}
> 						}
> 					}
> 					return super.determineProxy(target, context);
> 				}
> 			});
> 		}
> 		final CloseableHttpClient httpClient = httpBuild.build();
> 
> 		return httpClient;
> 	}
> 
> 
> 	private void basicRequest(final String basicCommand, final String urls1) throws Exception {
> 		int status = 0;
> 		String returnString = "";
> 		try (CloseableHttpClient httpClient = this.getHttpClient()) {
> 			for (final String url : this.getURL(this.replace(urls1))) {
> 				final HttpUriRequestBase basicRequest = new HttpUriRequestBase(basicCommand, new URI(url));
> 				final URL aURL = new URL(url);
> 
> 				this.setHeaders(basicRequest);
> 				final HttpCacheContext context = this.getHttpCacheContext(aURL);
> 				this.log.info("[basicRequest]  " + basicRequest.getRequestUri());
> 				final CloseableHttpResponse response = httpClient.execute(basicRequest, context);
> 
> 				try {
> 					status = response.getCode();
> 					...
> 
> Regards,
> 
> Peter
> 
> -----Ursprüngliche Nachricht-----
> Von: Christophe Darville <cd...@internetvista.com> 
> Gesendet: Donnerstag, 10. Februar 2022 08:42
> An: HttpClient User Discussion <ht...@hc.apache.org>
> Betreff: Re: Preemptive authentication in Http Client 5 Async
> 
> Hi Peter,
> 
> Thank you for your answer. Once you get an HttpCacheContext instance, how do you link it with the request ? I see no setter on the HttpClient nor on the RequestConfig.
> 
> Regards,
> Christophe
> 
>> On 9 Feb 2022, at 17:15, Naber, Peter <pe...@alfa.de> wrote:
>> 
>> Hi,
>> 
>> I use the HttpCacheContext but I think with the httpclient5 the preemtive authentication is implemented the same way.
>> 
>> 
>> 	public HttpCacheContext getHttpCacheContext(final URL aURL) throws Exception {
>> 		final HttpHost targetHost = new HttpHost(aURL.getProtocol(), aURL.getHost(), aURL.getPort()==-1?aURL.getDefaultPort():aURL.getPort());
>> 		final HttpCacheContext context = HttpCacheContext.create();
>> 		final AuthCache authCache = new BasicAuthCache();
>> 		if (this.getPreAuth() && this.getUser()!= null && this.getPassword()!=null ) {
>> 			if (this.getAuthScheme() == AuthScheme.BASIC) {
>> 				final BasicScheme basicAuth = new BasicScheme();
>> 				basicAuth.initPreemptive(
>> 						new UsernamePasswordCredentials(this.getUser(), this.getPassword().toCharArray()));
>> 				authCache.put(targetHost, basicAuth);
>> 			} else if (this.getAuthScheme() == AuthScheme.DIGEST) {
>> 				final DigestScheme digestScheme = new DigestScheme();
>> 				final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(this.replace(this.getUser()),
>> 						this.replace(this.getPassword()).toCharArray());
>> 				digestScheme.initPreemptive(creds, UUID.randomUUID().toString().replaceAll("-", ""), "vectorius");
>> 				authCache.put(targetHost, digestScheme);
>> 			}
>> 			context.setAuthCache(authCache);
>> 		}
>> 		context.setCredentialsProvider(this.getCredentialsProvider(aURL));
>> 		return context;
>> 	}
>> 
>> regards,
>> 
>> Peter
>> 
>> -----Ursprüngliche Nachricht-----
>> Von: Christophe Darville <cd...@internetvista.com> 
>> Gesendet: Mittwoch, 9. Februar 2022 17:00
>> An: HttpClient User Discussion <ht...@hc.apache.org>
>> Betreff: Preemptive authentication in Http Client 5 Async
>> 
>> Hi,
>> 
>> I am trying to make preemptive authentication in HttpClient 5 Async mode using the following code, but I does not work, first request is still without authentication and the authentication is done on the second request : 
>> 
>> 	HttpClientContext httpContext = HttpClientContext.create();
>> 	CredentialsProvider credentialsProvider = getCredentialsProvider();
>> 	if (preemptive) {
>> 		URI uri = URI.create(url);
>> 		HttpHost targetHost = new HttpHost(uri.getScheme(), uri.getHost(), uri.getPort());
>> 		AuthCache authCache = new BasicAuthCache();
>> 		BasicScheme basicAuth = new BasicScheme();
>> 		authCache.put(targetHost, basicAuth);
>> 		httpContext.setAuthCache(authCache);
>> 	}
>> 	httpContext.setCredentialsProvider(credentialsProvider);
>> 
>> This code was working in httpClient 4. Any suggestion on how to make preemptive authentication work in HttpClient5 Async ?
>> 
>> Thank you,
>> Christophe
>> 
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Preemptive authentication in Http Client 5 Async

Posted by Christophe Darville <cd...@internetvista.com>.
Thank you very much Peter. I missed the point that HttpCacheContext was extending HttpClientContext.

Unfortunately, httpClient5 Async (CloseableHttpAsyncClient) is not sending credentials at first request even with your code (the same as mine except using HttpCacheContext in place of HttpClientContext).

I will check with Oleg on the way to produce logs.

Regards,
Christophe

> On 10 Feb 2022, at 10:26, Naber, Peter <pe...@alfa.de> wrote:
> 
> Hi,
> 
> ok, than a little bit more code 😊
> 
> 
> 	public CloseableHttpClient getHttpClient() throws IOException, NoSuchAlgorithmException {
> 		final SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).build();
> 		String tlsString = System.getProperty("https.protocols");
> 		if ((tlsString == null) || tlsString.isEmpty()) {
> 			tlsString = "";
> 			final String[] protocols = SSLContext.getDefault().getSupportedSSLParameters().getProtocols();
> 			for (final String protocol : protocols) {
> 				if (protocol.startsWith("TLS")) {
> 					tlsString = tlsString.length() == 0 ? tlsString + protocol : tlsString + "," + protocol;
> 				}
> 			}
> 		}
> 		final PoolingHttpClientConnectionManager connManager = PoolingHttpClientConnectionManagerBuilder.create()
> 				.setConnectionFactory(this.connFactory).setDnsResolver(new SystemDefaultDnsResolver())
> 				.setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create().setSslContext(this.sslContext)
> 						.setTlsVersions(tlsString.split(",")).build())
> 				.setDefaultSocketConfig(socketConfig).setValidateAfterInactivity(TimeValue.ofSeconds(10L)).build();
> 
> 		this.defaultRequestConfig = RequestConfig.custom().setCookieSpec(StandardCookieSpec.RELAXED)
> 				.setAuthenticationEnabled(true).setExpectContinueEnabled(false).setContentCompressionEnabled(true)
> 				.setConnectionRequestTimeout(Timeout.ofMilliseconds(this.getConnectionRequestTimeout()))
> 				.setConnectTimeout(Timeout.ofMilliseconds(this.getConnectTimeout()))
> 				.setResponseTimeout(Timeout.ofMilliseconds(this.getSocketTimeout()))
> 				.setRedirectsEnabled(this.getRedirect()).setCircularRedirectsAllowed(false)
> 				.setTargetPreferredAuthSchemes(
> 						Arrays.asList(StandardAuthScheme.DIGEST, StandardAuthScheme.BASIC, StandardAuthScheme.NTLM))
> 				.setProxyPreferredAuthSchemes(Arrays.asList(StandardAuthScheme.BASIC, StandardAuthScheme.NTLM)).build();
> 
> 		final RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
> 
> 		final CachingHttpClientBuilder cachingHttpClients = CachingHttpClients.custom();
> 		cachingHttpClients.setCacheConfig(this.getHttpCacheConfig().getCacheConfig()).setConnectionManager(connManager)
> 				.setRedirectStrategy(redirectStrategy).setDefaultCookieStore(this.getCookieStore())
> 				.setDefaultRequestConfig(this.defaultRequestConfig);
> 		if (this.getHttpCacheConfig().getCacheFileName() != null) {
> 			cachingHttpClients.setCacheDir(new File(this.getHttpCacheConfig().getCacheFileName()));
> 		}
> 
> 		final HttpClientBuilder httpBuild = cachingHttpClients;
> 		httpBuild.addExecInterceptorBefore("test", "compress", new ContentCompressionExec());
> 		if (this.getHttpProxy() != null) {
> 			final HttpProxy hproxy = this.getHttpProxy();
> 			this.proxy = new HttpHost(hproxy.getHost(), hproxy.getPort());
> 			httpBuild.setProxy(this.proxy);
> 			httpBuild.setRoutePlanner(new DefaultProxyRoutePlanner(this.proxy) {
> 				@Override
> 				protected HttpHost determineProxy(final HttpHost target, final HttpContext context)
> 						throws HttpException {
> 
> 					if (ExecuteHttp.this.httpProxy == null) {
> 						return null;
> 					}
> 					if (ExecuteHttp.this.httpProxy.getProxyNonHosts() != null) {
> 						for (final String proxy1 : ExecuteHttp.this.httpProxy.getProxyNonHosts()) {
> 							try {
> 								if (target.getHostName().matches(proxy1)) {
> 									return null;
> 								}
> 							} catch (final Exception e) {
> 								e.printStackTrace();
> 							}
> 						}
> 					}
> 					return super.determineProxy(target, context);
> 				}
> 			});
> 		}
> 		final CloseableHttpClient httpClient = httpBuild.build();
> 
> 		return httpClient;
> 	}
> 
> 
> 	private void basicRequest(final String basicCommand, final String urls1) throws Exception {
> 		int status = 0;
> 		String returnString = "";
> 		try (CloseableHttpClient httpClient = this.getHttpClient()) {
> 			for (final String url : this.getURL(this.replace(urls1))) {
> 				final HttpUriRequestBase basicRequest = new HttpUriRequestBase(basicCommand, new URI(url));
> 				final URL aURL = new URL(url);
> 
> 				this.setHeaders(basicRequest);
> 				final HttpCacheContext context = this.getHttpCacheContext(aURL);
> 				this.log.info("[basicRequest]  " + basicRequest.getRequestUri());
> 				final CloseableHttpResponse response = httpClient.execute(basicRequest, context);
> 
> 				try {
> 					status = response.getCode();
> 					...
> 
> Regards,
> 
> Peter
> 
> -----Ursprüngliche Nachricht-----
> Von: Christophe Darville <cd...@internetvista.com> 
> Gesendet: Donnerstag, 10. Februar 2022 08:42
> An: HttpClient User Discussion <ht...@hc.apache.org>
> Betreff: Re: Preemptive authentication in Http Client 5 Async
> 
> Hi Peter,
> 
> Thank you for your answer. Once you get an HttpCacheContext instance, how do you link it with the request ? I see no setter on the HttpClient nor on the RequestConfig.
> 
> Regards,
> Christophe
> 
>> On 9 Feb 2022, at 17:15, Naber, Peter <pe...@alfa.de> wrote:
>> 
>> Hi,
>> 
>> I use the HttpCacheContext but I think with the httpclient5 the preemtive authentication is implemented the same way.
>> 
>> 
>> 	public HttpCacheContext getHttpCacheContext(final URL aURL) throws Exception {
>> 		final HttpHost targetHost = new HttpHost(aURL.getProtocol(), aURL.getHost(), aURL.getPort()==-1?aURL.getDefaultPort():aURL.getPort());
>> 		final HttpCacheContext context = HttpCacheContext.create();
>> 		final AuthCache authCache = new BasicAuthCache();
>> 		if (this.getPreAuth() && this.getUser()!= null && this.getPassword()!=null ) {
>> 			if (this.getAuthScheme() == AuthScheme.BASIC) {
>> 				final BasicScheme basicAuth = new BasicScheme();
>> 				basicAuth.initPreemptive(
>> 						new UsernamePasswordCredentials(this.getUser(), this.getPassword().toCharArray()));
>> 				authCache.put(targetHost, basicAuth);
>> 			} else if (this.getAuthScheme() == AuthScheme.DIGEST) {
>> 				final DigestScheme digestScheme = new DigestScheme();
>> 				final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(this.replace(this.getUser()),
>> 						this.replace(this.getPassword()).toCharArray());
>> 				digestScheme.initPreemptive(creds, UUID.randomUUID().toString().replaceAll("-", ""), "vectorius");
>> 				authCache.put(targetHost, digestScheme);
>> 			}
>> 			context.setAuthCache(authCache);
>> 		}
>> 		context.setCredentialsProvider(this.getCredentialsProvider(aURL));
>> 		return context;
>> 	}
>> 
>> regards,
>> 
>> Peter
>> 
>> -----Ursprüngliche Nachricht-----
>> Von: Christophe Darville <cd...@internetvista.com> 
>> Gesendet: Mittwoch, 9. Februar 2022 17:00
>> An: HttpClient User Discussion <ht...@hc.apache.org>
>> Betreff: Preemptive authentication in Http Client 5 Async
>> 
>> Hi,
>> 
>> I am trying to make preemptive authentication in HttpClient 5 Async mode using the following code, but I does not work, first request is still without authentication and the authentication is done on the second request : 
>> 
>> 	HttpClientContext httpContext = HttpClientContext.create();
>> 	CredentialsProvider credentialsProvider = getCredentialsProvider();
>> 	if (preemptive) {
>> 		URI uri = URI.create(url);
>> 		HttpHost targetHost = new HttpHost(uri.getScheme(), uri.getHost(), uri.getPort());
>> 		AuthCache authCache = new BasicAuthCache();
>> 		BasicScheme basicAuth = new BasicScheme();
>> 		authCache.put(targetHost, basicAuth);
>> 		httpContext.setAuthCache(authCache);
>> 	}
>> 	httpContext.setCredentialsProvider(credentialsProvider);
>> 
>> This code was working in httpClient 4. Any suggestion on how to make preemptive authentication work in HttpClient5 Async ?
>> 
>> Thank you,
>> Christophe
>> 
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


AW: Preemptive authentication in Http Client 5 Async

Posted by "Naber, Peter" <pe...@alfa.de>.
Hi,

ok, than a little bit more code 😊


	public CloseableHttpClient getHttpClient() throws IOException, NoSuchAlgorithmException {
		final SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).build();
		String tlsString = System.getProperty("https.protocols");
		if ((tlsString == null) || tlsString.isEmpty()) {
			tlsString = "";
			final String[] protocols = SSLContext.getDefault().getSupportedSSLParameters().getProtocols();
			for (final String protocol : protocols) {
				if (protocol.startsWith("TLS")) {
					tlsString = tlsString.length() == 0 ? tlsString + protocol : tlsString + "," + protocol;
				}
			}
		}
		final PoolingHttpClientConnectionManager connManager = PoolingHttpClientConnectionManagerBuilder.create()
				.setConnectionFactory(this.connFactory).setDnsResolver(new SystemDefaultDnsResolver())
				.setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create().setSslContext(this.sslContext)
						.setTlsVersions(tlsString.split(",")).build())
				.setDefaultSocketConfig(socketConfig).setValidateAfterInactivity(TimeValue.ofSeconds(10L)).build();

		this.defaultRequestConfig = RequestConfig.custom().setCookieSpec(StandardCookieSpec.RELAXED)
				.setAuthenticationEnabled(true).setExpectContinueEnabled(false).setContentCompressionEnabled(true)
				.setConnectionRequestTimeout(Timeout.ofMilliseconds(this.getConnectionRequestTimeout()))
				.setConnectTimeout(Timeout.ofMilliseconds(this.getConnectTimeout()))
				.setResponseTimeout(Timeout.ofMilliseconds(this.getSocketTimeout()))
				.setRedirectsEnabled(this.getRedirect()).setCircularRedirectsAllowed(false)
				.setTargetPreferredAuthSchemes(
						Arrays.asList(StandardAuthScheme.DIGEST, StandardAuthScheme.BASIC, StandardAuthScheme.NTLM))
				.setProxyPreferredAuthSchemes(Arrays.asList(StandardAuthScheme.BASIC, StandardAuthScheme.NTLM)).build();

		final RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();

		final CachingHttpClientBuilder cachingHttpClients = CachingHttpClients.custom();
		cachingHttpClients.setCacheConfig(this.getHttpCacheConfig().getCacheConfig()).setConnectionManager(connManager)
				.setRedirectStrategy(redirectStrategy).setDefaultCookieStore(this.getCookieStore())
				.setDefaultRequestConfig(this.defaultRequestConfig);
		if (this.getHttpCacheConfig().getCacheFileName() != null) {
			cachingHttpClients.setCacheDir(new File(this.getHttpCacheConfig().getCacheFileName()));
		}

		final HttpClientBuilder httpBuild = cachingHttpClients;
		httpBuild.addExecInterceptorBefore("test", "compress", new ContentCompressionExec());
		if (this.getHttpProxy() != null) {
			final HttpProxy hproxy = this.getHttpProxy();
			this.proxy = new HttpHost(hproxy.getHost(), hproxy.getPort());
			httpBuild.setProxy(this.proxy);
			httpBuild.setRoutePlanner(new DefaultProxyRoutePlanner(this.proxy) {
				@Override
				protected HttpHost determineProxy(final HttpHost target, final HttpContext context)
						throws HttpException {

					if (ExecuteHttp.this.httpProxy == null) {
						return null;
					}
					if (ExecuteHttp.this.httpProxy.getProxyNonHosts() != null) {
						for (final String proxy1 : ExecuteHttp.this.httpProxy.getProxyNonHosts()) {
							try {
								if (target.getHostName().matches(proxy1)) {
									return null;
								}
							} catch (final Exception e) {
								e.printStackTrace();
							}
						}
					}
					return super.determineProxy(target, context);
				}
			});
		}
		final CloseableHttpClient httpClient = httpBuild.build();

		return httpClient;
	}


	private void basicRequest(final String basicCommand, final String urls1) throws Exception {
		int status = 0;
		String returnString = "";
		try (CloseableHttpClient httpClient = this.getHttpClient()) {
			for (final String url : this.getURL(this.replace(urls1))) {
				final HttpUriRequestBase basicRequest = new HttpUriRequestBase(basicCommand, new URI(url));
				final URL aURL = new URL(url);

				this.setHeaders(basicRequest);
				final HttpCacheContext context = this.getHttpCacheContext(aURL);
				this.log.info("[basicRequest]  " + basicRequest.getRequestUri());
				final CloseableHttpResponse response = httpClient.execute(basicRequest, context);

				try {
					status = response.getCode();
					...

Regards,

Peter

-----Ursprüngliche Nachricht-----
Von: Christophe Darville <cd...@internetvista.com> 
Gesendet: Donnerstag, 10. Februar 2022 08:42
An: HttpClient User Discussion <ht...@hc.apache.org>
Betreff: Re: Preemptive authentication in Http Client 5 Async

Hi Peter,

Thank you for your answer. Once you get an HttpCacheContext instance, how do you link it with the request ? I see no setter on the HttpClient nor on the RequestConfig.

Regards,
Christophe

> On 9 Feb 2022, at 17:15, Naber, Peter <pe...@alfa.de> wrote:
> 
> Hi,
> 
> I use the HttpCacheContext but I think with the httpclient5 the preemtive authentication is implemented the same way.
> 
> 
> 	public HttpCacheContext getHttpCacheContext(final URL aURL) throws Exception {
> 		final HttpHost targetHost = new HttpHost(aURL.getProtocol(), aURL.getHost(), aURL.getPort()==-1?aURL.getDefaultPort():aURL.getPort());
> 		final HttpCacheContext context = HttpCacheContext.create();
> 		final AuthCache authCache = new BasicAuthCache();
> 		if (this.getPreAuth() && this.getUser()!= null && this.getPassword()!=null ) {
> 			if (this.getAuthScheme() == AuthScheme.BASIC) {
> 				final BasicScheme basicAuth = new BasicScheme();
> 				basicAuth.initPreemptive(
> 						new UsernamePasswordCredentials(this.getUser(), this.getPassword().toCharArray()));
> 				authCache.put(targetHost, basicAuth);
> 			} else if (this.getAuthScheme() == AuthScheme.DIGEST) {
> 				final DigestScheme digestScheme = new DigestScheme();
> 				final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(this.replace(this.getUser()),
> 						this.replace(this.getPassword()).toCharArray());
> 				digestScheme.initPreemptive(creds, UUID.randomUUID().toString().replaceAll("-", ""), "vectorius");
> 				authCache.put(targetHost, digestScheme);
> 			}
> 			context.setAuthCache(authCache);
> 		}
> 		context.setCredentialsProvider(this.getCredentialsProvider(aURL));
> 		return context;
> 	}
> 
> regards,
> 
> Peter
> 
> -----Ursprüngliche Nachricht-----
> Von: Christophe Darville <cd...@internetvista.com> 
> Gesendet: Mittwoch, 9. Februar 2022 17:00
> An: HttpClient User Discussion <ht...@hc.apache.org>
> Betreff: Preemptive authentication in Http Client 5 Async
> 
> Hi,
> 
> I am trying to make preemptive authentication in HttpClient 5 Async mode using the following code, but I does not work, first request is still without authentication and the authentication is done on the second request : 
> 
> 	HttpClientContext httpContext = HttpClientContext.create();
> 	CredentialsProvider credentialsProvider = getCredentialsProvider();
> 	if (preemptive) {
> 		URI uri = URI.create(url);
> 		HttpHost targetHost = new HttpHost(uri.getScheme(), uri.getHost(), uri.getPort());
> 		AuthCache authCache = new BasicAuthCache();
> 		BasicScheme basicAuth = new BasicScheme();
> 		authCache.put(targetHost, basicAuth);
> 		httpContext.setAuthCache(authCache);
> 	}
> 	httpContext.setCredentialsProvider(credentialsProvider);
> 
> This code was working in httpClient 4. Any suggestion on how to make preemptive authentication work in HttpClient5 Async ?
> 
> Thank you,
> Christophe
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Preemptive authentication in Http Client 5 Async

Posted by Christophe Darville <cd...@internetvista.com>.
Hi Peter,

Thank you for your answer. Once you get an HttpCacheContext instance, how do you link it with the request ? I see no setter on the HttpClient nor on the RequestConfig.

Regards,
Christophe

> On 9 Feb 2022, at 17:15, Naber, Peter <pe...@alfa.de> wrote:
> 
> Hi,
> 
> I use the HttpCacheContext but I think with the httpclient5 the preemtive authentication is implemented the same way.
> 
> 
> 	public HttpCacheContext getHttpCacheContext(final URL aURL) throws Exception {
> 		final HttpHost targetHost = new HttpHost(aURL.getProtocol(), aURL.getHost(), aURL.getPort()==-1?aURL.getDefaultPort():aURL.getPort());
> 		final HttpCacheContext context = HttpCacheContext.create();
> 		final AuthCache authCache = new BasicAuthCache();
> 		if (this.getPreAuth() && this.getUser()!= null && this.getPassword()!=null ) {
> 			if (this.getAuthScheme() == AuthScheme.BASIC) {
> 				final BasicScheme basicAuth = new BasicScheme();
> 				basicAuth.initPreemptive(
> 						new UsernamePasswordCredentials(this.getUser(), this.getPassword().toCharArray()));
> 				authCache.put(targetHost, basicAuth);
> 			} else if (this.getAuthScheme() == AuthScheme.DIGEST) {
> 				final DigestScheme digestScheme = new DigestScheme();
> 				final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(this.replace(this.getUser()),
> 						this.replace(this.getPassword()).toCharArray());
> 				digestScheme.initPreemptive(creds, UUID.randomUUID().toString().replaceAll("-", ""), "vectorius");
> 				authCache.put(targetHost, digestScheme);
> 			}
> 			context.setAuthCache(authCache);
> 		}
> 		context.setCredentialsProvider(this.getCredentialsProvider(aURL));
> 		return context;
> 	}
> 
> regards,
> 
> Peter
> 
> -----Ursprüngliche Nachricht-----
> Von: Christophe Darville <cd...@internetvista.com> 
> Gesendet: Mittwoch, 9. Februar 2022 17:00
> An: HttpClient User Discussion <ht...@hc.apache.org>
> Betreff: Preemptive authentication in Http Client 5 Async
> 
> Hi,
> 
> I am trying to make preemptive authentication in HttpClient 5 Async mode using the following code, but I does not work, first request is still without authentication and the authentication is done on the second request : 
> 
> 	HttpClientContext httpContext = HttpClientContext.create();
> 	CredentialsProvider credentialsProvider = getCredentialsProvider();
> 	if (preemptive) {
> 		URI uri = URI.create(url);
> 		HttpHost targetHost = new HttpHost(uri.getScheme(), uri.getHost(), uri.getPort());
> 		AuthCache authCache = new BasicAuthCache();
> 		BasicScheme basicAuth = new BasicScheme();
> 		authCache.put(targetHost, basicAuth);
> 		httpContext.setAuthCache(authCache);
> 	}
> 	httpContext.setCredentialsProvider(credentialsProvider);
> 
> This code was working in httpClient 4. Any suggestion on how to make preemptive authentication work in HttpClient5 Async ?
> 
> Thank you,
> Christophe
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


AW: Preemptive authentication in Http Client 5 Async

Posted by "Naber, Peter" <pe...@alfa.de>.
Hi,

I use the HttpCacheContext but I think with the httpclient5 the preemtive authentication is implemented the same way.


	public HttpCacheContext getHttpCacheContext(final URL aURL) throws Exception {
		final HttpHost targetHost = new HttpHost(aURL.getProtocol(), aURL.getHost(), aURL.getPort()==-1?aURL.getDefaultPort():aURL.getPort());
		final HttpCacheContext context = HttpCacheContext.create();
		final AuthCache authCache = new BasicAuthCache();
		if (this.getPreAuth() && this.getUser()!= null && this.getPassword()!=null ) {
			if (this.getAuthScheme() == AuthScheme.BASIC) {
				final BasicScheme basicAuth = new BasicScheme();
				basicAuth.initPreemptive(
						new UsernamePasswordCredentials(this.getUser(), this.getPassword().toCharArray()));
				authCache.put(targetHost, basicAuth);
			} else if (this.getAuthScheme() == AuthScheme.DIGEST) {
				final DigestScheme digestScheme = new DigestScheme();
				final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(this.replace(this.getUser()),
						this.replace(this.getPassword()).toCharArray());
				digestScheme.initPreemptive(creds, UUID.randomUUID().toString().replaceAll("-", ""), "vectorius");
				authCache.put(targetHost, digestScheme);
			}
			context.setAuthCache(authCache);
		}
		context.setCredentialsProvider(this.getCredentialsProvider(aURL));
		return context;
	}

regards,

Peter

-----Ursprüngliche Nachricht-----
Von: Christophe Darville <cd...@internetvista.com> 
Gesendet: Mittwoch, 9. Februar 2022 17:00
An: HttpClient User Discussion <ht...@hc.apache.org>
Betreff: Preemptive authentication in Http Client 5 Async

Hi,

I am trying to make preemptive authentication in HttpClient 5 Async mode using the following code, but I does not work, first request is still without authentication and the authentication is done on the second request : 

	HttpClientContext httpContext = HttpClientContext.create();
	CredentialsProvider credentialsProvider = getCredentialsProvider();
	if (preemptive) {
		URI uri = URI.create(url);
		HttpHost targetHost = new HttpHost(uri.getScheme(), uri.getHost(), uri.getPort());
		AuthCache authCache = new BasicAuthCache();
		BasicScheme basicAuth = new BasicScheme();
		authCache.put(targetHost, basicAuth);
		httpContext.setAuthCache(authCache);
	}
	httpContext.setCredentialsProvider(credentialsProvider);

This code was working in httpClient 4. Any suggestion on how to make preemptive authentication work in HttpClient5 Async ?

Thank you,
Christophe




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Preemptive authentication in Http Client 5 Async

Posted by Christophe Darville <cd...@internetvista.com>.
Hi,

I am trying to make preemptive authentication in HttpClient 5 Async mode using the following code, but I does not work, first request is still without authentication and the authentication is done on the second request : 

	HttpClientContext httpContext = HttpClientContext.create();
	CredentialsProvider credentialsProvider = getCredentialsProvider();
	if (preemptive) {
		URI uri = URI.create(url);
		HttpHost targetHost = new HttpHost(uri.getScheme(), uri.getHost(), uri.getPort());
		AuthCache authCache = new BasicAuthCache();
		BasicScheme basicAuth = new BasicScheme();
		authCache.put(targetHost, basicAuth);
		httpContext.setAuthCache(authCache);
	}
	httpContext.setCredentialsProvider(credentialsProvider);

This code was working in httpClient 4. Any suggestion on how to make preemptive authentication work in HttpClient5 Async ?

Thank you,
Christophe