1717package org .apache .dubbo .remoting .telnet .support ;
1818
1919import org .apache .dubbo .common .Constants ;
20+ import org .apache .dubbo .common .URL ;
2021import org .apache .dubbo .common .extension .ExtensionLoader ;
22+ import org .apache .dubbo .common .utils .StringUtils ;
2123import org .apache .dubbo .remoting .Channel ;
2224import org .apache .dubbo .remoting .RemotingException ;
2325import 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