Wednesday, 24 August 2016

Apache Camel - https4 Component SSL Trust Store issue

Problem:
 javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found

in apache camel https4 component


Solution:

Please add this truststore logic for verifying certificates from root ca by java itself.


 try {
   
    SSLContext sslContext = SSLContext.getInstance("TLS");
       SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext,
               new String[]{"TLSv1.2", "TLSv1.1", "TLSv1", "SSLv3"}, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier());
       final org.apache.http.config.Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
               .register("http", PlainConnectionSocketFactory.getSocketFactory())
               .register("https", sslConnectionSocketFactory)
               .build();
     
   
     
        HttpComponent http4 = camelContext.getComponent("https4", HttpComponent.class);
       
        http4.setHttpClientConfigurer(
        new HttpClientConfigurer() {

            @Override
            public void configureHttpClient(HttpClientBuilder builder) {

                builder.setSSLSocketFactory(sslConnectionSocketFactory);

                HttpClientConnectionManager ccm = new  BasicHttpClientConnectionManager(registry);

                builder.setConnectionManager(ccm);
            }
        });
    }catch (Exception e) {
        e.printStackTrace();
    }

1 comment:

  1. hello good night excuse me where should I integrate the ssl configuration. Will it be configuration?

    ReplyDelete

Please comment here