Search in sources :

Example 1 with MyX509TrustManager

use of org.apache.eventmesh.client.http.ssl.MyX509TrustManager in project incubator-eventmesh by apache.

the class AbstractHttpClient method setHttpClient.

private CloseableHttpClient setHttpClient() throws EventMeshException {
    if (!eventMeshHttpClientConfig.isUseTls()) {
        return HttpClients.createDefault();
    }
    SSLContext sslContext;
    try {
        // todo: config in properties file?
        String protocol = System.getProperty("ssl.client.protocol", "TLSv1.2");
        TrustManager[] tm = new TrustManager[] { new MyX509TrustManager() };
        sslContext = SSLContext.getInstance(protocol);
        sslContext.init(null, tm, new SecureRandom());
        // todo: custom client pool
        return HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(new DefaultHostnameVerifier()).build();
    } catch (Exception e) {
        log.error("Error in creating HttpClient.", e);
        throw new EventMeshException(e);
    }
}
Also used : DefaultHostnameVerifier(org.apache.http.conn.ssl.DefaultHostnameVerifier) SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) EventMeshException(org.apache.eventmesh.common.exception.EventMeshException) IOException(java.io.IOException) EventMeshException(org.apache.eventmesh.common.exception.EventMeshException) TrustManager(javax.net.ssl.TrustManager) MyX509TrustManager(org.apache.eventmesh.client.http.ssl.MyX509TrustManager) MyX509TrustManager(org.apache.eventmesh.client.http.ssl.MyX509TrustManager)

Aggregations

IOException (java.io.IOException)1 SecureRandom (java.security.SecureRandom)1 SSLContext (javax.net.ssl.SSLContext)1 TrustManager (javax.net.ssl.TrustManager)1 MyX509TrustManager (org.apache.eventmesh.client.http.ssl.MyX509TrustManager)1 EventMeshException (org.apache.eventmesh.common.exception.EventMeshException)1 DefaultHostnameVerifier (org.apache.http.conn.ssl.DefaultHostnameVerifier)1