Showing posts with label Camel. Show all posts
Showing posts with label Camel. Show all posts

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();
    }

Monday, 11 April 2016

Apache Camel Custome Annotated Beans Access



How to do Custom Bean Annotation Process in Apache Camel?
Sol:

In Camel we always have access to Camel Context. Using camel context we can access spring context as shown below. Once we have spring context we can access all features provided by Spring like getting annotated  beans .

Steps:
  1. Add Component scan to Spring for annotated beans.
  2. Annotate the class with  intended annotation
  3. As Code show below  
  4. Java code -   Link here   Java code