Skip to content
Snippets Groups Projects
Unverified Commit e9ff5f99 authored by squall's avatar squall Committed by GitHub
Browse files

optimize: opt the logic of SpringProxyUtils.findTargetClass(#3155) (#3156)

parent eee0c741
No related branches found
No related tags found
No related merge requests found
......@@ -23,10 +23,9 @@ import java.util.Set;
import io.seata.common.util.CollectionUtils;
import io.seata.rm.tcc.remoting.parser.DubboUtil;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.AdvisedSupport;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.target.EmptyTargetSource;
/**
* Proxy tools base on spring
......@@ -34,9 +33,7 @@ import org.springframework.aop.target.EmptyTargetSource;
* @author zhangsen
*/
public class SpringProxyUtils {
private SpringProxyUtils() {
}
/**
......@@ -47,18 +44,14 @@ public class SpringProxyUtils {
* @throws Exception the exception
*/
public static Class<?> findTargetClass(Object proxy) throws Exception {
if (AopUtils.isAopProxy(proxy)) {
AdvisedSupport advised = getAdvisedSupport(proxy);
if (AopUtils.isJdkDynamicProxy(proxy)) {
TargetSource targetSource = advised.getTargetSource();
return targetSource instanceof EmptyTargetSource ? getFirstInterfaceByAdvised(advised)
: targetSource.getTargetClass();
}
Object target = advised.getTargetSource().getTarget();
return findTargetClass(target);
} else {
return proxy == null ? null : proxy.getClass();
if (proxy == null) {
return null;
}
if (AopUtils.isAopProxy(proxy) && proxy instanceof Advised) {
Object targetObject = ((Advised) proxy).getTargetSource().getTarget();
return findTargetClass(targetObject);
}
return proxy.getClass();
}
public static Class<?>[] findInterfaces(Object proxy) throws Exception {
......@@ -79,15 +72,6 @@ public class SpringProxyUtils {
}
}
private static Class<?> getFirstInterfaceByAdvised(AdvisedSupport advised) {
Class<?>[] interfaces = advised.getProxiedInterfaces();
if (interfaces.length > 0) {
return interfaces[0];
} else {
throw new IllegalStateException("Find the jdk dynamic proxy class that does not implement the interface");
}
}
/**
* Gets advised support.
*
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment