title: Apache camel http4 with self signed SSL certificate
body: <p>I'm really stuck configuring Apache camel https4 for self signed server certificates that does not match the hostname.</p>
  <pre><code>[Do. 2020 16 Juli 13:13:19] [DEBUG] org.apache.camel.processor.Pipeline () - Message exchange has failed: so breaking out of pipeline for exchange: Exchange[ID-lvm-cdbservice-01ct-1594888044674-0-15551] Exception: javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  </code></pre>
  <p>That's why I created a custom HttpClientConfigurer as stated in the apache camel http configuration. But this configurer does not seem to be used for my route?! Does anybody know why?</p>
  <p>The configureHttpClient method is used at some point</p>
  <pre><code>[Do. 2020 16 Juli 10:27:25] [INFO ] com.test.SelfSignedHttpClientConfigurer () - Using SelfSignedHttpClientConfigurer...
  [Do. 2020 16 Juli 10:27:25] [INFO ] com.test.SelfSignedHttpClientConfigurer () - ... HttpClient configured!
  </code></pre>
  <p>But the protocols didn't change. That's why I guess it is not used for my route.</p>
  <pre><code>available protocols [[TLSv1.3, TLSv1.2, TLSv1.1, TLSv1]],
  currently enabled protocols [[TLSv1.3, TLSv1.2, TLSv1.1, TLSv1]],
  and default protocol patterns [Patterns [includes=[.*], excludes=[SSL.*]]].
  Resulting enabled protocols are [[TLSv1.3, TLSv1.2, TLSv1.1, TLSv1]].
  </code></pre>
  <p><strong>pom.xml</strong></p>
  <pre><code>&lt;properties&gt;
      &lt;camel.version&gt;2.24.3&lt;/camel.version&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
      &lt;!-- camel --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
          &lt;artifactId&gt;camel-core&lt;/artifactId&gt;
          &lt;version&gt;${camel.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
          &lt;artifactId&gt;camel-spring&lt;/artifactId&gt;
          &lt;version&gt;${camel.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
          &lt;artifactId&gt;camel-http4&lt;/artifactId&gt;
          &lt;version&gt;${camel.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  <p><strong>applicationContext.xml</strong></p>
  <pre><code>&lt;!-- Apache Camel --&gt;
  &lt;camelContext
      xmlns=&quot;http://camel.apache.org/schema/spring&quot;&gt;
      &lt;!-- HTTP myTime --&gt;
      &lt;route id=&quot;myTimeRoute&quot;&gt;
          &lt;from uri=&quot;file:///tmp/test?consumer.delay=10000&quot; /&gt;
          &lt;setHeader headerName=&quot;CamelHttpMethod&quot;&gt;
              &lt;constant&gt;POST&lt;/constant&gt;
          &lt;/setHeader&gt;
          &lt;setHeader headerName=&quot;Content-Type&quot;&gt;
              &lt;constant&gt;application/json&lt;/constant&gt;
          &lt;/setHeader&gt;
          &lt;to uri=&quot;https4://test.de/test?delay=60000&amp;connectTimeout=20000&amp;httpClientConfigurer=#selfSignedHttpClientConfigurer&amp;sslContextParameters=#mySSLContextParameters&amp;throwExceptionOnFailure=false&quot; /&gt;
      &lt;/route&gt;
  &lt;/camelContext&gt;
  
  &lt;bean id=&quot;selfSignedHttpClientConfigurer&quot;
      class=&quot;com.test.SelfSignedHttpClientConfigurer&quot; /&gt;
  </code></pre>
  <p>I tried it with and without # (httpClientConfigurer=#selfSignedHttpClientConfigurer and httpClientConfigurer=selfSignedHttpClientConfigurer)</p>
  <p><strong>SelfSignedHttpClientConfigurer.class</strong></p>
  <pre><code>package com.test;
  
  import java.security.KeyManagementException;
  import java.security.KeyStoreException;
  import java.security.NoSuchAlgorithmException;
  
  import javax.net.ssl.SSLContext;
  
  import org.apache.camel.component.http4.HttpClientConfigurer;
  import org.apache.http.conn.ssl.NoopHostnameVerifier;
  import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
  import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
  import org.apache.http.impl.client.HttpClientBuilder;
  import org.apache.http.ssl.SSLContexts;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  public class SelfSignedHttpClientConfigurer implements HttpClientConfigurer {
  
      /** the logger. */
      private static final Logger LOG = LoggerFactory.getLogger(SelfSignedHttpClientConfigurer.class);
  
      @Override
      public void configureHttpClient(HttpClientBuilder clientBuilder) {
  
          try {
              LOG.info(&quot;Using SelfSignedHttpClientConfigurer...&quot;);
  
              SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();
  
              // Allow TLSv1.2 protocol only
              SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { &quot;TLSv1.2&quot; },
                  null, NoopHostnameVerifier.INSTANCE);
  
              clientBuilder.setSSLSocketFactory(sslsf);
  
              LOG.info(&quot;... HttpClient configured!&quot;);
  
          } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  <p>I tried with .build() and without.</p>