Я пытаюсь установить httpClient5 в Spring ... У меня есть следующий код:
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);
класс ClosableHttpClient реализует интерфейс org. apache .h c .client5.http .classi c .HttpClient, который не совместим с setHttpClient (клиент); Это ошибка времени выполнения:
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')
Я использую Spring 5.0 и HttpComponents-client-5. Как конвертировать HttpClient 4.X в HttpClient 5?