This is an automated email from the ASF dual-hosted git repository. mercyblitz pushed a commit to branch 2.7.8-dev in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/2.7.8-dev by this push: new 173df9a 2.7.8 release (#6407) 173df9a is described below commit 173df9a471b08ff0dacd6405c684b751740eeb21 Author: Mercy Ma <mercybl...@gmail.com> AuthorDate: Thu Jul 2 17:08:14 2020 +0800 2.7.8 release (#6407) * Polish apache/dubbo#6296 : Adding the new methods into MetadataReport to manipulate the exported URLs for service introspection * Polish apache/dubbo#6296 : Adding the new methods into MetadataReport to manipulate the exported URLs for service introspection * Polish apache/dubbo#6171 : [Feature] Introducing the composite implementation of MetadataService * Revert "fix wrong check of InvokerListener when export a service (fix issue_6269) (#6271)" This reverts commit 91989cae508f8482f31ac335879da4a5975661c8. * Revert "fix wrong check of InvokerListener when export a service (fix issue_6269) (#6271)" This reverts commit 91989cae508f8482f31ac335879da4a5975661c8. * Revert the MetadataReport * Polish apache/dubbo#6305 : [Refactor] ServiceConfig and ReferenceConfig publish the ServiceDefinition based on the Dubbo Event * Polish apache/dubbo#6198 : [Issue] Fixing NacosDynamicConfiguration#publishConfig bug * Polish apache/dubbo#6310 : Refactoring MetadataReport's methods * Polish apache/dubbo#6198 : [Issue] Fixing NacosDynamicConfiguration#publishConfig bug * Polish apache/dubbo#6198 : [Issue] Fixing NacosDynamicConfiguration#publishConfig bug * Polish apache/dubbo#6315 : [Refactor] Refactoring the implementation of MetadataReport based on The Config-Center infrastructure Deprecated List : - NacosMetadataReport - ZookeeperMetadataReport * Polish apache/dubbo#6315 : Refactoring by TreePathDynamicConfiguration * Polish apache/dubbo#6315 : Refactoring ConsulDynamicConfiguration by TreePathDynamicConfiguration * Polish apache/dubbo#6315 : Reset the config base path to be "metadata" for ConfigCenterBasedMetadataReportFactory * Polish apache/dubbo#6315 : Bugfix * Polish apache/dubbo#6315 : Bugfix * Polish apache/dubbo#6315 : Correct words * sync wait netty server to finish shutdown (#6281) * Polish apache/dubbo#6333 : [Refactor] Using mandatory implementation of Service Instance registration instead of the event * maybe we can remove null judge in this case (#6321) * update * update * Polish apache/dubbo#6336 : [Refactor] org.apache.dubbo.metadata.ServiceNameMapping * Polish apache/dubbo#6170 : [Feature] Introducing the externalized configuration for ServiceNameMapping * Polish apache/dubbo#6342 : [Enhancement] Introducing the composite ServiceNameMapping * Refactor * fix method name typo in JValidator.java (#6344) * [Dubbo-6340]fix application cannot exit when use consul registry (#6341) * fix application cannot exit when use consul registry * make consul registry suppor ACL (#6313) * make consul registry suppor ACL * Polish apache/dubbo#6172 : [Feature] Adding the "services" attribute methods into @DubboReference * Polish apache/dubbo#6173 : [Feature] Adding the "services" attribute into <dubbo:reference> element * Polish apache/dubbo#6346 : [Issue] Merging all subscribied URLs from the multiple services * Polish apache/dubbo#6346 : [Issue] Merging all subscribied URLs from the multiple services * fix publish null value when use consul config center (#6351) * fix publish null value when use consul config center * Polish apache/dubbo#6252 * Polish apache/dubbo#6356 & apache/dubbo#6171 * Polish apache/dubbo#6356 & apache/dubbo#6171 * Polish apache/dubbo#6224 : Filter chain was not invoked with local calls since v2.7.6 * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * Polish apache/dubbo#6322 : Adding META-INF/dubbo/internal/org.apache.dubbo.metadata.MetadataServiceExporter * fix the priority of ListenableRouter were not effective (#6148) fixes #4822 * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * when the url is generic, the log level should be info (#6363) * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * fix NPE when check=false is set and provider is empty. (#6376) fixes #6228 * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * fix #6306. support TypeBuilder sort (#6365) * fix #6306. support TypeBuilder sort * fix #6306. support TypeBuilder sort * fix #6306. support TypeBuilder sort * remove unused import * add license for test file * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * enhance ClusterInvoker & ExtensionLoader (#6343) - Introduce ClusterInvoker to better support multiple registries subscription - Wrapper sort and enable/disable - some small fixes * Polish apache/dubbo#6322 : [Enhancement] Fix the issues of test-cases after refactoring * Fixed the test-cases * Enhancement, support Map auto recognize in PojoUtils (#6106) Fix #5939 * Polish apache/dubbo#6389 : [Issue] Resolving the issues with ConsulServiceDiscovery * fix typo in CommonConstants (#6373) * Fix export provider error, change to catch throwable, handle NoClassDefFoundError (#6380) * check parameterTypesDesc of Generic and Echo (#6374) * add tps filter to SPI list (#6282) * Do not clear all configurator instances when override is empty (#6395) * Service callback throws "Not found exported service" when 'bind.port' is set (#6223) * Removing RpcContext after test finishes. (#6314) * Introduce ClusterInvoker to better support multiple registries subscription (#6343) * return same reference invokers as much as possible (#6083) fixes #6082 * fix ut * Fixes the test-cases * Fixes the test-cases * Fixes the test-cases Co-authored-by: tswstarplanet <tswstarpla...@apache.org> Co-authored-by: Nine <nine.yang.cod...@gmail.com> Co-authored-by: 陈哈哈 <chenyongjia...@outlook.com> Co-authored-by: luoning810 <18311333...@163.com> Co-authored-by: cvictory <shenglic...@gmail.com> Co-authored-by: ken.lj <ken.lj...@gmail.com> Co-authored-by: Siqu Chen <32302975+discord...@users.noreply.github.com> Co-authored-by: D-H-T <dht925n...@126.com> Co-authored-by: skyguard1 <qhdx...@qq.com> Co-authored-by: Jeff Lu <278400...@qq.com> Co-authored-by: Christophe·liwei <2484713...@qq.com> Co-authored-by: Joe Zou <joe...@apache.org> Co-authored-by: 李黄河 <jameslover...@gmail.com> Co-authored-by: OrDTesters <44483852+ordtest...@users.noreply.github.com> Co-authored-by: zjseu2009 <zjseu2...@163.com> --- .../org/apache/dubbo/rpc/cluster/Configurator.java | 5 ++- .../dubbo/rpc/cluster/router/tag/TagRouter.java | 12 ++++++++ .../support/registry/ZoneAwareClusterInvoker.java | 2 +- .../dubbo/common/constants/CommonConstants.java | 7 +++-- .../org/apache/dubbo/common/utils/PojoUtils.java | 36 +++++++++++++++++++++- .../apache/dubbo/config/MetadataReportConfig.java | 4 +-- .../apache/dubbo/common/utils/PojoUtilsTest.java | 36 ++++++++++++++++++++++ .../dubbo/config/utils/ConfigValidationUtils.java | 7 +++-- .../apache/dubbo/config/ReferenceConfigTest.java | 5 +-- .../config/url/ExporterSideConfigUrlTest.java | 5 +-- .../dubbo/qos/legacy/InvokerTelnetHandlerTest.java | 14 +++++++++ .../dubbo/qos/legacy/service/DemoService.java | 2 ++ .../dubbo/qos/legacy/service/DemoServiceImpl.java | 5 +++ .../consul/ConsulServiceDiscoveryTest.java | 16 +++++----- .../registry/dubbo/RegistryDirectoryTest.java | 2 +- .../main/java/org/apache/dubbo/rpc/Constants.java | 1 + .../org/apache/dubbo/rpc/filter/ContextFilter.java | 4 +-- .../apache/dubbo/rpc/filter/GenericImplFilter.java | 3 +- .../org/apache/dubbo/rpc/support/RpcUtils.java | 16 ++++++---- .../dubbo/internal/org.apache.dubbo.rpc.Filter | 3 +- .../java/org/apache/dubbo/rpc/RpcContextTest.java | 3 +- .../rpc/protocol/dubbo/CallbackServiceCodec.java | 3 ++ .../protocol/dubbo/DecodeableRpcInvocation.java | 2 +- .../dubbo/rpc/protocol/dubbo/DubboInvoker.java | 6 ++-- .../rpc/protocol/dubbo/ArgumentCallbackTest.java | 22 +++++++++++++ 25 files changed, 179 insertions(+), 42 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Configurator.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Configurator.java index 24e5683..2a69f6e 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Configurator.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Configurator.java @@ -27,9 +27,9 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import static org.apache.dubbo.rpc.cluster.Constants.PRIORITY_KEY; import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; +import static org.apache.dubbo.rpc.cluster.Constants.PRIORITY_KEY; /** * Configurator. (SPI, Prototype, ThreadSafe) @@ -86,8 +86,7 @@ public interface Configurator extends Comparable<Configurator> { Map<String, String> override = new HashMap<>(url.getParameters()); //The anyhost parameter of override may be added automatically, it can't change the judgement of changing url override.remove(ANYHOST_KEY); - if (override.size() == 0) { - configurators.clear(); + if (CollectionUtils.isEmptyMap(override)) { continue; } configurators.add(configuratorFactory.getConfigurator(url)); diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java index eb11120..77429b5 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java @@ -193,6 +193,18 @@ public class TagRouter extends AbstractRouter implements ConfigurationListener { } private <T> List<Invoker<T>> filterInvoker(List<Invoker<T>> invokers, Predicate<Invoker<T>> predicate) { + boolean filter = false; + for (int i = 0; i < invokers.size(); ++i) { + Invoker<T> invoker = invokers.get(i); + if (!predicate.test(invoker)) { + filter = true; + break; + } + } + if (!filter) { + return invokers; + } + return invokers.stream() .filter(predicate) .collect(Collectors.toList()); diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/registry/ZoneAwareClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/registry/ZoneAwareClusterInvoker.java index 5585b35..f5043e3 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/registry/ZoneAwareClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/registry/ZoneAwareClusterInvoker.java @@ -40,7 +40,7 @@ import static org.apache.dubbo.common.constants.RegistryConstants.ZONE_KEY; /** * When there're more than one registry for subscription. - * + * <p> * This extension provides a strategy to decide how to distribute traffics among them: * 1. registry marked as 'preferred=true' has the highest priority. * 2. check the zone the current request belongs, pick the registry that has the same zone first. diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java index 1dcbb67..657c1ab 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java @@ -118,7 +118,7 @@ public interface CommonConstants { // used by invocation attachments to transfer timeout from Consumer to Provider. // works as a replacement of TIMEOUT_KEY on wire, which seems to be totally useless in previous releases). - String TIMEOUT_ATTACHENT_KEY = "_TO"; + String TIMEOUT_ATTACHMENT_KEY = "_TO"; String TIME_COUNTDOWN_KEY = "timeout-countdown"; @@ -126,13 +126,13 @@ public interface CommonConstants { String REMOVE_VALUE_PREFIX = "-"; - String PROPERTIES_CHAR_SEPERATOR = "-"; + String PROPERTIES_CHAR_SEPARATOR = "-"; String UNDERLINE_SEPARATOR = "_"; String SEPARATOR_REGEX = "_|-"; - String GROUP_CHAR_SEPERATOR = ":"; + String GROUP_CHAR_SEPARATOR = ":"; String HIDE_KEY_PREFIX = "."; @@ -211,6 +211,7 @@ public interface CommonConstants { */ String $INVOKE = "$invoke"; String $INVOKE_ASYNC = "$invokeAsync"; + String GENERIC_PARAMETER_DESC = "Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;"; /** * package version in the manifest diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java index c46fcbc..84e2a11 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java @@ -417,7 +417,19 @@ public class PojoUtils { } if (Map.class.isAssignableFrom(type) || type == Object.class) { - final Map<Object, Object> result = createMap(map); + final Map<Object, Object> result; + // fix issue#5939 + Type mapKeyType = getKeyTypeForMap(map.getClass()); + Type typeKeyType = getGenericClassByIndex(genericType, 0); + boolean typeMismatch = mapKeyType instanceof Class + && typeKeyType instanceof Class + && !typeKeyType.getTypeName().equals(mapKeyType.getTypeName()); + if (typeMismatch) { + result = createMap(new HashMap(0)); + } else { + result = createMap(map); + } + history.put(pojo, result); for (Map.Entry<Object, Object> entry : map.entrySet()) { Type keyType = getGenericClassByIndex(genericType, 0); @@ -504,6 +516,28 @@ public class PojoUtils { } /** + * Get key type for {@link Map} directly implemented by {@code clazz}. + * If {@code clazz} does not implement {@link Map} directly, return {@code null}. + * + * @param clazz {@link Class} + * @return Return String.class for {@link com.alibaba.fastjson.JSONObject} + */ + private static Type getKeyTypeForMap(Class<?> clazz) { + Type[] interfaces = clazz.getGenericInterfaces(); + if (!ArrayUtils.isEmpty(interfaces)) { + for (Type type : interfaces) { + if (type instanceof ParameterizedType) { + ParameterizedType t = (ParameterizedType)type; + if ("java.util.Map".equals(t.getRawType().getTypeName())) { + return t.getActualTypeArguments()[0]; + } + } + } + } + return null; + } + + /** * Get parameterized type * * @param genericType generic type diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java index 0abda27..175288c 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java @@ -24,7 +24,7 @@ import java.util.HashMap; import java.util.Map; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; -import static org.apache.dubbo.common.constants.CommonConstants.PROPERTIES_CHAR_SEPERATOR; +import static org.apache.dubbo.common.constants.CommonConstants.PROPERTIES_CHAR_SEPARATOR; /** * MetadataReportConfig @@ -38,7 +38,7 @@ public class MetadataReportConfig extends AbstractConfig { * the value is : metadata-report */ private static final String PREFIX_TAG = StringUtils.camelToSplitName( - MetadataReportConfig.class.getSimpleName().substring(0, MetadataReportConfig.class.getSimpleName().length() - 6), PROPERTIES_CHAR_SEPERATOR); + MetadataReportConfig.class.getSimpleName().substring(0, MetadataReportConfig.class.getSimpleName().length() - 6), PROPERTIES_CHAR_SEPARATOR); // Register center address private String address; diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java index e05c09d..24cb292 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java @@ -25,6 +25,7 @@ import org.apache.dubbo.common.model.person.PersonInfo; import org.apache.dubbo.common.model.person.PersonStatus; import org.apache.dubbo.common.model.person.Phone; +import com.alibaba.fastjson.JSONObject; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -280,6 +281,41 @@ public class PojoUtilsTest { } @Test + public void testJsonObjectToMap() throws Exception { + Method method = PojoUtilsTest.class.getMethod("setMap", Map.class); + assertNotNull(method); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("1", "test"); + @SuppressWarnings("unchecked") + Map<Integer, Object> value = (Map<Integer, Object>)PojoUtils.realize(jsonObject, + method.getParameterTypes()[0], + method.getGenericParameterTypes()[0]); + method.invoke(new PojoUtilsTest(), value); + assertEquals("test", value.get(1)); + } + + @Test + public void testListJsonObjectToListMap() throws Exception { + Method method = PojoUtilsTest.class.getMethod("setListMap", List.class); + assertNotNull(method); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("1", "test"); + List<JSONObject> list = new ArrayList<>(1); + list.add(jsonObject); + @SuppressWarnings("unchecked") + List<Map<Integer, Object>> result = (List<Map<Integer, Object>>)PojoUtils.realize( + list, + method.getParameterTypes()[0], + method.getGenericParameterTypes()[0]); + method.invoke(new PojoUtilsTest(), result); + assertEquals("test", result.get(0).get(1)); + } + + public void setMap(Map<Integer, Object> map) {} + + public void setListMap(List<Map<Integer, Object>> list) {} + + @Test public void testException() throws Exception { Map map = new HashMap(); map.put("message", "dubbo exception"); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java index 2e46fa2..8a91d1c 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java @@ -223,10 +223,12 @@ public class ConfigValidationUtils { ApplicationConfig application = interfaceConfig.getApplication(); AbstractConfig.appendParameters(map, monitor); AbstractConfig.appendParameters(map, application); - String address = monitor.getAddress(); + String address = null; String sysaddress = System.getProperty("dubbo.monitor.address"); if (sysaddress != null && sysaddress.length() > 0) { address = sysaddress; + } else if (monitor != null) { + address = monitor.getAddress(); } if (ConfigUtils.isNotEmpty(address)) { if (!map.containsKey(PROTOCOL_KEY)) { @@ -237,7 +239,8 @@ public class ConfigValidationUtils { } } return UrlUtils.parseURL(address, map); - } else if ((REGISTRY_PROTOCOL.equals(monitor.getProtocol()) || SERVICE_REGISTRY_PROTOCOL.equals(monitor.getProtocol())) + } else if (monitor != null && + (REGISTRY_PROTOCOL.equals(monitor.getProtocol()) || SERVICE_REGISTRY_PROTOCOL.equals(monitor.getProtocol())) && registryURL != null) { return URLBuilder.from(registryURL) .setProtocol(DUBBO_PROTOCOL) diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java index c992e48..775596c 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java @@ -21,6 +21,7 @@ import org.apache.dubbo.config.annotation.Method; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.api.DemoService; import org.apache.dubbo.config.provider.impl.DemoServiceImpl; +import org.apache.dubbo.rpc.model.ApplicationModel; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; @@ -33,12 +34,12 @@ public class ReferenceConfigTest { @BeforeEach public void setUp() { -// ApplicationModel.getConfigManager().clear(); + ApplicationModel.reset(); } @AfterEach public void tearDown() { -// ApplicationModel.getConfigManager().clear(); + ApplicationModel.reset(); } @Test diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/url/ExporterSideConfigUrlTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/url/ExporterSideConfigUrlTest.java index e1fbfb4..5c19d04 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/url/ExporterSideConfigUrlTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/url/ExporterSideConfigUrlTest.java @@ -19,6 +19,7 @@ package org.apache.dubbo.config.url; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.rpc.model.ApplicationModel; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -42,13 +43,13 @@ public class ExporterSideConfigUrlTest extends UrlTestBase { @BeforeEach public void setUp() { + ApplicationModel.reset(); initServConf(); -// ApplicationModel.getConfigManager().clear(); } @AfterEach() public void teardown() { -// ApplicationModel.getConfigManager().clear(); + ApplicationModel.reset(); } @Test diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/InvokerTelnetHandlerTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/InvokerTelnetHandlerTest.java index fd0f2b2..d8bcd0c 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/InvokerTelnetHandlerTest.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/InvokerTelnetHandlerTest.java @@ -155,6 +155,20 @@ public class InvokerTelnetHandlerTest { } @Test + public void testInvokeMethodWithMapParameter() throws RemotingException { + mockChannel = mock(Channel.class); + given(mockChannel.getAttribute("telnet.service")).willReturn(DemoService.class.getName()); + given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555")); + given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886")); + + registerProvider(DemoService.class.getName(), new DemoServiceImpl(), DemoService.class); + + String param = "{1:\"Dubbo\",2:\"test\"}"; + String result = invoke.telnet(mockChannel, "getMap(" + param + ")"); + assertTrue(result.contains("result: {1:\"Dubbo\",2:\"test\"}")); + } + + @Test public void testInvokeMultiJsonParamMethod() throws RemotingException { mockChannel = mock(Channel.class); given(mockChannel.getAttribute("telnet.service")).willReturn(null); diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/service/DemoService.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/service/DemoService.java index c862f08..8ffa550 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/service/DemoService.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/service/DemoService.java @@ -66,4 +66,6 @@ public interface DemoService { String getPerson(Man man); String getRemoteApplicationName(); + + Map<Integer, Object> getMap(Map<Integer, Object> map); } \ No newline at end of file diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/service/DemoServiceImpl.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/service/DemoServiceImpl.java index dcefeff..675aeba 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/service/DemoServiceImpl.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/service/DemoServiceImpl.java @@ -126,4 +126,9 @@ public class DemoServiceImpl implements DemoService { public String getRemoteApplicationName() { return RpcContext.getContext().getRemoteApplicationName(); } + + @Override + public Map<Integer, Object> getMap(Map<Integer, Object> map) { + return map; + } } \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-consul/src/test/java/org/apache/dubbo/registry/consul/ConsulServiceDiscoveryTest.java b/dubbo-registry/dubbo-registry-consul/src/test/java/org/apache/dubbo/registry/consul/ConsulServiceDiscoveryTest.java index e106248..9f10d0a 100644 --- a/dubbo-registry/dubbo-registry-consul/src/test/java/org/apache/dubbo/registry/consul/ConsulServiceDiscoveryTest.java +++ b/dubbo-registry/dubbo-registry-consul/src/test/java/org/apache/dubbo/registry/consul/ConsulServiceDiscoveryTest.java @@ -16,12 +16,13 @@ */ package org.apache.dubbo.registry.consul; -import com.pszymczyk.consul.ConsulProcess; -import com.pszymczyk.consul.ConsulStarterBuilder; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.registry.client.DefaultServiceInstance; import org.apache.dubbo.registry.client.ServiceInstance; + +import com.pszymczyk.consul.ConsulProcess; +import com.pszymczyk.consul.ConsulStarterBuilder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -36,9 +37,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class ConsulServiceDiscoveryTest { - private static ConsulProcess consul; private URL url; - static ConsulServiceDiscovery consulServiceDiscovery; + private ConsulServiceDiscovery consulServiceDiscovery; + private ConsulProcess consul; private static final String SERVICE_NAME = "A"; private static final String LOCALHOST = "127.0.0.1"; @@ -49,7 +50,6 @@ public class ConsulServiceDiscoveryTest { .start(); url = URL.valueOf("consul://localhost:" + consul.getHttpPort()); consulServiceDiscovery = new ConsulServiceDiscovery(); - Assertions.assertNull(consulServiceDiscovery.getServices()); consulServiceDiscovery.initialize(url); } @@ -60,7 +60,7 @@ public class ConsulServiceDiscoveryTest { } @Test - public void testRegistration() throws InterruptedException{ + public void testRegistration() throws InterruptedException { DefaultServiceInstance serviceInstance = createServiceInstance(SERVICE_NAME, LOCALHOST, NetUtils.getAvailablePort()); consulServiceDiscovery.register(serviceInstance); Thread.sleep(5000); @@ -94,8 +94,8 @@ public class ConsulServiceDiscoveryTest { Thread.sleep(5000); Assertions.assertFalse(consulServiceDiscovery.getInstances(serviceName).isEmpty()); List<String> r = convertToIpPort(consulServiceDiscovery.getInstances(serviceName)); - assertTrue(r.contains("127.0.0.1:"+portA)); - assertTrue(r.contains("127.0.0.1:"+portB)); + assertTrue(r.contains("127.0.0.1:" + portA)); + assertTrue(r.contains("127.0.0.1:" + portB)); } private List<String> convertToIpPort(List<ServiceInstance> serviceInstances) { diff --git a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java index 9ce163c..c38a7f2 100644 --- a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java +++ b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java @@ -768,7 +768,7 @@ public class RegistryDirectoryTest { List<Invoker<?>> invokers = registryDirectory.list(invocation); Invoker<?> aInvoker = invokers.get(0); //Need to be restored to the original providerUrl - Assertions.assertEquals("1", aInvoker.getUrl().getParameter("timeout")); + Assertions.assertEquals("3", aInvoker.getUrl().getParameter("timeout")); } /** diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java index b7698e8..f5fd982 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java @@ -27,6 +27,7 @@ public interface Constants { String DEPRECATED_KEY = "deprecated"; String $ECHO = "$echo"; + String $ECHO_PARAMETER_DESC = "Ljava/lang/Object;"; String RETURN_PREFIX = "return "; diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java index 81ad8df..291601a 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java @@ -40,7 +40,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER; import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_APPLICATION_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_ATTACHENT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_ATTACHMENT_KEY; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; import static org.apache.dubbo.common.constants.CommonConstants.TIME_COUNTDOWN_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; @@ -71,7 +71,7 @@ public class ContextFilter implements Filter, Filter.Listener { UNLOADING_KEYS.add(DUBBO_VERSION_KEY); UNLOADING_KEYS.add(TOKEN_KEY); UNLOADING_KEYS.add(TIMEOUT_KEY); - UNLOADING_KEYS.add(TIMEOUT_ATTACHENT_KEY); + UNLOADING_KEYS.add(TIMEOUT_ATTACHMENT_KEY); // Remove async property to avoid being passed to the following invoke chain. UNLOADING_KEYS.add(ASYNC_KEY); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericImplFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericImplFilter.java index 194a98b..20ef2ce 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericImplFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericImplFilter.java @@ -43,6 +43,7 @@ import java.lang.reflect.Type; import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE; import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE_ASYNC; +import static org.apache.dubbo.common.constants.CommonConstants.GENERIC_PARAMETER_DESC; import static org.apache.dubbo.rpc.Constants.GENERIC_KEY; /** @@ -55,8 +56,6 @@ public class GenericImplFilter implements Filter, Filter.Listener { private static final Class<?>[] GENERIC_PARAMETER_TYPES = new Class<?>[]{String.class, String[].class, Object[].class}; - private static final String GENERIC_PARAMETER_DESC = "Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;"; - private static final String GENERIC_IMPL_MARKER = "GENERIC_IMPL"; @Override diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java index 18f9f68..3e8f81e 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java @@ -34,9 +34,11 @@ import java.util.concurrent.atomic.AtomicLong; import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE; import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE_ASYNC; -import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_ATTACHENT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.GENERIC_PARAMETER_DESC; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_ATTACHMENT_KEY; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; import static org.apache.dubbo.rpc.Constants.$ECHO; +import static org.apache.dubbo.rpc.Constants.$ECHO_PARAMETER_DESC; import static org.apache.dubbo.rpc.Constants.ASYNC_KEY; import static org.apache.dubbo.rpc.Constants.AUTO_ATTACH_INVOCATIONID_KEY; import static org.apache.dubbo.rpc.Constants.ID_KEY; @@ -176,12 +178,14 @@ public class RpcUtils { return $INVOKE_ASYNC.equals(inv.getMethodName()); } - public static boolean isGenericCall(String path, String method) { - return $INVOKE.equals(method) || $INVOKE_ASYNC.equals(method); + // check parameterTypesDesc to fix CVE-2020-1948 + public static boolean isGenericCall(String parameterTypesDesc, String method) { + return ($INVOKE.equals(method) || $INVOKE_ASYNC.equals(method)) && GENERIC_PARAMETER_DESC.equals(parameterTypesDesc); } - public static boolean isEcho(String path, String method) { - return $ECHO.equals(method); + // check parameterTypesDesc to fix CVE-2020-1948 + public static boolean isEcho(String parameterTypesDesc, String method) { + return $ECHO.equals(method) && $ECHO_PARAMETER_DESC.equals(parameterTypesDesc); } public static InvokeMode getInvokeMode(URL url, Invocation inv) { @@ -217,7 +221,7 @@ public class RpcUtils { public static long getTimeout(Invocation invocation, long defaultTimeout) { long timeout = defaultTimeout; - Object genericTimeout = invocation.getObjectAttachment(TIMEOUT_ATTACHENT_KEY); + Object genericTimeout = invocation.getObjectAttachment(TIMEOUT_ATTACHMENT_KEY); if (genericTimeout != null) { timeout = convertToNumber(genericTimeout, defaultTimeout); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter b/dubbo-rpc/dubbo-rpc-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter index 376f966..3d6da08 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter +++ b/dubbo-rpc/dubbo-rpc-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter @@ -11,4 +11,5 @@ exception=org.apache.dubbo.rpc.filter.ExceptionFilter executelimit=org.apache.dubbo.rpc.filter.ExecuteLimitFilter deprecated=org.apache.dubbo.rpc.filter.DeprecatedFilter compatible=org.apache.dubbo.rpc.filter.CompatibleFilter -timeout=org.apache.dubbo.rpc.filter.TimeoutFilter \ No newline at end of file +timeout=org.apache.dubbo.rpc.filter.TimeoutFilter +tps=org.apache.dubbo.rpc.filter.TpsLimitFilter \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java index 7e7e1df..380b2c3 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java @@ -25,8 +25,6 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; public class RpcContextTest { @@ -157,6 +155,7 @@ public class RpcContextTest { rpcContext.stopAsync(); Assertions.assertTrue(rpcContext.isAsyncStarted()); + RpcContext.removeContext(); } @Test diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java index 7a60e0e..eead37c 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java @@ -24,6 +24,7 @@ import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.ConcurrentHashSet; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.Channel; +import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invocation; @@ -113,7 +114,9 @@ class CallbackServiceCodec { } } tmpMap.putAll(params); + tmpMap.remove(VERSION_KEY);// doesn't need to distinguish version for callback + tmpMap.remove(Constants.BIND_PORT_KEY); //callback doesn't needs bind.port tmpMap.put(INTERFACE_KEY, clazz.getName()); URL exportUrl = new URL(DubboProtocol.NAME, channel.getLocalAddress().getAddress().getHostAddress(), channel.getLocalAddress().getPort(), clazz.getName() + "." + instid, tmpMap); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java index c5f6a0a..f286ddb 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java @@ -130,7 +130,7 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec } } if (pts == DubboCodec.EMPTY_CLASS_ARRAY) { - if (!RpcUtils.isGenericCall(path, getMethodName()) && !RpcUtils.isEcho(path, getMethodName())) { + if (!RpcUtils.isGenericCall(desc, getMethodName()) && !RpcUtils.isEcho(desc, getMethodName())) { throw new IllegalArgumentException("Service not found:" + path + ", " + getMethodName()); } pts = ReflectUtils.desc2classArray(desc); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java index d88ae54..c415ac4 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java @@ -47,7 +47,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.ENABLE_TIMEOUT_C import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_ATTACHENT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_ATTACHMENT_KEY; import static org.apache.dubbo.common.constants.CommonConstants.TIME_COUNTDOWN_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; import static org.apache.dubbo.rpc.Constants.TOKEN_KEY; @@ -168,12 +168,12 @@ public class DubboInvoker<T> extends AbstractInvoker<T> { if (countdown == null) { timeout = (int) RpcUtils.getTimeout(getUrl(), methodName, RpcContext.getContext(), DEFAULT_TIMEOUT); if (getUrl().getParameter(ENABLE_TIMEOUT_COUNTDOWN_KEY, false)) { - invocation.setObjectAttachment(TIMEOUT_ATTACHENT_KEY, timeout); // pass timeout to remote server + invocation.setObjectAttachment(TIMEOUT_ATTACHMENT_KEY, timeout); // pass timeout to remote server } } else { TimeoutCountDown timeoutCountDown = (TimeoutCountDown) countdown; timeout = (int) timeoutCountDown.timeRemaining(TimeUnit.MILLISECONDS); - invocation.setObjectAttachment(TIMEOUT_ATTACHENT_KEY, timeout);// pass timeout to remote server + invocation.setObjectAttachment(TIMEOUT_ATTACHMENT_KEY, timeout);// pass timeout to remote server } return timeout; } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/ArgumentCallbackTest.java b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/ArgumentCallbackTest.java index a51244a..4bc0800 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/ArgumentCallbackTest.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/ArgumentCallbackTest.java @@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.protocol.dubbo; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcException; @@ -104,6 +105,27 @@ public class ArgumentCallbackTest { } catch (Exception e) { } } + + @Test + public void TestCallbackNormalWithBindPort() throws Exception { + initOrResetUrl(1, 10000000); + consumerUrl = serviceURL.addParameter(Constants.BIND_PORT_KEY,"7653"); + initOrResetService(); + + final AtomicInteger count = new AtomicInteger(0); + + demoProxy.xxx(new IDemoCallback() { + public String yyy(String msg) { + System.out.println("Recived callback: " + msg); + count.incrementAndGet(); + return "ok"; + } + }, "other custom args", 10, 100); + System.out.println("Async..."); + assertCallbackCount(10, 100, count); + destroyService(); + + } @Test public void TestCallbackNormal() throws Exception {