[System properties] Add the system properties tool, unified system configuration items (#13307)

* Initialize

* update code style

* delete redundant file

* Change position

* delete redundant import

* Add JsonCompatibilityUtils

* Delete unused import

* change funcs

* Add test case

* update color class

* add license

* fix style

* Add class of SystemPropertyConfigUtils

* Unify config

* Delete permit

* Fix style

* unify config

* Fix code style

* Update comment

* Normalized style

* Fix native CI bug

* unify code style

* Add log

* fix code format

* Add log

* Update graalvm

* Delete log

* Fix bugs
This commit is contained in:
hjyp 2023-11-20 16:42:18 +08:00 committed by GitHub
parent 633bdbd08f
commit f441e79d8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
83 changed files with 859 additions and 375 deletions

View File

@ -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}.

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.common.cache;
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.Set;
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 final class FileCacheStoreFactory {
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);

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.common.compact;
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;

View File

@ -25,6 +25,7 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
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 class Environment extends LifecycleAdapter implements ApplicationExt {
*/
@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;
}

View File

@ -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";
}
}

View File

@ -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.slf4j.Slf4jLoggerAdapter;
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());

View File

@ -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.threadpool.event.ThreadPoolExhaustedListener;
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 java.lang.String.format;
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<ThreadPoolExhaustedListener> listeners = new ConcurrentHashSet<>();
@ -168,7 +171,8 @@ public class AbortPolicyWithReport extends ThreadPoolExecutor.AbortPolicy {
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)) {

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.common.timer;
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.AtomicInteger;
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 @@ public class HashedWheelTimer implements Timer {
}
}
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;

View File

@ -164,9 +164,9 @@ public class ConfigUtils {
* @return
*/
public static Properties getProperties(Set<ClassLoader> 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;
}

View File

@ -19,6 +19,8 @@ package org.apache.dubbo.common.utils;
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 enum JRE {
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");

View File

@ -56,7 +56,8 @@ public class JVMUtil {
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);

View File

@ -35,7 +35,8 @@ public class JsonUtils {
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;

View File

@ -48,8 +48,6 @@ import java.util.regex.PatternSyntaxException;
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 final class NetUtils {
/**
* 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 final class NetUtils {
/**
* 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 final class NetUtils {
/**
* 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 @@ public final class NetUtils {
|| !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 @@ public final class NetUtils {
*
* @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 <code>true</code>,
* the property value from {@link CommonConstants.DubboProperty#DUBBO_PREFERRED_NETWORK_INTERFACE}, return <code>true</code>,
* or <code>false</code>
*/
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);
}

View File

@ -40,9 +40,6 @@ import java.util.Optional;
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 @@ public class SerializeSecurityConfigurator implements ScopeClassLoaderListener<M
}
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 class SerializeSecurityConfigurator implements ScopeClassLoaderListener<M
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;
}

View File

@ -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<String> 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);
}
}

View File

@ -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";

View File

@ -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 class ConsumerConfig extends AbstractReferenceConfig {
@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 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)}
*/
@Deprecated
public void setReferBackground(Boolean referBackground) {

View File

@ -18,9 +18,11 @@ package org.apache.dubbo.config;
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.Map;
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 @@ public abstract class ReferenceConfigBase<T> extends AbstractReferenceConfig {
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();
}

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.common;
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 java.util.function.Predicate;
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 @@ class URLTest {
@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.");

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.common.threadpool.support;
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 java.util.concurrent.atomic.AtomicReference;
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 @@ class AbortPolicyWithReportTest {
+ "&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 @@ class AbortPolicyWithReportTest {
+ "&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

View File

@ -166,19 +166,21 @@ class ConfigUtilsTest {
@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"));
}

View File

@ -71,8 +71,8 @@ class DefaultSerializeClassCheckerTest {
@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 @@ class DefaultSerializeClassCheckerTest {
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 @@ class DefaultSerializeClassCheckerTest {
.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 @@ class DefaultSerializeClassCheckerTest {
.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

View File

@ -22,12 +22,14 @@ import org.junit.jupiter.api.Assertions;
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);
}

View File

@ -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 @@ class JsonUtilsTest {
// 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 @@ class JsonUtilsTest {
// 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 @@ class JsonUtilsTest {
// 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 @@ class JsonUtilsTest {
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);

View File

@ -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.junit.jupiter.api.Test;
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 @@ class NetUtilsInterfaceDisplayNameHasMetaCharactersTest {
}
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, "");
}
}
}

View File

@ -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 java.util.regex.Pattern;
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 @@ class NetUtilsTest {
}
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, "");
}
}
}

