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

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new 4bb3002  [SCB-2255]common client Web socket  support (#2355)
4bb3002 is described below

commit 4bb30021c13390ed3b5148551422da34639d73a4
Author: zyl <[email protected]>
AuthorDate: Sun Apr 25 14:36:55 2021 +0800

    [SCB-2255]common client Web socket  support (#2355)
---
 .../http/client/common/SSLSocketFactoryExt.java    | 80 ++++++++++++++++++++++
 .../http/client/common/WebSocketTransport.java     |  3 +-
 2 files changed, 82 insertions(+), 1 deletion(-)

diff --git 
a/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/common/SSLSocketFactoryExt.java
 
b/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/common/SSLSocketFactoryExt.java
new file mode 100644
index 0000000..cd9f941
--- /dev/null
+++ 
b/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/common/SSLSocketFactoryExt.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.http.client.common;
+
+import javax.net.ssl.SSLSocketFactory;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+public class SSLSocketFactoryExt extends SSLSocketFactory {
+  private SSLSocketFactory sslSocketFactory;
+
+  private String host;
+
+  private int port;
+
+  public SSLSocketFactoryExt(SSLSocketFactory factory, String host, int port) {
+    this.sslSocketFactory = factory;
+    this.host = host;
+    this.port = port;
+  }
+
+  @Override
+  public String[] getDefaultCipherSuites() {
+    return this.sslSocketFactory.getDefaultCipherSuites();
+  }
+
+  @Override
+  public String[] getSupportedCipherSuites() {
+    return this.sslSocketFactory.getSupportedCipherSuites();
+  }
+
+  @Override
+  public Socket createSocket() throws IOException {
+    return this.sslSocketFactory.createSocket(host, port);
+  }
+
+  @Override
+  public Socket createSocket(Socket socket, String host, int port, boolean 
autoClose) throws IOException {
+    return this.sslSocketFactory.createSocket(socket, host, port, autoClose);
+  }
+
+  @Override
+  public Socket createSocket(String host, int port) throws IOException, 
UnknownHostException {
+    return this.sslSocketFactory.createSocket(host, port);
+  }
+
+  @Override
+  public Socket createSocket(String host, int port, InetAddress localHost, int 
localPort) throws IOException,
+      UnknownHostException {
+    return this.sslSocketFactory.createSocket(host, port, localHost, 
localPort);
+  }
+
+  @Override
+  public Socket createSocket(InetAddress localHost, int port) throws 
IOException {
+    return this.sslSocketFactory.createSocket(localHost, port);
+  }
+
+  @Override
+  public Socket createSocket(InetAddress localHost, int localPort, InetAddress 
localHost1, int localPort1)
+      throws IOException {
+    return this.sslSocketFactory.createSocket(localHost, localPort, 
localHost1, localPort1);
+  }
+}
diff --git 
a/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/common/WebSocketTransport.java
 
b/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/common/WebSocketTransport.java
index c24d963..7d36e28 100644
--- 
a/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/common/WebSocketTransport.java
+++ 
b/clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/common/WebSocketTransport.java
@@ -41,7 +41,8 @@ public class WebSocketTransport extends WebSocketClient {
     if (sslProperties.isEnabled()) {
       SSLSocketFactory sslSocketFactory = SSLManager
           .createSSLSocketFactory(sslProperties.getSslOption(), 
sslProperties.getSslCustom());
-      setSocketFactory(sslSocketFactory);
+      URI uri = new URI(serverUri);
+      setSocketFactory(new SSLSocketFactoryExt(sslSocketFactory, 
uri.getHost(), uri.getPort()));
     }
 
     this.webSocketListener = webSocketListener;

Reply via email to