Browse Source

covert connect param host delete start http:// or https://. (#391)

Signed-off-by: xun.huang@zilliz.com <xun.huang@zilliz.com>

Signed-off-by: xun.huang@zilliz.com <xun.huang@zilliz.com>
yelusion 2 years ago
parent
commit
860dfa7c04

+ 10 - 0
src/main/java/io/milvus/common/constant/MilvusClientConstant.java

@@ -0,0 +1,10 @@
+package io.milvus.common.constant;
+
+public class MilvusClientConstant {
+
+    public static class MilvusConsts {
+        public final static String HOST_HTTPS_PREFIX = "https://";
+
+        public final static String HOST_HTTP_PREFIX = "http://";
+    }
+}

+ 9 - 0
src/main/java/io/milvus/param/ConnectParam.java

@@ -26,6 +26,9 @@ import java.nio.charset.StandardCharsets;
 import java.util.Base64;
 import java.util.concurrent.TimeUnit;
 
+import static io.milvus.common.constant.MilvusClientConstant.MilvusConsts.HOST_HTTPS_PREFIX;
+import static io.milvus.common.constant.MilvusClientConstant.MilvusConsts.HOST_HTTP_PREFIX;
+
 /**
  * Parameters for client connection.
  */
@@ -239,6 +242,12 @@ public class ConnectParam {
          */
         public ConnectParam build() throws ParamException {
             ParamUtils.CheckNullEmptyString(host, "Host name");
+            if(host.startsWith(HOST_HTTPS_PREFIX)){
+                this.host = host.replace(HOST_HTTPS_PREFIX, "");
+                this.secure = true;
+            }else if(host.startsWith(HOST_HTTP_PREFIX)){
+                this.host = host.replace(HOST_HTTP_PREFIX, "");
+            }
 
             if (port < 0 || port > 0xFFFF) {
                 throw new ParamException("Port is out of range!");

+ 19 - 1
src/main/java/io/milvus/param/MultiConnectParam.java

@@ -1,5 +1,6 @@
 package io.milvus.param;
 
+import com.google.common.collect.Lists;
 import io.milvus.exception.ParamException;
 import lombok.NonNull;
 import org.apache.commons.collections4.CollectionUtils;
@@ -9,6 +10,9 @@ import java.util.Base64;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
+import static io.milvus.common.constant.MilvusClientConstant.MilvusConsts.HOST_HTTPS_PREFIX;
+import static io.milvus.common.constant.MilvusClientConstant.MilvusConsts.HOST_HTTP_PREFIX;
+
 /**
  * Parameters for client connection of multi server.
  */
@@ -215,13 +219,27 @@ public class MultiConnectParam {
                 throw new ParamException("Server addresses is empty!");
             }
 
+            List<ServerAddress> hostAddress = Lists.newArrayList();
             for (ServerAddress serverAddress : hosts) {
-                ParamUtils.CheckNullEmptyString(serverAddress.getHost(), "Host name");
+                String host = serverAddress.getHost();
+                ParamUtils.CheckNullEmptyString(host, "Host name");
+                if(host.startsWith(HOST_HTTPS_PREFIX)){
+                    host = host.replace(HOST_HTTPS_PREFIX, "");
+                    this.secure = true;
+                }else if(host.startsWith(HOST_HTTP_PREFIX)){
+                    host = host.replace(HOST_HTTP_PREFIX, "");
+                }
+                hostAddress.add(ServerAddress.newBuilder()
+                        .withHost(host)
+                        .withPort(serverAddress.getPort())
+                        .withHealthPort(serverAddress.getHealthPort())
+                        .build());
 
                 if (serverAddress.getPort() < 0 || serverAddress.getPort() > 0xFFFF) {
                     throw new ParamException("Port is out of range!");
                 }
             }
+            this.withHosts(hostAddress);
 
             if (keepAliveTimeMs <= 0L) {
                 throw new ParamException("Keep alive time must be positive!");