Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix telnet can not find method with enum type #2803

Merged
merged 1 commit into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
LiZhenNet marked this conversation as resolved.
Show resolved Hide resolved
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