Skip to content

Commit

Permalink
make telnet config work again (apache#2925)
Browse files Browse the repository at this point in the history
  • Loading branch information
kexianjun authored and khanimteyaz committed Dec 17, 2018
1 parent 72803ba commit 1d46c45
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ public class Constants {

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

public static final String TELNET = "telnet";
/*
* private Constants(){ }
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,14 +51,20 @@ public String telnet(Channel channel, String message) throws RemotingException {
}
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: ");
Expand All @@ -72,4 +80,21 @@ public String telnet(Channel channel, String message) throws RemotingException {
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;
}

}

0 comments on commit 1d46c45

Please sign in to comment.