Fix deprecations according latest SF

Use as much as possible SF API for proxies and their classes
This commit is contained in:
Artem Bilan
2019-03-29 13:12:38 -04:00
committed by Gary Russell
parent 62f576b64f
commit ae2be1bb23
2 changed files with 17 additions and 32 deletions

View File

@@ -41,6 +41,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanExpressionContext;
@@ -978,23 +979,20 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator im
}
private Class<?> getTargetClass(Object targetObject) {
Class<?> targetClass = targetObject.getClass();
if (AopUtils.isAopProxy(targetObject)) {
targetClass = AopUtils.getTargetClass(targetObject);
if (targetClass == targetObject.getClass()) {
try {
// Maybe a proxy with no target - e.g. gateway
Class<?>[] interfaces = ((Advised) targetObject).getProxiedInterfaces();
if (interfaces.length == 1) {
targetClass = interfaces[0];
}
}
catch (Exception e) {
LOGGER.debug("Exception trying to extract interface", e);
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(targetObject);
if (targetClass == targetObject.getClass()) {
try {
// Maybe a proxy with no target - e.g. gateway
Class<?>[] interfaces = ((Advised) targetObject).getProxiedInterfaces();
if (interfaces.length == 1) {
targetClass = interfaces[0];
}
}
catch (Exception e) {
LOGGER.debug("Exception trying to extract interface", e);
}
}
else if (ClassUtils.isCglibProxyClass(targetClass) || targetClass.getSimpleName().contains("$MockitoMock$")) {
if (targetClass.getSimpleName().contains("$MockitoMock$")) {
Class<?> superClass = targetObject.getClass().getSuperclass();
if (!Object.class.equals(superClass)) {
targetClass = superClass;

View File

@@ -21,7 +21,7 @@ import java.lang.reflect.Method;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.annotation.EndpointId;
@@ -30,7 +30,6 @@ import org.springframework.messaging.MessagingException;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@@ -42,6 +41,7 @@ import org.springframework.util.StringUtils;
* @author Gunnar Hillert
* @author Soby Chacko
* @author Artem Bilan
*
* @since 4.0
*/
public final class MessagingAnnotationUtils {
@@ -77,9 +77,9 @@ public final class MessagingAnnotationUtils {
}
public static Method findAnnotatedMethod(Object target, final Class<? extends Annotation> annotationType) {
final AtomicReference<Method> reference = new AtomicReference<Method>();
final AtomicReference<Method> reference = new AtomicReference<>();
ReflectionUtils.doWithMethods(getTargetClass(target),
ReflectionUtils.doWithMethods(AopProxyUtils.ultimateTargetClass(target),
method -> reference.compareAndSet(null, method),
method -> ReflectionUtils.USER_DECLARED_METHODS.matches(method) &&
AnnotatedElementUtils.isAnnotated(method, annotationType.getName()));
@@ -129,20 +129,7 @@ public final class MessagingAnnotationUtils {
return endpointId != null ? endpointId.value() : null;
}
private static Class<?> getTargetClass(Object targetObject) {
Class<?> targetClass = targetObject.getClass();
if (AopUtils.isAopProxy(targetObject)) {
targetClass = AopUtils.getTargetClass(targetObject);
}
else if (ClassUtils.isCglibProxyClass(targetClass)) {
Class<?> superClass = targetObject.getClass().getSuperclass();
if (!Object.class.equals(superClass)) {
targetClass = superClass;
}
}
return targetClass;
private MessagingAnnotationUtils() {
}
private MessagingAnnotationUtils() { }
}