Skip to content

Commit 8daad25

Browse files
LiZhenNetkhanimteyaz
authored andcommitted
Fix telnet can not find method with enum type (apache#2803)
1 parent 52a9320 commit 8daad25

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokeTelnetHandler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.dubbo.rpc.protocol.dubbo.telnet;
1818

1919
import org.apache.dubbo.common.extension.Activate;
20+
import org.apache.dubbo.common.utils.CompatibleTypeUtils;
2021
import org.apache.dubbo.common.utils.PojoUtils;
2122
import org.apache.dubbo.common.utils.ReflectUtils;
2223
import org.apache.dubbo.common.utils.StringUtils;
@@ -75,6 +76,14 @@ private static boolean isMatch(Class<?>[] types, List<Object> args) {
7576
}
7677

7778
if (ReflectUtils.isPrimitive(arg.getClass())) {
79+
if (arg instanceof String && type.isEnum()) {
80+
try {
81+
CompatibleTypeUtils.compatibleTypeConvert(arg, type);
82+
} catch (RuntimeException e) {
83+
return false;
84+
}
85+
continue;
86+
}
7887
if (!ReflectUtils.isPrimitive(type)) {
7988
return false;
8089
}

dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/support/DemoService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public interface DemoService {
4747

4848
Type enumlength(Type... types);
4949

50-
// Type enumlength(Type type);
50+
Type getType(Type type);
5151

5252
String get(CustomArgument arg1);
5353

dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/support/DemoServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public Type enumlength(Type... types) {
7171
return Type.Lower;
7272
return types[0];
7373
}
74-
75-
public Type enumlength(Type type) {
74+
75+
public Type getType(Type type) {
7676
return type;
7777
}
7878

dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokerTelnetHandlerTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ public void testInvokeByPassingNullValue() throws RemotingException {
108108
}
109109
}
110110

111+
@Test
112+
public void testInvokeByPassingEnumValue() throws RemotingException {
113+
mockInvoker = mock(Invoker.class);
114+
given(mockInvoker.getInterface()).willReturn(DemoService.class);
115+
given(mockInvoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:20886/demo"));
116+
given(mockInvoker.invoke(any(Invocation.class))).willReturn(new RpcResult("ok"));
117+
mockChannel = mock(Channel.class);
118+
given(mockChannel.getAttribute("telnet.service")).willReturn(null);
119+
given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555"));
120+
given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886"));
121+
122+
DubboProtocol.getDubboProtocol().export(mockInvoker);
123+
String result = invoke.telnet(mockChannel, "getType(\"High\")");
124+
assertTrue(result.contains("ok"));
125+
}
126+
127+
111128
@SuppressWarnings("unchecked")
112129
@Test
113130
public void testInvokeAutoFindMethod() throws RemotingException {

0 commit comments

Comments
 (0)