Search in sources :

Example 1 with BasicHttpClientConnectionManager

use of org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager in project pact-jvm by DiUS.

the class HttpClient method insecureHttpClient.

static CloseableHttpClient insecureHttpClient() {
    SSLContext sslContext = null;
    try {
        sslContext = SSLContexts.custom().loadTrustMaterial(new TrustSelfSignedStrategy()).build();
    } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
        throw new RuntimeException(e);
    }
    SSLConnectionSocketFactory socketFactory = SSLConnectionSocketFactoryBuilder.create().setSslContext(sslContext).build();
    CloseableHttpClient httpClient = HttpClientBuilder.create().setConnectionManager(new BasicHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", socketFactory).build())).build();
    return httpClient;
}
Also used : CloseableHttpClient(org.apache.hc.client5.http.impl.classic.CloseableHttpClient) ConnectionSocketFactory(org.apache.hc.client5.http.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.hc.client5.http.socket.PlainConnectionSocketFactory) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) TrustSelfSignedStrategy(org.apache.hc.client5.http.ssl.TrustSelfSignedStrategy) KeyManagementException(java.security.KeyManagementException) BasicHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager)

Aggregations

KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SSLContext (javax.net.ssl.SSLContext)1 CloseableHttpClient (org.apache.hc.client5.http.impl.classic.CloseableHttpClient)1 BasicHttpClientConnectionManager (org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager)1 ConnectionSocketFactory (org.apache.hc.client5.http.socket.ConnectionSocketFactory)1 PlainConnectionSocketFactory (org.apache.hc.client5.http.socket.PlainConnectionSocketFactory)1 SSLConnectionSocketFactory (org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory)1 TrustSelfSignedStrategy (org.apache.hc.client5.http.ssl.TrustSelfSignedStrategy)1