Merge pull request #6 from qixiaobo/fix-group-for-register master
authormin <z82507200@gmail.com>
Thu, 1 Aug 2019 09:04:45 +0000 (17:04 +0800)
committerGitHub <noreply@github.com>
Thu, 1 Aug 2019 09:04:45 +0000 (17:04 +0800)
dubbo group not set for reference

src/main/java/org/apache/dubbo/proxy/service/GenericInvoke.java
src/main/java/org/apache/dubbo/proxy/worker/RequestWorker.java

index 8c600b0d6a4036ad7a69e9e351c1cd83623e22e9..eccdcd885f23708115f97cecf275d61a19796d0f 100644 (file)
@@ -24,7 +24,7 @@ public class GenericInvoke {
         GenericInvoke.registry = registry;
     }
 
-    public static void init() {
+    private static void init() {
         RegistryConfig registryConfig = new RegistryConfig();
         registryConfig.setAddress(registry.getUrl().getProtocol() + "://" + registry.getUrl().getAddress());
         registryConfig.setGroup(registry.getUrl().getParameter(org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY));
@@ -33,7 +33,7 @@ public class GenericInvoke {
         applicationConfig.setRegistry(registryConfig);
     }
 
-    private static ConcurrentHashMap<String, ReferenceConfig> cachedConfig = new ConcurrentHashMap<>();
+    private static ConcurrentHashMap<String, ReferenceConfig<GenericService>> cachedConfig = new ConcurrentHashMap<>();
     private static Logger logger = LoggerFactory.getLogger(GenericInvoke.class);
 
     public static Object genericCall(String interfaceName, String group,
@@ -42,15 +42,15 @@ public class GenericInvoke {
         if (init.compareAndSet(false, true)) {
             init();
         }
-        ReferenceConfig<GenericService> reference = null;
+        ReferenceConfig<GenericService> reference;
         reference = addNewReference(interfaceName, group, version);
 
         try {
             GenericService svc = reference.get();
-            logger.info("hsf generic invoke, service is {}, method is {} , paramTypes is {} , paramObjs is {} , svc is {}.", interfaceName
+            logger.info("dubbo generic invoke, service is {}, method is {} , paramTypes is {} , paramObjs is {} , svc" +
+                            " is {}.", interfaceName
                     , methodName,paramTypes,paramObjs,svc);
-            Object result = svc.$invoke(methodName, paramTypes, paramObjs);
-            return result;
+            return svc.$invoke(methodName, paramTypes, paramObjs);
         } catch (Exception e) {
             logger.error("Generic invoke failed",e);
             if (e instanceof RpcException) {
@@ -72,9 +72,9 @@ public class GenericInvoke {
         }
     }
 
-    private static ReferenceConfig addNewReference(String interfaceName,
-                                                     String group, String version) {
-        ReferenceConfig reference;
+    private static ReferenceConfig<GenericService> addNewReference(String interfaceName,
+                                                                   String group, String version) {
+        ReferenceConfig<GenericService> reference;
         String cachedKey = interfaceName + group + version;
         reference = cachedConfig.get(cachedKey);
         if (reference == null) {
@@ -90,8 +90,8 @@ public class GenericInvoke {
         return reference;
     }
 
-    private static ReferenceConfig initReference(String interfaceName, String group,
-                                                String version) {
+    private static ReferenceConfig<GenericService> initReference(String interfaceName, String group,
+                                                                 String version) {
         ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
         reference.setGeneric(true);
         reference.setApplication(applicationConfig);
index 60262a70eec8cbd35ec898d62c85f607dcd0dce5..cc89b83b0476658d1d55a1e0bf76843c8478252f 100644 (file)
@@ -1,6 +1,7 @@
 package org.apache.dubbo.proxy.worker;
 
 import com.alibaba.fastjson.JSON;
+
 import org.apache.dubbo.proxy.dao.ServiceDefinition;
 import org.apache.dubbo.proxy.dao.ServiceMapping;
 import org.apache.dubbo.proxy.metadata.MetadataCollector;
@@ -33,7 +34,7 @@ import static io.netty.handler.codec.http.HttpResponseStatus.OK;
 import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
 
 
-public class RequestWorker implements Runnable{
+public class RequestWorker implements Runnable {
 
     private ServiceDefinition serviceDefinition;
     private ChannelHandlerContext ctx;
@@ -60,7 +61,7 @@ public class RequestWorker implements Runnable{
         String interfaze = Tool.getInterface(serviceID);
         String group = Tool.getGroup(serviceID);
         String version = Tool.getVersion(serviceID);
-        if (serviceDefinition.getParamTypes() == null) {
+        if (serviceDefinition.getParamTypes() == null && serviceDefinition.getParamValues() != null) {
             String[] types = getTypesFromMetadata(serviceDefinition.getApplication(), interfaze, group, version,
                     serviceDefinition.getMethodName(), serviceDefinition.getParamValues().length);
             serviceDefinition.setParamTypes(types);
@@ -103,7 +104,7 @@ public class RequestWorker implements Runnable{
             Set<Cookie> cookies = ServerCookieDecoder.STRICT.decode(cookieString);
             if (!cookies.isEmpty()) {
                 // Reset the cookies if necessary.
-                for (Cookie cookie: cookies) {
+                for (Cookie cookie : cookies) {
                     response.headers().add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie));
                 }
             }
@@ -119,7 +120,7 @@ public class RequestWorker implements Runnable{
         MetadataIdentifier identifier = new MetadataIdentifier(interfaze, version, group, Constants.PROVIDER_SIDE, application);
         String metadata = metadataCollector.getProviderMetaData(identifier);
         FullServiceDefinition serviceDefinition = JSON.parseObject(metadata, FullServiceDefinition.class);
-        List<MethodDefinition> methods  = serviceDefinition.getMethods();
+        List<MethodDefinition> methods = serviceDefinition.getMethods();
         if (methods != null) {
             for (MethodDefinition m : methods) {
                 if (Tool.sameMethod(m, methodName, paramLen)) {