Skip to content

Migrate HttpClientBuilder.setSSLSocketFactory #68

@FieteO

Description

@FieteO

What problem are you trying to solve?

In httpclient 5, setSSLSocketFactory is not available on the HttpClientBuilder anymore (also see this SO question with 35k views as of writing).
Instead the method is available on the HttpClientConnectionManager which can then be set on the builder HttpClientBuilder.setConnectionManager.

What precondition(s) should be checked before applying this recipe?

PoolingHttpClientConnectionManagerBuilder.setSSLSocketFactory is deprecated in httpclient5, so a version check may be needed in the future

Describe the situation before applying the recipe

class A {
    void foo(String bar) {
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(null);

        CloseableHttpClient httpClient = HttpClientBuilder
            .create()
            .setSSLSocketFactory(sslSocketFactory)
            .build();
    }
}

Describe the situation after applying the recipe

class A {
    void foo(String bar) {
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(null);

        HttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder
            .create()
            .setSSLSocketFactory(sslSocketFactory)
            .build();

        CloseableHttpClient httpClient = HttpClientBuilder
            .create()
            .setConnectionManager(connectionManager)
            .build();
    }
}

Are you interested in contributing this recipe to OpenRewrite?

no

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Recipes Wanted

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions