All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.co.mruoc.rest.client.insecure.InsecureHttpClientFactory Maven / Gradle / Ivy

package uk.co.mruoc.rest.client.insecure;

import org.apache.http.client.HttpClient;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.ssl.SSLContexts;

import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;

public class InsecureHttpClientFactory {

    public static HttpClient build() {
        SSLContext sslContext = buildSslContext();
        return HttpClientBuilder.create()
                .setSSLContext(sslContext)
                .setSSLHostnameVerifier(new NoopHostnameVerifier())
                .build();
    }

    private static SSLContext buildSslContext() {
        try {
            return SSLContexts.custom()
                    .loadTrustMaterial(new InsecureTrustStrategy())
                    .build();
        } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
            throw new InsecureHttpClientException(e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy