Skip to content

Commit

Permalink
Fix telnet can not find method with enum type (apache#2803)
Browse files Browse the repository at this point in the history
  • Loading branch information
LiZhenNet authored and khanimteyaz committed Dec 17, 2018
1 parent 52a9320 commit 8daad25
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.rpc.protocol.dubbo.telnet;

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

if (ReflectUtils.isPrimitive(arg.getClass())) {
if (arg instanceof String && type.isEnum()) {
try {
CompatibleTypeUtils.compatibleTypeConvert(arg, type);
} catch (RuntimeException e) {
return false;
}
continue;
}
if (!ReflectUtils.isPrimitive(type)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface DemoService {

Type enumlength(Type... types);

// Type enumlength(Type type);
Type getType(Type type);

String get(CustomArgument arg1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public Type enumlength(Type... types) {
return Type.Lower;
return types[0];
}

public Type enumlength(Type type) {
public Type getType(Type type) {
return type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ public void testInvokeByPassingNullValue() throws RemotingException {
}
}

@Test
public void testInvokeByPassingEnumValue() throws RemotingException {
mockInvoker = mock(Invoker.class);
given(mockInvoker.getInterface()).willReturn(DemoService.class);
given(mockInvoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:20886/demo"));
given(mockInvoker.invoke(any(Invocation.class))).willReturn(new RpcResult("ok"));
mockChannel = mock(Channel.class);
given(mockChannel.getAttribute("telnet.service")).willReturn(null);
given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555"));
given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886"));

DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = invoke.telnet(mockChannel, "getType(\"High\")");
assertTrue(result.contains("ok"));
}


@SuppressWarnings("unchecked")
@Test
public void testInvokeAutoFindMethod() throws RemotingException {
Expand Down

0 comments on commit 8daad25

Please sign in to comment.