This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new eec80a8  Refactor Codec check, default deny (#8449)
eec80a8 is described below

commit eec80a861a969f8b525211af9875e9816c94b5cc
Author: Albumen Kevin <[email protected]>
AuthorDate: Mon Aug 9 11:46:57 2021 +0800

    Refactor Codec check, default deny (#8449)
    
    * Refactor Codec check, default deny
    
    * fix ut
    
    * fix ut
    
    * fix ut
    
    * fix ut
---
 .../apache/dubbo/rpc/model/ServiceRepository.java  | 23 ++++++++
 .../org/apache/dubbo/config/spring/ConfigTest.java |  9 ++++
 .../DubboComponentScanRegistrarTest.java           |  8 +++
 .../consumer/PropertyConfigurerTest.java           | 10 +++-
 .../consumer2/PropertySourcesConfigurerTest.java   | 10 +++-
 .../consumer3/PropertySourcesInJavaConfigTest.java | 14 ++++-
 .../dubbo/qos/command/impl/ChangeTelnetTest.java   |  8 +--
 .../dubbo/qos/command/impl/CountTelnetTest.java    |  4 +-
 .../dubbo/qos/command/impl/PortTelnetTest.java     |  4 +-
 .../dubbo/qos/legacy/ChangeTelnetHandlerTest.java  |  8 +--
 .../dubbo/qos/legacy/TraceTelnetHandlerTest.java   |  5 +-
 .../dubbo/remoting/transport/CodecSupport.java     | 32 ++++++-----
 .../rpc/protocol/ProtocolSerializationWrapper.java | 63 ++++++++++++++++++++++
 .../dubbo/internal/org.apache.dubbo.rpc.Protocol   |  3 +-
 .../rpc/protocol/dubbo/CallbackServiceCodec.java   |  4 +-
 .../dubbo/ReferenceCountExchangeClientTest.java    |  6 +--
 16 files changed, 180 insertions(+), 31 deletions(-)

diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceRepository.java 
b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceRepository.java
index 405dd2a..8442070 100644
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceRepository.java
+++ 
b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ServiceRepository.java
@@ -16,10 +16,12 @@
  */
 package org.apache.dubbo.rpc.model;
 
+import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.context.FrameworkExt;
 import org.apache.dubbo.common.context.LifecycleAdapter;
 import org.apache.dubbo.common.extension.ExtensionLoader;
 import org.apache.dubbo.common.utils.CollectionUtils;
+import org.apache.dubbo.common.utils.ConcurrentHashSet;
 import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.config.ReferenceConfigBase;
 import org.apache.dubbo.config.ServiceConfigBase;
@@ -50,6 +52,9 @@ public class ServiceRepository extends LifecycleAdapter 
implements FrameworkExt
     // useful to find a provider model quickly with 
serviceInterfaceName:version
     private ConcurrentMap<String, ProviderModel> providersWithoutGroup = new 
ConcurrentHashMap<>();
 
+    // useful to find a url quickly with serviceInterfaceName:version
+    private ConcurrentMap<String, Set<URL>> providerUrlsWithoutGroup = new 
ConcurrentHashMap<>();
+
     public ServiceRepository() {
         Set<BuiltinServiceDetector> builtinServices
                 = 
ExtensionLoader.getExtensionLoader(BuiltinServiceDetector.class).getSupportedExtensionInstances();
@@ -180,6 +185,24 @@ public class ServiceRepository extends LifecycleAdapter 
implements FrameworkExt
         return consumers.get(serviceKey);
     }
 
+    public void registerProviderUrl(URL url) {
+        
providerUrlsWithoutGroup.computeIfAbsent(keyWithoutGroup(url.getServiceKey()), 
(k) -> new ConcurrentHashSet<>()).add(url);
+    }
+
+    public Set<URL> lookupRegisteredProviderUrlsWithoutGroup(String key) {
+        return providerUrlsWithoutGroup.get(key);
+    }
+
+    @Deprecated
+    public ConcurrentMap<String, Set<URL>> getProviderUrlsWithoutGroup() {
+        return providerUrlsWithoutGroup;
+    }
+
+    @Deprecated
+    public void setProviderUrlsWithoutGroup(ConcurrentMap<String, Set<URL>> 
providerUrlsWithoutGroup) {
+        this.providerUrlsWithoutGroup = providerUrlsWithoutGroup;
+    }
+
     @Override
     public void destroy() throws IllegalStateException {
         // currently works for unit test
diff --git 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java
 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java
index 8b026a8..401fab0 100644
--- 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java
+++ 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java
@@ -52,6 +52,7 @@ import org.apache.dubbo.rpc.RpcContext;
 import org.apache.dubbo.rpc.RpcException;
 import org.apache.dubbo.rpc.model.ApplicationModel;
 import org.apache.dubbo.rpc.service.GenericService;
+
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
@@ -66,6 +67,8 @@ import 
org.springframework.context.support.ClassPathXmlApplicationContext;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
 
 import static 
org.apache.dubbo.common.constants.CommonConstants.GENERIC_SERIALIZATION_BEAN;
 import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
@@ -132,8 +135,10 @@ public class ConfigTest {
         try {
             ctx.start();
 
+            ConcurrentMap<String, Set<URL>> tmp = 
ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
             // clear config manager
             DubboBootstrap.reset(false);
+            
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);
 
             DemoService demoService = refer("dubbo://127.0.0.1:20887");
             String hello = demoService.sayName("hello");
@@ -240,8 +245,10 @@ public class ConfigTest {
         try {
             ctx.start();
 
+            ConcurrentMap<String, Set<URL>> tmp = 
ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
             // clear config manager
             DubboBootstrap.reset(false);
+            
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);
 
             DemoService demoService = refer("dubbo://127.0.0.1:20881");
             String hello = demoService.sayName("hello");
@@ -480,8 +487,10 @@ public class ConfigTest {
         try {
             providerContext.start();
 
+            ConcurrentMap<String, Set<URL>> tmp = 
ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
             // clear config manager
             DubboBootstrap.reset(false);
+            
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);
 
             ClassPathXmlApplicationContext ctx = new 
ClassPathXmlApplicationContext(resourcePath + "/init-reference.xml",
                     resourcePath + "/init-reference-properties.xml");
diff --git 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/DubboComponentScanRegistrarTest.java
 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/DubboComponentScanRegistrarTest.java
index ae7589c..e15175d 100644
--- 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/DubboComponentScanRegistrarTest.java
+++ 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/DubboComponentScanRegistrarTest.java
@@ -16,11 +16,14 @@
  */
 package org.apache.dubbo.config.spring.context.annotation;
 
+import org.apache.dubbo.common.URL;
 import org.apache.dubbo.config.bootstrap.DubboBootstrap;
 import org.apache.dubbo.config.spring.api.DemoService;
 import 
org.apache.dubbo.config.spring.context.annotation.consumer.ConsumerConfiguration;
 import 
org.apache.dubbo.config.spring.context.annotation.provider.DemoServiceImpl;
 import 
org.apache.dubbo.config.spring.context.annotation.provider.ProviderConfiguration;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
@@ -29,6 +32,9 @@ import org.springframework.aop.support.AopUtils;
 import 
org.springframework.context.annotation.AnnotationConfigApplicationContext;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+
 import static 
org.springframework.core.annotation.AnnotationUtils.findAnnotation;
 
 /**
@@ -70,8 +76,10 @@ public class DubboComponentScanRegistrarTest {
         // Test @Transactional is present or not
         Assertions.assertNotNull(findAnnotation(beanClass, 
Transactional.class));
 
+        ConcurrentMap<String, Set<URL>> tmp = 
ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
         // reset ConfigManager of provider context
         DubboBootstrap.reset(false);
+        
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);
 
         AnnotationConfigApplicationContext consumerContext = new 
AnnotationConfigApplicationContext();
 
diff --git 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/PropertyConfigurerTest.java
 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/PropertyConfigurerTest.java
index 4635c33..c9acd72 100644
--- 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/PropertyConfigurerTest.java
+++ 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer/PropertyConfigurerTest.java
@@ -16,11 +16,14 @@
  */
 package org.apache.dubbo.config.spring.propertyconfigurer.consumer;
 
+import org.apache.dubbo.common.URL;
 import org.apache.dubbo.config.bootstrap.DubboBootstrap;
 import org.apache.dubbo.config.spring.api.HelloService;
 import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
 import 
org.apache.dubbo.config.spring.registrycenter.DefaultSingleRegistryCenter;
 import org.apache.dubbo.config.spring.registrycenter.SingleRegistryCenter;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
@@ -32,6 +35,9 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.ImportResource;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+
 public class PropertyConfigurerTest {
 
     private static SingleRegistryCenter singleRegistryCenter;
@@ -56,8 +62,10 @@ public class PropertyConfigurerTest {
         try {
             providerContext.start();
 
-            // clear config manager
+            ConcurrentMap<String, Set<URL>> tmp = 
ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
+            // reset ConfigManager of provider context
             DubboBootstrap.reset(false);
+            
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);
 
             try {
                 Thread.sleep(1000);
diff --git 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/PropertySourcesConfigurerTest.java
 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/PropertySourcesConfigurerTest.java
index 7caea6c..323803e 100644
--- 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/PropertySourcesConfigurerTest.java
+++ 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer2/PropertySourcesConfigurerTest.java
@@ -16,12 +16,15 @@
  */
 package org.apache.dubbo.config.spring.propertyconfigurer.consumer2;
 
+import org.apache.dubbo.common.URL;
 import org.apache.dubbo.config.bootstrap.DubboBootstrap;
 import org.apache.dubbo.config.spring.api.HelloService;
 import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
 import 
org.apache.dubbo.config.spring.propertyconfigurer.consumer.DemoBeanFactoryPostProcessor;
 import 
org.apache.dubbo.config.spring.registrycenter.DefaultSingleRegistryCenter;
 import org.apache.dubbo.config.spring.registrycenter.SingleRegistryCenter;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
@@ -33,6 +36,9 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.ImportResource;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+
 public class PropertySourcesConfigurerTest {
 
     private static SingleRegistryCenter singleRegistryCenter;
@@ -62,8 +68,10 @@ public class PropertySourcesConfigurerTest {
             } catch (InterruptedException e) {
             }
 
-            // reset config
+            ConcurrentMap<String, Set<URL>> tmp = 
ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
+            // reset ConfigManager of provider context
             DubboBootstrap.reset(false);
+            
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);
 
             // Resolve placeholder by PropertySourcesPlaceholderConfigurer in 
dubbo-consumer.xml, without import property source.
             AnnotationConfigApplicationContext context = new 
AnnotationConfigApplicationContext(ConsumerConfiguration.class);
diff --git 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/PropertySourcesInJavaConfigTest.java
 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/PropertySourcesInJavaConfigTest.java
index 33b6a13..f7d066c 100644
--- 
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/PropertySourcesInJavaConfigTest.java
+++ 
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/propertyconfigurer/consumer3/PropertySourcesInJavaConfigTest.java
@@ -16,12 +16,15 @@
  */
 package org.apache.dubbo.config.spring.propertyconfigurer.consumer3;
 
+import org.apache.dubbo.common.URL;
 import org.apache.dubbo.config.bootstrap.DubboBootstrap;
 import org.apache.dubbo.config.spring.api.HelloService;
 import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
 import 
org.apache.dubbo.config.spring.propertyconfigurer.consumer.DemoBeanFactoryPostProcessor;
 import 
org.apache.dubbo.config.spring.registrycenter.DefaultSingleRegistryCenter;
 import org.apache.dubbo.config.spring.registrycenter.SingleRegistryCenter;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
@@ -37,6 +40,9 @@ import 
org.springframework.context.support.ClassPathXmlApplicationContext;
 import 
org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
 import org.springframework.core.io.ClassPathResource;
 
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+
 public class PropertySourcesInJavaConfigTest {
 
     private static final String SCAN_PACKAGE_NAME = 
"org.apache.dubbo.config.spring.propertyconfigurer.consumer3.notexist";
@@ -72,8 +78,10 @@ public class PropertySourcesInJavaConfigTest {
             } catch (InterruptedException e) {
             }
 
-            // reset config
+            ConcurrentMap<String, Set<URL>> tmp = 
ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
+            // reset ConfigManager of provider context
             DubboBootstrap.reset(false);
+            
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);
 
             // Resolve placeholder by import property sources
             AnnotationConfigApplicationContext context = new 
AnnotationConfigApplicationContext(ConsumerConfiguration.class, 
ImportPropertyConfiguration.class);
@@ -108,8 +116,10 @@ public class PropertySourcesInJavaConfigTest {
             } catch (InterruptedException e) {
             }
 
-            // reset config
+            ConcurrentMap<String, Set<URL>> tmp = 
ApplicationModel.getServiceRepository().getProviderUrlsWithoutGroup();
+            // reset ConfigManager of provider context
             DubboBootstrap.reset(false);
+            
ApplicationModel.getServiceRepository().setProviderUrlsWithoutGroup(tmp);
 
             // Resolve placeholder by custom 
PropertySourcesPlaceholderConfigurer bean
             AnnotationConfigApplicationContext context = new 
AnnotationConfigApplicationContext(ConsumerConfiguration.class, 
PropertyBeanConfiguration.class);
diff --git 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/ChangeTelnetTest.java
 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/ChangeTelnetTest.java
index 81e17a9..b349f9d 100644
--- 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/ChangeTelnetTest.java
+++ 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/ChangeTelnetTest.java
@@ -17,11 +17,13 @@
 package org.apache.dubbo.qos.command.impl;
 
 import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.ExtensionLoader;
 import org.apache.dubbo.qos.command.BaseCommand;
 import org.apache.dubbo.qos.command.CommandContext;
 import org.apache.dubbo.qos.legacy.ProtocolUtils;
 import org.apache.dubbo.qos.legacy.service.DemoService;
 import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Protocol;
 import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;
 
 import io.netty.channel.Channel;
@@ -71,14 +73,14 @@ public class ChangeTelnetTest {
 
     @Test
     public void testChangeSimpleName() {
-        DubboProtocol.getDubboProtocol().export(mockInvoker);
+        
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
         String result = change.execute(mockCommandContext, new 
String[]{"DemoService"});
         assertEquals("Used the DemoService as default.\r\nYou can cancel 
default service by command: cd /", result);
     }
 
     @Test
     public void testChangeName() {
-        DubboProtocol.getDubboProtocol().export(mockInvoker);
+        
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
         String result = change.execute(mockCommandContext, new 
String[]{"org.apache.dubbo.qos.legacy.service.DemoService"});
         assertEquals("Used the org.apache.dubbo.qos.legacy.service.DemoService 
as default.\r\nYou can cancel default service by command: cd /",
             result);
@@ -86,7 +88,7 @@ public class ChangeTelnetTest {
 
     @Test
     public void testChangePath() {
-        DubboProtocol.getDubboProtocol().export(mockInvoker);
+        
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
         String result = change.execute(mockCommandContext, new 
String[]{"demo"});
         assertEquals("Used the demo as default.\r\nYou can cancel default 
service by command: cd /", result);
     }
diff --git 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/CountTelnetTest.java
 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/CountTelnetTest.java
index 71c1f85..113be4d 100644
--- 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/CountTelnetTest.java
+++ 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/CountTelnetTest.java
@@ -17,6 +17,7 @@
 package org.apache.dubbo.qos.command.impl;
 
 import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.ExtensionLoader;
 import org.apache.dubbo.qos.command.BaseCommand;
 import org.apache.dubbo.qos.command.CommandContext;
 import org.apache.dubbo.qos.command.impl.channel.MockNettyChannel;
@@ -24,6 +25,7 @@ import org.apache.dubbo.qos.legacy.ProtocolUtils;
 import org.apache.dubbo.qos.legacy.service.DemoService;
 import org.apache.dubbo.remoting.telnet.support.TelnetUtils;
 import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Protocol;
 import org.apache.dubbo.rpc.RpcStatus;
 import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;
 
@@ -76,7 +78,7 @@ public class CountTelnetTest {
         String methodName = "sayHello";
         String[] args = new 
String[]{"org.apache.dubbo.qos.legacy.service.DemoService", "sayHello", "1"};
 
-        DubboProtocol.getDubboProtocol().export(mockInvoker);
+        
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
         RpcStatus.beginCount(url, methodName);
         RpcStatus.endCount(url, methodName, 10L, true);
         count.execute(mockCommandContext, args);
diff --git 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/PortTelnetTest.java
 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/PortTelnetTest.java
index 1b61ed6..2a268d9 100644
--- 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/PortTelnetTest.java
+++ 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/impl/PortTelnetTest.java
@@ -17,6 +17,7 @@
 package org.apache.dubbo.qos.command.impl;
 
 import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.ExtensionLoader;
 import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.qos.command.BaseCommand;
 import org.apache.dubbo.qos.command.CommandContext;
@@ -26,6 +27,7 @@ import org.apache.dubbo.remoting.RemotingException;
 import org.apache.dubbo.remoting.exchange.ExchangeClient;
 import org.apache.dubbo.remoting.exchange.Exchangers;
 import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Protocol;
 import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;
 
 import org.junit.jupiter.api.AfterEach;
@@ -54,7 +56,7 @@ public class PortTelnetTest {
         given(mockInvoker.getInterface()).willReturn(DemoService.class);
         
given(mockInvoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:" + 
availablePort + "/demo"));
 
-        DubboProtocol.getDubboProtocol().export(mockInvoker);
+        
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
     }
 
     @AfterEach
diff --git 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/ChangeTelnetHandlerTest.java
 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/ChangeTelnetHandlerTest.java
index be57f2b..3a93d44 100644
--- 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/ChangeTelnetHandlerTest.java
+++ 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/ChangeTelnetHandlerTest.java
@@ -17,11 +17,13 @@
 package org.apache.dubbo.qos.legacy;
 
 import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.ExtensionLoader;
 import org.apache.dubbo.qos.legacy.service.DemoService;
 import org.apache.dubbo.remoting.Channel;
 import org.apache.dubbo.remoting.RemotingException;
 import org.apache.dubbo.remoting.telnet.TelnetHandler;
 import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Protocol;
 import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;
 
 import org.junit.jupiter.api.AfterAll;
@@ -78,14 +80,14 @@ public class ChangeTelnetHandlerTest {
 
     @Test
     public void testChangeSimpleName() throws RemotingException {
-        DubboProtocol.getDubboProtocol().export(mockInvoker);
+        
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
         String result = change.telnet(mockChannel, "DemoService");
         assertEquals("Used the DemoService as default.\r\nYou can cancel 
default service by command: cd /", result);
     }
 
     @Test
     public void testChangeName() throws RemotingException {
-        DubboProtocol.getDubboProtocol().export(mockInvoker);
+        
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
         String result = change.telnet(mockChannel, 
"org.apache.dubbo.qos.legacy.service.DemoService");
         assertEquals("Used the org.apache.dubbo.qos.legacy.service.DemoService 
as default.\r\nYou can cancel default service by command: cd /",
                 result);
@@ -93,7 +95,7 @@ public class ChangeTelnetHandlerTest {
 
     @Test
     public void testChangePath() throws RemotingException {
-        DubboProtocol.getDubboProtocol().export(mockInvoker);
+        
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
         String result = change.telnet(mockChannel, "demo");
         assertEquals("Used the demo as default.\r\nYou can cancel default 
service by command: cd /", result);
     }
diff --git 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/TraceTelnetHandlerTest.java
 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/TraceTelnetHandlerTest.java
index 13c626e..dd74db3 100644
--- 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/TraceTelnetHandlerTest.java
+++ 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/legacy/TraceTelnetHandlerTest.java
@@ -17,12 +17,15 @@
 package org.apache.dubbo.qos.legacy;
 
 import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.ExtensionLoader;
 import org.apache.dubbo.qos.legacy.service.DemoService;
 import org.apache.dubbo.remoting.Channel;
 import org.apache.dubbo.remoting.telnet.TelnetHandler;
 import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Protocol;
 import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;
 import org.apache.dubbo.rpc.protocol.dubbo.filter.TraceFilter;
+
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
@@ -64,7 +67,7 @@ public class TraceTelnetHandlerTest {
         String message = "org.apache.dubbo.qos.legacy.service.DemoService 
sayHello 1";
         Class<?> type = DemoService.class;
 
-        DubboProtocol.getDubboProtocol().export(mockInvoker);
+        
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(mockInvoker);
         handler.telnet(mockChannel, message);
 
         String key = type.getName() + "." + method;
diff --git 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/CodecSupport.java
 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/CodecSupport.java
index d4beb50..6db207b 100644
--- 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/CodecSupport.java
+++ 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/CodecSupport.java
@@ -25,9 +25,9 @@ import org.apache.dubbo.common.serialize.ObjectInput;
 import org.apache.dubbo.common.serialize.ObjectOutput;
 import org.apache.dubbo.common.serialize.Serialization;
 import org.apache.dubbo.common.utils.CollectionUtils;
+import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.remoting.Constants;
 import org.apache.dubbo.rpc.model.ApplicationModel;
-import org.apache.dubbo.rpc.model.ProviderModel;
 import org.apache.dubbo.rpc.model.ServiceRepository;
 
 import java.io.ByteArrayOutputStream;
@@ -35,7 +35,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -160,22 +159,29 @@ public class CodecSupport {
 
     public static void checkSerialization(String path, String version, Byte 
id) throws IOException {
         ServiceRepository repository = ApplicationModel.getServiceRepository();
-        ProviderModel providerModel = 
repository.lookupExportedServiceWithoutGroup(path + ":" + version);
-        if (providerModel == null) {
-            if (logger.isWarnEnabled()) {
-                logger.warn("Serialization security check is enabled but 
cannot work as expected because " +
-                        "there's no matched provider model for path " + path + 
", version " + version);
-            }
+        Set<URL> urls = 
repository.lookupRegisteredProviderUrlsWithoutGroup(keyWithoutGroup(path, 
version));
+        if (CollectionUtils.isEmpty(urls)) {
+            throw new IOException("Service " + path + " with version " + 
version + " not found, invocation rejected.");
         } else {
-            List<URL> urls = 
providerModel.getServiceConfig().getExportedUrls();
-            if (CollectionUtils.isNotEmpty(urls)) {
-                URL url = urls.get(0);
+            boolean match = false;
+            for (URL url : urls) {
                 String serializationName = 
url.getParameter(org.apache.dubbo.remoting.Constants.SERIALIZATION_KEY, 
Constants.DEFAULT_REMOTING_SERIALIZATION);
                 Byte localId = SERIALIZATIONNAME_ID_MAP.get(serializationName);
-                if (localId != null && !localId.equals(id)) {
-                    throw new IOException("Unexpected serialization id:" + id 
+ " received from network, please check if the peer send the right id.");
+                if (localId != null && localId.equals(id)) {
+                    match = true;
                 }
             }
+            if(!match) {
+                throw new IOException("Unexpected serialization id:" + id + " 
received from network, please check if the peer send the right id.");
+            }
+        }
+
+    }
+
+    private static String keyWithoutGroup(String interfaceName, String 
version) {
+        if (StringUtils.isEmpty(version)) {
+            return interfaceName + ":0.0.0";
         }
+        return interfaceName + ":" + version;
     }
 }
diff --git 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolSerializationWrapper.java
 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolSerializationWrapper.java
new file mode 100644
index 0000000..7d9722b
--- /dev/null
+++ 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolSerializationWrapper.java
@@ -0,0 +1,63 @@
+/*
+ * 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.rpc.protocol;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.rpc.Exporter;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Protocol;
+import org.apache.dubbo.rpc.ProtocolServer;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
+import java.util.List;
+
+@Activate
+public class ProtocolSerializationWrapper implements Protocol {
+    private Protocol protocol;
+
+    public ProtocolSerializationWrapper(Protocol protocol) {
+        this.protocol = protocol;
+    }
+
+    @Override
+    public int getDefaultPort() {
+        return protocol.getDefaultPort();
+    }
+
+    @Override
+    public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
+        
ApplicationModel.getServiceRepository().registerProviderUrl(invoker.getUrl());
+        return protocol.export(invoker);
+    }
+
+    @Override
+    public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
+        return protocol.refer(type, url);
+    }
+
+    @Override
+    public void destroy() {
+        protocol.destroy();
+    }
+
+    @Override
+    public List<ProtocolServer> getServers() {
+        return protocol.getServers();
+    }
+}
diff --git 
a/dubbo-rpc/dubbo-rpc-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
 
b/dubbo-rpc/dubbo-rpc-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
index 3830dd1..ab69b9c 100644
--- 
a/dubbo-rpc/dubbo-rpc-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
+++ 
b/dubbo-rpc/dubbo-rpc-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
@@ -1,2 +1,3 @@
 listener=org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper
-mock=org.apache.dubbo.rpc.support.MockProtocol
\ No newline at end of file
+mock=org.apache.dubbo.rpc.support.MockProtocol
+serializationwrapper=org.apache.dubbo.rpc.protocol.ProtocolSerializationWrapper
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 7378831..6ef932d 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
@@ -30,6 +30,7 @@ import org.apache.dubbo.remoting.RemotingException;
 import org.apache.dubbo.rpc.Exporter;
 import org.apache.dubbo.rpc.Invocation;
 import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Protocol;
 import org.apache.dubbo.rpc.ProxyFactory;
 import org.apache.dubbo.rpc.RpcInvocation;
 import org.apache.dubbo.rpc.model.ApplicationModel;
@@ -41,6 +42,7 @@ import java.util.Set;
 
 import static 
org.apache.dubbo.common.constants.CommonConstants.CALLBACK_INSTANCES_LIMIT_KEY;
 import static 
org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CALLBACK_INSTANCES;
+import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL;
 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.METHODS_KEY;
@@ -58,7 +60,7 @@ class CallbackServiceCodec {
     private static final Logger logger = 
LoggerFactory.getLogger(CallbackServiceCodec.class);
 
     private static final ProxyFactory PROXY_FACTORY = 
ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
-    private static final DubboProtocol PROTOCOL = 
DubboProtocol.getDubboProtocol();
+    private static final Protocol PROTOCOL = 
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DUBBO_PROTOCOL);
     private static final byte CALLBACK_NONE = 0x0;
     private static final byte CALLBACK_CREATE = 0x1;
     private static final byte CALLBACK_DESTROY = 0x2;
diff --git 
a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClientTest.java
 
b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClientTest.java
index 3341192..7d2c543 100644
--- 
a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClientTest.java
+++ 
b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClientTest.java
@@ -24,6 +24,7 @@ import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.remoting.exchange.ExchangeClient;
 import org.apache.dubbo.rpc.Exporter;
 import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Protocol;
 import org.apache.dubbo.rpc.ProxyFactory;
 import org.apache.dubbo.rpc.protocol.dubbo.support.ProtocolUtils;
 
@@ -47,7 +48,6 @@ import static 
org.apache.dubbo.rpc.protocol.dubbo.Constants.SHARE_CONNECTIONS_KE
 public class ReferenceCountExchangeClientTest {
 
     public static ProxyFactory proxy = 
ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
-    private static DubboProtocol protocol = DubboProtocol.getDubboProtocol();
     Exporter<?> demoExporter;
     Exporter<?> helloExporter;
     Invoker<IDemoService> demoServiceInvoker;
@@ -68,7 +68,7 @@ public class ReferenceCountExchangeClientTest {
     }
 
     public static Invoker<?> referInvoker(Class<?> type, URL url) {
-        return (Invoker<?>) protocol.refer(type, url);
+        return (Invoker<?>) DubboProtocol.getDubboProtocol().refer(type, url);
     }
 
     public static <T> Exporter<T> export(T instance, Class<T> type, String 
url) {
@@ -76,7 +76,7 @@ public class ReferenceCountExchangeClientTest {
     }
 
     public static <T> Exporter<T> export(T instance, Class<T> type, URL url) {
-        return protocol.export(proxy.getInvoker(instance, type, url));
+        return 
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(DubboProtocol.NAME).export(proxy.getInvoker(instance,
 type, url));
     }
 
     @BeforeEach

Reply via email to