This is an automated email from the ASF dual-hosted git repository.
iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new fe456d9 make telnet config work again (#2925)
fe456d9 is described below
commit fe456d9661947b1e0633a59b98a12d1ce8d4a152
Author: kexianjun <[email protected]>
AuthorDate: Mon Dec 10 13:13:22 2018 +0800
make telnet config work again (#2925)
---
.../java/org/apache/dubbo/common/Constants.java | 1 +
.../telnet/support/TelnetHandlerAdapter.java | 39 ++++++++++++++++++----
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
index 18ad19f..9265287 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
@@ -665,6 +665,7 @@ public class Constants {
public static final String REQUEST_TAG_KEY = "request.tag";
+ public static final String TELNET = "telnet";
/*
* private Constants(){ }
*/
diff --git
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java
index 580238b..a5ceda8 100644
---
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java
+++
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java
@@ -17,7 +17,9 @@
package org.apache.dubbo.remoting.telnet.support;
import org.apache.dubbo.common.Constants;
+import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.RemotingException;
import org.apache.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;
+ }
+
}