This commit is contained in:
得少 2019-03-05 13:07:23 +08:00
parent 557464bd2c
commit 369f19608e
3 changed files with 18 additions and 9 deletions

View File

@ -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.config.utils.TenantUtil;
import com.alibaba.nacos.client.utils.LogUtils; import com.alibaba.nacos.client.utils.LogUtils;
import com.alibaba.nacos.client.utils.StringUtils; import com.alibaba.nacos.client.utils.StringUtils;
import com.alibaba.nacos.client.utils.TemplateUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.io.IOException; import java.io.IOException;
@ -42,6 +43,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.Callable;
/** /**
* Config Impl * Config Impl
@ -82,14 +84,20 @@ public class NacosConfigService implements ConfigService {
private void initNamespace(Properties properties) { private void initNamespace(Properties properties) {
String namespaceTmp = properties.getProperty(PropertyKeyConst.NAMESPACE); String namespaceTmp = properties.getProperty(PropertyKeyConst.NAMESPACE);
if (StringUtils.isBlank(namespaceTmp)) { namespaceTmp = TemplateUtils.stringBlankAndThenExecute(namespaceTmp, new Callable<String>() {
namespaceTmp = TenantUtil.getUserTenant(); @Override
public String call() {
return TenantUtil.getUserTenant();
} }
});
if (StringUtils.isBlank(namespaceTmp)) { namespaceTmp = TemplateUtils.stringBlankAndThenExecute(namespaceTmp, new Callable<String>() {
namespaceTmp = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_NAMESPACE); @Override
public String call() {
String namespace = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_NAMESPACE);
return StringUtils.isNotBlank(namespace) ? namespace : "";
} }
});
namespace = namespaceTmp; namespace = namespaceTmp;
properties.put(PropertyKeyConst.NAMESPACE, namespace); properties.put(PropertyKeyConst.NAMESPACE, namespace);
} }

View File

@ -174,7 +174,8 @@ public class ServerListManager {
return TemplateUtils.stringBlankAndThenExecute(endpointTmp, new Callable<String>() { return TemplateUtils.stringBlankAndThenExecute(endpointTmp, new Callable<String>() {
@Override @Override
public String call() { 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 : "";
} }
}); });
} }

View File

@ -167,7 +167,7 @@ public class NacosNamingService implements NamingService {
} }
}); });
if (StringUtils.isEmpty(endpointUrl)) { if (com.alibaba.nacos.client.utils.StringUtils.isNotBlank(endpointUrl)) {
return; return;
} }