You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/10/30 04:29:39 UTC

[camel] branch master updated: CAMEL-14070 camel-netty-http: update client to support Server Name Indication (SNI) (#3291)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 587823c  CAMEL-14070 camel-netty-http: update client to support Server Name Indication (SNI) (#3291)
587823c is described below

commit 587823cff1514f0cfa0647f62fb015216a30f236
Author: Amos Feng <zf...@redhat.com>
AuthorDate: Wed Oct 30 12:29:27 2019 +0800

    CAMEL-14070 camel-netty-http: update client to support Server Name Indication (SNI) (#3291)
---
 .../component/netty/http/HttpClientInitializerFactory.java     | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
index 43f6c95..25c2a6d 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
@@ -16,11 +16,15 @@
  */
 package org.apache.camel.component.netty.http;
 
+import java.net.URI;
+import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
+import javax.net.ssl.SNIHostName;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLParameters;
 
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelHandler;
@@ -180,8 +184,12 @@ public class HttpClientInitializerFactory extends ClientInitializerFactory {
         if (producer.getConfiguration().getSslHandler() != null) {
             return producer.getConfiguration().getSslHandler();
         } else if (sslContext != null) {
-            SSLEngine engine = sslContext.createSSLEngine();
+            URI uri = new URI(producer.getEndpoint().getEndpointUri());
+            SSLEngine engine = sslContext.createSSLEngine(uri.getHost(), uri.getPort());
             engine.setUseClientMode(true);
+            SSLParameters sslParameters = engine.getSSLParameters();
+            sslParameters.setServerNames(Arrays.asList(new SNIHostName(uri.getHost())));
+            engine.setSSLParameters(sslParameters);
             if (producer.getConfiguration().getSslContextParameters() == null) {
                 // just set the enabledProtocols if the SslContextParameter doesn't set
                 engine.setEnabledProtocols(producer.getConfiguration().getEnabledProtocols().split(","));