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

liujun pushed a commit to branch 2.6.x
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git


The following commit(s) were added to refs/heads/2.6.x by this push:
     new 0f9cef9  Merge pull request #3511, apply #2925 to branch 2.6.x (to 
make telnet config work again).
0f9cef9 is described below

commit 0f9cef935de04a437d7ffe910c55c600591611cd
Author: min <[email protected]>
AuthorDate: Wed Feb 20 15:32:27 2019 +0800

    Merge pull request #3511, apply #2925 to branch 2.6.x (to make telnet 
config work again).
---
 .../java/com/alibaba/dubbo/common/Constants.java   |  2 ++
 .../telnet/support/TelnetHandlerAdapter.java       | 39 ++++++++++++++++++----
 2 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/Constants.java 
b/dubbo-common/src/main/java/com/alibaba/dubbo/common/Constants.java
index cedb20b..a993c3f 100644
--- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/Constants.java
+++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/Constants.java
@@ -641,6 +641,8 @@ public class Constants {
 
     public static final String FORCE_USE_TAG = "dubbo.force.tag";
 
+    public static final String TELNET = "telnet";
+
     /*
      * private Constants(){ }
      */
diff --git 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java
 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java
index 478ce0f..f42d81f 100644
--- 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java
+++ 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java
@@ -17,7 +17,9 @@
 package com.alibaba.dubbo.remoting.telnet.support;
 
 import com.alibaba.dubbo.common.Constants;
+import com.alibaba.dubbo.common.URL;
 import com.alibaba.dubbo.common.extension.ExtensionLoader;
+import com.alibaba.dubbo.common.utils.StringUtils;
 import com.alibaba.dubbo.remoting.Channel;
 import com.alibaba.dubbo.remoting.RemotingException;
 import com.alibaba.dubbo.remoting.telnet.TelnetHandler;
@@ -49,14 +51,20 @@ public class TelnetHandlerAdapter extends 
ChannelHandlerAdapter implements Telne
         }
         if (command.length() > 0) {
             if (extensionLoader.hasExtension(command)) {
-                try {
-                    String result = 
extensionLoader.getExtension(command).telnet(channel, message);
-                    if (result == null) {
-                        return null;
+                if (commandEnabled(channel.getUrl(), command)) {
+                    try {
+                        String result = 
extensionLoader.getExtension(command).telnet(channel, message);
+                        if (result == null) {
+                            return null;
+                        }
+                        buf.append(result);
+                    } catch (Throwable t) {
+                        buf.append(t.getMessage());
                     }
-                    buf.append(result);
-                } catch (Throwable t) {
-                    buf.append(t.getMessage());
+                } else {
+                    buf.append("Command: ");
+                    buf.append(command);
+                    buf.append(" disabled");
                 }
             } else {
                 buf.append("Unsupported command: ");
@@ -72,4 +80,21 @@ public class TelnetHandlerAdapter extends 
ChannelHandlerAdapter implements Telne
         return buf.toString();
     }
 
+    private boolean commandEnabled(URL url, String command) {
+        boolean commandEnable = false;
+        String supportCommands = url.getParameter(Constants.TELNET);
+        if (StringUtils.isEmpty(supportCommands)) {
+            commandEnable = true;
+        } else {
+            String[] commands = 
Constants.COMMA_SPLIT_PATTERN.split(supportCommands);
+            for (String c : commands) {
+                if (command.equals(c)) {
+                    commandEnable = true;
+                    break;
+                }
+            }
+        }
+        return commandEnable;
+    }
+
 }

Reply via email to