Merge branch 'apache-3.1' into apache-3.2
# Conflicts: # dubbo-native/src/main/java/org/apache/dubbo/remoting/api/pu/PortUnificationTransporter$Adaptive.java # dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java # dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCallListener.java
This commit is contained in:
commit
5c082eaefa
|
|
@ -331,6 +331,7 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
ref: "3.1"
|
||||
path: "./dubbo"
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
|
|
|
|||
|
|
@ -330,6 +330,7 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
ref: "3.2"
|
||||
path: "./dubbo"
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
|
|
|
|||
|
|
@ -48,3 +48,9 @@ dubbo-demo/dubbo-demo-triple/build/*
|
|||
|
||||
# global registry center
|
||||
.tmp
|
||||
|
||||
dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/src/main/resources/META-INF/native-image
|
||||
dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/src/main/generated
|
||||
dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/src/main/resources/META-INF/native-image
|
||||
dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/src/main/generated
|
||||
|
||||
|
|
|
|||
|
|
@ -89,4 +89,20 @@ public class CompositeConfiguration implements Configuration {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
for (Configuration config : configList) {
|
||||
try {
|
||||
Object value = config.getProperty(key, defaultValue);
|
||||
if (!ConfigurationUtils.isEmptyValue(value)) {
|
||||
return value;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Error when trying to get value for key " + key + " from " + config + ", " +
|
||||
"will continue to try the next one.");
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,18 +127,19 @@ public interface Configuration {
|
|||
* Gets a property from the configuration. The default value will return if the configuration doesn't contain
|
||||
* the mapping for the specified key.
|
||||
*
|
||||
* @param key property to retrieve
|
||||
* @param key property to retrieve
|
||||
* @param defaultValue default value
|
||||
* @return the value to which this configuration maps the specified key, or default value if the configuration
|
||||
* contains no mapping for this key.
|
||||
*/
|
||||
default Object getProperty(String key, Object defaultValue) {
|
||||
Object value = getInternalProperty(key);
|
||||
return value != null ? value : defaultValue;
|
||||
return getInternalProperty(key, defaultValue);
|
||||
}
|
||||
|
||||
Object getInternalProperty(String key);
|
||||
|
||||
Object getInternalProperty(String key, Object defaultValue);
|
||||
|
||||
/**
|
||||
* Check if the configuration contains the specified key.
|
||||
*
|
||||
|
|
@ -153,9 +154,12 @@ public interface Configuration {
|
|||
|
||||
default <T> T convert(Class<T> cls, String key, T defaultValue) {
|
||||
// we only process String properties for now
|
||||
String value = (String) getProperty(key);
|
||||
Object value = getProperty(key, defaultValue);
|
||||
|
||||
if (value == null) {
|
||||
if (!String.class.isInstance(value)) {
|
||||
if (cls.isInstance(value)) {
|
||||
return cls.cast(value);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
|
@ -164,24 +168,26 @@ public interface Configuration {
|
|||
return cls.cast(value);
|
||||
}
|
||||
|
||||
String str = (String) value;
|
||||
|
||||
if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls)) {
|
||||
obj = Boolean.valueOf(value);
|
||||
obj = Boolean.valueOf(str);
|
||||
} else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive()) {
|
||||
if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) {
|
||||
obj = Integer.valueOf(value);
|
||||
obj = Integer.valueOf(str);
|
||||
} else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) {
|
||||
obj = Long.valueOf(value);
|
||||
obj = Long.valueOf(str);
|
||||
} else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) {
|
||||
obj = Byte.valueOf(value);
|
||||
obj = Byte.valueOf(str);
|
||||
} else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) {
|
||||
obj = Short.valueOf(value);
|
||||
obj = Short.valueOf(str);
|
||||
} else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) {
|
||||
obj = Float.valueOf(value);
|
||||
obj = Float.valueOf(str);
|
||||
} else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) {
|
||||
obj = Double.valueOf(value);
|
||||
obj = Double.valueOf(str);
|
||||
}
|
||||
} else if (cls.isEnum()) {
|
||||
obj = Enum.valueOf(cls.asSubclass(Enum.class), value);
|
||||
obj = Enum.valueOf(cls.asSubclass(Enum.class), str);
|
||||
}
|
||||
|
||||
return cls.cast(obj);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,19 @@ public class EnvironmentConfiguration implements Configuration {
|
|||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
String value = System.getenv(key);
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
value = System.getenv(StringUtils.toOSStyleKey(key));
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return getenv();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,16 @@ public class InmemoryConfiguration implements Configuration {
|
|||
return store.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = store.get(key);
|
||||
if (v != null) {
|
||||
return v;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add one property into the store, the previous value will be replaced if the key exists
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -68,6 +68,16 @@ public class OrderedPropertiesConfiguration implements Configuration {
|
|||
return properties.getProperty(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = properties.getProperty(key);
|
||||
if (v != null){
|
||||
return v;
|
||||
}else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void setProperty(String key, String value) {
|
||||
properties.setProperty(key, value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,4 +42,17 @@ public class PrefixedConfiguration implements Configuration {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
if (StringUtils.isBlank(prefix)) {
|
||||
return origin.getInternalProperty(key, defaultValue);
|
||||
}
|
||||
|
||||
Object value = origin.getInternalProperty(prefix + "." + key, defaultValue);
|
||||
if (!ConfigurationUtils.isEmptyValue(value)) {
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,16 @@ public class PropertiesConfiguration implements Configuration {
|
|||
return properties.getProperty(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = properties.getProperty(key);
|
||||
if (v != null){
|
||||
return v;
|
||||
}else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void setProperty(String key, String value) {
|
||||
properties.setProperty(key, value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,17 +18,61 @@ package org.apache.dubbo.common.config;
|
|||
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Configuration from system properties
|
||||
* FIXME: is this really necessary? PropertiesConfiguration should have already covered this:
|
||||
*
|
||||
* @See ConfigUtils#getProperty(String)
|
||||
* @see PropertiesConfiguration
|
||||
*/
|
||||
public class SystemConfiguration implements Configuration {
|
||||
|
||||
private final Map<String, Object> cache = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key) {
|
||||
return System.getProperty(key);
|
||||
if (cache.containsKey(key)) {
|
||||
return cache.get(key);
|
||||
} else {
|
||||
Object val = System.getProperty(key);
|
||||
if (val != null) {
|
||||
cache.putIfAbsent(key, val);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
if (cache.containsKey(key)) {
|
||||
return cache.get(key);
|
||||
} else {
|
||||
Object val = System.getProperty(key);
|
||||
if (val != null) {
|
||||
cache.putIfAbsent(key, val);
|
||||
} else {
|
||||
val = defaultValue;
|
||||
if (defaultValue != null) {
|
||||
cache.putIfAbsent(key, defaultValue);
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
public void overwriteCache(String key, Object value) {
|
||||
if (value != null) {
|
||||
cache.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return (Map) System.getProperties();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,6 +120,11 @@ public abstract class AbstractDynamicConfiguration implements DynamicConfigurati
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void close() throws Exception {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,11 @@ public class NopDynamicConfiguration implements DynamicConfiguration {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(String key, String group, ConfigurationListener listener) {
|
||||
// no-op
|
||||
|
|
|
|||
|
|
@ -75,6 +75,11 @@ public class CompositeDynamicConfiguration implements DynamicConfiguration {
|
|||
return iterateConfigOperation(configuration -> configuration.getInternalProperty(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
return iterateConfigOperation(configuration -> configuration.getInternalProperty(key, defaultValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean publishConfig(String key, String group, String content) throws UnsupportedOperationException {
|
||||
boolean publishedAll = true;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ public interface QosConstants {
|
|||
|
||||
String ACCEPT_FOREIGN_IP = "qos.accept.foreign.ip";
|
||||
|
||||
String ACCEPT_FOREIGN_IP_WHITELIST = "qos.accept.foreign.ip.whitelist";
|
||||
|
||||
String QOS_ENABLE_COMPATIBLE = "qos-enable";
|
||||
|
||||
String QOS_HOST_COMPATIBLE = "qos-host";
|
||||
|
|
@ -37,4 +39,6 @@ public interface QosConstants {
|
|||
String QOS_PORT_COMPATIBLE = "qos-port";
|
||||
|
||||
String ACCEPT_FOREIGN_IP_COMPATIBLE = "qos-accept-foreign-ip";
|
||||
|
||||
String ACCEPT_FOREIGN_IP_WHITELIST_COMPATIBLE = "qos-accept-foreign-ip-whitelist";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -743,7 +743,12 @@ public abstract class AbstractConfig implements Serializable {
|
|||
&& ClassUtils.isTypeMatch(method.getParameterTypes()[0], value)
|
||||
&& !isIgnoredAttribute(obj.getClass(), propertyName)) {
|
||||
value = environment.resolvePlaceholders(value);
|
||||
method.invoke(obj, ClassUtils.convertPrimitive(ScopeModelUtil.getFrameworkModel(getScopeModel()), method.getParameterTypes()[0], value));
|
||||
if (StringUtils.hasText(value)) {
|
||||
Object arg = ClassUtils.convertPrimitive(ScopeModelUtil.getFrameworkModel(getScopeModel()), method.getParameterTypes()[0], value);
|
||||
if (arg != null) {
|
||||
method.invoke(obj, arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("Failed to override the property " + method.getName() + " in " +
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ import static org.apache.dubbo.common.constants.CommonConstants.STARTUP_PROBE;
|
|||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP_COMPATIBLE;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP_WHITELIST;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP_WHITELIST_COMPATIBLE;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE_COMPATIBLE;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.QOS_HOST;
|
||||
|
|
@ -157,6 +159,11 @@ public class ApplicationConfig extends AbstractConfig {
|
|||
*/
|
||||
private Boolean qosAcceptForeignIp;
|
||||
|
||||
/**
|
||||
* When we disable accept foreign ip, support specify foreign ip in the whitelist
|
||||
*/
|
||||
private String qosAcceptForeignIpWhitelist;
|
||||
|
||||
/**
|
||||
* Customized parameters
|
||||
*/
|
||||
|
|
@ -428,6 +435,15 @@ public class ApplicationConfig extends AbstractConfig {
|
|||
this.qosAcceptForeignIp = qosAcceptForeignIp;
|
||||
}
|
||||
|
||||
@Parameter(key = ACCEPT_FOREIGN_IP_WHITELIST)
|
||||
public String getQosAcceptForeignIpWhitelist() {
|
||||
return qosAcceptForeignIpWhitelist;
|
||||
}
|
||||
|
||||
public void setQosAcceptForeignIpWhitelist(String qosAcceptForeignIpWhitelist) {
|
||||
this.qosAcceptForeignIpWhitelist = qosAcceptForeignIpWhitelist;
|
||||
}
|
||||
|
||||
/**
|
||||
* The format is the same as the springboot, including: getQosEnableCompatible(), getQosPortCompatible(), getQosAcceptForeignIpCompatible().
|
||||
*
|
||||
|
|
@ -469,6 +485,15 @@ public class ApplicationConfig extends AbstractConfig {
|
|||
this.setQosAcceptForeignIp(qosAcceptForeignIp);
|
||||
}
|
||||
|
||||
@Parameter(key = ACCEPT_FOREIGN_IP_WHITELIST_COMPATIBLE, excluded = true, attribute = false)
|
||||
public String getQosAcceptForeignIpWhitelistCompatible() {
|
||||
return this.getQosAcceptForeignIpWhitelist();
|
||||
}
|
||||
|
||||
public void setQosAcceptForeignIpWhitelistCompatible(String qosAcceptForeignIpWhitelist) {
|
||||
this.setQosAcceptForeignIpWhitelist(qosAcceptForeignIpWhitelist);
|
||||
}
|
||||
|
||||
public Map<String, String> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.dubbo.config;
|
||||
|
||||
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP_COMPATIBLE;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP_WHITELIST_COMPATIBLE;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE_COMPATIBLE;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.QOS_HOST_COMPATIBLE;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.QOS_PORT_COMPATIBLE;
|
||||
|
|
@ -140,7 +141,7 @@ public interface Constants {
|
|||
String MULTI_SERIALIZATION_KEY = "serialize.multiple";
|
||||
|
||||
String[] DOT_COMPATIBLE_KEYS = new String[]{QOS_ENABLE_COMPATIBLE, QOS_HOST_COMPATIBLE, QOS_PORT_COMPATIBLE,
|
||||
ACCEPT_FOREIGN_IP_COMPATIBLE, REGISTRY_TYPE_KEY};
|
||||
ACCEPT_FOREIGN_IP_COMPATIBLE, ACCEPT_FOREIGN_IP_WHITELIST_COMPATIBLE, REGISTRY_TYPE_KEY};
|
||||
|
||||
String IGNORE_CHECK_KEYS = "ignoreCheckKeys";
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,16 @@ public class ConfigConfigurationAdapter implements Configuration {
|
|||
return metaData.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = metaData.get(key);
|
||||
if (v != null) {
|
||||
return v;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return metaData;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,23 +70,23 @@ class SystemConfigurationTest {
|
|||
void testConvert() {
|
||||
Assertions.assertEquals(
|
||||
MOCK_STRING_VALUE, sysConfig.convert(String.class, NOT_EXIST_KEY, MOCK_STRING_VALUE));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_BOOL_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_BOOL_VALUE));
|
||||
Assertions.assertEquals(MOCK_BOOL_VALUE, sysConfig.convert(Boolean.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_STRING_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_STRING_VALUE));
|
||||
Assertions.assertEquals(MOCK_STRING_VALUE, sysConfig.convert(String.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_INT_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_INT_VALUE));
|
||||
Assertions.assertEquals(MOCK_INT_VALUE, sysConfig.convert(Integer.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_LONG_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_LONG_VALUE));
|
||||
Assertions.assertEquals(MOCK_LONG_VALUE, sysConfig.convert(Long.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_SHORT_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_SHORT_VALUE));
|
||||
Assertions.assertEquals(MOCK_SHORT_VALUE, sysConfig.convert(Short.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_FLOAT_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_FLOAT_VALUE));
|
||||
Assertions.assertEquals(MOCK_FLOAT_VALUE, sysConfig.convert(Float.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_DOUBLE_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_DOUBLE_VALUE));
|
||||
Assertions.assertEquals(MOCK_DOUBLE_VALUE, sysConfig.convert(Double.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_BYTE_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_BYTE_VALUE));
|
||||
Assertions.assertEquals(MOCK_BYTE_VALUE, sysConfig.convert(Byte.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(ConfigMock.MockOne));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(ConfigMock.MockOne));
|
||||
Assertions.assertEquals(ConfigMock.MockOne, sysConfig.convert(ConfigMock.class, MOCK_KEY, null));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,11 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.apache.dubbo.common.config.SystemConfiguration;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
|
||||
import javassist.compiler.Javac;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
|
@ -57,14 +59,16 @@ class SerializeClassCheckerTest {
|
|||
serializeClassChecker.validateClass(int.class.getName().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()-> {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
serializeClassChecker.validateClass(Socket.class.getName());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddAllow() {
|
||||
System.setProperty(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST, Socket.class.getName() + "," + Javac.class.getName());
|
||||
SystemConfiguration systemConfiguration = ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration();
|
||||
|
||||
systemConfiguration.overwriteCache(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST, Socket.class.getName() + "," + Javac.class.getName());
|
||||
|
||||
SerializeClassChecker serializeClassChecker = SerializeClassChecker.getInstance();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
|
@ -72,40 +76,44 @@ class SerializeClassCheckerTest {
|
|||
serializeClassChecker.validateClass(Javac.class.getName());
|
||||
}
|
||||
|
||||
System.clearProperty(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST);
|
||||
systemConfiguration.clearCache();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddBlock() {
|
||||
System.setProperty(CommonConstants.CLASS_DESERIALIZE_BLOCKED_LIST, LinkedList.class.getName() + "," + Integer.class.getName());
|
||||
SystemConfiguration systemConfiguration = ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration();
|
||||
systemConfiguration.overwriteCache(CommonConstants.CLASS_DESERIALIZE_BLOCKED_LIST, LinkedList.class.getName() + "," + Integer.class.getName());
|
||||
|
||||
SerializeClassChecker serializeClassChecker = SerializeClassChecker.getInstance();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()-> {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
serializeClassChecker.validateClass(LinkedList.class.getName());
|
||||
});
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()-> {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
serializeClassChecker.validateClass(Integer.class.getName());
|
||||
});
|
||||
}
|
||||
|
||||
System.clearProperty(CommonConstants.CLASS_DESERIALIZE_BLOCKED_LIST);
|
||||
systemConfiguration.clearCache();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBlockAll() {
|
||||
System.setProperty(CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL, "true");
|
||||
System.setProperty(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST, LinkedList.class.getName());
|
||||
SystemConfiguration systemConfiguration = ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration();
|
||||
|
||||
systemConfiguration.overwriteCache(CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL, "true");
|
||||
systemConfiguration.overwriteCache(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST, LinkedList.class.getName());
|
||||
|
||||
SerializeClassChecker serializeClassChecker = SerializeClassChecker.getInstance();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
serializeClassChecker.validateClass(LinkedList.class.getName());
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()-> {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
serializeClassChecker.validateClass(Integer.class.getName());
|
||||
});
|
||||
}
|
||||
|
||||
System.clearProperty(CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL);
|
||||
System.clearProperty(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST);
|
||||
systemConfiguration.clearCache();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,7 +122,6 @@ class MultiInstanceTest {
|
|||
@AfterEach
|
||||
public void afterEach() {
|
||||
SysProps.clear();
|
||||
DubboBootstrap.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -154,12 +153,12 @@ class MultiInstanceTest {
|
|||
|
||||
@Test
|
||||
void testDefaultProviderApplication() {
|
||||
DubboBootstrap.reset();
|
||||
DubboBootstrap dubboBootstrap = DubboBootstrap.getInstance();
|
||||
try {
|
||||
configProviderApp(dubboBootstrap).start();
|
||||
} finally {
|
||||
dubboBootstrap.destroy();
|
||||
DubboBootstrap.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -174,13 +173,12 @@ class MultiInstanceTest {
|
|||
Assertions.assertTrue(e.toString().contains("No provider available"), StringUtils.toString(e));
|
||||
} finally {
|
||||
dubboBootstrap.destroy();
|
||||
DubboBootstrap.reset();
|
||||
SysProps.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultMixedApplication() {
|
||||
DubboBootstrap.reset();
|
||||
DubboBootstrap dubboBootstrap = DubboBootstrap.getInstance();
|
||||
try {
|
||||
dubboBootstrap.application("mixed-app");
|
||||
|
|
@ -191,7 +189,6 @@ class MultiInstanceTest {
|
|||
testConsumer(dubboBootstrap);
|
||||
} finally {
|
||||
dubboBootstrap.destroy();
|
||||
DubboBootstrap.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -221,6 +218,8 @@ class MultiInstanceTest {
|
|||
void testMultiModuleApplication() throws InterruptedException {
|
||||
|
||||
//SysProps.setProperty(METADATA_PUBLISH_DELAY_KEY, "100");
|
||||
|
||||
FrameworkModel frameworkModel = new FrameworkModel();
|
||||
String version1 = "1.0";
|
||||
String version2 = "2.0";
|
||||
String version3 = "3.0";
|
||||
|
|
@ -230,7 +229,7 @@ class MultiInstanceTest {
|
|||
|
||||
try {
|
||||
// provider app
|
||||
providerBootstrap = DubboBootstrap.newInstance();
|
||||
providerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
|
||||
ServiceConfig serviceConfig1 = new ServiceConfig();
|
||||
serviceConfig1.setInterface(DemoService.class);
|
||||
|
|
@ -274,7 +273,7 @@ class MultiInstanceTest {
|
|||
//Thread.sleep(200);
|
||||
|
||||
// consumer app
|
||||
consumerBootstrap = DubboBootstrap.newInstance();
|
||||
consumerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
consumerBootstrap.application("consumer-app")
|
||||
.registry(registryConfig)
|
||||
.reference(builder -> builder
|
||||
|
|
@ -308,10 +307,12 @@ class MultiInstanceTest {
|
|||
|
||||
@Test
|
||||
void testMultiProviderApplicationsStopOneByOne() {
|
||||
DubboBootstrap.reset();
|
||||
|
||||
String version1 = "1.0";
|
||||
String version2 = "2.0";
|
||||
|
||||
FrameworkModel frameworkModel = new FrameworkModel();
|
||||
DubboBootstrap providerBootstrap1 = null;
|
||||
DubboBootstrap providerBootstrap2 = null;
|
||||
|
||||
|
|
@ -328,7 +329,7 @@ class MultiInstanceTest {
|
|||
|
||||
ProtocolConfig protocolConfig1 = new ProtocolConfig("dubbo", NetUtils.getAvailablePort());
|
||||
|
||||
providerBootstrap1 = DubboBootstrap.getInstance();
|
||||
providerBootstrap1 = DubboBootstrap.newInstance(frameworkModel);
|
||||
providerBootstrap1.application("provider1")
|
||||
.registry(registryConfig)
|
||||
.service(serviceConfig1)
|
||||
|
|
@ -351,7 +352,7 @@ class MultiInstanceTest {
|
|||
|
||||
ProtocolConfig protocolConfig2 = new ProtocolConfig("dubbo", NetUtils.getAvailablePort());
|
||||
|
||||
providerBootstrap2 = DubboBootstrap.newInstance();
|
||||
providerBootstrap2 = DubboBootstrap.newInstance(frameworkModel);
|
||||
providerBootstrap2.application("provider2")
|
||||
.registry(registryConfig2)
|
||||
.service(serviceConfig2)
|
||||
|
|
@ -430,6 +431,7 @@ class MultiInstanceTest {
|
|||
String version2 = "2.0";
|
||||
String version3 = "3.0";
|
||||
|
||||
FrameworkModel frameworkModel = new FrameworkModel();
|
||||
String serviceKey1 = DemoService.class.getName() + ":" + version1;
|
||||
String serviceKey2 = DemoService.class.getName() + ":" + version2;
|
||||
String serviceKey3 = DemoService.class.getName() + ":" + version3;
|
||||
|
|
@ -439,7 +441,7 @@ class MultiInstanceTest {
|
|||
|
||||
try {
|
||||
// provider app
|
||||
providerBootstrap = DubboBootstrap.newInstance();
|
||||
providerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
|
||||
ServiceConfig serviceConfig1 = new ServiceConfig();
|
||||
serviceConfig1.setInterface(DemoService.class);
|
||||
|
|
@ -477,7 +479,7 @@ class MultiInstanceTest {
|
|||
Assertions.assertNull(frameworkServiceRepository.lookupExportedServiceWithoutGroup(serviceKey3));
|
||||
|
||||
// consumer module 1
|
||||
consumerBootstrap = DubboBootstrap.newInstance();
|
||||
consumerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
consumerBootstrap.application("consumer-app")
|
||||
.registry(registryConfig)
|
||||
.reference(builder -> builder
|
||||
|
|
@ -572,6 +574,7 @@ class MultiInstanceTest {
|
|||
String version2 = "2.0";
|
||||
String version3 = "3.0";
|
||||
|
||||
FrameworkModel frameworkModel = new FrameworkModel();
|
||||
String serviceKey1 = DemoService.class.getName() + ":" + version1;
|
||||
String serviceKey2 = DemoService.class.getName() + ":" + version2;
|
||||
String serviceKey3 = DemoService.class.getName() + ":" + version3;
|
||||
|
|
@ -579,7 +582,7 @@ class MultiInstanceTest {
|
|||
// provider app
|
||||
DubboBootstrap providerBootstrap = null;
|
||||
try {
|
||||
providerBootstrap = DubboBootstrap.newInstance();
|
||||
providerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
|
||||
ServiceConfig serviceConfig1 = new ServiceConfig();
|
||||
serviceConfig1.setInterface(DemoService.class);
|
||||
|
|
@ -652,6 +655,7 @@ class MultiInstanceTest {
|
|||
String version2 = "2.0";
|
||||
String version3 = "3.0";
|
||||
|
||||
FrameworkModel frameworkModel = new FrameworkModel();
|
||||
String serviceKey1 = DemoService.class.getName() + ":" + version1;
|
||||
String serviceKey2 = DemoService.class.getName() + ":" + version2;
|
||||
String serviceKey3 = DemoService.class.getName() + ":" + version3;
|
||||
|
|
@ -659,7 +663,7 @@ class MultiInstanceTest {
|
|||
// provider app
|
||||
DubboBootstrap providerBootstrap = null;
|
||||
try {
|
||||
providerBootstrap = DubboBootstrap.newInstance();
|
||||
providerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
|
||||
ServiceConfig serviceConfig1 = new ServiceConfig();
|
||||
serviceConfig1.setInterface(DemoService.class);
|
||||
|
|
@ -706,6 +710,7 @@ class MultiInstanceTest {
|
|||
@Test
|
||||
void testOldApiDeploy() throws Exception {
|
||||
|
||||
DubboBootstrap.reset();
|
||||
try {
|
||||
// provider app
|
||||
ApplicationModel providerApplicationModel = ApplicationModel.defaultModel();
|
||||
|
|
@ -781,8 +786,10 @@ class MultiInstanceTest {
|
|||
|
||||
@Test
|
||||
void testAsyncExportAndReferServices() throws ExecutionException, InterruptedException {
|
||||
DubboBootstrap providerBootstrap = DubboBootstrap.newInstance();
|
||||
DubboBootstrap consumerBootstrap = DubboBootstrap.newInstance();
|
||||
FrameworkModel frameworkModel = new FrameworkModel();
|
||||
|
||||
DubboBootstrap providerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
DubboBootstrap consumerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
try {
|
||||
|
||||
ServiceConfig serviceConfig = new ServiceConfig();
|
||||
|
|
|
|||
|
|
@ -215,6 +215,16 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration {
|
|||
return dubboConfig.getProperty(key, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = dubboConfig.getProperty(key, null);
|
||||
if (v != null) {
|
||||
return v;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignores the group parameter.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -220,6 +220,17 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = defaultValue;
|
||||
try {
|
||||
v = configService.getConfig(key, DEFAULT_GROUP, getDefaultTimeout());
|
||||
} catch (NacosException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean publishConfig(String key, String group, String content) {
|
||||
boolean published = false;
|
||||
|
|
|
|||
|
|
@ -85,6 +85,16 @@ public class ZookeeperDynamicConfiguration extends TreePathDynamicConfiguration
|
|||
return zkClient.getContent(buildPathKey("", key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = zkClient.getContent(buildPathKey("", key));
|
||||
if (v != null) {
|
||||
return v;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doClose() throws Exception {
|
||||
// remove data listener
|
||||
|
|
|
|||
|
|
@ -85,6 +85,16 @@
|
|||
<artifactId>dubbo-remoting-http</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-native</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
|
|
@ -184,11 +194,20 @@
|
|||
--initialize-at-run-time=io.netty.channel.unix.Limits
|
||||
--initialize-at-run-time=io.netty.channel.unix.Socket
|
||||
--initialize-at-run-time=io.netty.channel.ChannelHandlerMask
|
||||
--initialize-at-run-time=io.netty.internal.tcnative.CertificateVerifier
|
||||
--initialize-at-run-time=io.netty.internal.tcnative.AsyncSSLPrivateKeyMethod
|
||||
--initialize-at-run-time=io.netty.handler.ssl.ReferenceCountedOpenSslEngine
|
||||
--initialize-at-run-time=io.netty.handler.ssl.OpenSslPrivateKeyMethod
|
||||
--initialize-at-run-time=io.netty.internal.tcnative.CertificateVerifier
|
||||
--initialize-at-run-time=io.netty.internal.tcnative.SSL
|
||||
--initialize-at-run-time=io.netty.handler.ssl.OpenSslAsyncPrivateKeyMethod
|
||||
--initialize-at-run-time=io.netty.internal.tcnative.SSLPrivateKeyMethod
|
||||
|
||||
--report-unsupported-elements-at-runtime
|
||||
--allow-incomplete-classpath
|
||||
--enable-url-protocols=http
|
||||
-H:+ReportExceptionStackTraces
|
||||
-H:+AllowJRTFileSystem
|
||||
</buildArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ public class Application {
|
|||
public static void main(String[] args) {
|
||||
System.setProperty("dubbo.application.logger", "log4j");
|
||||
System.setProperty("native", "true");
|
||||
System.setProperty("dubbo.json-framework.prefer","fastjson");
|
||||
if (isClassic(args)) {
|
||||
runWithRefer();
|
||||
} else {
|
||||
|
|
@ -45,11 +46,8 @@ public class Application {
|
|||
}
|
||||
|
||||
private static void runWithBootstrap() {
|
||||
ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
|
||||
reference.setInterface(DemoService.class);
|
||||
reference.setGeneric("false");
|
||||
|
||||
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
|
||||
|
||||
ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-demo-api-consumer");
|
||||
applicationConfig.setQosEnable(false);
|
||||
applicationConfig.setCompiler("jdk");
|
||||
|
|
@ -57,6 +55,10 @@ public class Application {
|
|||
m.put("proxy", "jdk");
|
||||
applicationConfig.setParameters(m);
|
||||
|
||||
ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
|
||||
reference.setInterface(DemoService.class);
|
||||
reference.setGeneric("false");
|
||||
|
||||
bootstrap.application(applicationConfig)
|
||||
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
|
||||
.protocol(new ProtocolConfig(CommonConstants.DUBBO, -1))
|
||||
|
|
|
|||
|
|
@ -79,6 +79,17 @@
|
|||
<artifactId>dubbo-remoting-http</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-native</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
@ -180,11 +191,20 @@
|
|||
--initialize-at-run-time=io.netty.channel.unix.Limits
|
||||
--initialize-at-run-time=io.netty.channel.unix.Socket
|
||||
--initialize-at-run-time=io.netty.channel.ChannelHandlerMask
|
||||
--initialize-at-run-time=io.netty.internal.tcnative.CertificateVerifier
|
||||
--initialize-at-run-time=io.netty.internal.tcnative.AsyncSSLPrivateKeyMethod
|
||||
--initialize-at-run-time=io.netty.handler.ssl.ReferenceCountedOpenSslEngine
|
||||
--initialize-at-run-time=io.netty.handler.ssl.OpenSslPrivateKeyMethod
|
||||
--initialize-at-run-time=io.netty.internal.tcnative.CertificateVerifier
|
||||
--initialize-at-run-time=io.netty.internal.tcnative.SSL
|
||||
--initialize-at-run-time=io.netty.handler.ssl.OpenSslAsyncPrivateKeyMethod
|
||||
--initialize-at-run-time=io.netty.internal.tcnative.SSLPrivateKeyMethod
|
||||
|
||||
--report-unsupported-elements-at-runtime
|
||||
--allow-incomplete-classpath
|
||||
--enable-url-protocols=http
|
||||
-H:+ReportExceptionStackTraces
|
||||
-H:+AllowJRTFileSystem
|
||||
</buildArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.apache.dubbo.config.ServiceConfig;
|
|||
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
|
||||
|
||||
import org.apace.dubbo.graalvm.demo.DemoService;
|
||||
import org.apache.dubbo.rpc.model.ModuleModel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -34,6 +35,7 @@ public class Application {
|
|||
public static void main(String[] args) throws Exception {
|
||||
System.setProperty("dubbo.application.logger", "log4j");
|
||||
System.setProperty("native", "true");
|
||||
System.setProperty("dubbo.json-framework.prefer","fastjson");
|
||||
if (isClassic(args)) {
|
||||
startWithExport();
|
||||
} else {
|
||||
|
|
@ -47,32 +49,30 @@ public class Application {
|
|||
}
|
||||
|
||||
private static void startWithBootstrap() {
|
||||
ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
|
||||
service.setInterface(DemoService.class);
|
||||
service.setRef(new DemoServiceImpl());
|
||||
|
||||
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
|
||||
|
||||
ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-demo-api-provider");
|
||||
ApplicationConfig applicationConfig = new ApplicationConfig( "dubbo-demo-api-provider");
|
||||
applicationConfig.setQosEnable(false);
|
||||
applicationConfig.setCompiler("jdk");
|
||||
Map<String, String> m = new HashMap<>(1);
|
||||
m.put("proxy", "jdk");
|
||||
applicationConfig.setParameters(m);
|
||||
|
||||
ServiceConfig<DemoService> service = new ServiceConfig<>();
|
||||
service.setInterface(DemoService.class);
|
||||
service.setRef(new DemoServiceImpl());
|
||||
|
||||
bootstrap.application(applicationConfig)
|
||||
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
|
||||
.protocol(new ProtocolConfig(CommonConstants.DUBBO, -1))
|
||||
.service(service)
|
||||
.start()
|
||||
.await();
|
||||
|
||||
System.out.println("dubbo service started");
|
||||
}
|
||||
|
||||
private static void startWithExport() throws InterruptedException {
|
||||
ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
|
||||
service.setInterface(DemoService.class);
|
||||
service.setRef(new DemoServiceImpl());
|
||||
|
||||
ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-demo-api-provider");
|
||||
applicationConfig.setQosEnable(false);
|
||||
applicationConfig.setCompiler("jdk");
|
||||
|
|
@ -81,6 +81,13 @@ public class Application {
|
|||
m.put("proxy", "jdk");
|
||||
applicationConfig.setParameters(m);
|
||||
|
||||
ModuleModel moduleModel = applicationConfig.getApplicationModel().newModule();
|
||||
|
||||
|
||||
ServiceConfig<DemoService> service = new ServiceConfig<>(moduleModel);
|
||||
service.setInterface(DemoService.class);
|
||||
service.setRef(new DemoServiceImpl());
|
||||
|
||||
service.setApplication(applicationConfig);
|
||||
service.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
|
||||
service.export();
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@
|
|||
<reactor.version>3.4.19</reactor.version>
|
||||
|
||||
<rs_api_version>2.0</rs_api_version>
|
||||
<resteasy_version>3.0.19.Final</resteasy_version>
|
||||
<resteasy_version>3.0.20.Final</resteasy_version>
|
||||
<tomcat_embed_version>8.5.78</tomcat_embed_version>
|
||||
<jetcd_version>0.5.3</jetcd_version>
|
||||
<nacos_version>2.1.2</nacos_version>
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_ERR
|
|||
|
||||
public class KubernetesMeshEnvListener implements MeshEnvListener {
|
||||
public static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(KubernetesMeshEnvListener.class);
|
||||
private volatile static boolean usingApiServer = false;
|
||||
private volatile static KubernetesClient kubernetesClient;
|
||||
private volatile static String namespace;
|
||||
private static volatile boolean usingApiServer = false;
|
||||
private static volatile KubernetesClient kubernetesClient;
|
||||
private static volatile String namespace;
|
||||
|
||||
private final Map<String, MeshAppRuleListener> appRuleListenerMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
|
@ -103,11 +103,11 @@ public class KubernetesMeshEnvListener implements MeshEnvListener {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(WatcherException cause) {
|
||||
// ignore
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onClose(WatcherException cause) {
|
||||
// ignore
|
||||
}
|
||||
});
|
||||
vsAppWatch.put(appName, watch);
|
||||
try {
|
||||
GenericKubernetesResource vsRule = kubernetesClient
|
||||
|
|
|
|||
|
|
@ -1107,7 +1107,7 @@
|
|||
"methods": [
|
||||
{
|
||||
"name": "<init>",
|
||||
"parameterTypes": []
|
||||
"parameterTypes": ["org.apache.dubbo.rpc.model.ApplicationModel"]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -1332,7 +1332,13 @@
|
|||
},
|
||||
{
|
||||
"name": "org.apache.dubbo.config.deploy.DefaultApplicationDeployer",
|
||||
"allPublicConstructors": true
|
||||
"allPublicConstructors": true,
|
||||
"methods": [
|
||||
{
|
||||
"name": "<init>",
|
||||
"parameterTypes": ["org.apache.dubbo.rpc.model.ApplicationModel"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "org.apache.dubbo.config.deploy.DefaultModuleDeployer",
|
||||
|
|
@ -1481,7 +1487,7 @@
|
|||
"methods": [
|
||||
{
|
||||
"name": "<init>",
|
||||
"parameterTypes": []
|
||||
"parameterTypes": ["org.apache.dubbo.rpc.model.ApplicationModel"]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -2062,7 +2068,13 @@
|
|||
{
|
||||
"name": "org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter",
|
||||
"allPublicMethods": true,
|
||||
"allPublicConstructors": true
|
||||
"allPublicConstructors": true,
|
||||
"methods": [
|
||||
{
|
||||
"name": "<init>",
|
||||
"parameterTypes": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "org.apache.dubbo.rpc.cluster.filter.support.ZoneAwareFilter"
|
||||
|
|
@ -2347,9 +2359,6 @@
|
|||
{
|
||||
"name": "org.apache.dubbo.rpc.filter.CompatibleFilter"
|
||||
},
|
||||
{
|
||||
"name": "org.apache.dubbo.rpc.filter.ContextFilter"
|
||||
},
|
||||
{
|
||||
"name": "org.apache.dubbo.rpc.filter.DeprecatedFilter"
|
||||
},
|
||||
|
|
@ -2671,5 +2680,97 @@
|
|||
"parameterTypes": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "org.apache.dubbo.rpc.cluster.router.RouterSnapshotSwitcher",
|
||||
"allPublicMethods": true,
|
||||
"methods": [
|
||||
{
|
||||
"name": "<init>",
|
||||
"parameterTypes": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository",
|
||||
"allPublicMethods": true,
|
||||
"methods": [
|
||||
{
|
||||
"name": "<init>",
|
||||
"parameterTypes": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "org.apache.dubbo.common.convert.ConverterUtil",
|
||||
"allPublicMethods": true,
|
||||
"methods": [
|
||||
{
|
||||
"name": "<init>",
|
||||
"parameterTypes": ["org.apache.dubbo.rpc.model.FrameworkModel"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "org.apache.dubbo.rpc.cluster.router.mesh.route.MeshRuleManager",
|
||||
"allPublicMethods": true,
|
||||
"methods": [
|
||||
{
|
||||
"name": "<init>",
|
||||
"parameterTypes": ["org.apache.dubbo.rpc.model.ModuleModel"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "org.apache.dubbo.config.context.ModuleConfigManager",
|
||||
"allPublicMethods": true,
|
||||
"methods": [
|
||||
{
|
||||
"name": "<init>",
|
||||
"parameterTypes": ["org.apache.dubbo.rpc.model.ModuleModel"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "org.apache.dubbo.common.store.support.SimpleDataStore",
|
||||
"allPublicMethods": true,
|
||||
"methods": [
|
||||
{
|
||||
"name": "<init>",
|
||||
"parameterTypes": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "org.apache.dubbo.common.metrics.collector.DefaultMetricsCollector",
|
||||
"allPublicMethods": true,
|
||||
"methods": [
|
||||
{
|
||||
"name": "<init>",
|
||||
"parameterTypes": ["org.apache.dubbo.rpc.model.ApplicationModel"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "org.apache.dubbo.config.deploy.DefaultMetricsServiceExporter",
|
||||
"allPublicMethods": true,
|
||||
"methods": [
|
||||
{
|
||||
"name": "<init>",
|
||||
"parameterTypes": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "com.alibaba.fastjson.JSON",
|
||||
"allPublicMethods": true
|
||||
},
|
||||
{
|
||||
"name": "java.util.Collections$UnmodifiableMap",
|
||||
"allPublicMethods": true
|
||||
},
|
||||
{
|
||||
"name": "java.util.Collections$UnmodifiableCollection",
|
||||
"allPublicMethods": true
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -153,6 +153,12 @@
|
|||
},
|
||||
{
|
||||
"pattern": "\\Qorg/apache/dubbo/remoting/exchange/Exchangers.class\\E"
|
||||
},
|
||||
{
|
||||
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.store.DataStore\\E"
|
||||
},
|
||||
{
|
||||
"pattern": "\\QMETA-INF/dubbo/internal/org.apache.dubbo.common.metrics.service.MetricsServiceExporter\\E"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
|||
|
|
@ -18,22 +18,22 @@ package org.apache.dubbo.remoting.api.pu;
|
|||
import org.apache.dubbo.rpc.model.ScopeModel;
|
||||
import org.apache.dubbo.rpc.model.ScopeModelUtil;
|
||||
public class PortUnificationTransporter$Adaptive implements org.apache.dubbo.remoting.api.pu.PortUnificationTransporter {
|
||||
public org.apache.dubbo.remoting.api.connection.AbstractConnectionClient connect(org.apache.dubbo.common.URL arg0, org.apache.dubbo.remoting.ChannelHandler arg1) throws org.apache.dubbo.remoting.RemotingException {
|
||||
if (arg0 == null) throw new IllegalArgumentException("url == null");
|
||||
org.apache.dubbo.common.URL url = arg0;
|
||||
String extName = url.getParameter("client", url.getParameter("transporter", "netty4"));
|
||||
if(extName == null) throw new IllegalStateException("Failed to get extension (org.apache.dubbo.remoting.api.pu.PortUnificationTransporter) name from url (" + url.toString() + ") use keys([client, transporter])");
|
||||
ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), org.apache.dubbo.remoting.api.pu.PortUnificationTransporter.class);
|
||||
org.apache.dubbo.remoting.api.pu.PortUnificationTransporter extension = (org.apache.dubbo.remoting.api.pu.PortUnificationTransporter)scopeModel.getExtensionLoader(org.apache.dubbo.remoting.api.pu.PortUnificationTransporter.class).getExtension(extName);
|
||||
return extension.connect(arg0, arg1);
|
||||
}
|
||||
public org.apache.dubbo.remoting.api.pu.AbstractPortUnificationServer bind(org.apache.dubbo.common.URL arg0, org.apache.dubbo.remoting.ChannelHandler arg1) throws org.apache.dubbo.remoting.RemotingException {
|
||||
if (arg0 == null) throw new IllegalArgumentException("url == null");
|
||||
org.apache.dubbo.common.URL url = arg0;
|
||||
String extName = url.getParameter("server", url.getParameter("transporter", "netty4"));
|
||||
if(extName == null) throw new IllegalStateException("Failed to get extension (org.apache.dubbo.remoting.api.pu.PortUnificationTransporter) name from url (" + url.toString() + ") use keys([server, transporter])");
|
||||
ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), org.apache.dubbo.remoting.api.pu.PortUnificationTransporter.class);
|
||||
org.apache.dubbo.remoting.api.pu.PortUnificationTransporter extension = (org.apache.dubbo.remoting.api.pu.PortUnificationTransporter)scopeModel.getExtensionLoader(org.apache.dubbo.remoting.api.pu.PortUnificationTransporter.class).getExtension(extName);
|
||||
return extension.bind(arg0, arg1);
|
||||
}
|
||||
public org.apache.dubbo.remoting.api.connection.AbstractConnectionClient connect(org.apache.dubbo.common.URL arg0, org.apache.dubbo.remoting.ChannelHandler arg1) throws org.apache.dubbo.remoting.RemotingException {
|
||||
if (arg0 == null) throw new IllegalArgumentException("url == null");
|
||||
org.apache.dubbo.common.URL url = arg0;
|
||||
String extName = url.getParameter("client", url.getParameter("transporter", "netty4"));
|
||||
if(extName == null) throw new IllegalStateException("Failed to get extension (org.apache.dubbo.remoting.api.pu.PortUnificationTransporter) name from url (" + url.toString() + ") use keys([client, transporter])");
|
||||
ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), org.apache.dubbo.remoting.api.pu.PortUnificationTransporter.class);
|
||||
org.apache.dubbo.remoting.api.pu.PortUnificationTransporter extension = (org.apache.dubbo.remoting.api.pu.PortUnificationTransporter)scopeModel.getExtensionLoader(org.apache.dubbo.remoting.api.pu.PortUnificationTransporter.class).getExtension(extName);
|
||||
return extension.connect(arg0, arg1);
|
||||
}
|
||||
public org.apache.dubbo.remoting.api.pu.AbstractPortUnificationServer bind(org.apache.dubbo.common.URL arg0, org.apache.dubbo.remoting.ChannelHandler arg1) throws org.apache.dubbo.remoting.RemotingException {
|
||||
if (arg0 == null) throw new IllegalArgumentException("url == null");
|
||||
org.apache.dubbo.common.URL url = arg0;
|
||||
String extName = url.getParameter("server", url.getParameter("transporter", "netty4"));
|
||||
if(extName == null) throw new IllegalStateException("Failed to get extension (org.apache.dubbo.remoting.api.pu.PortUnificationTransporter) name from url (" + url.toString() + ") use keys([server, transporter])");
|
||||
ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), org.apache.dubbo.remoting.api.pu.PortUnificationTransporter.class);
|
||||
org.apache.dubbo.remoting.api.pu.PortUnificationTransporter extension = (org.apache.dubbo.remoting.api.pu.PortUnificationTransporter)scopeModel.getExtensionLoader(org.apache.dubbo.remoting.api.pu.PortUnificationTransporter.class).getExtension(extName);
|
||||
return extension.bind(arg0, arg1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL;
|
|||
import org.apache.dubbo.common.extension.Activate;
|
||||
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.qos.common.QosConstants;
|
||||
import org.apache.dubbo.qos.pu.QosWireProtocol;
|
||||
import org.apache.dubbo.qos.server.Server;
|
||||
|
|
@ -37,6 +38,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.QOS_FAILED_START_SERVER;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP_WHITELIST;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.QOS_HOST;
|
||||
import static org.apache.dubbo.common.constants.QosConstants.QOS_PORT;
|
||||
|
|
@ -113,6 +115,7 @@ public class QosProtocolWrapper implements Protocol, ScopeModelAware {
|
|||
String host = url.getParameter(QOS_HOST);
|
||||
int port = url.getParameter(QOS_PORT, QosConstants.DEFAULT_PORT);
|
||||
boolean acceptForeignIp = Boolean.parseBoolean(url.getParameter(ACCEPT_FOREIGN_IP, "false"));
|
||||
String acceptForeignIpWhitelist = url.getParameter(ACCEPT_FOREIGN_IP_WHITELIST, StringUtils.EMPTY_STRING);
|
||||
Server server = frameworkModel.getBeanFactory().getBean(Server.class);
|
||||
|
||||
if (server.isStarted()) {
|
||||
|
|
@ -122,6 +125,7 @@ public class QosProtocolWrapper implements Protocol, ScopeModelAware {
|
|||
server.setHost(host);
|
||||
server.setPort(port);
|
||||
server.setAcceptForeignIp(acceptForeignIp);
|
||||
server.setAcceptForeignIpWhitelist(acceptForeignIpWhitelist);
|
||||
server.start();
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package org.apache.dubbo.qos.pu;
|
|||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.extension.Activate;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.qos.server.DubboLogo;
|
||||
import org.apache.dubbo.qos.server.handler.QosProcessHandler;
|
||||
import org.apache.dubbo.remoting.ChannelHandler;
|
||||
|
|
@ -45,7 +46,7 @@ public class QosWireProtocol extends AbstractWireProtocol implements ScopeModelA
|
|||
public void configServerProtocolHandler(URL url, ChannelOperator operator) {
|
||||
// add qosProcess handler
|
||||
QosProcessHandler handler = new QosProcessHandler(url.getOrDefaultFrameworkModel(),
|
||||
DubboLogo.DUBBO, false);
|
||||
DubboLogo.DUBBO, false, StringUtils.EMPTY_STRING);
|
||||
List<ChannelHandler> handlers = new ArrayList<>();
|
||||
handlers.add(new ChannelHandlerPretender(handler));
|
||||
operator.configChannelHandler(handlers);
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ public class Server {
|
|||
private int port;
|
||||
|
||||
private boolean acceptForeignIp = true;
|
||||
private String acceptForeignIpWhitelist = StringUtils.EMPTY_STRING;
|
||||
|
||||
private EventLoopGroup boss;
|
||||
|
||||
|
|
@ -97,7 +98,7 @@ public class Server {
|
|||
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception {
|
||||
ch.pipeline().addLast(new QosProcessHandler(frameworkModel, welcome, acceptForeignIp));
|
||||
ch.pipeline().addLast(new QosProcessHandler(frameworkModel, welcome, acceptForeignIp, acceptForeignIpWhitelist));
|
||||
}
|
||||
});
|
||||
try {
|
||||
|
|
@ -147,6 +148,10 @@ public class Server {
|
|||
this.acceptForeignIp = acceptForeignIp;
|
||||
}
|
||||
|
||||
public void setAcceptForeignIpWhitelist(String acceptForeignIpWhitelist) {
|
||||
this.acceptForeignIpWhitelist = acceptForeignIpWhitelist;
|
||||
}
|
||||
|
||||
public String getWelcome() {
|
||||
return welcome;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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.qos.server.handler;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerAdapter;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.apache.dubbo.common.utils.NetUtils;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.qos.common.QosConstants;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ForeignHostPermitHandler extends ChannelHandlerAdapter {
|
||||
|
||||
// true means to accept foreign IP
|
||||
private boolean acceptForeignIp;
|
||||
|
||||
// the whitelist of foreign IP when acceptForeignIp = false, the delimiter is colon(,)
|
||||
// support specific ip and an ip range from CIDR specification
|
||||
private String acceptForeignIpWhitelist;
|
||||
private Predicate<String> whitelistPredicate = foreignIp -> false;
|
||||
|
||||
public ForeignHostPermitHandler(boolean acceptForeignIp, String foreignIpWhitelist) {
|
||||
this.acceptForeignIp = acceptForeignIp;
|
||||
this.acceptForeignIpWhitelist = foreignIpWhitelist;
|
||||
if (StringUtils.isNotEmpty(foreignIpWhitelist)) {
|
||||
whitelistPredicate = Arrays.stream(foreignIpWhitelist.split(","))
|
||||
.map(String::trim)
|
||||
.filter(StringUtils::isNotEmpty)
|
||||
.map(foreignIpPattern -> (Predicate<String>) foreignIp -> {
|
||||
try {
|
||||
// hard code port to -1
|
||||
return NetUtils.matchIpExpression(foreignIpPattern, foreignIp, -1);
|
||||
} catch (UnknownHostException ignore) {
|
||||
// ignore illegal CIDR specification
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.reduce(Predicate::or).orElse(s -> false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
|
||||
if (acceptForeignIp) {
|
||||
return;
|
||||
}
|
||||
|
||||
final InetAddress inetAddress = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress();
|
||||
// loopback address, return
|
||||
if (inetAddress.isLoopbackAddress()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// the ip is in the whitelist, return
|
||||
if (checkForeignIpInWhiteList(inetAddress)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ByteBuf cb = Unpooled.wrappedBuffer((QosConstants.BR_STR + "Foreign Ip Not Permitted, Consider Config It In Whitelist."
|
||||
+ QosConstants.BR_STR).getBytes());
|
||||
ctx.writeAndFlush(cb).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
|
||||
private boolean checkForeignIpInWhiteList(InetAddress inetAddress) {
|
||||
if (StringUtils.isEmpty(acceptForeignIpWhitelist)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final String foreignIp = inetAddress.getHostAddress();
|
||||
return whitelistPredicate.test(foreignIp);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* 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.qos.server.handler;
|
||||
|
||||
import org.apache.dubbo.qos.common.QosConstants;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerAdapter;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class LocalHostPermitHandler extends ChannelHandlerAdapter {
|
||||
|
||||
// true means to accept foreign IP
|
||||
private boolean acceptForeignIp;
|
||||
|
||||
public LocalHostPermitHandler(boolean acceptForeignIp) {
|
||||
this.acceptForeignIp = acceptForeignIp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
|
||||
if (!acceptForeignIp) {
|
||||
if (!((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().isLoopbackAddress()) {
|
||||
ByteBuf cb = Unpooled.wrappedBuffer((QosConstants.BR_STR + "Foreign Ip Not Permitted."
|
||||
+ QosConstants.BR_STR).getBytes());
|
||||
ctx.writeAndFlush(cb).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -44,15 +44,17 @@ public class QosProcessHandler extends ByteToMessageDecoder {
|
|||
private String welcome;
|
||||
// true means to accept foreign IP
|
||||
private boolean acceptForeignIp;
|
||||
private String acceptForeignIpWhitelist;
|
||||
|
||||
private FrameworkModel frameworkModel;
|
||||
|
||||
public static final String PROMPT = "dubbo>";
|
||||
|
||||
public QosProcessHandler(FrameworkModel frameworkModel, String welcome, boolean acceptForeignIp) {
|
||||
public QosProcessHandler(FrameworkModel frameworkModel, String welcome, boolean acceptForeignIp, String acceptForeignIpWhitelist) {
|
||||
this.frameworkModel = frameworkModel;
|
||||
this.welcome = welcome;
|
||||
this.acceptForeignIp = acceptForeignIp;
|
||||
this.acceptForeignIpWhitelist = acceptForeignIpWhitelist;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -75,7 +77,7 @@ public class QosProcessHandler extends ByteToMessageDecoder {
|
|||
final int magic = in.getByte(in.readerIndex());
|
||||
|
||||
ChannelPipeline p = ctx.pipeline();
|
||||
p.addLast(new LocalHostPermitHandler(acceptForeignIp));
|
||||
p.addLast(new ForeignHostPermitHandler(acceptForeignIp, acceptForeignIpWhitelist));
|
||||
if (isHttp(magic)) {
|
||||
// no welcome output for http protocol
|
||||
if (welcomeFuture != null && welcomeFuture.isCancellable()) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* 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.qos.server.handler;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class ForeignHostPermitHandlerTest {
|
||||
@Test
|
||||
void shouldShowIpNotPermittedMsg_GivenAcceptForeignIpFalseAndEmptyWhiteList() throws Exception {
|
||||
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
|
||||
Channel channel = mock(Channel.class);
|
||||
when(context.channel()).thenReturn(channel);
|
||||
InetAddress addr = mock(InetAddress.class);
|
||||
when(addr.isLoopbackAddress()).thenReturn(false);
|
||||
InetSocketAddress address = new InetSocketAddress(addr, 12345);
|
||||
when(channel.remoteAddress()).thenReturn(address);
|
||||
ChannelFuture future = mock(ChannelFuture.class);
|
||||
when(context.writeAndFlush(any(ByteBuf.class))).thenReturn(future);
|
||||
ForeignHostPermitHandler handler = new ForeignHostPermitHandler(false, StringUtils.EMPTY_STRING);
|
||||
handler.handlerAdded(context);
|
||||
ArgumentCaptor<ByteBuf> captor = ArgumentCaptor.forClass(ByteBuf.class);
|
||||
verify(context).writeAndFlush(captor.capture());
|
||||
assertThat(new String(captor.getValue().array()), containsString("Foreign Ip Not Permitted, Consider Config It In Whitelist"));
|
||||
verify(future).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldShowIpNotPermittedMsg_GivenAcceptForeignIpFalseAndNotMatchWhiteList() throws Exception {
|
||||
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
|
||||
Channel channel = mock(Channel.class);
|
||||
when(context.channel()).thenReturn(channel);
|
||||
InetAddress addr = mock(InetAddress.class);
|
||||
when(addr.isLoopbackAddress()).thenReturn(false);
|
||||
when(addr.getHostAddress()).thenReturn("179.23.44.1");
|
||||
InetSocketAddress address = new InetSocketAddress(addr, 12345);
|
||||
when(channel.remoteAddress()).thenReturn(address);
|
||||
ChannelFuture future = mock(ChannelFuture.class);
|
||||
when(context.writeAndFlush(any(ByteBuf.class))).thenReturn(future);
|
||||
ForeignHostPermitHandler handler = new ForeignHostPermitHandler(false, "175.23.44.1 , 192.168.1.192/26");
|
||||
handler.handlerAdded(context);
|
||||
ArgumentCaptor<ByteBuf> captor = ArgumentCaptor.forClass(ByteBuf.class);
|
||||
verify(context).writeAndFlush(captor.capture());
|
||||
assertThat(new String(captor.getValue().array()), containsString("Foreign Ip Not Permitted, Consider Config It In Whitelist"));
|
||||
verify(future).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotShowIpNotPermittedMsg_GivenAcceptForeignIpFalseAndMatchWhiteList() throws Exception {
|
||||
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
|
||||
Channel channel = mock(Channel.class);
|
||||
when(context.channel()).thenReturn(channel);
|
||||
InetAddress addr = mock(InetAddress.class);
|
||||
when(addr.isLoopbackAddress()).thenReturn(false);
|
||||
when(addr.getHostAddress()).thenReturn("175.23.44.1");
|
||||
InetSocketAddress address = new InetSocketAddress(addr, 12345);
|
||||
when(channel.remoteAddress()).thenReturn(address);
|
||||
|
||||
ForeignHostPermitHandler handler = new ForeignHostPermitHandler(false, "175.23.44.1, 192.168.1.192/26 ");
|
||||
handler.handlerAdded(context);
|
||||
verify(context, never()).writeAndFlush(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotShowIpNotPermittedMsg_GivenAcceptForeignIpFalseAndMatchWhiteListRange() throws Exception {
|
||||
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
|
||||
Channel channel = mock(Channel.class);
|
||||
when(context.channel()).thenReturn(channel);
|
||||
InetAddress addr = mock(InetAddress.class);
|
||||
when(addr.isLoopbackAddress()).thenReturn(false);
|
||||
when(addr.getHostAddress()).thenReturn("192.168.1.199");
|
||||
InetSocketAddress address = new InetSocketAddress(addr, 12345);
|
||||
when(channel.remoteAddress()).thenReturn(address);
|
||||
|
||||
ForeignHostPermitHandler handler = new ForeignHostPermitHandler(false, "175.23.44.1, 192.168.1.192/26");
|
||||
handler.handlerAdded(context);
|
||||
verify(context, never()).writeAndFlush(any());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* 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.qos.server.handler;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class LocalHostPermitHandlerTest {
|
||||
@Test
|
||||
void testHandlerAdded() throws Exception {
|
||||
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
|
||||
Channel channel = mock(Channel.class);
|
||||
when(context.channel()).thenReturn(channel);
|
||||
InetAddress addr = mock(InetAddress.class);
|
||||
when(addr.isLoopbackAddress()).thenReturn(false);
|
||||
InetSocketAddress address = new InetSocketAddress(addr, 12345);
|
||||
when(channel.remoteAddress()).thenReturn(address);
|
||||
ChannelFuture future = mock(ChannelFuture.class);
|
||||
when(context.writeAndFlush(any(ByteBuf.class))).thenReturn(future);
|
||||
LocalHostPermitHandler handler = new LocalHostPermitHandler(false);
|
||||
handler.handlerAdded(context);
|
||||
ArgumentCaptor<ByteBuf> captor = ArgumentCaptor.forClass(ByteBuf.class);
|
||||
verify(context).writeAndFlush(captor.capture());
|
||||
assertThat(new String(captor.getValue().array()), containsString("Foreign Ip Not Permitted"));
|
||||
verify(future).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.qos.server.handler;
|
||||
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.rpc.model.FrameworkModel;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
|
@ -42,7 +43,7 @@ class QosProcessHandlerTest {
|
|||
ChannelHandlerContext context = Mockito.mock(ChannelHandlerContext.class);
|
||||
ChannelPipeline pipeline = Mockito.mock(ChannelPipeline.class);
|
||||
Mockito.when(context.pipeline()).thenReturn(pipeline);
|
||||
QosProcessHandler handler = new QosProcessHandler(FrameworkModel.defaultModel(), "welcome", false);
|
||||
QosProcessHandler handler = new QosProcessHandler(FrameworkModel.defaultModel(), "welcome", false, StringUtils.EMPTY_STRING);
|
||||
handler.decode(context, buf, Collections.emptyList());
|
||||
verify(pipeline).addLast(any(HttpServerCodec.class));
|
||||
verify(pipeline).addLast(any(HttpObjectAggregator.class));
|
||||
|
|
@ -56,7 +57,7 @@ class QosProcessHandlerTest {
|
|||
ChannelHandlerContext context = Mockito.mock(ChannelHandlerContext.class);
|
||||
ChannelPipeline pipeline = Mockito.mock(ChannelPipeline.class);
|
||||
Mockito.when(context.pipeline()).thenReturn(pipeline);
|
||||
QosProcessHandler handler = new QosProcessHandler(FrameworkModel.defaultModel(), "welcome", false);
|
||||
QosProcessHandler handler = new QosProcessHandler(FrameworkModel.defaultModel(), "welcome", false, StringUtils.EMPTY_STRING);
|
||||
handler.decode(context, buf, Collections.emptyList());
|
||||
verify(pipeline).addLast(any(LineBasedFrameDecoder.class));
|
||||
verify(pipeline).addLast(any(StringDecoder.class));
|
||||
|
|
@ -66,4 +67,4 @@ class QosProcessHandlerTest {
|
|||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,7 +138,9 @@ public class NettyPortUnificationServerHandler extends ByteToMessageDecoder {
|
|||
|
||||
private void enableSsl(ChannelHandlerContext ctx) {
|
||||
ChannelPipeline p = ctx.pipeline();
|
||||
p.addLast("ssl", sslCtx.newHandler(ctx.alloc()));
|
||||
if (sslCtx != null) {
|
||||
p.addLast("ssl", sslCtx.newHandler(ctx.alloc()));
|
||||
}
|
||||
p.addLast("unificationA",
|
||||
new NettyPortUnificationServerHandler(url, sslCtx, false, protocols,
|
||||
handler, dubboChannels, urlMapper, handlerMapper));
|
||||
|
|
|
|||
|
|
@ -66,11 +66,6 @@ public class AsyncRpcResult implements Result {
|
|||
|
||||
private CompletableFuture<AppResponse> responseFuture;
|
||||
|
||||
/**
|
||||
* 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"));
|
||||
|
||||
public AsyncRpcResult(CompletableFuture<AppResponse> future, Invocation invocation) {
|
||||
this.responseFuture = future;
|
||||
this.invocation = invocation;
|
||||
|
|
@ -216,7 +211,11 @@ public class AsyncRpcResult implements Result {
|
|||
fn.accept(v, t);
|
||||
});
|
||||
|
||||
if (setFutureWhenSync || ((RpcInvocation) invocation).getInvokeMode() != InvokeMode.SYNC) {
|
||||
// Whether set future to Thread Local when invocation mode is sync
|
||||
String setFutureWhenSync = invocation.getModuleModel().getModelEnvironment().getSystemConfiguration()
|
||||
.getString(CommonConstants.SET_FUTURE_IN_SYNC_MODE, "true");
|
||||
|
||||
if (Boolean.parseBoolean(setFutureWhenSync) || ((RpcInvocation) invocation).getInvokeMode() != InvokeMode.SYNC) {
|
||||
// Necessary! update future in context, see https://github.com/apache/dubbo/issues/9461
|
||||
RpcContext.getServiceContext().setFuture(new FutureAdapter<>(this.responseFuture));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public class AccessLogFilter implements Filter {
|
|||
|
||||
private AtomicBoolean scheduled = new AtomicBoolean();
|
||||
|
||||
private static final String LINE_SEPARATOR = "line.separator";
|
||||
private final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||
|
||||
/**
|
||||
* Default constructor initialize demon thread for writing into access log file with names with access log key
|
||||
|
|
@ -173,7 +173,7 @@ public class AccessLogFilter implements Filter {
|
|||
try {
|
||||
while (!logQueue.isEmpty()) {
|
||||
writer.write(logQueue.poll().getLogMessage());
|
||||
writer.write(System.getProperty(LINE_SEPARATOR));
|
||||
writer.write(LINE_SEPARATOR);
|
||||
}
|
||||
} finally {
|
||||
writer.flush();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.rpc.listener;
|
||||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.constants.LoggerCodeConstants;
|
||||
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
|
|
@ -100,11 +101,12 @@ public class ListenerInvokerWrapper<T> implements Invoker<T> {
|
|||
try {
|
||||
consumer.accept(listener);
|
||||
} catch (RuntimeException t) {
|
||||
logger.error(t.getMessage(), t);
|
||||
logger.error(LoggerCodeConstants.INTERNAL_ERROR, "wrapped listener internal error", "", t.getMessage(), t);
|
||||
exception = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,11 +85,6 @@ public abstract class AbstractInvoker<T> implements Invoker<T> {
|
|||
*/
|
||||
private boolean destroyed = false;
|
||||
|
||||
/**
|
||||
* 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"));
|
||||
|
||||
// -- Constructor
|
||||
|
||||
public AbstractInvoker(Class<T> type, URL url) {
|
||||
|
|
@ -254,7 +249,11 @@ public abstract class AbstractInvoker<T> implements Invoker<T> {
|
|||
asyncResult = AsyncRpcResult.newDefaultAsyncResult(null, e, invocation);
|
||||
}
|
||||
|
||||
if (setFutureWhenSync || invocation.getInvokeMode() != InvokeMode.SYNC) {
|
||||
// Whether set future to Thread Local when invocation mode is sync
|
||||
String setFutureWhenSync = invocation.getModuleModel().getModelEnvironment().getSystemConfiguration()
|
||||
.getString(CommonConstants.SET_FUTURE_IN_SYNC_MODE, "true");
|
||||
|
||||
if (Boolean.parseBoolean(setFutureWhenSync) || invocation.getInvokeMode() != InvokeMode.SYNC) {
|
||||
// set server context
|
||||
RpcContext.getServiceContext().setFuture(new FutureAdapter<>(asyncResult.getResponseFuture()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.rpc.protocol.dubbo;
|
||||
|
||||
|
||||
import org.apache.dubbo.common.config.ConfigurationUtils;
|
||||
import org.apache.dubbo.common.utils.CacheableSupplier;
|
||||
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
|
|
@ -38,6 +39,7 @@ import org.apache.dubbo.rpc.model.FrameworkServiceRepository;
|
|||
import org.apache.dubbo.rpc.model.MethodDescriptor;
|
||||
import org.apache.dubbo.rpc.model.ModuleModel;
|
||||
import org.apache.dubbo.rpc.model.ProviderModel;
|
||||
import org.apache.dubbo.rpc.model.ScopeModel;
|
||||
import org.apache.dubbo.rpc.model.ServiceDescriptor;
|
||||
import org.apache.dubbo.rpc.support.RpcUtils;
|
||||
|
||||
|
|
@ -137,7 +139,17 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec
|
|||
|
||||
ClassLoader originClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
if (Boolean.parseBoolean(System.getProperty(SERIALIZATION_SECURITY_CHECK_KEY, "true"))) {
|
||||
ScopeModel scopeModel = channel.getUrl().getScopeModel();
|
||||
if (scopeModel instanceof ModuleModel) {
|
||||
scopeModel = scopeModel.getParent();
|
||||
} else {
|
||||
scopeModel = ApplicationModel.defaultModel();
|
||||
}
|
||||
String serializationSecurityCheck = ConfigurationUtils.getSystemConfiguration(
|
||||
scopeModel).getString(SERIALIZATION_SECURITY_CHECK_KEY, "true");
|
||||
|
||||
|
||||
if (Boolean.parseBoolean(serializationSecurityCheck)) {
|
||||
CodecSupport.checkSerialization(frameworkModel.getServiceRepository(), path, version, serializationType);
|
||||
}
|
||||
Object[] args = DubboCodec.EMPTY_OBJECT_ARRAY;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.apache.dubbo.rpc.protocol.dubbo.decode;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.url.component.ServiceConfigURL;
|
||||
|
|
@ -38,10 +41,6 @@ import org.apache.dubbo.rpc.model.ModuleServiceRepository;
|
|||
import org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation;
|
||||
import org.apache.dubbo.rpc.protocol.dubbo.DubboCodec;
|
||||
import org.apache.dubbo.rpc.protocol.dubbo.support.DemoService;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
|
@ -78,13 +77,13 @@ class DubboTelnetDecodeTest {
|
|||
|
||||
// disable org.apache.dubbo.remoting.transport.CodecSupport.checkSerialization to avoid error:
|
||||
// java.io.IOException: Service org.apache.dubbo.rpc.protocol.dubbo.support.DemoService with version 0.0.0 not found, invocation rejected.
|
||||
System.setProperty(SERIALIZATION_SECURITY_CHECK_KEY, "false");
|
||||
ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration().overwriteCache(SERIALIZATION_SECURITY_CHECK_KEY, "false");
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void teardown() {
|
||||
FrameworkModel.defaultModel().destroy();
|
||||
System.clearProperty(SERIALIZATION_SECURITY_CHECK_KEY);
|
||||
ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration().clearCache();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -101,25 +100,26 @@ class DubboTelnetDecodeTest {
|
|||
try {
|
||||
Codec2 codec = ExtensionLoader.getExtensionLoader(Codec2.class).getExtension("dubbo");
|
||||
URL url = new ServiceConfigURL("dubbo", "localhost", 22226);
|
||||
url = url.setScopeModel(ApplicationModel.defaultModel().newModule());
|
||||
NettyCodecAdapter adapter = new NettyCodecAdapter(codec, url, new MockChannelHandler());
|
||||
|
||||
MockHandler mockHandler = new MockHandler(null,
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
dubbo.incrementAndGet();
|
||||
}
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
dubbo.incrementAndGet();
|
||||
}
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
|
||||
ch = new LocalEmbeddedChannel();
|
||||
ch.pipeline()
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
|
||||
ch.writeInbound(dubboByteBuf);
|
||||
} catch (Exception e) {
|
||||
|
|
@ -148,6 +148,7 @@ class DubboTelnetDecodeTest {
|
|||
try {
|
||||
Codec2 codec = ExtensionLoader.getExtensionLoader(Codec2.class).getExtension("dubbo");
|
||||
URL url = new ServiceConfigURL("dubbo", "localhost", 22226);
|
||||
url = url.setScopeModel(ApplicationModel.defaultModel().newModule());
|
||||
NettyCodecAdapter adapter = new NettyCodecAdapter(codec, url, new MockChannelHandler());
|
||||
|
||||
MockHandler mockHandler = new MockHandler((msg) -> {
|
||||
|
|
@ -155,19 +156,19 @@ class DubboTelnetDecodeTest {
|
|||
telnet.incrementAndGet();
|
||||
}
|
||||
},
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
|
||||
ch = new LocalEmbeddedChannel();
|
||||
ch.pipeline()
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
|
||||
ch.writeInbound(telnetByteBuf);
|
||||
} catch (Exception e) {
|
||||
|
|
@ -192,13 +193,13 @@ class DubboTelnetDecodeTest {
|
|||
* | telnet(incomplete) |
|
||||
* +--------------------------------------------------+
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* Second ByteBuf:
|
||||
* +--------------------------++----------------------+
|
||||
* | telnet(the remaining) || dubbo(complete) |
|
||||
* +--------------------------++----------------------+
|
||||
* ||
|
||||
* Magic Code
|
||||
* ||
|
||||
* Magic Code
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
|
|
@ -211,6 +212,7 @@ class DubboTelnetDecodeTest {
|
|||
try {
|
||||
Codec2 codec = ExtensionLoader.getExtensionLoader(Codec2.class).getExtension("dubbo");
|
||||
URL url = new ServiceConfigURL("dubbo", "localhost", 22226);
|
||||
url = url.setScopeModel(ApplicationModel.defaultModel().newModule());
|
||||
NettyCodecAdapter adapter = new NettyCodecAdapter(codec, url, new MockChannelHandler());
|
||||
|
||||
MockHandler mockHandler = new MockHandler((msg) -> {
|
||||
|
|
@ -218,23 +220,23 @@ class DubboTelnetDecodeTest {
|
|||
telnetDubbo.incrementAndGet();
|
||||
}
|
||||
},
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
telnetDubbo.incrementAndGet();
|
||||
}
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
telnetDubbo.incrementAndGet();
|
||||
}
|
||||
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
|
||||
ch = new LocalEmbeddedChannel();
|
||||
ch.pipeline()
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
|
||||
ch.writeInbound(telnetByteBuf);
|
||||
ch.writeInbound(Unpooled.wrappedBuffer(Unpooled.wrappedBuffer("\n".getBytes()), dubboByteBuf));
|
||||
|
|
@ -265,7 +267,7 @@ class DubboTelnetDecodeTest {
|
|||
* | telnet(incomplete) |
|
||||
* +--------------------------------------------------+
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* Second ByteBuf (secondByteBuf):
|
||||
* +--------------------------------------------------+
|
||||
* | telnet(the remaining) | telnet(complete) |
|
||||
|
|
@ -283,6 +285,7 @@ class DubboTelnetDecodeTest {
|
|||
try {
|
||||
Codec2 codec = ExtensionLoader.getExtensionLoader(Codec2.class).getExtension("dubbo");
|
||||
URL url = new ServiceConfigURL("dubbo", "localhost", 22226);
|
||||
url = url.setScopeModel(ApplicationModel.defaultModel().newModule());
|
||||
NettyCodecAdapter adapter = new NettyCodecAdapter(codec, url, new MockChannelHandler());
|
||||
|
||||
MockHandler mockHandler = new MockHandler((msg) -> {
|
||||
|
|
@ -290,19 +293,19 @@ class DubboTelnetDecodeTest {
|
|||
telnetTelnet.incrementAndGet();
|
||||
}
|
||||
},
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
|
||||
ch = new LocalEmbeddedChannel();
|
||||
ch.pipeline()
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
|
||||
ch.writeInbound(firstByteBuf);
|
||||
ch.writeInbound(secondByteBuf);
|
||||
|
|
@ -336,8 +339,8 @@ class DubboTelnetDecodeTest {
|
|||
* +-------------------------++-----------------------+
|
||||
* | dubbo(the remaining) || dubbo(complete) |
|
||||
* +-------------------------++-----------------------+
|
||||
* ||
|
||||
* Magic Code
|
||||
* ||
|
||||
* Magic Code
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
|
|
@ -354,25 +357,26 @@ class DubboTelnetDecodeTest {
|
|||
try {
|
||||
Codec2 codec = ExtensionLoader.getExtensionLoader(Codec2.class).getExtension("dubbo");
|
||||
URL url = new ServiceConfigURL("dubbo", "localhost", 22226);
|
||||
url = url.setScopeModel(ApplicationModel.defaultModel().newModule());
|
||||
NettyCodecAdapter adapter = new NettyCodecAdapter(codec, url, new MockChannelHandler());
|
||||
|
||||
MockHandler mockHandler = new MockHandler(null,
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
dubboDubbo.incrementAndGet();
|
||||
}
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
dubboDubbo.incrementAndGet();
|
||||
}
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
|
||||
ch = new LocalEmbeddedChannel();
|
||||
ch.pipeline()
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
|
||||
ch.writeInbound(firstDubboByteBuf);
|
||||
ch.writeInbound(secondDubboByteBuf);
|
||||
|
|
@ -421,6 +425,7 @@ class DubboTelnetDecodeTest {
|
|||
try {
|
||||
Codec2 codec = ExtensionLoader.getExtensionLoader(Codec2.class).getExtension("dubbo");
|
||||
URL url = new ServiceConfigURL("dubbo", "localhost", 22226);
|
||||
url = url.setScopeModel(ApplicationModel.defaultModel().newModule());
|
||||
NettyCodecAdapter adapter = new NettyCodecAdapter(codec, url, new MockChannelHandler());
|
||||
|
||||
MockHandler mockHandler = new MockHandler((msg) -> {
|
||||
|
|
@ -428,22 +433,22 @@ class DubboTelnetDecodeTest {
|
|||
dubboTelnet.incrementAndGet();
|
||||
}
|
||||
},
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
dubboTelnet.incrementAndGet();
|
||||
}
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
dubboTelnet.incrementAndGet();
|
||||
}
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
|
||||
ch = new LocalEmbeddedChannel();
|
||||
ch.pipeline()
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
|
||||
ch.writeInbound(firstDubboByteBuf);
|
||||
ch.writeInbound(secondByteBuf);
|
||||
|
|
@ -496,13 +501,13 @@ class DubboTelnetDecodeTest {
|
|||
if (msg instanceof DecodeableRpcInvocation) {
|
||||
DecodeableRpcInvocation invocation = (DecodeableRpcInvocation) msg;
|
||||
if ("sayHello".equals(invocation.getMethodName())
|
||||
&& invocation.getParameterTypes().length == 1
|
||||
&& String.class.equals(invocation.getParameterTypes()[0])
|
||||
&& invocation.getArguments().length == 1
|
||||
&& "dubbo".equals(invocation.getArguments()[0])
|
||||
&& DemoService.class.getName().equals(invocation.getAttachment("path"))
|
||||
&& DemoService.class.getName().equals(invocation.getAttachment("interface"))
|
||||
&& "0.0.0".equals(invocation.getAttachment("version"))) {
|
||||
&& invocation.getParameterTypes().length == 1
|
||||
&& String.class.equals(invocation.getParameterTypes()[0])
|
||||
&& invocation.getArguments().length == 1
|
||||
&& "dubbo".equals(invocation.getArguments()[0])
|
||||
&& DemoService.class.getName().equals(invocation.getAttachment("path"))
|
||||
&& DemoService.class.getName().equals(invocation.getAttachment("interface"))
|
||||
&& "0.0.0".equals(invocation.getAttachment("version"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import org.apache.dubbo.rpc.protocol.tri.observer.ServerCallToObserverAdapter;
|
|||
import java.net.InetSocketAddress;
|
||||
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_TIMEOUT_SERVER;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_APPLICATION_KEY;
|
||||
|
||||
public abstract class AbstractServerCallListener implements AbstractServerCall.Listener {
|
||||
|
||||
|
|
@ -57,6 +58,7 @@ public abstract class AbstractServerCallListener implements AbstractServerCall.L
|
|||
.remove(TripleHeaderEnum.CONSUMER_APP_NAME_KEY);
|
||||
if (null != remoteApp) {
|
||||
RpcContext.getServiceContext().setRemoteApplicationName(remoteApp);
|
||||
invocation.setAttachmentIfAbsent(REMOTE_APPLICATION_KEY, remoteApp);
|
||||
}
|
||||
final long stInMillis = System.currentTimeMillis();
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -402,14 +402,6 @@ public class TripleServerStream extends AbstractStream implements ServerStream {
|
|||
}
|
||||
}
|
||||
|
||||
try {
|
||||
final TriDecoder.Listener listener = new ServerDecoderListener();
|
||||
deframer = new TriDecoder(deCompressor, listener);
|
||||
} catch (Throwable t) {
|
||||
responseErr(TriRpcStatus.INTERNAL.withCause(t));
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> requestMetadata = headersToMap(headers);
|
||||
boolean hasStub = pathResolver.hasNativeStub(path);
|
||||
if (hasStub) {
|
||||
|
|
@ -421,10 +413,9 @@ public class TripleServerStream extends AbstractStream implements ServerStream {
|
|||
frameworkModel, acceptEncoding, serviceName, originalMethodName, filters,
|
||||
executor);
|
||||
}
|
||||
// must before onHeader
|
||||
deframer = new TriDecoder(deCompressor, new ServerDecoderListener(listener));
|
||||
listener.onHeader(requestMetadata);
|
||||
if (listener == null) {
|
||||
deframer.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -458,21 +449,27 @@ public class TripleServerStream extends AbstractStream implements ServerStream {
|
|||
.withDescription("Canceled by client ,errorCode=" + errorCode));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private class ServerDecoderListener implements TriDecoder.Listener {
|
||||
|
||||
@Override
|
||||
public void onRawMessage(byte[] data) {
|
||||
listener.onMessage(data);
|
||||
}
|
||||
private static class ServerDecoderListener implements TriDecoder.Listener {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (listener != null) {
|
||||
listener.onComplete();
|
||||
}
|
||||
}
|
||||
private final ServerStream.Listener listener;
|
||||
|
||||
public ServerDecoderListener(ServerStream.Listener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRawMessage(byte[] data) {
|
||||
listener.onMessage(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
listener.onComplete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class DefaultHessian2FactoryInitializer extends AbstractHessian2FactoryIn
|
|||
@Override
|
||||
protected SerializerFactory createSerializerFactory() {
|
||||
Hessian2SerializerFactory hessian2SerializerFactory = new Hessian2SerializerFactory();
|
||||
hessian2SerializerFactory.setAllowNonSerializable(Boolean.parseBoolean(System.getProperty("dubbo.hessian.allowNonSerializable", "false")));
|
||||
hessian2SerializerFactory.setAllowNonSerializable(Boolean.parseBoolean(ALLOW_NON_SERIALIZABLE));
|
||||
hessian2SerializerFactory.getClassFactory().allow("org.apache.dubbo.*");
|
||||
return hessian2SerializerFactory;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,9 @@ import com.alibaba.com.caucho.hessian.io.SerializerFactory;
|
|||
@SPI(value = "default", scope = ExtensionScope.FRAMEWORK)
|
||||
public interface Hessian2FactoryInitializer {
|
||||
String ALLOW = System.getProperty("dubbo.application.hessian2.allow");
|
||||
|
||||
String DENY = System.getProperty("dubbo.application.hessian2.deny");
|
||||
|
||||
String WHITELIST = System.getProperty("dubbo.application.hessian2.whitelist");
|
||||
|
||||
String ALLOW_NON_SERIALIZABLE = System.getProperty("dubbo.hessian.allowNonSerializable", "false");
|
||||
|
|
|
|||
Loading…
Reference in New Issue