diff --git a/client/src/main/java/com/alibaba/nacos/client/utils/AppNameUtils.java b/client/src/main/java/com/alibaba/nacos/client/utils/AppNameUtils.java index 12b0f662a07..e7d920927ac 100644 --- a/client/src/main/java/com/alibaba/nacos/client/utils/AppNameUtils.java +++ b/client/src/main/java/com/alibaba/nacos/client/utils/AppNameUtils.java @@ -17,6 +17,7 @@ package com.alibaba.nacos.client.utils; import com.alibaba.nacos.client.constant.Constants; +import com.alibaba.nacos.client.env.NacosClientProperties; import com.alibaba.nacos.common.utils.StringUtils; import java.io.File; @@ -63,17 +64,17 @@ public static String getAppName() { } private static String getAppNameByProjectName() { - return System.getProperty(Constants.SysEnv.PROJECT_NAME); + return NacosClientProperties.PROTOTYPE.getProperty(Constants.SysEnv.PROJECT_NAME); } private static String getAppNameByServerHome() { String serverHome = null; if (SERVER_JBOSS.equals(getServerType())) { - serverHome = System.getProperty(PARAM_MARKING_JBOSS); + serverHome = NacosClientProperties.PROTOTYPE.getProperty(PARAM_MARKING_JBOSS); } else if (SERVER_JETTY.equals(getServerType())) { - serverHome = System.getProperty(PARAM_MARKING_JETTY); + serverHome = NacosClientProperties.PROTOTYPE.getProperty(PARAM_MARKING_JETTY); } else if (SERVER_TOMCAT.equals(getServerType())) { - serverHome = System.getProperty(PARAM_MARKING_TOMCAT); + serverHome = NacosClientProperties.PROTOTYPE.getProperty(PARAM_MARKING_TOMCAT); } if (serverHome != null && serverHome.startsWith(LINUX_ADMIN_HOME)) { @@ -85,11 +86,11 @@ private static String getAppNameByServerHome() { private static String getServerType() { String serverType; - if (System.getProperty(PARAM_MARKING_JBOSS) != null) { + if (NacosClientProperties.PROTOTYPE.getProperty(PARAM_MARKING_JBOSS) != null) { serverType = SERVER_JBOSS; - } else if (System.getProperty(PARAM_MARKING_JETTY) != null) { + } else if (NacosClientProperties.PROTOTYPE.getProperty(PARAM_MARKING_JETTY) != null) { serverType = SERVER_JETTY; - } else if (System.getProperty(PARAM_MARKING_TOMCAT) != null) { + } else if (NacosClientProperties.PROTOTYPE.getProperty(PARAM_MARKING_TOMCAT) != null) { serverType = SERVER_TOMCAT; } else { serverType = SERVER_UNKNOWN; diff --git a/client/src/main/java/com/alibaba/nacos/client/utils/ParamUtil.java b/client/src/main/java/com/alibaba/nacos/client/utils/ParamUtil.java index cb35487c9d0..89f8c2e70b9 100644 --- a/client/src/main/java/com/alibaba/nacos/client/utils/ParamUtil.java +++ b/client/src/main/java/com/alibaba/nacos/client/utils/ParamUtil.java @@ -19,6 +19,7 @@ import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.SystemPropertyKeyConst; import com.alibaba.nacos.api.common.Constants; +import com.alibaba.nacos.client.env.NacosClientProperties; import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.common.utils.VersionUtils; import org.slf4j.Logger; @@ -77,18 +78,18 @@ public class ParamUtil { static { // Client identity information - appKey = System.getProperty(NACOS_CLIENT_APP_KEY, BLANK_STR); + appKey = NacosClientProperties.PROTOTYPE.getProperty(NACOS_CLIENT_APP_KEY, BLANK_STR); - defaultContextPath = System.getProperty(NACOS_CLIENT_CONTEXTPATH_KEY, DEFAULT_NACOS_CLIENT_CONTEXTPATH); + defaultContextPath = NacosClientProperties.PROTOTYPE.getProperty(NACOS_CLIENT_CONTEXTPATH_KEY, DEFAULT_NACOS_CLIENT_CONTEXTPATH); appName = AppNameUtils.getAppName(); - serverPort = System.getProperty(NACOS_SERVER_PORT_KEY, DEFAULT_SERVER_PORT); + serverPort = NacosClientProperties.PROTOTYPE.getProperty(NACOS_SERVER_PORT_KEY, DEFAULT_SERVER_PORT); LOGGER.info("[settings] [req-serv] nacos-server port:{}", serverPort); String tmp = "1000"; try { - tmp = System.getProperty(NACOS_CONNECT_TIMEOUT_KEY, DEFAULT_NACOS_CONNECT_TIMEOUT); + tmp = NacosClientProperties.PROTOTYPE.getProperty(NACOS_CONNECT_TIMEOUT_KEY, DEFAULT_NACOS_CONNECT_TIMEOUT); connectTimeout = Integer.parseInt(tmp); } catch (NumberFormatException e) { final String msg = "[http-client] invalid connect timeout:" + tmp; @@ -101,7 +102,7 @@ public class ParamUtil { try { perTaskConfigSize = Double - .parseDouble(System.getProperty(PER_TASK_CONFIG_SIZE_KEY, DEFAULT_PER_TASK_CONFIG_SIZE_KEY)); + .parseDouble(NacosClientProperties.PROTOTYPE.getProperty(PER_TASK_CONFIG_SIZE_KEY, DEFAULT_PER_TASK_CONFIG_SIZE_KEY)); LOGGER.info("PER_TASK_CONFIG_SIZE: {}", perTaskConfigSize); } catch (Throwable t) { LOGGER.error("[PER_TASK_CONFIG_SIZE] PER_TASK_CONFIG_SIZE invalid", t); @@ -178,14 +179,14 @@ public static String parseNamespace(Properties properties) { String namespaceTmp = null; String isUseCloudNamespaceParsing = properties.getProperty(PropertyKeyConst.IS_USE_CLOUD_NAMESPACE_PARSING, - System.getProperty(SystemPropertyKeyConst.IS_USE_CLOUD_NAMESPACE_PARSING, + NacosClientProperties.PROTOTYPE.getProperty(SystemPropertyKeyConst.IS_USE_CLOUD_NAMESPACE_PARSING, String.valueOf(Constants.DEFAULT_USE_CLOUD_NAMESPACE_PARSING))); if (Boolean.parseBoolean(isUseCloudNamespaceParsing)) { namespaceTmp = TenantUtil.getUserTenantForAcm(); namespaceTmp = TemplateUtils.stringBlankAndThenExecute(namespaceTmp, () -> { - String namespace = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_NAMESPACE); + String namespace = NacosClientProperties.PROTOTYPE.getProperty(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_NAMESPACE); return StringUtils.isNotBlank(namespace) ? namespace : StringUtils.EMPTY; }); } @@ -206,7 +207,7 @@ public static String parsingEndpointRule(String endpointUrl) { // If entered in the configuration file, the priority in ENV will be given priority. if (endpointUrl == null || !PATTERN.matcher(endpointUrl).find()) { // skip retrieve from system property and retrieve directly from system env - String endpointUrlSource = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL); + String endpointUrlSource = NacosClientProperties.PROTOTYPE.getProperty(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL); if (StringUtils.isNotBlank(endpointUrlSource)) { endpointUrl = endpointUrlSource; } @@ -223,8 +224,8 @@ public static String parsingEndpointRule(String endpointUrl) { } String endpointUrlSource = TemplateUtils - .stringBlankAndThenExecute(System.getProperty(endpointUrl, System.getenv(endpointUrl)), - () -> System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL)); + .stringBlankAndThenExecute(NacosClientProperties.PROTOTYPE.getProperty(endpointUrl, System.getenv(endpointUrl)), + () -> NacosClientProperties.PROTOTYPE.getProperty(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL)); if (StringUtils.isBlank(endpointUrlSource)) { if (StringUtils.isNotBlank(defaultEndpointUrl)) { diff --git a/client/src/main/java/com/alibaba/nacos/client/utils/TenantUtil.java b/client/src/main/java/com/alibaba/nacos/client/utils/TenantUtil.java index dfbcf87970f..b6e673180df 100644 --- a/client/src/main/java/com/alibaba/nacos/client/utils/TenantUtil.java +++ b/client/src/main/java/com/alibaba/nacos/client/utils/TenantUtil.java @@ -17,6 +17,7 @@ package com.alibaba.nacos.client.utils; import com.alibaba.nacos.api.SystemPropertyKeyConst; +import com.alibaba.nacos.client.env.NacosClientProperties; import com.alibaba.nacos.common.utils.StringUtils; /** @@ -35,7 +36,7 @@ public class TenantUtil { private static final String ACM_NAMESPACE_PROPERTY = "acm.namespace"; static { - USER_TENANT = System.getProperty(TENANT_ID, ""); + USER_TENANT = NacosClientProperties.PROTOTYPE.getProperty(TENANT_ID, ""); } /** @@ -51,7 +52,7 @@ public static String getUserTenantForAcm() { String tmp = USER_TENANT; if (StringUtils.isBlank(USER_TENANT)) { - tmp = System.getProperty(ACM_NAMESPACE_PROPERTY, DEFAULT_ACM_NAMESPACE); + tmp = NacosClientProperties.PROTOTYPE.getProperty(ACM_NAMESPACE_PROPERTY, DEFAULT_ACM_NAMESPACE); } return tmp; @@ -66,7 +67,7 @@ public static String getUserTenantForAns() { String tmp = USER_TENANT; if (StringUtils.isBlank(USER_TENANT)) { - tmp = System.getProperty(SystemPropertyKeyConst.ANS_NAMESPACE); + tmp = NacosClientProperties.PROTOTYPE.getProperty(SystemPropertyKeyConst.ANS_NAMESPACE); } return tmp; }