How to set Spring HttpComponentsClientHttpRequestFactory with Apache httpcomponent5?

1 answer

I'm trying to set httpClient5 in Spring ... I have the following code:

PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create()                 .setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create()                         .setSslContext(SSLContexts.createSystemDefault())                         .setTlsVersions(TLS.V_1_3, TLS.V_1_2)                         .build())                 .setDefaultSocketConfig(SocketConfig.custom()                         .setSoTimeout(Timeout.ofSeconds(5))                         .build())                 .setPoolConcurrencyPolicy(PoolConcurrencyPolicy.STRICT)                 .setConnPoolPolicy(PoolReusePolicy.LIFO)                 .setConnectionTimeToLive(TimeValue.ofMinutes(1L))                 .build();          CloseableHttpClient client = HttpClients.custom()                 .setConnectionManager(connectionManager)                 .setDefaultRequestConfig(RequestConfig.custom()                         .setConnectTimeout(Timeout.ofSeconds(5))                         .setResponseTimeout(Timeout.ofSeconds(5))                         .setCookieSpec(StandardCookieSpec.STRICT)                         .build())                 .build();          CookieStore cookieStore = new BasicCookieStore();          CredentialsProvider credentialsProvider = new BasicCredentialsProvider();          HttpClientContext clientContext = HttpClientContext.create();         clientContext.setCookieStore(cookieStore);         clientContext.setCredentialsProvider(credentialsProvider);         clientContext.setRequestConfig(RequestConfig.custom()                 .setConnectTimeout(Timeout.ofSeconds(5000))                 .setResponseTimeout(Timeout.ofSeconds(5000))                 .build());            // connect Spring httpComponent (client-side) with Apache httpClient         HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();         httpRequestFactory.setReadTimeout(60000);         httpRequestFactory.setConnectTimeout(60000);         httpRequestFactory.setHttpClient(client); 

the class ClosableHttpClient implements the interface org.apache.hc.client5.http.classic.HttpClient that is not compatible with setHttpClient(client); this the runtime error:

java.lang.ClassCastException: class org.apache.hc.client5.http.impl.classic.InternalHttpClient cannot be cast to class org.apache.http.client.HttpClient (org.apache.hc.client5.http.impl.classic.InternalHttpClient and org.apache.http.client.HttpClient are in unnamed module of loader 'app') 

I'm using Spring 5.0 and HttpComponents-client-5. How to convert HttpClient 4.X to HttpClient 5 ?

All answers to this question, which has the identifier 61210545

The best answer:

Apache HttpClient 4.5 and HttpClient 5.0 classic are very similar but are fully API incompatible.

Until Spring provides Apache HttpClient 5.x based RequestFactory implementation one cannot integrate HttpClient 5.x with Spring.

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data