From 369f19608e768f0e817119391450fa7d337cbe1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=97=E5=B0=91?= <314226532@qq.com> Date: Tue, 5 Mar 2019 13:07:23 +0800 Subject: [PATCH] #863 --- .../client/config/NacosConfigService.java | 22 +++++++++++++------ .../client/config/impl/ServerListManager.java | 3 ++- .../client/naming/NacosNamingService.java | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/client/src/main/java/com/alibaba/nacos/client/config/NacosConfigService.java b/client/src/main/java/com/alibaba/nacos/client/config/NacosConfigService.java index 2b2e9c0c0..aa304a472 100644 --- a/client/src/main/java/com/alibaba/nacos/client/config/NacosConfigService.java +++ b/client/src/main/java/com/alibaba/nacos/client/config/NacosConfigService.java @@ -34,6 +34,7 @@ import com.alibaba.nacos.client.config.utils.ParamUtils; import com.alibaba.nacos.client.config.utils.TenantUtil; import com.alibaba.nacos.client.utils.LogUtils; import com.alibaba.nacos.client.utils.StringUtils; +import com.alibaba.nacos.client.utils.TemplateUtils; import org.slf4j.Logger; import java.io.IOException; @@ -42,6 +43,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Properties; +import java.util.concurrent.Callable; /** * Config Impl @@ -82,14 +84,20 @@ public class NacosConfigService implements ConfigService { private void initNamespace(Properties properties) { String namespaceTmp = properties.getProperty(PropertyKeyConst.NAMESPACE); - if (StringUtils.isBlank(namespaceTmp)) { - namespaceTmp = TenantUtil.getUserTenant(); - } - - if (StringUtils.isBlank(namespaceTmp)) { - namespaceTmp = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_NAMESPACE); - } + namespaceTmp = TemplateUtils.stringBlankAndThenExecute(namespaceTmp, new Callable() { + @Override + public String call() { + return TenantUtil.getUserTenant(); + } + }); + namespaceTmp = TemplateUtils.stringBlankAndThenExecute(namespaceTmp, new Callable() { + @Override + public String call() { + String namespace = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_NAMESPACE); + return StringUtils.isNotBlank(namespace) ? namespace : ""; + } + }); namespace = namespaceTmp; properties.put(PropertyKeyConst.NAMESPACE, namespace); } diff --git a/client/src/main/java/com/alibaba/nacos/client/config/impl/ServerListManager.java b/client/src/main/java/com/alibaba/nacos/client/config/impl/ServerListManager.java index 838af5183..6907bec1a 100644 --- a/client/src/main/java/com/alibaba/nacos/client/config/impl/ServerListManager.java +++ b/client/src/main/java/com/alibaba/nacos/client/config/impl/ServerListManager.java @@ -174,7 +174,8 @@ public class ServerListManager { return TemplateUtils.stringBlankAndThenExecute(endpointTmp, new Callable() { @Override public String call() { - return System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL); + String endpointUrl = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL); + return StringUtils.isNotBlank(endpointUrl) ? endpointUrl : ""; } }); } diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java b/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java index 0b5266efa..ddf518139 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java @@ -167,7 +167,7 @@ public class NacosNamingService implements NamingService { } }); - if (StringUtils.isEmpty(endpointUrl)) { + if (com.alibaba.nacos.client.utils.StringUtils.isNotBlank(endpointUrl)) { return; }