org.apache.http.impl.client.CloseableHttpClient cannot be converted to org.apache.hc.client5.http.classic.HttpClient

69 views Asked by At

So I updated to spring boot 3 and get this error. I looked up a few solution but the solutions all give me error. I tried the code below but it give me error on ".register(URIScheme.HTTPS.getId(), new SSLConnectionSocketFactory(sslContext))" where it expect ConnectionSocketFactory instead of SSLConnectionSocketFactory. Anyone know how to fix this issue?

Registry<ConnectionSocketFactory> socketRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
                    .register(URIScheme.HTTPS.getId(), new SSLConnectionSocketFactory(sslContext))
                    .register(URIScheme.HTTP.getId(), new PlainConnectionSocketFactory())
                    .build();
            HttpClient httpClient = HttpClientBuilder.create()
                    .setConnectionManager(new PoolingHttpClientConnectionManager(socketRegistry))
                    .setConnectionManagerShared(true)
                    .build();

Also this is the original code that's causing issues.

HttpClient httpClient =  HttpClients.custom().setSSLSocketFactory(socketFactory).disableRedirectHandling().build();

Thank for any help!

1

There are 1 answers

0
Rex On

I figured out the issue, the SSLConnectionSocketFactory import I had was not updated to httpclient5 version.