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

interfaces参数数组下标bug,javassist代理支持除声明接口外的接口调用支持 #200

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -39,7 +39,7 @@ public <T> T getProxy(Invoker<T> invoker) throws RpcException {
interfaces[0] = invoker.getInterface();
interfaces[1] = EchoService.class;
for (int i = 0; i < types.length; i ++) {
interfaces[i + 1] = ReflectUtils.forName(types[i]);
interfaces[i + 2] = ReflectUtils.forName(types[i]);
}
}
}
Expand All @@ -51,4 +51,4 @@ public <T> T getProxy(Invoker<T> invoker) throws RpcException {

public abstract <T> T getProxy(Invoker<T> invoker, Class<?>[] types);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
*/
package com.alibaba.dubbo.rpc.proxy.javassist;

import java.lang.reflect.Method;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.bytecode.Proxy;
import com.alibaba.dubbo.common.bytecode.Wrapper;
import com.alibaba.dubbo.common.utils.ReflectUtils;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.proxy.AbstractProxyFactory;
import com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker;
Expand All @@ -37,13 +41,51 @@ public <T> T getProxy(Invoker<T> invoker, Class<?>[] interfaces) {

public <T> Invoker<T> getInvoker(T proxy, Class<T> type, URL url) {
// TODO Wrapper类不能正确处理带$的类名
final Wrapper wrapper = Wrapper.getWrapper(proxy.getClass().getName().indexOf('$') < 0 ? proxy.getClass() : type);
final Wrapper wrapper = Wrapper.getWrapper(proxy.getClass().getName().indexOf('$') < 0 ? proxy.getClass() : type);
final String config = url.getParameter("interfaces");
return new AbstractProxyInvoker<T>(proxy, type, url) {
@Override
protected Object doInvoke(T proxy, String methodName,
Class<?>[] parameterTypes,
Object[] arguments) throws Throwable {
return wrapper.invokeMethod(proxy, methodName, parameterTypes, arguments);
Object[] arguments) throws Throwable {
Object obj = null;
Exception exception = null;

try {
obj = wrapper.invokeMethod(proxy, methodName, parameterTypes, arguments);
return obj;
} catch (Exception e) {
exception = e;
}

if (obj == null ){

if (config != null && config.length() > 0) {
String[] types = Constants.COMMA_SPLIT_PATTERN.split(config);
if (types != null && types.length > 0) {

for (int i = 0; i < types.length; i ++) {
Class<?> interfaces = ReflectUtils.forName(types[i]);
try {
if (methodName.equals("getInvocationHandler")) {
Method method = interfaces.getMethod(methodName, parameterTypes);
return method.invoke(proxy, arguments);
}
} catch (NoSuchMethodException e) {

} catch (SecurityException e){

}
}
}
}
}

if (obj == null && exception != null ) {
throw exception;
}

return obj;
}
};
}
Expand Down