diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/aot/NativeDetector.java b/dubbo-common/src/main/java/org/apache/dubbo/common/aot/NativeDetector.java index 657cfb6ee1a..4d71e84ce26 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/aot/NativeDetector.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/aot/NativeDetector.java @@ -16,12 +16,17 @@ */ package org.apache.dubbo.common.aot; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; + +import static org.apache.dubbo.common.constants.CommonConstants.ThirdPartyProperty.GRAALVM_NATIVEIMAGE_IMAGECODE; + public abstract class NativeDetector { /** * See https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/ImageInfo.java */ - private static final boolean IMAGE_CODE = (System.getProperty("org.graalvm.nativeimage.imagecode") != null); + private static final boolean IMAGE_CODE = + (SystemPropertyConfigUtils.getSystemProperty(GRAALVM_NATIVEIMAGE_IMAGECODE) != null); /** * Returns {@code true} if invoked in the context of image building or during image runtime, else {@code false}. diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java index 1f25041116c..a538096a8b3 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.ConcurrentHashMapUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import java.io.File; import java.io.IOException; @@ -34,6 +35,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.USER_HOME; import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_CACHE_PATH_INACCESSIBLE; /** @@ -81,7 +83,7 @@ public static FileCacheStore getInstance(String basePath, String cacheName) { public static FileCacheStore getInstance(String basePath, String cacheName, boolean enableFileCache) { if (basePath == null) { // default case: ~/.dubbo - basePath = System.getProperty("user.home") + File.separator + ".dubbo"; + basePath = SystemPropertyConfigUtils.getSystemProperty(USER_HOME) + File.separator + ".dubbo"; } if (basePath.endsWith(File.separator)) { basePath = basePath.substring(0, basePath.length() - 1); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/compact/Dubbo2CompactUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/compact/Dubbo2CompactUtils.java index f492847a68b..4e92b8663d2 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/compact/Dubbo2CompactUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/compact/Dubbo2CompactUtils.java @@ -18,6 +18,7 @@ import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import java.lang.annotation.Annotation; @@ -38,17 +39,18 @@ public class Dubbo2CompactUtils { private static void initEnabled() { try { - String fromProp = System.getProperty(CommonConstants.DUBBO2_COMPACT_ENABLE); + String fromProp = + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.DubboProperty.DUBBO2_COMPACT_ENABLE); if (StringUtils.isNotEmpty(fromProp)) { enabled = Boolean.parseBoolean(fromProp); return; } - String fromEnv = System.getenv(CommonConstants.DUBBO2_COMPACT_ENABLE); + String fromEnv = System.getenv(CommonConstants.DubboProperty.DUBBO2_COMPACT_ENABLE); if (StringUtils.isNotEmpty(fromEnv)) { enabled = Boolean.parseBoolean(fromEnv); return; } - fromEnv = System.getenv(StringUtils.toOSStyleKey(CommonConstants.DUBBO2_COMPACT_ENABLE)); + fromEnv = System.getenv(StringUtils.toOSStyleKey(CommonConstants.DubboProperty.DUBBO2_COMPACT_ENABLE)); enabled = !StringUtils.isNotEmpty(fromEnv) || Boolean.parseBoolean(fromEnv); } catch (Throwable t) { enabled = true; diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java index 644ed4a2f95..70d15a18ef9 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java @@ -25,6 +25,7 @@ import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.config.AbstractConfig; import org.apache.dubbo.config.context.ConfigConfigurationAdapter; import org.apache.dubbo.rpc.model.ScopeModel; @@ -96,10 +97,12 @@ public void initialize() throws IllegalStateException { */ @Deprecated private void loadMigrationRule() { - if (Boolean.parseBoolean(System.getProperty(CommonConstants.DUBBO_MIGRATION_FILE_ENABLE, "false"))) { - String path = System.getProperty(CommonConstants.DUBBO_MIGRATION_KEY); + if (Boolean.parseBoolean(SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.DubboProperty.DUBBO_MIGRATION_FILE_ENABLE, "false"))) { + String path = + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.DubboProperty.DUBBO_MIGRATION_KEY); if (StringUtils.isEmpty(path)) { - path = System.getenv(CommonConstants.DUBBO_MIGRATION_KEY); + path = System.getenv(CommonConstants.DubboProperty.DUBBO_MIGRATION_KEY); if (StringUtils.isEmpty(path)) { path = CommonConstants.DEFAULT_DUBBO_MIGRATION_FILE; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java index c4ee8a92555..92b46c77f55 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java @@ -60,14 +60,8 @@ public interface CommonConstants { String DISABLED_KEY = "disabled"; - String DUBBO_PROPERTIES_KEY = "dubbo.properties.file"; - String DEFAULT_DUBBO_PROPERTIES = "dubbo.properties"; - String DUBBO_MIGRATION_KEY = "dubbo.migration.file"; - - String DUBBO_MIGRATION_FILE_ENABLE = "dubbo.migration-file.enable"; - String DEFAULT_DUBBO_MIGRATION_FILE = "dubbo-migration.yaml"; String ANY_VALUE = "*"; @@ -299,14 +293,6 @@ public interface CommonConstants { */ String BROADCAST_CLUSTER = "broadcast"; - /** - * The property name for {@link NetworkInterface#getDisplayName() the name of network interface} that - * the Dubbo application prefers - * - * @since 2.7.6 - */ - String DUBBO_PREFERRED_NETWORK_INTERFACE = "dubbo.network.interface.preferred"; - @Deprecated String SHUTDOWN_WAIT_SECONDS_KEY = "dubbo.service.shutdown.wait.seconds"; @@ -439,12 +425,6 @@ public interface CommonConstants { */ String DEFAULT_SERVICE_NAME_MAPPING_PROPERTIES_PATH = "META-INF/dubbo/service-name-mapping.properties"; - String CLASS_DESERIALIZE_BLOCK_ALL = "dubbo.security.serialize.blockAllClassExceptAllow"; - - String CLASS_DESERIALIZE_ALLOWED_LIST = "dubbo.security.serialize.allowedClassList"; - - String CLASS_DESERIALIZE_BLOCKED_LIST = "dubbo.security.serialize.blockedClassList"; - String ENABLE_NATIVE_JAVA_GENERIC_SERIALIZE = "dubbo.security.serialize.generic.native-java-enable"; String SERIALIZE_BLOCKED_LIST_FILE_PATH = "security/serialize.blockedlist"; @@ -475,8 +455,6 @@ public interface CommonConstants { String DEFAULT_VERSION = "0.0.0"; - String CLASS_DESERIALIZE_OPEN_CHECK = "dubbo.security.serialize.openCheckClass"; - String ROUTER_KEY = "router"; String EXPORT_ASYNC_KEY = "export-async"; @@ -512,16 +490,6 @@ public interface CommonConstants { String SERVICE_MODEL = "serviceModel"; - /** - * The property name for {@link NetworkInterface#getDisplayName() the name of network interface} that - * the Dubbo application will be ignored - * - * @since 2.7.6 - */ - String DUBBO_NETWORK_IGNORED_INTERFACE = "dubbo.network.interface.ignored"; - - String OS_NAME_KEY = "os.name"; - String OS_LINUX_PREFIX = "linux"; String OS_WIN_PREFIX = "win"; @@ -566,10 +534,6 @@ public interface CommonConstants { String INJVM_IGNORE_SAME_MODULE_KEY = "injvm.ignore.same-module"; - String SET_FUTURE_IN_SYNC_MODE = "future.sync.set"; - - String CLEAR_FUTURE_AFTER_GET = "future.clear.once"; - String NATIVE_STUB = "nativestub"; String METADATA = "metadata"; @@ -578,8 +542,6 @@ public interface CommonConstants { String OPTIMIZER_KEY = "optimizer"; - String PREFER_JSON_FRAMEWORK_NAME = "dubbo.json-framework.prefer"; - /** * @since 3.1.0 */ @@ -616,19 +578,9 @@ public interface CommonConstants { String EXECUTOR_MANAGEMENT_MODE_DEFAULT = "default"; String EXECUTOR_MANAGEMENT_MODE_ISOLATION = "isolation"; - /** - * used in JVMUtil.java ,Control stack print lines, default is 32 lines - */ - String DUBBO_JSTACK_MAXLINE = "dubbo.jstack-dump.max-line"; - String ENCODE_IN_IO_THREAD_KEY = "encode.in.io"; boolean DEFAULT_ENCODE_IN_IO_THREAD = false; - /** - * @since 3.2.0 - */ - String BYTE_ACCESSOR_KEY = "byte.accessor"; - String PAYLOAD = "payload"; String DUBBO_METRICS_CONFIGCENTER_ENABLE = "dubbo.metrics.configcenter.enable"; @@ -643,12 +595,6 @@ public interface CommonConstants { String REST_SERVICE_DEPLOYER_URL_ATTRIBUTE_KEY = "restServiceDeployerAttributeKey"; - String SERVICE_DEPLOYER_ATTRIBUTE_KEY = "serviceDeployer"; - - String DUBBO_MANUAL_REGISTER_KEY = "dubbo.application.manual-register"; - - String DUBBO2_COMPACT_ENABLE = "dubbo.compact.enable"; - String POD_NAMESPACE = "POD_NAMESPACE"; String CLUSTER_DOMAIN = "CLUSTER_DOMAIN"; @@ -656,4 +602,150 @@ public interface CommonConstants { String EXT_PROTOCOL = "ext.protocol"; String IS_EXTRA = "isExtra"; + + /** + * System-related VM properties + */ + interface SystemProperty { + + String USER_HOME = "user.home"; + + String SYSTEM_JAVA_VERSION = "java.version"; + + String SYSTEM_JAVA_IO_TMPDIR = "java.io.tmpdir"; + + String SYSTEM_LINE_SEPARATOR = "line.separator"; + + String SERIALIZATION_SECURITY_CHECK_KEY = "serialization.security.check"; + + String SYSTEM_BYTE_ACCESSOR_KEY = "byte.accessor"; + + String SYSTEM_OS_NAME = "os.name"; + + String SYSTEM_OS_VERSION = "os.version"; + + String JAVA_RUNTIME_NAME = "java.runtime.name"; + + String JAVA_RUNTIME_VERSION = "java.runtime.version"; + + String JAVA_VM_NAME = "java.vm.name"; + + String JAVA_VM_VERSION = "java.vm.version"; + + String JAVA_VM_INFO = "java.vm.info"; + + String JAVA_HOME = "java.home"; + + String OS_ARCH = "os.arch"; + + String SYSTEM_FILE_ENCODING = "file.encoding"; + + String SYSTEM_TCP_RESPONSE_TIMEOUT = "sun.rmi.transport.tcp.responseTimeout"; + } + + /** + * Third-party-related VM properties + */ + interface ThirdPartyProperty { + String NETTY_EPOLL_ENABLE_KEY = "netty.epoll.enable"; + + String SET_FUTURE_IN_SYNC_MODE = "future.sync.set"; + + String CLEAR_FUTURE_AFTER_GET = "future.clear.once"; + + String APOLLO_ADDR_KEY = "apollo.meta"; + + String APOLLO_CLUSTER_KEY = "apollo.cluster"; + + String APOLLO_ENV_KEY = "env"; + + String APOLLO_APPID_KEY = "app.id"; + + String NACOS_SERVICE_NAME_SEPARATOR = "nacos.service.name.separator"; + + String GRAALVM_NATIVEIMAGE_IMAGECODE = "org.graalvm.nativeimage.imagecode"; + + /** + * The JVM arguments to set if it can use embedded zookeeper, the default value is {@code true}. + */ + String ZOOKEEPER_CONFIG_ENABLE_EMBEDDED = "enableEmbeddedZookeeper"; + } + + /** + * Dubbo custom VM properties + */ + interface DubboProperty { + String DUBBO_MIGRATION_FILE_ENABLE = "dubbo.migration-file.enable"; + String DUBBO_MIGRATION_KEY = "dubbo.migration.file"; + String DUBBO_APPLICATION_LOGGER = "dubbo.application.logger"; + String DUBBO_PROPERTIES_KEY = "dubbo.properties.file"; + String DUBBO_PREFER_JSON_FRAMEWORK_NAME = "dubbo.json-framework.prefer"; + + /** + * used in JVMUtil.java ,Control stack print lines, default is 32 lines + */ + String DUBBO_JSTACK_MAXLINE = "dubbo.jstack-dump.max-line"; + + /** + * The property name for {@link NetworkInterface#getDisplayName() the name of network interface} that + * the Dubbo application will be ignored + * + * @since 2.7.6 + */ + String DUBBO_NETWORK_IGNORED_INTERFACE = "dubbo.network.interface.ignored"; + + /** + * The property name for {@link NetworkInterface#getDisplayName() the name of network interface} that + * the Dubbo application prefers + * + * @since 2.7.6 + */ + String DUBBO_PREFERRED_NETWORK_INTERFACE = "dubbo.network.interface.preferred"; + + String DUBBO_CLASS_DESERIALIZE_ALLOWED_LIST = "dubbo.security.serialize.allowedClassList"; + String DUBBO_CLASS_DESERIALIZE_BLOCKED_LIST = "dubbo.security.serialize.blockedClassList"; + String DUBBO_CLASS_DESERIALIZE_OPEN_CHECK = "dubbo.security.serialize.openCheckClass"; + String DUBBO_CLASS_DESERIALIZE_BLOCK_ALL = "dubbo.security.serialize.blockAllClassExceptAllow"; + String DUBBO_RESOLVE_FILE = "dubbo.resolve.file"; + String DUBBO_IP_TO_REGISTRY = "DUBBO_IP_TO_REGISTRY"; + String DUBBO_MONITOR_ADDRESS = "dubbo.monitor.address"; + String DUBBO_CONTAINER_KEY = "dubbo.container"; + String DUBBO_SHUTDOWN_HOOK_KEY = "dubbo.shutdown.hook"; + String DUBBO_SPRING_CONFIG = "dubbo.spring.config"; + String DUBBO_MAPPING_CACHE_FILEPATH = "dubbo.mapping.cache.filePath"; + + String DUBBO_MAPPING_CACHE_FILENAME = "dubbo.mapping.cache.fileName"; + + String DUBBO_MAPPING_CACHE_ENTRYSIZE = "dubbo.mapping.cache.entrySize"; + + String DUBBO_MAPPING_CACHE_MAXFILESIZE = "dubbo.mapping.cache.maxFileSize"; + + String DUBBO_META_CACHE_FILEPATH = "dubbo.meta.cache.filePath"; + + String DUBBO_META_CACHE_FILENAME = "dubbo.meta.cache.fileName"; + + String DUBBO_META_CACHE_ENTRYSIZE = "dubbo.meta.cache.entrySize"; + + String DUBBO_META_CACHE_MAXFILESIZE = "dubbo.meta.cache.maxFileSize"; + + String DUBBO_USE_SECURE_RANDOM_ID = "dubbo.application.use-secure-random-request-id"; + + String DUBBO_CLOSE_TIMEOUT_CONFIG_KEY = "dubbo.protocol.default-close-timeout"; + + String DUBBO_HEARTBEAT_CONFIG_KEY = "dubbo.protocol.default-heartbeat"; + + String DUBBO_DEFAULT_REMOTING_SERIALIZATION_PROPERTY = "DUBBO_DEFAULT_SERIALIZATION"; + + String DUBBO_HESSIAN_ALLOW_NON_SERIALIZABLE = "dubbo.hessian.allowNonSerializable"; + + String DUBBO_HESSIAN_WHITELIST = "dubbo.application.hessian2.whitelist"; + + String DUBBO_HESSIAN_ALLOW = "dubbo.application.hessian2.allow"; + + String DUBBO_HESSIAN_DENY = "dubbo.application.hessian2.deny"; + + String DUBBO_MANUAL_REGISTER_KEY = "dubbo.application.manual-register"; + + String DUBBO2_COMPACT_ENABLE = "dubbo.compact.enable"; + } } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/logger/LoggerFactory.java b/dubbo-common/src/main/java/org/apache/dubbo/common/logger/LoggerFactory.java index e52f2f4d628..00eaebe64cc 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/logger/LoggerFactory.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/logger/LoggerFactory.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common.logger; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.logger.jcl.JclLoggerAdapter; import org.apache.dubbo.common.logger.jdk.JdkLoggerAdapter; import org.apache.dubbo.common.logger.log4j.Log4jLoggerAdapter; @@ -24,6 +25,7 @@ import org.apache.dubbo.common.logger.support.FailsafeErrorTypeAwareLogger; import org.apache.dubbo.common.logger.support.FailsafeLogger; import org.apache.dubbo.common.utils.ConcurrentHashMapUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.rpc.model.FrameworkModel; import java.io.File; @@ -47,7 +49,8 @@ public class LoggerFactory { // search common-used logging frameworks static { - String logger = System.getProperty("dubbo.application.logger", ""); + String logger = + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.DubboProperty.DUBBO_APPLICATION_LOGGER, ""); switch (logger) { case Slf4jLoggerAdapter.NAME: setLoggerAdapter(new Slf4jLoggerAdapter()); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReport.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReport.java index 223a72419de..f35c6a0fefe 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReport.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReport.java @@ -17,6 +17,7 @@ package org.apache.dubbo.common.threadpool.support; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -25,6 +26,7 @@ import org.apache.dubbo.common.utils.ConcurrentHashSet; import org.apache.dubbo.common.utils.JVMUtil; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.rpc.model.FrameworkModel; import java.io.File; @@ -42,8 +44,8 @@ import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR_CHAR; import static org.apache.dubbo.common.constants.CommonConstants.DUMP_DIRECTORY; import static org.apache.dubbo.common.constants.CommonConstants.DUMP_ENABLE; -import static org.apache.dubbo.common.constants.CommonConstants.OS_NAME_KEY; import static org.apache.dubbo.common.constants.CommonConstants.OS_WIN_PREFIX; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_OS_NAME; import static org.apache.dubbo.common.constants.CommonConstants.THREAD_POOL_EXHAUSTED_LISTENERS_KEY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_THREAD_POOL_EXHAUSTED; import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_CREATE_DUMP; @@ -71,7 +73,8 @@ public class AbortPolicyWithReport extends ThreadPoolExecutor.AbortPolicy { protected static Semaphore guard = new Semaphore(1); - private static final String USER_HOME = System.getProperty("user.home"); + private static final String USER_HOME = + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.USER_HOME); private final Set listeners = new ConcurrentHashSet<>(); @@ -168,7 +171,8 @@ private void dumpJStack() { SimpleDateFormat sdf; - String os = System.getProperty(OS_NAME_KEY).toLowerCase(); + String os = SystemPropertyConfigUtils.getSystemProperty(SYSTEM_OS_NAME) + .toLowerCase(); // window system don't support ":" in file name if (os.contains(OS_WIN_PREFIX)) { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java b/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java index a5c255b2b8a..29207a1b3ee 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.ClassUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import java.util.Collections; import java.util.HashSet; @@ -36,7 +37,7 @@ import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicLong; -import static org.apache.dubbo.common.constants.CommonConstants.OS_NAME_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_OS_NAME; import static org.apache.dubbo.common.constants.CommonConstants.OS_WIN_PREFIX; import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_ERROR_RUN_THREAD_TASK; import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_ERROR_TOO_MANY_INSTANCES; @@ -811,7 +812,7 @@ private HashedWheelTimeout pollTimeout() { } } - private static final boolean IS_OS_WINDOWS = System.getProperty(OS_NAME_KEY, "").toLowerCase(Locale.US).contains(OS_WIN_PREFIX); + private static final boolean IS_OS_WINDOWS = SystemPropertyConfigUtils.getSystemProperty(SYSTEM_OS_NAME, "").toLowerCase(Locale.US).contains(OS_WIN_PREFIX); private boolean isWindows() { return IS_OS_WINDOWS; diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java index 74ad48add58..f6754ad0649 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java @@ -164,9 +164,9 @@ public static String replaceProperty(String expression, Configuration configurat * @return */ public static Properties getProperties(Set classLoaders) { - String path = System.getProperty(CommonConstants.DUBBO_PROPERTIES_KEY); + String path = SystemPropertyConfigUtils.getSystemProperty(CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY); if (StringUtils.isEmpty(path)) { - path = System.getenv(CommonConstants.DUBBO_PROPERTIES_KEY); + path = System.getenv(CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY); if (StringUtils.isEmpty(path)) { path = CommonConstants.DEFAULT_DUBBO_PROPERTIES; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JRE.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JRE.java index 6897bfae0aa..f71e38870c2 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JRE.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JRE.java @@ -19,6 +19,8 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_JAVA_VERSION; + /** * JRE version */ @@ -81,7 +83,7 @@ public boolean isCurrentVersion() { private static JRE getJre() { // get java version from system property - String version = System.getProperty("java.version"); + String version = SystemPropertyConfigUtils.getSystemProperty(SYSTEM_JAVA_VERSION); boolean isBlank = StringUtils.isBlank(version); if (isBlank) { logger.debug("java.version is blank"); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JVMUtil.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JVMUtil.java index bbd6df09b72..f38dfaeb5b2 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JVMUtil.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JVMUtil.java @@ -56,7 +56,8 @@ private static String getThreadDumpString(ThreadInfo threadInfo) { int i = 0; // default is 32, means only print up to 32 lines int jstackMaxLine = 32; - String jstackMaxLineStr = System.getProperty(CommonConstants.DUBBO_JSTACK_MAXLINE); + String jstackMaxLineStr = + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.DubboProperty.DUBBO_JSTACK_MAXLINE); if (StringUtils.isNotEmpty(jstackMaxLineStr)) { try { jstackMaxLine = Integer.parseInt(jstackMaxLineStr); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JsonUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JsonUtils.java index 05c3c40a8dd..2b47ee3ed5b 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JsonUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/JsonUtils.java @@ -35,7 +35,8 @@ protected static JsonUtil getJson() { if (jsonUtil == null) { synchronized (JsonUtils.class) { if (jsonUtil == null) { - String preferJsonFrameworkName = System.getProperty(CommonConstants.PREFER_JSON_FRAMEWORK_NAME); + String preferJsonFrameworkName = SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); if (StringUtils.isNotEmpty(preferJsonFrameworkName)) { try { JsonUtil instance = null; diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java index 6a04983b051..d53c36a73cd 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java @@ -48,8 +48,6 @@ import static java.util.Collections.emptyList; import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_IP_TO_BIND; -import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_NETWORK_IGNORED_INTERFACE; -import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PREFERRED_NETWORK_INTERFACE; import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_KEY; import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE; import static org.apache.dubbo.common.utils.CollectionUtils.first; @@ -138,6 +136,7 @@ public static synchronized int getAvailablePort(int port) { /** * Check the port whether is in use in os + * * @param port port to check * @return true if it's occupied */ @@ -153,9 +152,9 @@ public static boolean isPortInUsed(int port) { /** * Tells whether the port to test is an invalid port. * - * @implNote Numeric comparison only. * @param port port to test * @return true if invalid + * @implNote Numeric comparison only. */ public static boolean isInvalidPort(int port) { return port < MIN_PORT || port > MAX_PORT; @@ -164,9 +163,9 @@ public static boolean isInvalidPort(int port) { /** * Tells whether the address to test is an invalid address. * - * @implNote Pattern matching only. * @param address address to test * @return true if invalid + * @implNote Pattern matching only. */ public static boolean isValidAddress(String address) { return ADDRESS_PATTERN.matcher(address).matches(); @@ -452,7 +451,8 @@ private static boolean ignoreNetworkInterface(NetworkInterface networkInterface) || !networkInterface.isUp()) { return true; } - String ignoredInterfaces = System.getProperty(DUBBO_NETWORK_IGNORED_INTERFACE); + String ignoredInterfaces = SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.DubboProperty.DUBBO_NETWORK_IGNORED_INTERFACE); String networkInterfaceDisplayName; if (StringUtils.isNotEmpty(ignoredInterfaces) && StringUtils.isNotEmpty(networkInterfaceDisplayName = networkInterface.getDisplayName())) { @@ -505,11 +505,12 @@ private static List getValidNetworkInterfaces() throws SocketE * * @param networkInterface {@link NetworkInterface} * @return if the name of the specified {@link NetworkInterface} matches - * the property value from {@link CommonConstants#DUBBO_PREFERRED_NETWORK_INTERFACE}, return true, + * the property value from {@link CommonConstants.DubboProperty#DUBBO_PREFERRED_NETWORK_INTERFACE}, return true, * or false */ public static boolean isPreferredNetworkInterface(NetworkInterface networkInterface) { - String preferredNetworkInterface = System.getProperty(DUBBO_PREFERRED_NETWORK_INTERFACE); + String preferredNetworkInterface = SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFERRED_NETWORK_INTERFACE); return Objects.equals(networkInterface.getDisplayName(), preferredNetworkInterface); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/SerializeSecurityConfigurator.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/SerializeSecurityConfigurator.java index f49f7cfbfb7..468e412b2cb 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/SerializeSecurityConfigurator.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/SerializeSecurityConfigurator.java @@ -40,9 +40,6 @@ import java.util.Set; import java.util.stream.Collectors; -import static org.apache.dubbo.common.constants.CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST; -import static org.apache.dubbo.common.constants.CommonConstants.CLASS_DESERIALIZE_BLOCKED_LIST; -import static org.apache.dubbo.common.constants.CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL; import static org.apache.dubbo.common.constants.CommonConstants.SERIALIZE_ALLOW_LIST_FILE_PATH; import static org.apache.dubbo.common.constants.CommonConstants.SERIALIZE_BLOCKED_LIST_FILE_PATH; import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_IO_EXCEPTION; @@ -102,10 +99,12 @@ private void refreshClassLoader(ClassLoader classLoader) { } private void refreshConfig() { - String allowedClassList = - System.getProperty(CLASS_DESERIALIZE_ALLOWED_LIST, "").trim(); - String blockedClassList = - System.getProperty(CLASS_DESERIALIZE_BLOCKED_LIST, "").trim(); + String allowedClassList = SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_ALLOWED_LIST, "") + .trim(); + String blockedClassList = SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_BLOCKED_LIST, "") + .trim(); if (StringUtils.isNotEmpty(allowedClassList)) { String[] classStrings = allowedClassList.trim().split(","); @@ -184,11 +183,13 @@ public void refreshStatus() { SerializeCheckStatus checkStatus = null; if (StringUtils.isEmpty(statusString)) { - String openCheckClass = System.getProperty(CommonConstants.CLASS_DESERIALIZE_OPEN_CHECK, "true"); + String openCheckClass = SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_OPEN_CHECK, "true"); if (!Boolean.parseBoolean(openCheckClass)) { checkStatus = SerializeCheckStatus.DISABLE; } - String blockAllClassExceptAllow = System.getProperty(CLASS_DESERIALIZE_BLOCK_ALL, "false"); + String blockAllClassExceptAllow = SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_BLOCK_ALL, "false"); if (Boolean.parseBoolean(blockAllClassExceptAllow)) { checkStatus = SerializeCheckStatus.STRICT; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/SystemPropertyConfigUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/SystemPropertyConfigUtils.java new file mode 100644 index 00000000000..857807e79e0 --- /dev/null +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/SystemPropertyConfigUtils.java @@ -0,0 +1,120 @@ +/* + * 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.dubbo.common.utils; + +import org.apache.dubbo.common.constants.CommonConstants; + +import java.lang.reflect.Field; +import java.util.HashSet; +import java.util.Set; + +public class SystemPropertyConfigUtils { + + private static Set systemProperties = new HashSet<>(); + + static { + Class[] classes = new Class[] { + CommonConstants.SystemProperty.class, + CommonConstants.ThirdPartyProperty.class, + CommonConstants.DubboProperty.class + }; + for (Class clazz : classes) { + Field[] fields = clazz.getDeclaredFields(); + for (Field field : fields) { + try { + assert systemProperties != null; + systemProperties.add((String) field.get(null)); + } catch (IllegalAccessException e) { + throw new IllegalStateException( + String.format("%s does not have field of %s", clazz.getName(), field.getName())); + } + } + } + } + + /** + * Return property of VM. + * + * @param key + * @return + */ + public static String getSystemProperty(String key) { + if (containsKey(key)) { + return System.getProperty(key); + } else { + throw new IllegalStateException(String.format( + "System property [%s] does not define in org.apache.dubbo.common.constants.CommonConstants", key)); + } + } + + /** + * Return property of VM. If not exist, the default value is returned. + * + * @param key + * @param defaultValue + * @return + */ + public static String getSystemProperty(String key, String defaultValue) { + if (containsKey(key)) { + return System.getProperty(key, defaultValue); + } else { + throw new IllegalStateException(String.format( + "System property [%s] does not define in org.apache.dubbo.common.constants.CommonConstants", key)); + } + } + + /** + * Set property of VM. + * + * @param key + * @param value + * @return + */ + public static String setSystemProperty(String key, String value) { + if (containsKey(key)) { + return System.setProperty(key, value); + } else { + throw new IllegalStateException(String.format( + "System property [%s] does not define in org.apache.dubbo.common.constants.CommonConstants", key)); + } + } + + /** + * Clear property of VM. + * + * @param key + * @return + */ + public static String clearSystemProperty(String key) { + if (containsKey(key)) { + return System.clearProperty(key); + } else { + throw new IllegalStateException(String.format( + "System property [%s] does not define in org.apache.dubbo.common.constants.CommonConstants", key)); + } + } + + /** + * Check whether the key is valid. + * + * @param key + * @return + */ + private static boolean containsKey(String key) { + return systemProperties.contains(key); + } +} diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/config/Constants.java index 59b399843fc..822d81e9346 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/Constants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/Constants.java @@ -89,8 +89,6 @@ public interface Constants { String MULTICAST = "multicast"; - String DUBBO_IP_TO_REGISTRY = "DUBBO_IP_TO_REGISTRY"; - String DUBBO_PORT_TO_REGISTRY = "DUBBO_PORT_TO_REGISTRY"; String DUBBO_PORT_TO_BIND = "DUBBO_PORT_TO_BIND"; diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ConsumerConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ConsumerConfig.java index b34ee3c1403..81c30247a92 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ConsumerConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ConsumerConfig.java @@ -17,12 +17,14 @@ package org.apache.dubbo.config; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.config.support.Parameter; import org.apache.dubbo.rpc.model.ModuleModel; import static org.apache.dubbo.common.constants.CommonConstants.MESH_ENABLE; import static org.apache.dubbo.common.constants.CommonConstants.REFER_BACKGROUND_KEY; import static org.apache.dubbo.common.constants.CommonConstants.REFER_THREAD_NUM_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_TCP_RESPONSE_TIMEOUT; import static org.apache.dubbo.common.constants.CommonConstants.URL_MERGE_PROCESSOR_KEY; /** @@ -61,8 +63,8 @@ public class ConsumerConfig extends AbstractReferenceConfig { private Integer shareconnections; /** - * Url Merge Processor - * Used to customize the URL merge of consumer and provider + * Url Merge Processor + * Used to customize the URL merge of consumer and provider */ private String urlMergeProcessor; @@ -74,13 +76,14 @@ public class ConsumerConfig extends AbstractReferenceConfig { /** * Whether refer should run in background or not. * - * @deprecated replace with {@link ModuleConfig#setBackground(Boolean)} * @see ModuleConfig#setBackground(Boolean) + * @deprecated replace with {@link ModuleConfig#setBackground(Boolean)} */ private Boolean referBackground; /** * enable mesh mode + * * @since 3.1.0 */ private Boolean meshEnable; @@ -94,9 +97,9 @@ public ConsumerConfig(ModuleModel moduleModel) { @Override public void setTimeout(Integer timeout) { super.setTimeout(timeout); - String rmiTimeout = System.getProperty("sun.rmi.transport.tcp.responseTimeout"); + String rmiTimeout = SystemPropertyConfigUtils.getSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT); if (timeout != null && timeout > 0 && (StringUtils.isEmpty(rmiTimeout))) { - System.setProperty("sun.rmi.transport.tcp.responseTimeout", String.valueOf(timeout)); + SystemPropertyConfigUtils.setSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT, String.valueOf(timeout)); } } @@ -167,8 +170,8 @@ public Boolean getReferBackground() { /** * Whether refer should run in background or not. * - * @deprecated replace with {@link ModuleConfig#setBackground(Boolean)} * @see ModuleConfig#setBackground(Boolean) + * @deprecated replace with {@link ModuleConfig#setBackground(Boolean)} */ @Deprecated public void setReferBackground(Boolean referBackground) { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java index a168a8f53d5..da1b9bc831e 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java @@ -18,9 +18,11 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.compact.Dubbo2CompactUtils; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.common.utils.RegexProperties; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.context.ConfigMode; import org.apache.dubbo.config.support.Parameter; @@ -41,6 +43,7 @@ import java.util.Properties; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.USER_HOME; import static org.apache.dubbo.common.constants.CommonConstants.UNLOAD_CLUSTER_RELATED; import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION; @@ -310,9 +313,10 @@ protected void resolveFile() { String resolve = System.getProperty(interfaceName); String resolveFile = null; if (StringUtils.isEmpty(resolve)) { - resolveFile = System.getProperty("dubbo.resolve.file"); + resolveFile = SystemPropertyConfigUtils.getSystemProperty(CommonConstants.DubboProperty.DUBBO_RESOLVE_FILE); if (StringUtils.isEmpty(resolveFile)) { - File userResolveFile = new File(new File(System.getProperty("user.home")), "dubbo-resolve.properties"); + File userResolveFile = new File( + new File(SystemPropertyConfigUtils.getSystemProperty(USER_HOME)), "dubbo-resolve.properties"); if (userResolveFile.exists()) { resolveFile = userResolveFile.getAbsolutePath(); } diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java index ee03745d3d8..9c3583a1f94 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java @@ -18,6 +18,7 @@ import org.apache.dubbo.common.url.component.ServiceConfigURL; import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import java.io.File; import java.util.Arrays; @@ -28,8 +29,8 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import static org.apache.dubbo.common.constants.CommonConstants.OS_NAME_KEY; import static org.apache.dubbo.common.constants.CommonConstants.OS_WIN_PREFIX; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_OS_NAME; import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; @@ -720,7 +721,7 @@ void test_addParameterIfAbsent() throws Exception { @Test void test_windowAbsolutePathBeginWithSlashIsValid() throws Exception { - final String osProperty = System.getProperties().getProperty(OS_NAME_KEY); + final String osProperty = SystemPropertyConfigUtils.getSystemProperty(SYSTEM_OS_NAME); if (!osProperty.toLowerCase().contains(OS_WIN_PREFIX)) return; System.out.println("Test Windows valid path string."); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReportTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReportTest.java index 8179d42f0a0..74e58b716b6 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReportTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReportTest.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.threadpool.event.ThreadPoolExhaustedEvent; import org.apache.dubbo.common.threadpool.event.ThreadPoolExhaustedListener; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import java.io.FileOutputStream; import java.util.UUID; @@ -31,8 +32,9 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import static org.apache.dubbo.common.constants.CommonConstants.OS_NAME_KEY; import static org.apache.dubbo.common.constants.CommonConstants.OS_WIN_PREFIX; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_OS_NAME; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.USER_HOME; import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -69,11 +71,13 @@ void jStackDumpTest_dumpDirectoryNotExists_cannotBeCreatedTakeUserHome() { + "&version=1.0.0&application=morgan&noValue=true"); AbortPolicyWithReport abortPolicyWithReport = new AbortPolicyWithReport("Test", url); - Assertions.assertEquals(System.getProperty("user.home"), abortPolicyWithReport.getDumpPath()); + Assertions.assertEquals( + SystemPropertyConfigUtils.getSystemProperty(USER_HOME), abortPolicyWithReport.getDumpPath()); } private String dumpDirectoryCannotBeCreated() { - final String os = System.getProperty(OS_NAME_KEY).toLowerCase(); + final String os = + SystemPropertyConfigUtils.getSystemProperty(SYSTEM_OS_NAME).toLowerCase(); if (os.contains(OS_WIN_PREFIX)) { // "con" is one of Windows reserved names, // https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file @@ -92,7 +96,8 @@ void jStackDumpTest_dumpDirectoryNotExists_canBeCreated() { + "&version=1.0.0&application=morgan&noValue=true"); AbortPolicyWithReport abortPolicyWithReport = new AbortPolicyWithReport("Test", url); - Assertions.assertNotEquals(System.getProperty("user.home"), abortPolicyWithReport.getDumpPath()); + Assertions.assertNotEquals( + SystemPropertyConfigUtils.getSystemProperty(USER_HOME), abortPolicyWithReport.getDumpPath()); } @Test diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ConfigUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ConfigUtilsTest.java index 8905610b80c..f6fbb70b4c5 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ConfigUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ConfigUtilsTest.java @@ -166,19 +166,21 @@ void testReplaceProperty2() { @Test void testGetProperties1() throws Exception { try { - System.setProperty(CommonConstants.DUBBO_PROPERTIES_KEY, "properties.load"); + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY, "properties.load"); Properties p = ConfigUtils.getProperties(Collections.emptySet()); assertThat((String) p.get("a"), equalTo("12")); assertThat((String) p.get("b"), equalTo("34")); assertThat((String) p.get("c"), equalTo("56")); } finally { - System.clearProperty(CommonConstants.DUBBO_PROPERTIES_KEY); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY); } } @Test void testGetProperties2() throws Exception { - System.clearProperty(CommonConstants.DUBBO_PROPERTIES_KEY); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY); Properties p = ConfigUtils.getProperties(Collections.emptySet()); assertThat((String) p.get("dubbo"), equalTo("properties")); } diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/DefaultSerializeClassCheckerTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/DefaultSerializeClassCheckerTest.java index 29d116b7d61..2851b2c050f 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/DefaultSerializeClassCheckerTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/DefaultSerializeClassCheckerTest.java @@ -71,8 +71,8 @@ void testCommon() throws ClassNotFoundException { @Test void testAddAllow() throws ClassNotFoundException { - System.setProperty( - CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST, + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_ALLOWED_LIST, ReentrantReadWriteLock.WriteLock.class.getName() + "," + ReentrantReadWriteLock.ReadLock.class.getName()); @@ -84,13 +84,15 @@ void testAddAllow() throws ClassNotFoundException { Thread.currentThread().getContextClassLoader(), ReentrantReadWriteLock.ReadLock.class.getName()); } - System.clearProperty(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST); + SystemPropertyConfigUtils.clearSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_ALLOWED_LIST); } @Test void testAddBlock() { - System.setProperty( - CommonConstants.CLASS_DESERIALIZE_BLOCKED_LIST, Runtime.class.getName() + "," + Thread.class.getName()); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_BLOCKED_LIST, + Runtime.class.getName() + "," + Thread.class.getName()); DefaultSerializeClassChecker defaultSerializeClassChecker = DefaultSerializeClassChecker.getInstance(); for (int i = 0; i < 10; i++) { @@ -114,14 +116,17 @@ void testAddBlock() { .contains(Thread.class.getName())); } - System.clearProperty(CommonConstants.CLASS_DESERIALIZE_BLOCKED_LIST); + SystemPropertyConfigUtils.clearSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_BLOCKED_LIST); } @Test void testBlockAll() throws ClassNotFoundException { - System.setProperty(CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL, "true"); - System.setProperty( - CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST, ReentrantReadWriteLock.WriteLock.class.getName()); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_BLOCK_ALL, "true"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_ALLOWED_LIST, + ReentrantReadWriteLock.WriteLock.class.getName()); DefaultSerializeClassChecker defaultSerializeClassChecker = DefaultSerializeClassChecker.getInstance(); for (int i = 0; i < 10; i++) { @@ -139,8 +144,9 @@ void testBlockAll() throws ClassNotFoundException { .contains(ReentrantReadWriteLock.ReadLock.class.getName())); } - System.clearProperty(CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL); - System.clearProperty(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_BLOCK_ALL); + SystemPropertyConfigUtils.clearSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_ALLOWED_LIST); } @Test diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JRETest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JRETest.java index a42e1ae368f..6a58dcfc01b 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JRETest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JRETest.java @@ -22,12 +22,14 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_JAVA_VERSION; + class JRETest { @Test @Disabled void blankSystemVersion() { - System.setProperty("java.version", ""); + SystemPropertyConfigUtils.setSystemProperty(SYSTEM_JAVA_VERSION, ""); JRE jre = JRE.currentVersion(); Assertions.assertEquals(JRE.JAVA_8, jre); } diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java index 09889928944..b321877a94b 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/JsonUtilsTest.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common.utils; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.json.JsonUtil; import org.apache.dubbo.common.json.impl.FastJson2Impl; import org.apache.dubbo.common.json.impl.FastJsonImpl; @@ -79,39 +80,43 @@ void testGetJson1() { // prefer use fastjson2 setJson(null); - System.setProperty("dubbo.json-framework.prefer", "fastjson2"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson2"); Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); Assertions.assertEquals( Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); // prefer use fastjson setJson(null); - System.setProperty("dubbo.json-framework.prefer", "fastjson"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson"); Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); Assertions.assertEquals( Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); // prefer use gson setJson(null); - System.setProperty("dubbo.json-framework.prefer", "gson"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "gson"); Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); Assertions.assertEquals( Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); // prefer use jackson setJson(null); - System.setProperty("dubbo.json-framework.prefer", "jackson"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "jackson"); Assertions.assertEquals("{\"a\":\"a\"}", JsonUtils.getJson().toJson(map)); Assertions.assertEquals(map, JsonUtils.getJson().toJavaObject("{\"a\":\"a\"}", Map.class)); Assertions.assertEquals( Collections.singletonList(map), JsonUtils.getJson().toJavaList("[{\"a\":\"a\"}]", Map.class)); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); setJson(null); } @@ -177,31 +182,39 @@ void consistentTest() { // prefer use fastjson2 setJson(null); - System.setProperty("dubbo.json-framework.prefer", "fastjson2"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson2"); Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson()); String fromFastjson2 = JsonUtils.getJson().toJson(obj); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); // prefer use fastjson setJson(null); - System.setProperty("dubbo.json-framework.prefer", "fastjson"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson"); Assertions.assertInstanceOf(FastJsonImpl.class, JsonUtils.getJson()); String fromFastjson1 = JsonUtils.getJson().toJson(obj); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); // prefer use gson setJson(null); - System.setProperty("dubbo.json-framework.prefer", "gson"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "gson"); Assertions.assertInstanceOf(GsonImpl.class, JsonUtils.getJson()); String fromGson = JsonUtils.getJson().toJson(obj); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); // prefer use jackson setJson(null); - System.setProperty("dubbo.json-framework.prefer", "jackson"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "jackson"); Assertions.assertInstanceOf(JacksonImpl.class, JsonUtils.getJson()); String fromJackson = JsonUtils.getJson().toJson(obj); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); setJson(null); @@ -230,26 +243,30 @@ void testGetJson2() { // prefer use fastjson2 setJson(null); - System.setProperty("dubbo.json-framework.prefer", "fastjson2"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson2"); Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson()); // prefer use fastjson setJson(null); - System.setProperty("dubbo.json-framework.prefer", "fastjson"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson"); Assertions.assertInstanceOf(FastJsonImpl.class, JsonUtils.getJson()); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); // prefer use gson setJson(null); - System.setProperty("dubbo.json-framework.prefer", "gson"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "gson"); Assertions.assertInstanceOf(GsonImpl.class, JsonUtils.getJson()); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); // prefer use not found setJson(null); - System.setProperty("dubbo.json-framework.prefer", "notfound"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "notfound"); Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson()); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); setJson(null); // TCCL not found fastjson2 @@ -278,33 +295,37 @@ void testGetJson2() { setJson(null); // TCCL not found fastjson2, prefer use fastjson2 allowFastjson2.set(false); - System.setProperty("dubbo.json-framework.prefer", "fastjson2"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson2"); Assertions.assertInstanceOf(FastJsonImpl.class, JsonUtils.getJson()); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); allowFastjson2.set(true); setJson(null); // TCCL not found fastjson, prefer use fastjson allowFastjson.set(false); - System.setProperty("dubbo.json-framework.prefer", "fastjson"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson"); Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson()); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); allowFastjson.set(true); setJson(null); // TCCL not found gson, prefer use gson allowGson.set(false); - System.setProperty("dubbo.json-framework.prefer", "gson"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "gson"); Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson()); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); allowGson.set(true); setJson(null); // TCCL not found jackson, prefer use jackson allowJackson.set(false); - System.setProperty("dubbo.json-framework.prefer", "jackson"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "jackson"); Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson()); - System.clearProperty("dubbo.json-framework.prefer"); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); allowJackson.set(true); setJson(null); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsInterfaceDisplayNameHasMetaCharactersTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsInterfaceDisplayNameHasMetaCharactersTest.java index e35933531ce..7ffba230931 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsInterfaceDisplayNameHasMetaCharactersTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsInterfaceDisplayNameHasMetaCharactersTest.java @@ -16,6 +16,8 @@ */ package org.apache.dubbo.common.utils; +import org.apache.dubbo.common.constants.CommonConstants; + import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; @@ -25,7 +27,6 @@ import org.mockito.MockedStatic; import org.mockito.Mockito; -import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_NETWORK_IGNORED_INTERFACE; import static org.junit.jupiter.api.Assertions.assertTrue; class NetUtilsInterfaceDisplayNameHasMetaCharactersTest { @@ -105,14 +106,17 @@ public boolean hasMoreElements() { } private String getIgnoredInterfaces() { - return System.getProperty(DUBBO_NETWORK_IGNORED_INTERFACE); + return SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.DubboProperty.DUBBO_NETWORK_IGNORED_INTERFACE); } private void setIgnoredInterfaces(String ignoredInterfaces) { if (ignoredInterfaces != null) { - System.setProperty(DUBBO_NETWORK_IGNORED_INTERFACE, ignoredInterfaces); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_NETWORK_IGNORED_INTERFACE, ignoredInterfaces); } else { - System.setProperty(DUBBO_NETWORK_IGNORED_INTERFACE, ""); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_NETWORK_IGNORED_INTERFACE, ""); } } } diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java index 95eea9bca59..7df52218576 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java @@ -16,6 +16,8 @@ */ package org.apache.dubbo.common.utils; +import org.apache.dubbo.common.constants.CommonConstants; + import java.net.Inet6Address; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -26,7 +28,6 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_NETWORK_IGNORED_INTERFACE; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -387,14 +388,17 @@ void testIgnoreGivenPrefixInterfaceName() { } private String getIgnoredInterfaces() { - return System.getProperty(DUBBO_NETWORK_IGNORED_INTERFACE); + return SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.DubboProperty.DUBBO_NETWORK_IGNORED_INTERFACE); } private void setIgnoredInterfaces(String ignoredInterfaces) { if (ignoredInterfaces != null) { - System.setProperty(DUBBO_NETWORK_IGNORED_INTERFACE, ignoredInterfaces); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_NETWORK_IGNORED_INTERFACE, ignoredInterfaces); } else { - System.setProperty(DUBBO_NETWORK_IGNORED_INTERFACE, ""); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_NETWORK_IGNORED_INTERFACE, ""); } } } diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/SerializeSecurityConfiguratorTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/SerializeSecurityConfiguratorTest.java index 1b9e9e3e657..f4b5be0b9d5 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/SerializeSecurityConfiguratorTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/SerializeSecurityConfiguratorTest.java @@ -40,9 +40,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import static org.apache.dubbo.common.constants.CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST; -import static org.apache.dubbo.common.constants.CommonConstants.CLASS_DESERIALIZE_BLOCKED_LIST; - class SerializeSecurityConfiguratorTest { @Test @@ -131,7 +128,8 @@ void testStatus4() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); ModuleModel moduleModel = applicationModel.newModule(); - System.setProperty(CommonConstants.CLASS_DESERIALIZE_OPEN_CHECK, "false"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_OPEN_CHECK, "false"); SerializeSecurityManager ssm = frameworkModel.getBeanFactory().getBean(SerializeSecurityManager.class); @@ -141,7 +139,7 @@ void testStatus4() { Assertions.assertEquals(SerializeCheckStatus.DISABLE, ssm.getCheckStatus()); - System.clearProperty(CommonConstants.CLASS_DESERIALIZE_OPEN_CHECK); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_OPEN_CHECK); frameworkModel.destroy(); } @@ -150,7 +148,8 @@ void testStatus5() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); ModuleModel moduleModel = applicationModel.newModule(); - System.setProperty(CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL, "true"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_BLOCK_ALL, "true"); SerializeSecurityManager ssm = frameworkModel.getBeanFactory().getBean(SerializeSecurityManager.class); @@ -160,7 +159,7 @@ void testStatus5() { Assertions.assertEquals(SerializeCheckStatus.STRICT, ssm.getCheckStatus()); - System.clearProperty(CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_BLOCK_ALL); frameworkModel.destroy(); } @@ -169,7 +168,8 @@ void testConfig1() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); ModuleModel moduleModel = applicationModel.newModule(); - System.setProperty(CLASS_DESERIALIZE_ALLOWED_LIST, "test.package1, test.package2, ,"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_ALLOWED_LIST, "test.package1, test.package2, ,"); SerializeSecurityManager ssm = frameworkModel.getBeanFactory().getBean(SerializeSecurityManager.class); @@ -180,7 +180,8 @@ void testConfig1() { Assertions.assertTrue(ssm.getAllowedPrefix().contains("test.package1")); Assertions.assertTrue(ssm.getAllowedPrefix().contains("test.package2")); - System.clearProperty(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST); + SystemPropertyConfigUtils.clearSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_ALLOWED_LIST); frameworkModel.destroy(); } @@ -189,7 +190,8 @@ void testConfig2() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); ModuleModel moduleModel = applicationModel.newModule(); - System.setProperty(CLASS_DESERIALIZE_BLOCKED_LIST, "test.package1, test.package2, ,"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_BLOCKED_LIST, "test.package1, test.package2, ,"); SerializeSecurityManager ssm = frameworkModel.getBeanFactory().getBean(SerializeSecurityManager.class); @@ -200,7 +202,7 @@ void testConfig2() { Assertions.assertTrue(ssm.getDisAllowedPrefix().contains("test.package1")); Assertions.assertTrue(ssm.getDisAllowedPrefix().contains("test.package2")); - System.clearProperty(CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_BLOCK_ALL); frameworkModel.destroy(); } @@ -209,8 +211,10 @@ void testConfig3() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); ModuleModel moduleModel = applicationModel.newModule(); - System.setProperty(CLASS_DESERIALIZE_ALLOWED_LIST, "test.package1, test.package2, ,"); - System.setProperty(CLASS_DESERIALIZE_BLOCKED_LIST, "test.package1, test.package2, ,"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_ALLOWED_LIST, "test.package1, test.package2, ,"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_BLOCKED_LIST, "test.package1, test.package2, ,"); SerializeSecurityManager ssm = frameworkModel.getBeanFactory().getBean(SerializeSecurityManager.class); @@ -221,8 +225,9 @@ void testConfig3() { Assertions.assertTrue(ssm.getAllowedPrefix().contains("test.package1")); Assertions.assertTrue(ssm.getAllowedPrefix().contains("test.package2")); - System.clearProperty(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST); - System.clearProperty(CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL); + SystemPropertyConfigUtils.clearSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_ALLOWED_LIST); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_CLASS_DESERIALIZE_BLOCK_ALL); frameworkModel.destroy(); } diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/SystemPropertyConfigUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/SystemPropertyConfigUtilsTest.java new file mode 100644 index 00000000000..ce81f5c0b83 --- /dev/null +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/SystemPropertyConfigUtilsTest.java @@ -0,0 +1,62 @@ +/* + * 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.dubbo.common.utils; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrowsExactly; + +public class SystemPropertyConfigUtilsTest { + + @Test + public void testGetSystemProperty() { + SystemPropertyConfigUtils.setSystemProperty("dubbo.migration.file", "migration.xml"); + String value = SystemPropertyConfigUtils.getSystemProperty("dubbo.migration.file"); + assertEquals(value, "migration.xml"); + SystemPropertyConfigUtils.clearSystemProperty("dubbo.migration.file"); + } + + @Test + public void testGetSystemPropertyNotExist() { + assertThrowsExactly( + IllegalStateException.class, () -> SystemPropertyConfigUtils.getSystemProperty("dubbo.not.exist")); + } + + @Test + public void testGetSystemPropertyWithDefaultValue() { + String value = SystemPropertyConfigUtils.getSystemProperty("dubbo.migration.file", "migration.xml"); + assertEquals(value, "migration.xml"); + } + + @Test + public void testSetSystemProperty() { + SystemPropertyConfigUtils.setSystemProperty("dubbo.migration.file", "migration.xml"); + String expectValue = SystemPropertyConfigUtils.getSystemProperty("dubbo.migration.file"); + assertEquals(expectValue, "migration.xml"); + SystemPropertyConfigUtils.clearSystemProperty("dubbo.migration.file"); + } + + @Test + public void testClearSystemProperty() { + SystemPropertyConfigUtils.setSystemProperty("dubbo.migration.file", "migration33.xml"); + SystemPropertyConfigUtils.clearSystemProperty("dubbo.migration.file"); + String expectValue = SystemPropertyConfigUtils.getSystemProperty("dubbo.migration.file"); + assertNull(expectValue); + } +} diff --git a/dubbo-common/src/test/java/org/apache/dubbo/config/AbstractInterfaceConfigTest.java b/dubbo-common/src/test/java/org/apache/dubbo/config/AbstractInterfaceConfigTest.java index 1d852d32481..3a61fd6f093 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/config/AbstractInterfaceConfigTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/config/AbstractInterfaceConfigTest.java @@ -17,6 +17,7 @@ package org.apache.dubbo.config; import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import java.io.File; import java.nio.file.Path; @@ -32,14 +33,15 @@ class AbstractInterfaceConfigTest { @BeforeAll public static void setUp(@TempDir Path folder) { - File dubboProperties = - folder.resolve(CommonConstants.DUBBO_PROPERTIES_KEY).toFile(); - System.setProperty(CommonConstants.DUBBO_PROPERTIES_KEY, dubboProperties.getAbsolutePath()); + File dubboProperties = folder.resolve(CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY) + .toFile(); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY, dubboProperties.getAbsolutePath()); } @AfterAll public static void tearDown() { - System.clearProperty(CommonConstants.DUBBO_PROPERTIES_KEY); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY); } @Test diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/pages/SystemPageHandler.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/pages/SystemPageHandler.java index 0c8e3c26ec4..84c3e9439a2 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/pages/SystemPageHandler.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/container/page/pages/SystemPageHandler.java @@ -17,7 +17,9 @@ package com.alibaba.dubbo.container.page.pages; import org.apache.dubbo.common.Version; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import java.lang.management.ManagementFactory; import java.text.SimpleDateFormat; @@ -60,25 +62,30 @@ public Page handle(URL url) { row = new ArrayList(); row.add("OS"); - row.add(System.getProperty("os.name") + " " + System.getProperty("os.version")); + row.add(SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.SYSTEM_OS_NAME) + " " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.SYSTEM_OS_VERSION)); rows.add(row); row = new ArrayList(); row.add("JVM"); - row.add(System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version") + ",
" - + System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version") + " " - + System.getProperty("java.vm.info", "")); + row.add(SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_RUNTIME_NAME) + " " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_RUNTIME_VERSION) + + ",
" + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_VM_NAME) + " " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_VM_VERSION) + " " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_VM_INFO, "")); rows.add(row); row = new ArrayList(); row.add("CPU"); - row.add(System.getProperty("os.arch", "") + ", " + row.add(SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.OS_ARCH, "") + ", " + String.valueOf(Runtime.getRuntime().availableProcessors()) + " cores"); rows.add(row); row = new ArrayList(); row.add("Locale"); - row.add(Locale.getDefault().toString() + "/" + System.getProperty("file.encoding")); + row.add(Locale.getDefault().toString() + "/" + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.SYSTEM_FILE_ENCODING)); rows.add(row); row = new ArrayList(); diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java index 1e4a51fb1d3..f7254a868d0 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java @@ -16,9 +16,12 @@ */ package org.apache.dubbo.config; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; + import com.alibaba.dubbo.config.ConsumerConfig; import org.junit.jupiter.api.Test; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_TCP_RESPONSE_TIMEOUT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -27,13 +30,13 @@ class ConsumerConfigTest { @Test void testTimeout() throws Exception { try { - System.clearProperty("sun.rmi.transport.tcp.responseTimeout"); + SystemPropertyConfigUtils.clearSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT); ConsumerConfig consumer = new ConsumerConfig(); consumer.setTimeout(10); assertThat(consumer.getTimeout(), is(10)); - assertThat(System.getProperty("sun.rmi.transport.tcp.responseTimeout"), equalTo("10")); + assertThat(SystemPropertyConfigUtils.getSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT), equalTo("10")); } finally { - System.clearProperty("sun.rmi.transport.tcp.responseTimeout"); + SystemPropertyConfigUtils.clearSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT); } } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index 23bd4eaaa54..68afe871202 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -73,6 +73,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CLUSTER_DOMAIN; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_MESH_PORT; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_IP_TO_REGISTRY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.MESH_ENABLE; @@ -95,7 +96,6 @@ import static org.apache.dubbo.common.constants.RegistryConstants.SUBSCRIBED_SERVICE_NAMES_KEY; import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost; import static org.apache.dubbo.common.utils.StringUtils.splitToSet; -import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY; import static org.apache.dubbo.registry.Constants.CONSUMER_PROTOCOL; import static org.apache.dubbo.registry.Constants.REGISTER_IP_KEY; import static org.apache.dubbo.rpc.Constants.GENERIC_KEY; diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index f2e4869e7d5..1231b63528a 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -79,6 +79,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_IP_TO_BIND; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_IP_TO_REGISTRY; import static org.apache.dubbo.common.constants.CommonConstants.EXECUTOR_MANAGEMENT_MODE_ISOLATION; import static org.apache.dubbo.common.constants.CommonConstants.EXPORTER_LISTENER_KEY; import static org.apache.dubbo.common.constants.CommonConstants.EXT_PROTOCOL; @@ -104,7 +105,6 @@ import static org.apache.dubbo.common.utils.NetUtils.getLocalHost; import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost; import static org.apache.dubbo.common.utils.NetUtils.isInvalidPort; -import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY; import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_BIND; import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_REGISTRY; import static org.apache.dubbo.config.Constants.SCOPE_NONE; @@ -336,7 +336,7 @@ public void export(RegisterTypeEnum registerType) { doDelayExport(); } else if (Integer.valueOf(-1).equals(getDelay()) && Boolean.parseBoolean(ConfigurationUtils.getProperty( - getScopeModel(), CommonConstants.DUBBO_MANUAL_REGISTER_KEY, "false"))) { + getScopeModel(), CommonConstants.DubboProperty.DUBBO_MANUAL_REGISTER_KEY, "false"))) { // should not register by default doExport(RegisterTypeEnum.MANUAL_REGISTER); } else { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java index 6c12adc0974..635e3a6165f 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java @@ -31,6 +31,7 @@ import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.common.utils.UrlUtils; import org.apache.dubbo.config.AbstractConfig; import org.apache.dubbo.config.AbstractInterfaceConfig; @@ -82,8 +83,9 @@ import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_MONITOR_ADDRESS; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_IP_TO_REGISTRY; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_MONITOR_ADDRESS; import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.FILTER_KEY; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; @@ -116,7 +118,6 @@ import static org.apache.dubbo.common.utils.StringUtils.isNotEmpty; import static org.apache.dubbo.config.Constants.ARCHITECTURE; import static org.apache.dubbo.config.Constants.CONTEXTPATH_KEY; -import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY; import static org.apache.dubbo.config.Constants.ENVIRONMENT; import static org.apache.dubbo.config.Constants.IGNORE_CHECK_KEYS; import static org.apache.dubbo.config.Constants.LAYER_KEY; @@ -329,7 +330,7 @@ public static URL loadMonitor(AbstractInterfaceConfig interfaceConfig, URL regis AbstractConfig.appendParameters(map, monitor); AbstractConfig.appendParameters(map, application); String address = null; - String sysAddress = System.getProperty(DUBBO_MONITOR_ADDRESS); + String sysAddress = SystemPropertyConfigUtils.getSystemProperty(DUBBO_MONITOR_ADDRESS); if (sysAddress != null && sysAddress.length() > 0) { address = sysAddress; } else if (monitor != null) { diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java index f3a161c01c9..bb3d9488bf1 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java @@ -17,6 +17,7 @@ package org.apache.dubbo.config; import org.apache.dubbo.common.utils.JsonUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.config.api.DemoService; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.rpc.model.ApplicationModel; @@ -30,6 +31,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_TCP_RESPONSE_TIMEOUT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -48,11 +50,11 @@ public void afterEach() { @Test void testTimeout() { - System.clearProperty("sun.rmi.transport.tcp.responseTimeout"); + SystemPropertyConfigUtils.clearSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT); ConsumerConfig consumer = new ConsumerConfig(); consumer.setTimeout(10); assertThat(consumer.getTimeout(), is(10)); - assertThat(System.getProperty("sun.rmi.transport.tcp.responseTimeout"), equalTo("10")); + assertThat(SystemPropertyConfigUtils.getSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT), equalTo("10")); } @Test diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java index fe791af7c04..73c258e1fcf 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java @@ -22,6 +22,7 @@ import org.apache.dubbo.common.url.component.ServiceConfigURL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.ReflectUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.config.AbstractInterfaceConfig; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.MetadataReportConfig; @@ -84,13 +85,15 @@ class DubboBootstrapTest { public static void setUp(@TempDir Path folder) { DubboBootstrap.reset(); zkServerAddress = System.getProperty("zookeeper.connection.address.1"); - dubboProperties = folder.resolve(CommonConstants.DUBBO_PROPERTIES_KEY).toFile(); - System.setProperty(CommonConstants.DUBBO_PROPERTIES_KEY, dubboProperties.getAbsolutePath()); + dubboProperties = folder.resolve(CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY) + .toFile(); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY, dubboProperties.getAbsolutePath()); } @AfterAll public static void tearDown() { - System.clearProperty(CommonConstants.DUBBO_PROPERTIES_KEY); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY); } @AfterEach diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java index cb2211d7b90..6aa1972d913 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ArgumentConfig; import org.apache.dubbo.config.ConsumerConfig; @@ -66,6 +67,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import static org.apache.dubbo.common.constants.CommonConstants.GENERIC_SERIALIZATION_BEAN; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_TCP_RESPONSE_TIMEOUT; import static org.apache.dubbo.rpc.Constants.GENERIC_KEY; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; @@ -371,12 +373,12 @@ public void testDelayOnInitialized() throws Exception { @Test void testRmiTimeout() throws Exception { - System.clearProperty("sun.rmi.transport.tcp.responseTimeout"); + SystemPropertyConfigUtils.clearSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT); ConsumerConfig consumer = new ConsumerConfig(); consumer.setTimeout(1000); - assertEquals("1000", System.getProperty("sun.rmi.transport.tcp.responseTimeout")); + assertEquals("1000", SystemPropertyConfigUtils.getSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT)); consumer.setTimeout(2000); - assertEquals("1000", System.getProperty("sun.rmi.transport.tcp.responseTimeout")); + assertEquals("1000", SystemPropertyConfigUtils.getSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT)); } @Test diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/EmbeddedZooKeeper.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/EmbeddedZooKeeper.java index e4a6789ec1c..91a22ffb26b 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/EmbeddedZooKeeper.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/EmbeddedZooKeeper.java @@ -17,7 +17,9 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.test.common.utils.TestSocketUtils; + import org.apache.zookeeper.server.ServerConfig; import org.apache.zookeeper.server.ZooKeeperServerMain; import org.apache.zookeeper.server.quorum.QuorumPeerConfig; @@ -29,6 +31,7 @@ import java.util.Properties; import java.util.UUID; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_JAVA_IO_TMPDIR; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TESTING_INIT_ZOOKEEPER_SERVER_ERROR; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TESTING_REGISTRY_FAILED_TO_STOP_ZOOKEEPER; @@ -222,7 +225,7 @@ private class ServerRunnable implements Runnable { public void run() { try { Properties properties = new Properties(); - File file = new File(System.getProperty("java.io.tmpdir") + File file = new File(SystemPropertyConfigUtils.getSystemProperty(SYSTEM_JAVA_IO_TMPDIR) + File.separator + UUID.randomUUID()); file.deleteOnExit(); properties.setProperty("dataDir", file.getAbsolutePath()); diff --git a/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java index b9506d3fe34..e355bb22da5 100644 --- a/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java @@ -24,6 +24,7 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.metrics.config.event.ConfigCenterEvent; import org.apache.dubbo.metrics.event.MetricsEventBus; import org.apache.dubbo.rpc.model.ApplicationModel; @@ -50,6 +51,10 @@ import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; import static org.apache.dubbo.common.constants.CommonConstants.CONFIG_NAMESPACE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.ThirdPartyProperty.APOLLO_ADDR_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.ThirdPartyProperty.APOLLO_APPID_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.ThirdPartyProperty.APOLLO_CLUSTER_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.ThirdPartyProperty.APOLLO_ENV_KEY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_FAILED_CLOSE_CONNECT_APOLLO; import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_FAILED_CONNECT_REGISTRY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_NOT_EFFECT_EMPTY_RULE_APOLLO; @@ -70,12 +75,8 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration { private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(ApolloDynamicConfiguration.class); - private static final String APOLLO_ENV_KEY = "env"; - private static final String APOLLO_ADDR_KEY = "apollo.meta"; - private static final String APOLLO_CLUSTER_KEY = "apollo.cluster"; private static final String APOLLO_PROTOCOL_PREFIX = "http://"; private static final String APOLLO_APPLICATION_KEY = "application"; - private static final String APOLLO_APPID_KEY = "app.id"; private final URL url; private final Config dubboConfig; @@ -92,17 +93,19 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration { String configAddr = getAddressWithProtocolPrefix(url); String configCluster = url.getParameter(CLUSTER_KEY); String configAppId = url.getParameter(APOLLO_APPID_KEY); - if (StringUtils.isEmpty(System.getProperty(APOLLO_ENV_KEY)) && configEnv != null) { - System.setProperty(APOLLO_ENV_KEY, configEnv); + if (StringUtils.isEmpty(SystemPropertyConfigUtils.getSystemProperty(APOLLO_ENV_KEY)) && configEnv != null) { + SystemPropertyConfigUtils.getSystemProperty(APOLLO_ENV_KEY, configEnv); } - if (StringUtils.isEmpty(System.getProperty(APOLLO_ADDR_KEY)) && !ANYHOST_VALUE.equals(url.getHost())) { - System.setProperty(APOLLO_ADDR_KEY, configAddr); + if (StringUtils.isEmpty(SystemPropertyConfigUtils.getSystemProperty(APOLLO_ADDR_KEY)) + && !ANYHOST_VALUE.equals(url.getHost())) { + SystemPropertyConfigUtils.setSystemProperty(APOLLO_ADDR_KEY, configAddr); } - if (StringUtils.isEmpty(System.getProperty(APOLLO_CLUSTER_KEY)) && configCluster != null) { - System.setProperty(APOLLO_CLUSTER_KEY, configCluster); + if (StringUtils.isEmpty(SystemPropertyConfigUtils.getSystemProperty(APOLLO_CLUSTER_KEY)) + && configCluster != null) { + SystemPropertyConfigUtils.getSystemProperty(APOLLO_CLUSTER_KEY, configCluster); } - if (StringUtils.isEmpty(System.getProperty(APOLLO_APPID_KEY)) && configAppId != null) { - System.setProperty(APOLLO_APPID_KEY, configAppId); + if (StringUtils.isEmpty(SystemPropertyConfigUtils.getSystemProperty(APOLLO_APPID_KEY)) && configAppId != null) { + SystemPropertyConfigUtils.getSystemProperty(APOLLO_APPID_KEY, configAppId); } String namespace = url.getParameter(CONFIG_NAMESPACE_KEY, DEFAULT_GROUP); diff --git a/dubbo-configcenter/dubbo-configcenter-file/src/main/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-file/src/main/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfiguration.java index c18bd074e68..3fc059b6ff1 100644 --- a/dubbo-configcenter/dubbo-configcenter-file/src/main/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-file/src/main/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfiguration.java @@ -22,6 +22,7 @@ import org.apache.dubbo.common.config.configcenter.ConfigurationListener; import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.config.configcenter.TreePathDynamicConfiguration; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.function.ThrowableConsumer; import org.apache.dubbo.common.function.ThrowableFunction; import org.apache.dubbo.common.lang.ShutdownHookCallbacks; @@ -29,6 +30,7 @@ import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.rpc.model.ScopeModel; import org.apache.dubbo.rpc.model.ScopeModelUtil; @@ -84,7 +86,8 @@ public class FileSystemDynamicConfiguration extends TreePathDynamicConfiguration public static final String CONFIG_CENTER_ENCODING_PARAM_NAME = PARAM_NAME_PREFIX + "encoding"; public static final String DEFAULT_CONFIG_CENTER_DIR_PATH = - System.getProperty("user.home") + File.separator + ".dubbo" + File.separator + "config-center"; + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.USER_HOME) + File.separator + + ".dubbo" + File.separator + "config-center"; public static final int DEFAULT_THREAD_POOL_SIZE = 1; diff --git a/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java b/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java index c9eca15c10e..d80e7147d12 100644 --- a/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java +++ b/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.ArrayUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -30,21 +31,19 @@ import java.util.concurrent.locks.ReentrantLock; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_CONTAINER_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_SHUTDOWN_HOOK_KEY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_THREAD_INTERRUPTED_EXCEPTION; import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_START_DUBBO_ERROR; import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_STOP_DUBBO_ERROR; /** * Main. (API, Static, ThreadSafe) - * + *

* This class is entry point loading containers. */ public class Main { - public static final String CONTAINER_KEY = "dubbo.container"; - - public static final String SHUTDOWN_HOOK_KEY = "dubbo.shutdown.hook"; - private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(Main.class); private static final ExtensionLoader LOADER = ExtensionLoader.getExtensionLoader(Container.class); @@ -56,7 +55,8 @@ public class Main { public static void main(String[] args) { try { if (ArrayUtils.isEmpty(args)) { - String config = System.getProperty(CONTAINER_KEY, LOADER.getDefaultExtensionName()); + String config = SystemPropertyConfigUtils.getSystemProperty( + DUBBO_CONTAINER_KEY, LOADER.getDefaultExtensionName()); args = COMMA_SPLIT_PATTERN.split(config); } @@ -66,7 +66,7 @@ public static void main(String[] args) { } logger.info("Use container type(" + Arrays.toString(args) + ") to run dubbo serivce."); - if ("true".equals(System.getProperty(SHUTDOWN_HOOK_KEY))) { + if ("true".equals(SystemPropertyConfigUtils.getSystemProperty(DUBBO_SHUTDOWN_HOOK_KEY))) { Runtime.getRuntime().addShutdownHook(new Thread("dubbo-container-shutdown-hook") { @Override public void run() { diff --git a/dubbo-container/dubbo-container-spring/src/main/java/org/apache/dubbo/container/spring/SpringContainer.java b/dubbo-container/dubbo-container-spring/src/main/java/org/apache/dubbo/container/spring/SpringContainer.java index 0adb7986584..99c1ed4a609 100644 --- a/dubbo-container/dubbo-container-spring/src/main/java/org/apache/dubbo/container/spring/SpringContainer.java +++ b/dubbo-container/dubbo-container-spring/src/main/java/org/apache/dubbo/container/spring/SpringContainer.java @@ -19,20 +19,21 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.container.Container; import org.springframework.context.support.ClassPathXmlApplicationContext; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_SPRING_CONFIG; import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_STOP_DUBBO_ERROR; /** * SpringContainer. (SPI, Singleton, ThreadSafe) - * + *

* The container class implementation for Spring */ public class SpringContainer implements Container { - public static final String SPRING_CONFIG = "dubbo.spring.config"; public static final String DEFAULT_SPRING_CONFIG = "classpath*:META-INF/spring/*.xml"; private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(SpringContainer.class); static ClassPathXmlApplicationContext context; @@ -43,7 +44,7 @@ public static ClassPathXmlApplicationContext getContext() { @Override public void start() { - String configPath = System.getProperty(SPRING_CONFIG); + String configPath = SystemPropertyConfigUtils.getSystemProperty(DUBBO_SPRING_CONFIG); if (StringUtils.isEmpty(configPath)) { configPath = DEFAULT_SPRING_CONFIG; } diff --git a/dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/src/main/java/org/apache/dubbo/demo/graalvm/consumer/Application.java b/dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/src/main/java/org/apache/dubbo/demo/graalvm/consumer/Application.java index 77d77635f2b..a09871ebabb 100644 --- a/dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/src/main/java/org/apache/dubbo/demo/graalvm/consumer/Application.java +++ b/dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/src/main/java/org/apache/dubbo/demo/graalvm/consumer/Application.java @@ -17,6 +17,7 @@ package org.apache.dubbo.demo.graalvm.consumer; import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.ReferenceConfig; @@ -32,9 +33,10 @@ public class Application { private static final String REGISTRY_URL = "zookeeper://127.0.0.1:2181"; public static void main(String[] args) { - System.setProperty("dubbo.application.logger", "log4j"); + SystemPropertyConfigUtils.setSystemProperty(CommonConstants.DubboProperty.DUBBO_APPLICATION_LOGGER, "log4j"); System.setProperty("native", "true"); - System.setProperty("dubbo.json-framework.prefer", "fastjson"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson"); runWithBootstrap(); } diff --git a/dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/src/main/java/org/apache/dubbo/demo/graalvm/provider/Application.java b/dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/src/main/java/org/apache/dubbo/demo/graalvm/provider/Application.java index bfe638da2fe..a959686674b 100644 --- a/dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/src/main/java/org/apache/dubbo/demo/graalvm/provider/Application.java +++ b/dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/src/main/java/org/apache/dubbo/demo/graalvm/provider/Application.java @@ -17,6 +17,7 @@ package org.apache.dubbo.demo.graalvm.provider; import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.RegistryConfig; @@ -32,9 +33,10 @@ public class Application { private static final String REGISTRY_URL = "zookeeper://127.0.0.1:2181"; public static void main(String[] args) throws Exception { - System.setProperty("dubbo.application.logger", "log4j"); + SystemPropertyConfigUtils.setSystemProperty(CommonConstants.DubboProperty.DUBBO_APPLICATION_LOGGER, "log4j"); System.setProperty("native", "true"); - System.setProperty("dubbo.json-framework.prefer", "fastjson"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, "fastjson"); startWithBootstrap(); System.in.read(); } diff --git a/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/aot/JavaExecutable.java b/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/aot/JavaExecutable.java index d8bafe2e04b..2aaf8127565 100644 --- a/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/aot/JavaExecutable.java +++ b/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/aot/JavaExecutable.java @@ -17,8 +17,10 @@ package org.apache.dubbo.maven.plugin.aot; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.Assert; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import java.io.File; import java.io.IOException; @@ -31,41 +33,41 @@ */ public class JavaExecutable { - private final File file; + private final File file; - public JavaExecutable() { - String javaHome = System.getProperty("java.home"); - Assert.assertTrue(StringUtils.isNotEmpty(javaHome), "Unable to find java executable due to missing 'java.home'"); - this.file = findInJavaHome(javaHome); - } + public JavaExecutable() { + String javaHome = SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_HOME); + Assert.assertTrue(StringUtils.isNotEmpty(javaHome), "Unable to find java executable due to missing 'java.home'"); + this.file = findInJavaHome(javaHome); + } - private File findInJavaHome(String javaHome) { - File bin = new File(new File(javaHome), "bin"); - File command = new File(bin, "java.exe"); - command = command.exists() ? command : new File(bin, "java"); - Assert.assertTrue(command.exists(), () -> "Unable to find java in " + javaHome); - return command; - } + private File findInJavaHome(String javaHome) { + File bin = new File(new File(javaHome), "bin"); + File command = new File(bin, "java.exe"); + command = command.exists() ? command : new File(bin, "java"); + Assert.assertTrue(command.exists(), () -> "Unable to find java in " + javaHome); + return command; + } - /** - * Create a new {@link ProcessBuilder} that will run with the Java executable. - * @param arguments the command arguments - * @return a {@link ProcessBuilder} - */ - public ProcessBuilder processBuilder(String... arguments) { - ProcessBuilder processBuilder = new ProcessBuilder(toString()); - processBuilder.command().addAll(Arrays.asList(arguments)); - return processBuilder; - } + /** + * Create a new {@link ProcessBuilder} that will run with the Java executable. + * + * @param arguments the command arguments + * @return a {@link ProcessBuilder} + */ + public ProcessBuilder processBuilder(String... arguments) { + ProcessBuilder processBuilder = new ProcessBuilder(toString()); + processBuilder.command().addAll(Arrays.asList(arguments)); + return processBuilder; + } - @Override - public String toString() { - try { - return this.file.getCanonicalPath(); - } - catch (IOException ex) { - throw new IllegalStateException(ex); - } - } + @Override + public String toString() { + try { + return this.file.getCanonicalPath(); + } catch (IOException ex) { + throw new IllegalStateException(ex); + } + } } diff --git a/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/protoc/DubboProtocCompilerMojo.java b/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/protoc/DubboProtocCompilerMojo.java index 64fe3e923a4..7f0678165e5 100644 --- a/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/protoc/DubboProtocCompilerMojo.java +++ b/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/protoc/DubboProtocCompilerMojo.java @@ -15,6 +15,8 @@ */ package org.apache.dubbo.maven.plugin.protoc; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.maven.plugin.protoc.command.DefaultProtocCommandBuilder; import org.apache.dubbo.maven.plugin.protoc.enums.DubboGenerateTypeEnum; @@ -127,8 +129,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { protocVersion = versionMatrix.getProperty("protoc.version"); } if (protocArtifact == null) { - final String osName = System.getProperty("os.name"); - final String osArch = System.getProperty("os.arch"); + final String osName = SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.SYSTEM_OS_NAME); + final String osArch = SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.OS_ARCH); final String detectedName = normalizeOs(osName); final String detectedArch = normalizeArch(osArch); @@ -270,7 +272,7 @@ private DubboProtocPlugin buildDubboProtocPlugin(String dubboVersion, String dub dubboProtocPlugin.setMainClass(dubboGenerateTypeEnum.getMainClass()); dubboProtocPlugin.setDubboVersion(dubboVersion); dubboProtocPlugin.setPluginDirectory(protocPluginDirectory); - dubboProtocPlugin.setJavaHome(System.getProperty("java.home")); + dubboProtocPlugin.setJavaHome(SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_HOME)); DubboProtocPluginWrapper protocPluginWrapper = dubboProtocPluginWrapperFactory.findByOs(); dubboProtocPlugin.setResolvedJars(resolvePluginDependencies()); File protocPlugin = protocPluginWrapper.createProtocPlugin(dubboProtocPlugin, getLog()); @@ -345,7 +347,7 @@ protected Artifact createProtocArtifact(final String artifactSpec) { } final String type = parts.length >= 4 ? parts[3] : "exe"; final String classifier = parts.length == 5 ? parts[4] : null; - //parts: [com.google.protobuf, protoc, 3.6.0, exe, osx-x86_64] + // parts: [com.google.protobuf, protoc, 3.6.0, exe, osx-x86_64] getLog().info("parts: " + Arrays.toString(parts)); return createDependencyArtifact(parts[0], parts[1], parts[2], type, classifier); } diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MappingCacheManager.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MappingCacheManager.java index ca23dbf178d..ba8e8922ff1 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MappingCacheManager.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MappingCacheManager.java @@ -18,12 +18,18 @@ import org.apache.dubbo.common.utils.JsonUtils; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.rpc.model.ScopeModel; import java.util.HashSet; import java.util.Set; import java.util.concurrent.ScheduledExecutorService; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_MAPPING_CACHE_ENTRYSIZE; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_MAPPING_CACHE_FILENAME; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_MAPPING_CACHE_FILEPATH; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_MAPPING_CACHE_MAXFILESIZE; + /** * TODO, Using randomly accessible file-based cache can be another choice if memory consumption turns to be an issue. */ @@ -36,8 +42,8 @@ public static MappingCacheManager getInstance(ScopeModel scopeModel) { } public MappingCacheManager(boolean enableFileCache, String name, ScheduledExecutorService executorService) { - String filePath = System.getProperty("dubbo.mapping.cache.filePath"); - String fileName = System.getProperty("dubbo.mapping.cache.fileName"); + String filePath = SystemPropertyConfigUtils.getSystemProperty(DUBBO_MAPPING_CACHE_FILEPATH); + String fileName = SystemPropertyConfigUtils.getSystemProperty(DUBBO_MAPPING_CACHE_FILENAME); if (StringUtils.isEmpty(fileName)) { fileName = DEFAULT_FILE_NAME; } @@ -46,11 +52,11 @@ public MappingCacheManager(boolean enableFileCache, String name, ScheduledExecut fileName = fileName + "." + name; } - String rawEntrySize = System.getProperty("dubbo.mapping.cache.entrySize"); + String rawEntrySize = SystemPropertyConfigUtils.getSystemProperty(DUBBO_MAPPING_CACHE_ENTRYSIZE); int entrySize = StringUtils.parseInteger(rawEntrySize); entrySize = (entrySize == 0 ? DEFAULT_ENTRY_SIZE : entrySize); - String rawMaxFileSize = System.getProperty("dubbo.mapping.cache.maxFileSize"); + String rawMaxFileSize = SystemPropertyConfigUtils.getSystemProperty(DUBBO_MAPPING_CACHE_MAXFILESIZE); long maxFileSize = StringUtils.parseLong(rawMaxFileSize); init(enableFileCache, filePath, fileName, entrySize, maxFileSize, 50, executorService); diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java index a1575f00f1f..6d2dcb7a5ba 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java @@ -23,6 +23,7 @@ import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.JsonUtils; import org.apache.dubbo.common.utils.NamedThreadFactory; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; import org.apache.dubbo.metadata.definition.model.ServiceDefinition; import org.apache.dubbo.metadata.report.MetadataReport; @@ -70,6 +71,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.RETRY_PERIOD_KEY; import static org.apache.dubbo.common.constants.CommonConstants.RETRY_TIMES_KEY; import static org.apache.dubbo.common.constants.CommonConstants.SYNC_REPORT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.USER_HOME; import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROXY_FAILED_EXPORT_SERVICE; import static org.apache.dubbo.common.utils.StringUtils.replace; @@ -78,7 +80,6 @@ import static org.apache.dubbo.metadata.report.support.Constants.DEFAULT_METADATA_REPORT_RETRY_PERIOD; import static org.apache.dubbo.metadata.report.support.Constants.DEFAULT_METADATA_REPORT_RETRY_TIMES; import static org.apache.dubbo.metadata.report.support.Constants.DUBBO_METADATA; -import static org.apache.dubbo.metadata.report.support.Constants.USER_HOME; public abstract class AbstractMetadataReport implements MetadataReport { @@ -116,7 +117,8 @@ public AbstractMetadataReport(URL reportServerURL) { boolean localCacheEnabled = reportServerURL.getParameter(REGISTRY_LOCAL_FILE_CACHE_ENABLED, true); // Start file save timer - String defaultFilename = System.getProperty(USER_HOME) + DUBBO_METADATA + reportServerURL.getApplication() + String defaultFilename = SystemPropertyConfigUtils.getSystemProperty(USER_HOME) + DUBBO_METADATA + + reportServerURL.getApplication() + "-" + replace(reportServerURL.getAddress(), ":", "-") + CACHE; String filename = reportServerURL.getParameter(FILE_KEY, defaultFilename); diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/Constants.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/Constants.java index 4c1fa597ec4..b765631dd37 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/Constants.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/Constants.java @@ -25,8 +25,6 @@ public interface Constants { Boolean DEFAULT_METADATA_REPORT_CYCLE_REPORT = true; - String USER_HOME = "user.home"; - String CACHE = ".cache"; String DUBBO_METADATA = "/.dubbo/dubbo-metadata-"; diff --git a/dubbo-plugin/dubbo-native/src/main/java/org/apache/dubbo/aot/generate/AotProcessor.java b/dubbo-plugin/dubbo-native/src/main/java/org/apache/dubbo/aot/generate/AotProcessor.java index bfa3350ccad..f924e4a714b 100644 --- a/dubbo-plugin/dubbo-native/src/main/java/org/apache/dubbo/aot/generate/AotProcessor.java +++ b/dubbo-plugin/dubbo-native/src/main/java/org/apache/dubbo/aot/generate/AotProcessor.java @@ -20,10 +20,12 @@ import org.apache.dubbo.aot.api.ProxyDescriberRegistrar; import org.apache.dubbo.aot.api.ReflectionTypeDescriberRegistrar; import org.apache.dubbo.aot.api.TypeDescriber; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.rpc.model.FrameworkModel; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -55,6 +57,7 @@ public static void main(String[] args) { ClassSourceScanner.INSTANCE.adaptiveClasses().values())) .registerBeanType(ClassSourceScanner.INSTANCE.scopeModelInitializer()) .registerConfigType(ClassSourceScanner.INSTANCE.configClasses()) + .registerFieldType(getCustomClasses()) .registerTypeDescriber(getTypes()); writer.writeReflectionConfig(reflectRepository); @@ -98,4 +101,13 @@ private static List getProxyDescribers() { return jdkProxyDescribers; } + + private static List> getCustomClasses() { + Class[] configClasses = new Class[] { + CommonConstants.SystemProperty.class, + CommonConstants.ThirdPartyProperty.class, + CommonConstants.DubboProperty.class + }; + return new ArrayList<>(Arrays.asList(configClasses)); + } } diff --git a/dubbo-plugin/dubbo-native/src/main/java/org/apache/dubbo/aot/generate/ReflectConfigMetadataRepository.java b/dubbo-plugin/dubbo-native/src/main/java/org/apache/dubbo/aot/generate/ReflectConfigMetadataRepository.java index 728159ccdd1..c0bc5639a2d 100644 --- a/dubbo-plugin/dubbo-native/src/main/java/org/apache/dubbo/aot/generate/ReflectConfigMetadataRepository.java +++ b/dubbo-plugin/dubbo-native/src/main/java/org/apache/dubbo/aot/generate/ReflectConfigMetadataRepository.java @@ -78,6 +78,23 @@ private TypeDescriber buildTypeDescriberWithConstructor(Class c) { return new TypeDescriber(c.getName(), null, new HashSet<>(), constructors, new HashSet<>(), memberCategories); } + protected ReflectConfigMetadataRepository registerFieldType(List> classes) { + types.addAll(classes.stream() + .filter(Objects::nonNull) + .map(this::buildTypeDescriberWithField) + .collect(Collectors.toList())); + return this; + } + + private TypeDescriber buildTypeDescriberWithField(Class c) { + Set constructors = Arrays.stream(c.getConstructors()) + .map((constructor) -> new ExecutableDescriber(constructor, INVOKE)) + .collect(Collectors.toSet()); + Set memberCategories = new HashSet<>(); + memberCategories.add(MemberCategory.PUBLIC_FIELDS); + return new TypeDescriber(c.getName(), null, new HashSet<>(), constructors, new HashSet<>(), memberCategories); + } + public void registerTypeDescriber(List typeDescribers) { types.addAll(typeDescribers.stream().filter(Objects::nonNull).collect(Collectors.toList())); } diff --git a/dubbo-plugin/dubbo-plugin-access-log/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java b/dubbo-plugin/dubbo-plugin-access-log/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java index 14696307819..6513df80815 100644 --- a/dubbo-plugin/dubbo-plugin-access-log/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java +++ b/dubbo-plugin/dubbo-plugin-access-log/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java @@ -23,6 +23,7 @@ import org.apache.dubbo.common.utils.ConcurrentHashMapUtils; import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.rpc.Constants; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; @@ -49,6 +50,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_LINE_SEPARATOR; import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_FILTER_VALIDATION_EXCEPTION; import static org.apache.dubbo.common.constants.LoggerCodeConstants.VULNERABILITY_WARNING; import static org.apache.dubbo.rpc.Constants.ACCESS_LOG_FIXED_PATH_KEY; @@ -88,8 +90,6 @@ public class AccessLogFilter implements Filter { private final AtomicBoolean scheduled = new AtomicBoolean(); private ScheduledFuture future; - private static final String LINE_SEPARATOR = "line.separator"; - /** * Default constructor initialize demon thread for writing into access log file with names with access log key * defined in url accesslog @@ -215,7 +215,7 @@ private void processWithAccessKeyLogger(Queue logQueue, File file try { while (!logQueue.isEmpty()) { writer.write(logQueue.poll().getLogMessage()); - writer.write(System.getProperty(LINE_SEPARATOR)); + writer.write(SystemPropertyConfigUtils.getSystemProperty(SYSTEM_LINE_SEPARATOR)); } } finally { writer.flush(); diff --git a/dubbo-plugin/dubbo-plugin-mock/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java b/dubbo-plugin/dubbo-plugin-mock/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java index f5c10fbb6b0..190d6cb4528 100644 --- a/dubbo-plugin/dubbo-plugin-mock/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java +++ b/dubbo-plugin/dubbo-plugin-mock/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java @@ -23,6 +23,7 @@ import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.rpc.AsyncRpcResult; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.InvokeMode; @@ -47,8 +48,8 @@ public class MockClusterInvoker implements ClusterInvoker { private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(MockClusterInvoker.class); - private static final boolean setFutureWhenSync = - Boolean.parseBoolean(System.getProperty(CommonConstants.SET_FUTURE_IN_SYNC_MODE, "true")); + private static final boolean setFutureWhenSync = Boolean.parseBoolean(SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.ThirdPartyProperty.SET_FUTURE_IN_SYNC_MODE, "true")); private final Directory directory; diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/MetaCacheManager.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/MetaCacheManager.java index 8cb2c007114..73ff54c0e66 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/MetaCacheManager.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/MetaCacheManager.java @@ -18,12 +18,18 @@ import org.apache.dubbo.common.utils.JsonUtils; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.metadata.AbstractCacheManager; import org.apache.dubbo.metadata.MetadataInfo; import org.apache.dubbo.rpc.model.ScopeModel; import java.util.concurrent.ScheduledExecutorService; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_META_CACHE_ENTRYSIZE; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_META_CACHE_FILENAME; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_META_CACHE_FILEPATH; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_META_CACHE_MAXFILESIZE; + /** * Metadata cache with limited size that uses LRU expiry policy. */ @@ -36,8 +42,8 @@ public static MetaCacheManager getInstance(ScopeModel scopeModel) { } public MetaCacheManager(boolean enableFileCache, String registryName, ScheduledExecutorService executorService) { - String filePath = System.getProperty("dubbo.meta.cache.filePath"); - String fileName = System.getProperty("dubbo.meta.cache.fileName"); + String filePath = SystemPropertyConfigUtils.getSystemProperty(DUBBO_META_CACHE_FILEPATH); + String fileName = SystemPropertyConfigUtils.getSystemProperty(DUBBO_META_CACHE_FILENAME); if (StringUtils.isEmpty(fileName)) { fileName = DEFAULT_FILE_NAME; } @@ -46,11 +52,11 @@ public MetaCacheManager(boolean enableFileCache, String registryName, ScheduledE fileName = fileName + "." + registryName; } - String rawEntrySize = System.getProperty("dubbo.meta.cache.entrySize"); + String rawEntrySize = SystemPropertyConfigUtils.getSystemProperty(DUBBO_META_CACHE_ENTRYSIZE); int entrySize = StringUtils.parseInteger(rawEntrySize); entrySize = (entrySize == 0 ? DEFAULT_ENTRY_SIZE : entrySize); - String rawMaxFileSize = System.getProperty("dubbo.meta.cache.maxFileSize"); + String rawMaxFileSize = SystemPropertyConfigUtils.getSystemProperty(DUBBO_META_CACHE_MAXFILESIZE); long maxFileSize = StringUtils.parseLong(rawMaxFileSize); init(enableFileCache, filePath, fileName, entrySize, maxFileSize, 60, executorService); diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java index 431632a731a..27983bf958f 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java @@ -24,6 +24,7 @@ import org.apache.dubbo.common.utils.ConcurrentHashSet; import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.common.utils.UrlUtils; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; @@ -61,6 +62,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_LOCAL_FILE_CACHE_ENABLED; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.USER_HOME; import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR; import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_EMPTY_ADDRESS; import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DELETE_LOCKFILE; @@ -74,7 +76,6 @@ import static org.apache.dubbo.registry.Constants.CACHE; import static org.apache.dubbo.registry.Constants.DUBBO_REGISTRY; import static org.apache.dubbo.registry.Constants.REGISTRY_FILESAVE_SYNC_KEY; -import static org.apache.dubbo.registry.Constants.USER_HOME; /** *

@@ -129,8 +130,8 @@ protected AbstractRegistry(URL url) { // Start file save timer syncSaveFile = url.getParameter(REGISTRY_FILESAVE_SYNC_KEY, false); - String defaultFilename = System.getProperty(USER_HOME) + DUBBO_REGISTRY + url.getApplication() + "-" - + url.getAddress().replaceAll(":", "-") + CACHE; + String defaultFilename = SystemPropertyConfigUtils.getSystemProperty(USER_HOME) + DUBBO_REGISTRY + + url.getApplication() + "-" + url.getAddress().replaceAll(":", "-") + CACHE; String filename = url.getParameter(FILE_KEY, defaultFilename); File file = null; diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/PerformanceUtils.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/PerformanceUtils.java index 51238d8a400..27a83e1e334 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/PerformanceUtils.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/PerformanceUtils.java @@ -16,6 +16,9 @@ */ package org.apache.dubbo.registry; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; + import java.net.NetworkInterface; import java.net.SocketException; import java.text.DecimalFormat; @@ -25,7 +28,6 @@ /** * PerformanceUtils - * */ public class PerformanceUtils { @@ -57,11 +59,14 @@ public static boolean getBooleanProperty(String key, boolean defaultValue) { public static List getEnvironment() { List environment = new ArrayList(); - environment.add("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " - + System.getProperty("os.arch", "")); + environment.add("OS: " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.SYSTEM_OS_NAME) + " " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.SYSTEM_OS_VERSION) + " " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.OS_ARCH, "")); environment.add("CPU: " + Runtime.getRuntime().availableProcessors() + " cores"); - environment.add( - "JVM: " + System.getProperty("java.vm.name") + " " + System.getProperty("java.runtime.version")); + environment.add("JVM: " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_VM_NAME) + " " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_RUNTIME_VERSION)); environment.add("Memory: " + DecimalFormat.getIntegerInstance().format(Runtime.getRuntime().totalMemory()) + " bytes (Max: " + DecimalFormat.getIntegerInstance().format(Runtime.getRuntime().maxMemory()) + " bytes)"); diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/store/MetaCacheManagerTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/store/MetaCacheManagerTest.java index cd1d5312cf1..32e74a1cef1 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/store/MetaCacheManagerTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/store/MetaCacheManagerTest.java @@ -16,7 +16,9 @@ */ package org.apache.dubbo.registry.client.metadata.store; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.JsonUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.metadata.MetadataInfo; import java.net.URISyntaxException; @@ -39,14 +41,15 @@ class MetaCacheManagerTest { @BeforeEach public void setup() throws URISyntaxException { String directory = getDirectoryOfClassPath(); - System.setProperty("dubbo.meta.cache.filePath", directory); - System.setProperty("dubbo.meta.cache.fileName", "test-metadata.dubbo.cache"); + SystemPropertyConfigUtils.setSystemProperty(CommonConstants.DubboProperty.DUBBO_META_CACHE_FILEPATH, directory); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_META_CACHE_FILENAME, "test-metadata.dubbo.cache"); } @AfterEach public void clear() throws URISyntaxException { - System.clearProperty("dubbo.meta.cache.filePath"); - System.clearProperty("dubbo.meta.cache.fileName"); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_META_CACHE_FILEPATH); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_META_CACHE_FILENAME); } @Test diff --git a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java index 02922034c76..3547e0f93b6 100644 --- a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java +++ b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java @@ -18,11 +18,13 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URLBuilder; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.url.component.DubboServiceAddressURL; import org.apache.dubbo.common.url.component.ServiceConfigURL; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.common.utils.UrlUtils; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; @@ -111,7 +113,8 @@ public class NacosRegistry extends FailbackRegistry { * Change a constant to be configurable, it's designed for Windows file name that is compatible with old * Nacos binary release(< 0.6.1) */ - private static final String SERVICE_NAME_SEPARATOR = System.getProperty("nacos.service.name.separator", ":"); + private static final String SERVICE_NAME_SEPARATOR = SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.ThirdPartyProperty.NACOS_SERVICE_NAME_SEPARATOR, ":"); /** * The pagination size of query for Nacos service names(only for Dubbo-OPS) diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java index 25469e00e25..0a0ba1cd9f7 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java @@ -93,8 +93,6 @@ public interface Constants { */ String PREFER_SERIALIZATION_KEY = "prefer.serialization"; - String DEFAULT_REMOTING_SERIALIZATION_PROPERTY_KEY = "DUBBO_DEFAULT_SERIALIZATION"; - String CODEC_KEY = "codec"; String CODEC_VERSION_KEY = "codec.version"; @@ -123,8 +121,6 @@ public interface Constants { String EVENT_LOOP_WORKER_POOL_NAME = "NettyServerWorker"; - String NETTY_EPOLL_ENABLE_KEY = "netty.epoll.enable"; - String BIND_IP_KEY = "bind.ip"; String BIND_PORT_KEY = "bind.port"; @@ -158,8 +154,6 @@ public interface Constants { String DEFAULT_PROMPT = "dubbo>"; String TELNET_KEY = "telnet"; String HEARTBEAT_KEY = "heartbeat"; - String HEARTBEAT_CONFIG_KEY = "dubbo.protocol.default-heartbeat"; - String CLOSE_TIMEOUT_CONFIG_KEY = "dubbo.protocol.default-close-timeout"; int DEFAULT_HEARTBEAT = 60 * 1000; String HEARTBEAT_TIMEOUT_KEY = "heartbeat.timeout"; String CLOSE_TIMEOUT_KEY = "close.timeout"; @@ -180,7 +174,6 @@ public interface Constants { List REST_SERVER = Arrays.asList("jetty", "tomcat", "netty"); String CONTENT_LENGTH_KEY = "content-length"; - String USE_SECURE_RANDOM_ID = "dubbo.application.use-secure-random-request-id"; String CONNECTION_HANDLER_NAME = "connectionHandler"; } diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java index bab83e2023f..6a0739b78ca 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java @@ -17,13 +17,14 @@ package org.apache.dubbo.remoting.exchange; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import java.security.SecureRandom; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicLong; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_USE_SECURE_RANDOM_ID; import static org.apache.dubbo.common.constants.CommonConstants.HEARTBEAT_EVENT; -import static org.apache.dubbo.remoting.Constants.USE_SECURE_RANDOM_ID; /** * Request. @@ -56,7 +57,7 @@ public Request(long id) { static { long startID = ThreadLocalRandom.current().nextLong(); - if (Boolean.parseBoolean(System.getProperty(USE_SECURE_RANDOM_ID, "false"))) { + if (Boolean.parseBoolean(SystemPropertyConfigUtils.getSystemProperty(DUBBO_USE_SECURE_RANDOM_ID, "false"))) { try { SecureRandom rand = new SecureRandom(SecureRandom.getSeed(20)); startID = rand.nextLong(); diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/utils/UrlUtils.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/utils/UrlUtils.java index 2ba32fc4eba..42f10c05ab4 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/utils/UrlUtils.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/utils/UrlUtils.java @@ -17,8 +17,10 @@ package org.apache.dubbo.remoting.utils; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.serialize.support.DefaultSerializationSelector; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.transport.CodecSupport; @@ -36,7 +38,8 @@ public class UrlUtils { private static final String ALLOWED_SERIALIZATION_KEY = "allowedSerialization"; public static int getCloseTimeout(URL url) { - String configuredCloseTimeout = System.getProperty(Constants.CLOSE_TIMEOUT_CONFIG_KEY); + String configuredCloseTimeout = SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLOSE_TIMEOUT_CONFIG_KEY); int defaultCloseTimeout = -1; if (StringUtils.isNotEmpty(configuredCloseTimeout)) { try { @@ -67,7 +70,8 @@ public static int getIdleTimeout(URL url) { } public static int getHeartbeat(URL url) { - String configuredHeartbeat = System.getProperty(Constants.HEARTBEAT_CONFIG_KEY); + String configuredHeartbeat = + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.DubboProperty.DUBBO_HEARTBEAT_CONFIG_KEY); int defaultHeartbeat = Constants.DEFAULT_HEARTBEAT; if (StringUtils.isNotEmpty(configuredHeartbeat)) { try { @@ -111,7 +115,7 @@ public static Byte serializationId(URL url) { * @return {@link String} */ public static String serializationOrDefault(URL url) { - //noinspection OptionalGetWithoutIsPresent + // noinspection OptionalGetWithoutIsPresent Optional serializations = allSerializations(url).stream().findFirst(); return serializations.orElseGet(DefaultSerializationSelector::getDefaultRemotingSerialization); } diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceUtils.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceUtils.java index 56e9bd9906d..2714a26d3f5 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceUtils.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceUtils.java @@ -16,6 +16,9 @@ */ package org.apache.dubbo.remoting; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; + import java.net.NetworkInterface; import java.net.SocketException; import java.text.DecimalFormat; @@ -56,11 +59,14 @@ public static boolean getBooleanProperty(String key, boolean defaultValue) { public static List getEnvironment() { List environment = new ArrayList(); - environment.add("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " - + System.getProperty("os.arch", "")); + environment.add("OS: " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.SYSTEM_OS_NAME) + " " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.SYSTEM_OS_VERSION) + " " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.OS_ARCH, "")); environment.add("CPU: " + Runtime.getRuntime().availableProcessors() + " cores"); - environment.add( - "JVM: " + System.getProperty("java.vm.name") + " " + System.getProperty("java.runtime.version")); + environment.add("JVM: " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_VM_NAME) + " " + + SystemPropertyConfigUtils.getSystemProperty(CommonConstants.SystemProperty.JAVA_RUNTIME_VERSION)); environment.add("Memory: " + DecimalFormat.getIntegerInstance().format(Runtime.getRuntime().totalMemory()) + " bytes (Max: " + DecimalFormat.getIntegerInstance().format(Runtime.getRuntime().maxMemory()) + " bytes)"); diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/utils/UrlUtilsTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/utils/UrlUtilsTest.java index 6a957aee5e5..4538a6ebe49 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/utils/UrlUtilsTest.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/utils/UrlUtilsTest.java @@ -17,7 +17,8 @@ package org.apache.dubbo.remoting.utils; import org.apache.dubbo.common.URL; -import org.apache.dubbo.remoting.Constants; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -41,10 +42,10 @@ void testGetHeartbeat() { @Test void testConfiguredHeartbeat() { - System.setProperty(Constants.HEARTBEAT_CONFIG_KEY, "200"); + SystemPropertyConfigUtils.setSystemProperty(CommonConstants.DubboProperty.DUBBO_HEARTBEAT_CONFIG_KEY, "200"); URL url = URL.valueOf("dubbo://127.0.0.1:12345"); Assertions.assertEquals(200, UrlUtils.getHeartbeat(url)); - System.clearProperty(Constants.HEARTBEAT_CONFIG_KEY); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_HEARTBEAT_CONFIG_KEY); } @Test @@ -65,9 +66,10 @@ void testGetCloseTimeout() { @Test void testConfiguredClose() { - System.setProperty(Constants.CLOSE_TIMEOUT_CONFIG_KEY, "180000"); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_CLOSE_TIMEOUT_CONFIG_KEY, "180000"); URL url = URL.valueOf("dubbo://127.0.0.1:12345"); Assertions.assertEquals(180000, UrlUtils.getCloseTimeout(url)); - System.clearProperty(Constants.HEARTBEAT_CONFIG_KEY); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_CLOSE_TIMEOUT_CONFIG_KEY); } } diff --git a/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/tomcat/TomcatHttpServer.java b/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/tomcat/TomcatHttpServer.java index 3d73fcadb1c..002f963c350 100755 --- a/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/tomcat/TomcatHttpServer.java +++ b/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/tomcat/TomcatHttpServer.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.remoting.http.HttpHandler; import org.apache.dubbo.remoting.http.servlet.DispatcherServlet; import org.apache.dubbo.remoting.http.servlet.ServletManager; @@ -32,6 +33,7 @@ import org.apache.catalina.startup.Tomcat; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADS; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_JAVA_IO_TMPDIR; import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_FAILED_STOP_HTTP_SERVER; import static org.apache.dubbo.remoting.Constants.ACCEPTS_KEY; @@ -49,7 +51,7 @@ public TomcatHttpServer(URL url, final HttpHandler handler) { this.url = url; DispatcherServlet.addHttpHandler(url.getPort(), handler); - String baseDir = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath(); + String baseDir = new File(SystemPropertyConfigUtils.getSystemProperty(SYSTEM_JAVA_IO_TMPDIR)).getAbsolutePath(); tomcat = new Tomcat(); Connector connector = tomcat.getConnector(); diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyEventLoopFactory.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyEventLoopFactory.java index ad3c807cf61..0ecae22ee2c 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyEventLoopFactory.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyEventLoopFactory.java @@ -17,6 +17,7 @@ package org.apache.dubbo.remoting.transport.netty4; import org.apache.dubbo.common.resource.GlobalResourceInitializer; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.remoting.Constants; import java.util.concurrent.ThreadFactory; @@ -34,8 +35,8 @@ import io.netty.util.concurrent.DefaultThreadFactory; import static org.apache.dubbo.common.constants.CommonConstants.OS_LINUX_PREFIX; -import static org.apache.dubbo.common.constants.CommonConstants.OS_NAME_KEY; -import static org.apache.dubbo.remoting.Constants.NETTY_EPOLL_ENABLE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_OS_NAME; +import static org.apache.dubbo.common.constants.CommonConstants.ThirdPartyProperty.NETTY_EPOLL_ENABLE_KEY; public class NettyEventLoopFactory { /** @@ -62,8 +63,8 @@ public static Class serverSocketChannelClass() { } private static boolean shouldEpoll() { - if (Boolean.parseBoolean(System.getProperty(NETTY_EPOLL_ENABLE_KEY, "false"))) { - String osName = System.getProperty(OS_NAME_KEY); + if (Boolean.parseBoolean(SystemPropertyConfigUtils.getSystemProperty(NETTY_EPOLL_ENABLE_KEY, "false"))) { + String osName = SystemPropertyConfigUtils.getSystemProperty(SYSTEM_OS_NAME); return osName.toLowerCase().contains(OS_LINUX_PREFIX) && Epoll.isAvailable(); } diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/test/java/org/apache/dubbo/remoting/transport/netty4/NettyEventLoopFactoryTest.java b/dubbo-remoting/dubbo-remoting-netty4/src/test/java/org/apache/dubbo/remoting/transport/netty4/NettyEventLoopFactoryTest.java index 43fbdbe5a6a..5148bb1c5e1 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/test/java/org/apache/dubbo/remoting/transport/netty4/NettyEventLoopFactoryTest.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/test/java/org/apache/dubbo/remoting/transport/netty4/NettyEventLoopFactoryTest.java @@ -16,6 +16,8 @@ */ package org.apache.dubbo.remoting.transport.netty4; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; + import io.netty.channel.EventLoopGroup; import io.netty.channel.epoll.Epoll; import io.netty.channel.epoll.EpollEventLoopGroup; @@ -32,8 +34,8 @@ import org.junit.jupiter.api.Test; import static org.apache.dubbo.common.constants.CommonConstants.OS_LINUX_PREFIX; -import static org.apache.dubbo.common.constants.CommonConstants.OS_NAME_KEY; -import static org.apache.dubbo.remoting.Constants.NETTY_EPOLL_ENABLE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_OS_NAME; +import static org.apache.dubbo.common.constants.CommonConstants.ThirdPartyProperty.NETTY_EPOLL_ENABLE_KEY; /** * {@link NettyEventLoopFactory} @@ -42,12 +44,12 @@ class NettyEventLoopFactoryTest { @BeforeEach public void setUp() { - System.setProperty(NETTY_EPOLL_ENABLE_KEY, "true"); + SystemPropertyConfigUtils.setSystemProperty(NETTY_EPOLL_ENABLE_KEY, "true"); } @AfterEach public void reset() { - System.clearProperty(NETTY_EPOLL_ENABLE_KEY); + SystemPropertyConfigUtils.clearSystemProperty(NETTY_EPOLL_ENABLE_KEY); } @Test @@ -77,7 +79,7 @@ void eventLoopGroup() { } private boolean isEpoll() { - String osName = System.getProperty(OS_NAME_KEY); + String osName = SystemPropertyConfigUtils.getSystemProperty(SYSTEM_OS_NAME); return osName.toLowerCase().contains(OS_LINUX_PREFIX) && Epoll.isAvailable(); } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java index 4f9551ff6eb..c39e6d53a8c 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.threadpool.ThreadlessExecutor; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.rpc.model.ConsumerMethodModel; import org.apache.dubbo.rpc.protocol.dubbo.FutureAdapter; @@ -69,8 +70,8 @@ public class AsyncRpcResult implements Result { /** * Whether set future to Thread Local when invocation mode is sync */ - private static final boolean setFutureWhenSync = - Boolean.parseBoolean(System.getProperty(CommonConstants.SET_FUTURE_IN_SYNC_MODE, "true")); + private static final boolean setFutureWhenSync = Boolean.parseBoolean(SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.ThirdPartyProperty.SET_FUTURE_IN_SYNC_MODE, "true")); public AsyncRpcResult(CompletableFuture future, Invocation invocation) { this.responseFuture = future; diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java index e660ae1634b..dd557c61477 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java @@ -94,7 +94,6 @@ public interface Constants { String CONSUMER_MODEL = "consumerModel"; String METHOD_MODEL = "methodModel"; - String SERIALIZATION_SECURITY_CHECK_KEY = "serialization.security.check"; String INVOCATION_KEY = "invocation"; String SERIALIZATION_ID_KEY = "serialization_id"; diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/FutureContext.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/FutureContext.java index c125fb3c9c3..b5634383c29 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/FutureContext.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/FutureContext.java @@ -18,6 +18,7 @@ import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.threadlocal.InternalThreadLocal; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.rpc.protocol.dubbo.FutureAdapter; import java.util.concurrent.CompletableFuture; @@ -48,8 +49,8 @@ public static FutureContext getContext() { /** * Whether clear future once get */ - private static final boolean clearFutureAfterGet = - Boolean.parseBoolean(System.getProperty(CommonConstants.CLEAR_FUTURE_AFTER_GET, "false")); + private static final boolean clearFutureAfterGet = Boolean.parseBoolean(SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.ThirdPartyProperty.CLEAR_FUTURE_AFTER_GET, "false")); /** * get future. @@ -103,7 +104,7 @@ public CompletableFuture getCompatibleCompletableFuture() { * } * } * } - * + *

* Start from 2.7.3, you don't have to get Future from RpcContext, we recommend using Result directly: *

{@code
      *      public final class TracingFilter implements Filter {
@@ -114,7 +115,6 @@ public  CompletableFuture getCompatibleCompletableFuture() {
      *          }
      *      }
      * }
- * */ @Deprecated public void setCompatibleFuture(CompletableFuture compatibleFuture) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java index 556c0e9e5f7..28cc810cd2c 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java @@ -28,6 +28,7 @@ import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.remoting.TimeoutException; import org.apache.dubbo.remoting.utils.UrlUtils; @@ -92,8 +93,8 @@ public abstract class AbstractInvoker implements Invoker { /** * Whether set future to Thread Local when invocation mode is sync */ - private static final boolean setFutureWhenSync = - Boolean.parseBoolean(System.getProperty(CommonConstants.SET_FUTURE_IN_SYNC_MODE, "true")); + private static final boolean setFutureWhenSync = Boolean.parseBoolean(SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.ThirdPartyProperty.SET_FUTURE_IN_SYNC_MODE, "true")); // -- Constructor diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java index 7c197597ee6..aafad861f0c 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java @@ -24,6 +24,7 @@ import org.apache.dubbo.common.utils.CacheableSupplier; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.Codec; import org.apache.dubbo.remoting.Constants; @@ -56,11 +57,11 @@ import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PAYLOAD; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SERIALIZATION_SECURITY_CHECK_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_DECODE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TRANSPORT_EXCEED_PAYLOAD_LIMIT; import static org.apache.dubbo.rpc.Constants.SERIALIZATION_ID_KEY; -import static org.apache.dubbo.rpc.Constants.SERIALIZATION_SECURITY_CHECK_KEY; public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Decodeable { @@ -82,7 +83,7 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec protected final transient Supplier callbackServiceCodecFactory; private static final boolean CHECK_SERIALIZATION = - Boolean.parseBoolean(System.getProperty(SERIALIZATION_SECURITY_CHECK_KEY, "true")); + Boolean.parseBoolean(SystemPropertyConfigUtils.getSystemProperty(SERIALIZATION_SECURITY_CHECK_KEY, "true")); public DecodeableRpcInvocation( FrameworkModel frameworkModel, Channel channel, Request request, InputStream is, byte id) { diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java index 0469f9567ad..5b1f4a2a814 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java @@ -40,9 +40,9 @@ import java.io.OutputStream; import java.lang.reflect.Type; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SERIALIZATION_SECURITY_CHECK_KEY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_DECODE; import static org.apache.dubbo.rpc.Constants.SERIALIZATION_ID_KEY; -import static org.apache.dubbo.rpc.Constants.SERIALIZATION_SECURITY_CHECK_KEY; public class DecodeableRpcResult extends AppResponse implements Codec, Decodeable { diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java index bb446fcb15a..0872ebaaecb 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java @@ -26,6 +26,7 @@ import org.apache.dubbo.common.serialize.Serialization; import org.apache.dubbo.common.threadpool.manager.ExecutorRepository; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.exchange.HeartBeatRequest; import org.apache.dubbo.remoting.exchange.HeartBeatResponse; @@ -45,11 +46,11 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; -import static org.apache.dubbo.common.constants.CommonConstants.BYTE_ACCESSOR_KEY; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.EXECUTOR_MANAGEMENT_MODE_ISOLATION; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_BYTE_ACCESSOR_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_DECODE; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DEFAULT_DECODE_IN_IO_THREAD; @@ -80,7 +81,7 @@ public class DubboCodec extends ExchangeCodec { public DubboCodec(FrameworkModel frameworkModel) { this.frameworkModel = frameworkModel; callbackServiceCodec = new CallbackServiceCodec(frameworkModel); - customByteAccessor = Optional.ofNullable(System.getProperty(BYTE_ACCESSOR_KEY)) + customByteAccessor = Optional.ofNullable(SystemPropertyConfigUtils.getSystemProperty(SYSTEM_BYTE_ACCESSOR_KEY)) .filter(StringUtils::isNotBlank) .map(key -> frameworkModel.getExtensionLoader(ByteAccessor.class).getExtension(key)) diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java index 2b2463defed..9b3909d8252 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java @@ -22,6 +22,7 @@ import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.serialize.SerializationException; import org.apache.dubbo.common.utils.AtomicPositiveInteger; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.remoting.TimeoutException; @@ -70,8 +71,8 @@ public class DubboInvoker extends AbstractInvoker { private final int serverShutdownTimeout; - private static final boolean setFutureWhenSync = - Boolean.parseBoolean(System.getProperty(CommonConstants.SET_FUTURE_IN_SYNC_MODE, "true")); + private static final boolean setFutureWhenSync = Boolean.parseBoolean(SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.ThirdPartyProperty.SET_FUTURE_IN_SYNC_MODE, "true")); public DubboInvoker(Class serviceType, URL url, ClientsProvider clientsProvider) { this(serviceType, url, clientsProvider, null); diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java index 68054d7ddb7..15395450865 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java @@ -24,6 +24,7 @@ import org.apache.dubbo.common.utils.ArrayUtils; import org.apache.dubbo.common.utils.ExecutorUtil; import org.apache.dubbo.common.utils.ReflectUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.rpc.AppResponse; import org.apache.dubbo.rpc.AsyncRpcResult; import org.apache.dubbo.rpc.Constants; @@ -72,8 +73,8 @@ public class InjvmInvoker extends AbstractInvoker { private final boolean shouldIgnoreSameModule; - private static final boolean setFutureWhenSync = - Boolean.parseBoolean(System.getProperty(CommonConstants.SET_FUTURE_IN_SYNC_MODE, "true")); + private static final boolean setFutureWhenSync = Boolean.parseBoolean(SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.ThirdPartyProperty.SET_FUTURE_IN_SYNC_MODE, "true")); InjvmInvoker(Class type, URL url, String key, Map> exporterMap) { super(type, url); diff --git a/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/NoAnnotationRestProtocolTest.java b/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/NoAnnotationRestProtocolTest.java index ce9a2502fe4..f5c447a3957 100644 --- a/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/NoAnnotationRestProtocolTest.java +++ b/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/NoAnnotationRestProtocolTest.java @@ -21,6 +21,7 @@ import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.utils.JsonUtils; import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; @@ -57,7 +58,7 @@ public void clearJson() { setJson(null); } }.clearJson(); - System.clearProperty(CommonConstants.PREFER_JSON_FRAMEWORK_NAME); + SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME); } @Test @@ -69,7 +70,8 @@ public void clearJson() { setJson(null); } }.clearJson(); - System.setProperty(CommonConstants.PREFER_JSON_FRAMEWORK_NAME, json); + SystemPropertyConfigUtils.setSystemProperty( + CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, json); testRestProtocol(); } } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java index 76b26247cb2..21e1f85aee8 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java @@ -25,6 +25,7 @@ import org.apache.dubbo.common.stream.StreamObserver; import org.apache.dubbo.common.threadpool.ThreadlessExecutor; import org.apache.dubbo.common.utils.ReflectUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.remoting.api.connection.AbstractConnectionClient; import org.apache.dubbo.rpc.AppResponse; import org.apache.dubbo.rpc.AsyncRpcResult; @@ -94,8 +95,8 @@ public class TripleInvoker extends AbstractInvoker { private final String acceptEncodings; private final TripleWriteQueue writeQueue = new TripleWriteQueue(256); - private static final boolean setFutureWhenSync = - Boolean.parseBoolean(System.getProperty(CommonConstants.SET_FUTURE_IN_SYNC_MODE, "true")); + private static final boolean setFutureWhenSync = Boolean.parseBoolean(SystemPropertyConfigUtils.getSystemProperty( + CommonConstants.ThirdPartyProperty.SET_FUTURE_IN_SYNC_MODE, "true")); private final PackableMethodFactory packableMethodFactory; private final Map packableMethodCache = new ConcurrentHashMap<>(); diff --git a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/DefaultSerializationSelector.java b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/DefaultSerializationSelector.java index d7cb4a6e84d..b15f93c0578 100644 --- a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/DefaultSerializationSelector.java +++ b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/DefaultSerializationSelector.java @@ -16,20 +16,23 @@ */ package org.apache.dubbo.common.serialize.support; -public class DefaultSerializationSelector { +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; + +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_DEFAULT_REMOTING_SERIALIZATION_PROPERTY; - private static final String DEFAULT_REMOTING_SERIALIZATION_PROPERTY_KEY = "DUBBO_DEFAULT_SERIALIZATION"; +public class DefaultSerializationSelector { private static final String DEFAULT_REMOTING_SERIALIZATION_PROPERTY = "hessian2"; private static final String DEFAULT_REMOTING_SERIALIZATION; static { - String fromProperty = System.getProperty(DEFAULT_REMOTING_SERIALIZATION_PROPERTY_KEY); + String fromProperty = + SystemPropertyConfigUtils.getSystemProperty(DUBBO_DEFAULT_REMOTING_SERIALIZATION_PROPERTY); if (fromProperty != null) { DEFAULT_REMOTING_SERIALIZATION = fromProperty; } else { - String fromEnv = System.getenv(DEFAULT_REMOTING_SERIALIZATION_PROPERTY_KEY); + String fromEnv = System.getenv(DUBBO_DEFAULT_REMOTING_SERIALIZATION_PROPERTY); if (fromEnv != null) { DEFAULT_REMOTING_SERIALIZATION = fromEnv; } else { diff --git a/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2FactoryManager.java b/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2FactoryManager.java index ac342926600..aba58da02e9 100644 --- a/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2FactoryManager.java +++ b/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2FactoryManager.java @@ -21,16 +21,19 @@ import org.apache.dubbo.common.utils.SerializeCheckStatus; import org.apache.dubbo.common.utils.SerializeSecurityManager; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.rpc.model.FrameworkModel; import java.util.concurrent.ConcurrentHashMap; import com.alibaba.com.caucho.hessian.io.SerializerFactory; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_HESSIAN_ALLOW; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_HESSIAN_ALLOW_NON_SERIALIZABLE; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_HESSIAN_DENY; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_HESSIAN_WHITELIST; + public class Hessian2FactoryManager { - String WHITELIST = "dubbo.application.hessian2.whitelist"; - String ALLOW = "dubbo.application.hessian2.allow"; - String DENY = "dubbo.application.hessian2.deny"; private volatile SerializerFactory SYSTEM_SERIALIZER_FACTORY; private volatile SerializerFactory stickySerializerFactory = null; private final ConcurrentHashMap CL_2_SERIALIZER_FACTORY = new ConcurrentHashMap<>(); @@ -70,7 +73,7 @@ public SerializerFactory getSerializerFactory(ClassLoader classLoader) { } private SerializerFactory createSerializerFactory(ClassLoader classLoader) { - String whitelist = System.getProperty(WHITELIST); + String whitelist = SystemPropertyConfigUtils.getSystemProperty(DUBBO_HESSIAN_WHITELIST); if (StringUtils.isNotEmpty(whitelist)) { return createWhiteListSerializerFactory(classLoader); } @@ -81,18 +84,18 @@ private SerializerFactory createSerializerFactory(ClassLoader classLoader) { private SerializerFactory createDefaultSerializerFactory(ClassLoader classLoader) { Hessian2SerializerFactory hessian2SerializerFactory = new Hessian2SerializerFactory(classLoader, defaultSerializeClassChecker); - hessian2SerializerFactory.setAllowNonSerializable( - Boolean.parseBoolean(System.getProperty("dubbo.hessian.allowNonSerializable", "false"))); + hessian2SerializerFactory.setAllowNonSerializable(Boolean.parseBoolean( + SystemPropertyConfigUtils.getSystemProperty(DUBBO_HESSIAN_ALLOW_NON_SERIALIZABLE, "false"))); hessian2SerializerFactory.getClassFactory().allow("org.apache.dubbo.*"); return hessian2SerializerFactory; } public SerializerFactory createWhiteListSerializerFactory(ClassLoader classLoader) { SerializerFactory serializerFactory = new Hessian2SerializerFactory(classLoader, defaultSerializeClassChecker); - String whiteList = System.getProperty(WHITELIST); + String whiteList = SystemPropertyConfigUtils.getSystemProperty(DUBBO_HESSIAN_WHITELIST); if ("true".equals(whiteList)) { serializerFactory.getClassFactory().setWhitelist(true); - String allowPattern = System.getProperty(ALLOW); + String allowPattern = SystemPropertyConfigUtils.getSystemProperty(DUBBO_HESSIAN_ALLOW); if (StringUtils.isNotEmpty(allowPattern)) { for (String pattern : allowPattern.split(";")) { serializerFactory.getClassFactory().allow(pattern); @@ -102,7 +105,7 @@ public SerializerFactory createWhiteListSerializerFactory(ClassLoader classLoade serializeSecurityManager.setCheckStatus(SerializeCheckStatus.STRICT); } else { serializerFactory.getClassFactory().setWhitelist(false); - String denyPattern = System.getProperty(DENY); + String denyPattern = SystemPropertyConfigUtils.getSystemProperty(DUBBO_HESSIAN_DENY); if (StringUtils.isNotEmpty(denyPattern)) { for (String pattern : denyPattern.split(";")) { serializerFactory.getClassFactory().deny(pattern); @@ -110,8 +113,8 @@ public SerializerFactory createWhiteListSerializerFactory(ClassLoader classLoade } } } - serializerFactory.setAllowNonSerializable( - Boolean.parseBoolean(System.getProperty("dubbo.hessian.allowNonSerializable", "false"))); + serializerFactory.setAllowNonSerializable(Boolean.parseBoolean( + SystemPropertyConfigUtils.getSystemProperty(DUBBO_HESSIAN_ALLOW_NON_SERIALIZABLE, "false"))); serializerFactory.getClassFactory().allow("org.apache.dubbo.*"); return serializerFactory; } diff --git a/dubbo-serialization/dubbo-serialization-hessian2/src/test/java/org/apache/dubbo/common/serialize/hessian2/Hessian2SerializationTest.java b/dubbo-serialization/dubbo-serialization-hessian2/src/test/java/org/apache/dubbo/common/serialize/hessian2/Hessian2SerializationTest.java index 93dc9d1185e..559ed1e3b6a 100644 --- a/dubbo-serialization/dubbo-serialization-hessian2/src/test/java/org/apache/dubbo/common/serialize/hessian2/Hessian2SerializationTest.java +++ b/dubbo-serialization/dubbo-serialization-hessian2/src/test/java/org/apache/dubbo/common/serialize/hessian2/Hessian2SerializationTest.java @@ -22,6 +22,7 @@ import org.apache.dubbo.common.serialize.Serialization; import org.apache.dubbo.common.utils.SerializeCheckStatus; import org.apache.dubbo.common.utils.SerializeSecurityManager; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.rpc.model.FrameworkModel; import java.io.ByteArrayInputStream; @@ -38,6 +39,8 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_HESSIAN_ALLOW_NON_SERIALIZABLE; + class Hessian2SerializationTest { @Test void testReadString() throws IOException { @@ -617,7 +620,7 @@ void testLimit5() throws IOException, ClassNotFoundException { // write force un-serializable, read failed { - System.setProperty("dubbo.hessian.allowNonSerializable", "true"); + SystemPropertyConfigUtils.setSystemProperty(DUBBO_HESSIAN_ALLOW_NON_SERIALIZABLE, "true"); FrameworkModel frameworkModel = new FrameworkModel(); Serialization serialization = frameworkModel.getExtensionLoader(Serialization.class).getExtension("hessian2"); @@ -635,7 +638,7 @@ void testLimit5() throws IOException, ClassNotFoundException { objectOutput.flushBuffer(); frameworkModel.destroy(); - System.clearProperty("dubbo.hessian.allowNonSerializable"); + SystemPropertyConfigUtils.clearSystemProperty(DUBBO_HESSIAN_ALLOW_NON_SERIALIZABLE); } { diff --git a/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/util/DubboUtils.java b/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/util/DubboUtils.java index dc7f6f9b916..d434723fa1c 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/util/DubboUtils.java +++ b/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/util/DubboUtils.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.spring.boot.util; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationPostProcessor; import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; @@ -26,6 +27,8 @@ import org.springframework.boot.context.ContextIdApplicationContextInitializer; import org.springframework.core.env.PropertyResolver; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_LINE_SEPARATOR; + /** * The utilities class for Dubbo * @@ -36,7 +39,7 @@ public abstract class DubboUtils { /** * line separator */ - public static final String LINE_SEPARATOR = System.getProperty("line.separator"); + public static final String LINE_SEPARATOR = SystemPropertyConfigUtils.getSystemProperty(SYSTEM_LINE_SEPARATOR); /** * The separator of property name diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/AbstractRegistryCenterTestExecutionListener.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/AbstractRegistryCenterTestExecutionListener.java index 6c29169eb0e..89819d1aaea 100644 --- a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/AbstractRegistryCenterTestExecutionListener.java +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/AbstractRegistryCenterTestExecutionListener.java @@ -16,6 +16,8 @@ */ package org.apache.dubbo.test.check; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; + import java.util.HashSet; import java.util.Set; @@ -25,17 +27,14 @@ import org.junit.platform.launcher.TestIdentifier; import org.junit.platform.launcher.TestPlan; +import static org.apache.dubbo.common.constants.CommonConstants.ThirdPartyProperty.ZOOKEEPER_CONFIG_ENABLE_EMBEDDED; + /** * The abstract implementation provides the basic methods.

* {@link #needRegistryCenter(TestPlan)}: checks if current {@link TestPlan} need registry center. */ public abstract class AbstractRegistryCenterTestExecutionListener implements TestExecutionListener { - /** - * The JVM arguments to set if it can use embedded zookeeper, the default value is {@code true}. - */ - private static final String CONFIG_ENABLE_EMBEDDED_ZOOKEEPER = "enableEmbeddedZookeeper"; - /** * The registry center should start * if we want to run the test cases in the given package. @@ -59,7 +58,8 @@ public abstract class AbstractRegistryCenterTestExecutionListener implements Tes // dubbo-metadata-report-zookeeper PACKAGE_NAME.add("org.apache.dubbo.metadata.store.zookeeper"); - enableEmbeddedZookeeper = Boolean.valueOf(System.getProperty(CONFIG_ENABLE_EMBEDDED_ZOOKEEPER, "true")); + enableEmbeddedZookeeper = + Boolean.valueOf(SystemPropertyConfigUtils.getSystemProperty(ZOOKEEPER_CONFIG_ENABLE_EMBEDDED, "true")); } /** diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/ZookeeperRegistryCenter.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/ZookeeperRegistryCenter.java index e9aa0459fae..b08603398bb 100644 --- a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/ZookeeperRegistryCenter.java +++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/ZookeeperRegistryCenter.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.Assert; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperWindowsContext; @@ -43,6 +44,10 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_JAVA_IO_TMPDIR; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_OS_NAME; +import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.USER_HOME; + /** * Build the registry center with embedded zookeeper, which is run by a new process. */ @@ -142,11 +147,11 @@ private static String getEmbeddedZookeeperDirectory() { } // Use System.getProperty(user.home) logger.info(String.format("The user home is %s to store zookeeper binary archive.", directory)); - directory = System.getProperty("user.home"); + directory = SystemPropertyConfigUtils.getSystemProperty(USER_HOME); logger.info(String.format("user.home is %s", directory)); if (StringUtils.isEmpty(directory)) { // Use default temporary directory - directory = System.getProperty("java.io.tmpdir"); + directory = SystemPropertyConfigUtils.getSystemProperty(SYSTEM_JAVA_IO_TMPDIR); logger.info(String.format("The temporary directory is %s to store zookeeper binary archive.", directory)); } Assert.notEmptyString(directory, "The directory to store zookeeper binary archive cannot be null or empty."); @@ -167,7 +172,8 @@ private static Path getTargetFilePath() { * Returns the Operating System. */ private static OS getOS() { - String osName = System.getProperty("os.name").toLowerCase(); + String osName = + SystemPropertyConfigUtils.getSystemProperty(SYSTEM_OS_NAME).toLowerCase(); OS os = OS.Unix; if (osName.contains("windows")) { os = OS.Windows;