View File

@ -40,9 +40,6 @@ import com.service.deep1.deep2.deep3.DemoService3;
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 @@ class SerializeSecurityConfiguratorTest {
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 @@ class SerializeSecurityConfiguratorTest {
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 @@ class SerializeSecurityConfiguratorTest {
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 @@ class SerializeSecurityConfiguratorTest {
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 @@ class SerializeSecurityConfiguratorTest {
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 @@ class SerializeSecurityConfiguratorTest {
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 @@ class SerializeSecurityConfiguratorTest {
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 @@ class SerializeSecurityConfiguratorTest {
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 @@ class SerializeSecurityConfiguratorTest {
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 @@ class SerializeSecurityConfiguratorTest {
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();
}

View File

@ -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);
}
}

View File

@ -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

View File

@ -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 class SystemPageHandler implements PageHandler {
row = new ArrayList<String>();
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<String>();
row.add("JVM");
row.add(System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version") + ",<br/>"
+ 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)
+ ",<br/>"
+ 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<String>();
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<String>();
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<String>();

View File

@ -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);
}
}

View File

@ -73,6 +73,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR_
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.PROVIDED_BY;
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;

View File

@ -79,6 +79,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
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.getAvailablePort;
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 class ServiceConfig<T> extends ServiceConfigBase<T> {
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 {

View File

@ -31,6 +31,7 @@ import org.apache.dubbo.common.utils.CollectionUtils;
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 java.util.stream.Collectors;
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.isEmpty;
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 class ConfigValidationUtils {
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) {

View File

@ -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.Assertions;
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 @@ class ConsumerConfigTest {
@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

View File

@ -22,6 +22,7 @@ import org.apache.dubbo.common.deploy.ApplicationDeployListener;
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

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.config.spring;
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.annotation.AnnotationConfigApplicationContext
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 @@ class ConfigTest {
@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

View File

@ -17,7 +17,9 @@ package org.apache.dubbo.config.spring;
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.lang.reflect.Method;
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 @@ public class EmbeddedZooKeeper implements SmartLifecycle {
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());

View File

@ -24,6 +24,7 @@ import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
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.CHECK_KEY;
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 @@ import static org.apache.dubbo.metrics.MetricsConstants.SELF_INCREMENT_SIZE;
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);

View File

@ -22,6 +22,7 @@ import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent;
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.ErrorTypeAwareLogger;
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;

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.extension.ExtensionLoader;
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.Condition;
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)
*
* <p>
* 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<Container> 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 class Main {
}
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() {

View File

@ -19,20 +19,21 @@ package org.apache.dubbo.container.spring;
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)
*
* <p>
* 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 class SpringContainer implements Container {
@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;
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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 @@ import java.util.Arrays;
*/
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);
}
}
}

View File

@ -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 class DubboProtocCompilerMojo extends AbstractMojo {
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 @@ public class DubboProtocCompilerMojo extends AbstractMojo {
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 @@ public class DubboProtocCompilerMojo extends AbstractMojo {
}
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);
}

View File

@ -18,12 +18,18 @@ package org.apache.dubbo.metadata;
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 class MappingCacheManager extends AbstractCacheManager<Set<String>> {
}
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 class MappingCacheManager extends AbstractCacheManager<Set<String>> {
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);

View File

@ -23,6 +23,7 @@ import org.apache.dubbo.common.utils.CollectionUtils;
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.REPORT_METADATA_
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_METADAT
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 abstract class AbstractMetadataReport implements MetadataReport {
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);

View File

@ -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-";

View File

@ -20,10 +20,12 @@ import org.apache.dubbo.aot.api.JdkProxyDescriber;
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 class AotProcessor {
ClassSourceScanner.INSTANCE.adaptiveClasses().values()))
.registerBeanType(ClassSourceScanner.INSTANCE.scopeModelInitializer())
.registerConfigType(ClassSourceScanner.INSTANCE.configClasses())
.registerFieldType(getCustomClasses())
.registerTypeDescriber(getTypes());
writer.writeReflectionConfig(reflectRepository);
@ -98,4 +101,13 @@ public class AotProcessor {
return jdkProxyDescribers;
}
private static List<Class<?>> getCustomClasses() {
Class<?>[] configClasses = new Class[] {
CommonConstants.SystemProperty.class,
CommonConstants.ThirdPartyProperty.class,
CommonConstants.DubboProperty.class
};
return new ArrayList<>(Arrays.asList(configClasses));
}
}

View File

@ -78,6 +78,23 @@ public class ReflectConfigMetadataRepository {
return new TypeDescriber(c.getName(), null, new HashSet<>(), constructors, new HashSet<>(), memberCategories);
}
protected ReflectConfigMetadataRepository registerFieldType(List<Class<?>> classes) {
types.addAll(classes.stream()
.filter(Objects::nonNull)
.map(this::buildTypeDescriberWithField)
.collect(Collectors.toList()));
return this;
}
private TypeDescriber buildTypeDescriberWithField(Class<?> c) {
Set<ExecutableDescriber> constructors = Arrays.stream(c.getConstructors())
.map((constructor) -> new ExecutableDescriber(constructor, INVOKE))
.collect(Collectors.toSet());
Set<MemberCategory> memberCategories = new HashSet<>();
memberCategories.add(MemberCategory.PUBLIC_FIELDS);
return new TypeDescriber(c.getName(), null, new HashSet<>(), constructors, new HashSet<>(), memberCategories);
}
public void registerTypeDescriber(List<TypeDescriber> typeDescribers) {
types.addAll(typeDescribers.stream().filter(Objects::nonNull).collect(Collectors.toList()));
}

View File

@ -23,6 +23,7 @@ import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository;
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.TimeUnit;
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 <b>accesslog</b>
@ -215,7 +215,7 @@ public class AccessLogFilter implements Filter {
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();

View File

@ -23,6 +23,7 @@ import org.apache.dubbo.common.logger.LoggerFactory;
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 @@ import static org.apache.dubbo.rpc.cluster.Constants.INVOCATION_NEED_MOCK;
public class MockClusterInvoker<T> implements ClusterInvoker<T> {
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<T> directory;

View File

@ -18,12 +18,18 @@ package org.apache.dubbo.registry.client.metadata.store;
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 class MetaCacheManager extends AbstractCacheManager<MetadataInfo> {
}
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 class MetaCacheManager extends AbstractCacheManager<MetadataInfo> {
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);

View File

@ -24,6 +24,7 @@ import org.apache.dubbo.common.utils.CollectionUtils;
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.ANY_VALUE;
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.common.constants.RegistryConstants.EMPTY_PROTOCOL
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;
/**
* <p>
@ -129,8 +130,8 @@ public abstract class AbstractRegistry implements Registry {
// 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;

View File

@ -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 @@ import java.util.List;
/**
* PerformanceUtils
*
*/
public class PerformanceUtils {
@ -57,11 +59,14 @@ public class PerformanceUtils {
public static List<String> getEnvironment() {
List<String> environment = new ArrayList<String>();
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)");

View File

@ -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

View File

@ -18,11 +18,13 @@ package org.apache.dubbo.registry.nacos;
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)

View File

@ -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<String> 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";
}

View File

@ -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 class Request {
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();

View File

@ -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 class UrlUtils {
}
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 class UrlUtils {
* @return {@link String}
*/
public static String serializationOrDefault(URL url) {
//noinspection OptionalGetWithoutIsPresent
// noinspection OptionalGetWithoutIsPresent
Optional<String> serializations = allSerializations(url).stream().findFirst();
return serializations.orElseGet(DefaultSerializationSelector::getDefaultRemotingSerialization);
}

View File

@ -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 class PerformanceUtils {
public static List<String> getEnvironment() {
List<String> environment = new ArrayList<String>();
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)");

View File

@ -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 @@ class UrlUtilsTest {
@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 @@ class UrlUtilsTest {
@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);
}
}

View File

@ -19,6 +19,7 @@ package org.apache.dubbo.remoting.http.tomcat;
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.connector.Connector;
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 class TomcatHttpServer extends AbstractHttpServer {
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();

View File

@ -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.channel.socket.nio.NioSocketChannel;
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 class NettyEventLoopFactory {
}
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();
}

View File

@ -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.BeforeEach;
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 @@ class NettyEventLoopFactoryTest {
}
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();
}
}

View File

@ -20,6 +20,7 @@ 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.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<AppResponse> future, Invocation invocation) {
this.responseFuture = future;

View File

@ -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";

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.rpc;
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 class FutureContext {
/**
* 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 class FutureContext {
* }
* }
* }</pre>
*
* <p>
* Start from 2.7.3, you don't have to get Future from RpcContext, we recommend using Result directly:
* <pre>{@code
* public final class TracingFilter implements Filter {
@ -114,7 +115,6 @@ public class FutureContext {
* }
* }
* }</pre>
*
*/
@Deprecated
public void setCompatibleFuture(CompletableFuture<?> compatibleFuture) {

View File

@ -28,6 +28,7 @@ import org.apache.dubbo.common.threadpool.manager.ExecutorRepository;
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<T> implements Invoker<T> {
/**
* 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

View File

@ -24,6 +24,7 @@ import org.apache.dubbo.common.utils.Assert;
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.DUBBO_VERSION_KE
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<CallbackServiceCodec> 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) {

View File

@ -40,9 +40,9 @@ import java.io.InputStream;
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 {

View File

@ -26,6 +26,7 @@ import org.apache.dubbo.common.serialize.ObjectOutput;
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.io.InputStream;
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))

View File

@ -22,6 +22,7 @@ import org.apache.dubbo.common.config.ConfigurationUtils;
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<T> extends AbstractInvoker<T> {
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<T> serviceType, URL url, ClientsProvider clientsProvider) {
this(serviceType, url, clientsProvider, null);

View File

@ -24,6 +24,7 @@ import org.apache.dubbo.common.url.component.DubboServiceAddressURL;
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<T> extends AbstractInvoker<T> {
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<T> type, URL url, String key, Map<String, Exporter<?>> exporterMap) {
super(type, url);

View File

@ -21,6 +21,7 @@ import org.apache.dubbo.common.constants.CommonConstants;
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 @@ class NoAnnotationRestProtocolTest {
setJson(null);
}
}.clearJson();
System.clearProperty(CommonConstants.PREFER_JSON_FRAMEWORK_NAME);
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME);
}
@Test
@ -69,7 +70,8 @@ class NoAnnotationRestProtocolTest {
setJson(null);
}
}.clearJson();
System.setProperty(CommonConstants.PREFER_JSON_FRAMEWORK_NAME, json);
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PREFER_JSON_FRAMEWORK_NAME, json);
testRestProtocol();
}
}

View File

@ -25,6 +25,7 @@ import org.apache.dubbo.common.logger.LoggerFactory;
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<T> extends AbstractInvoker<T> {
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<MethodDescriptor, PackableMethod> packableMethodCache = new ConcurrentHashMap<>();

View File

@ -16,20 +16,23 @@
*/
package org.apache.dubbo.common.serialize.support;
public class DefaultSerializationSelector {
import org.apache.dubbo.common.utils.SystemPropertyConfigUtils;
private static final String DEFAULT_REMOTING_SERIALIZATION_PROPERTY_KEY = "DUBBO_DEFAULT_SERIALIZATION";
import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_DEFAULT_REMOTING_SERIALIZATION_PROPERTY;
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 {

View File

@ -21,16 +21,19 @@ import org.apache.dubbo.common.utils.DefaultSerializeClassChecker;
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<ClassLoader, SerializerFactory> CL_2_SERIALIZER_FACTORY = new ConcurrentHashMap<>();
@ -70,7 +73,7 @@ public class Hessian2FactoryManager {
}
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 @@ public class Hessian2FactoryManager {
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 class Hessian2FactoryManager {
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 class Hessian2FactoryManager {
}
}
}
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;
}

View File

@ -22,6 +22,7 @@ import org.apache.dubbo.common.serialize.ObjectOutput;
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 com.example.test.TestPojo;
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 @@ class Hessian2SerializationTest {
// 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 @@ class Hessian2SerializationTest {
objectOutput.flushBuffer();
frameworkModel.destroy();
System.clearProperty("dubbo.hessian.allowNonSerializable");
SystemPropertyConfigUtils.clearSystemProperty(DUBBO_HESSIAN_ALLOW_NON_SERIALIZABLE);
}
{

View File

@ -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 java.util.Set;
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

View File

@ -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.TestExecutionListener;
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. <p></p>
* {@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"));
}
/**

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.logger.Logger;
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.Map;
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 @@ class ZookeeperRegistryCenter implements RegistryCenter {
}
// 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 @@ class ZookeeperRegistryCenter implements RegistryCenter {
* 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;