Skip to content

Commit fe456d9

Browse files
kexianjunbeiwei30
authored andcommitted
make telnet config work again (#2925)
1 parent 3a05378 commit fe456d9

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ public class Constants {
665665

666666
public static final String REQUEST_TAG_KEY = "request.tag";
667667

668+
public static final String TELNET = "telnet";
668669
/*
669670
* private Constants(){ }
670671
*/

dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package org.apache.dubbo.remoting.telnet.support;
1818

1919
import org.apache.dubbo.common.Constants;
20+
import org.apache.dubbo.common.URL;
2021
import org.apache.dubbo.common.extension.ExtensionLoader;
22+
import org.apache.dubbo.common.utils.StringUtils;
2123
import org.apache.dubbo.remoting.Channel;
2224
import org.apache.dubbo.remoting.RemotingException;
2325
import org.apache.dubbo.remoting.telnet.TelnetHandler;
@@ -49,14 +51,20 @@ public String telnet(Channel channel, String message) throws RemotingException {
4951
}
5052
if (command.length() > 0) {
5153
if (extensionLoader.hasExtension(command)) {
52-
try {
53-
String result = extensionLoader.getExtension(command).telnet(channel, message);
54-
if (result == null) {
55-
return null;
54+
if (commandEnabled(channel.getUrl(), command)) {
55+
try {
56+
String result = extensionLoader.getExtension(command).telnet(channel, message);
57+
if (result == null) {
58+
return null;
59+
}
60+
buf.append(result);
61+
} catch (Throwable t) {
62+
buf.append(t.getMessage());
5663
}
57-
buf.append(result);
58-
} catch (Throwable t) {
59-
buf.append(t.getMessage());
64+
} else {
65+
buf.append("Command: ");
66+
buf.append(command);
67+
buf.append(" disabled");
6068
}
6169
} else {
6270
buf.append("Unsupported command: ");
@@ -72,4 +80,21 @@ public String telnet(Channel channel, String message) throws RemotingException {
7280
return buf.toString();
7381
}
7482

83+
private boolean commandEnabled(URL url, String command) {
84+
boolean commandEnable = false;
85+
String supportCommands = url.getParameter(Constants.TELNET);
86+
if (StringUtils.isEmpty(supportCommands)) {
87+
commandEnable = true;
88+
} else {
89+
String[] commands = Constants.COMMA_SPLIT_PATTERN.split(supportCommands);
90+
for (String c : commands) {
91+
if (command.equals(c)) {
92+
commandEnable = true;
93+
break;
94+
}
95+
}
96+
}
97+
return commandEnable;
98+
}
99+
75100
}

0 commit comments

Comments
 (0)