From ae2be1bb23e0a03d7ebd59412e69001cad940b7e Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 29 Mar 2019 13:12:38 -0400 Subject: [PATCH] Fix deprecations according latest SF Use as much as possible SF API for proxies and their classes --- .../support/MessagingMethodInvokerHelper.java | 26 +++++++++---------- .../util/MessagingAnnotationUtils.java | 23 ++++------------ 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java index dfb2543458..dc48004a83 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java @@ -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; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingAnnotationUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingAnnotationUtils.java index d6d6c77974..92bec5d1f7 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingAnnotationUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingAnnotationUtils.java @@ -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 annotationType) { - final AtomicReference reference = new AtomicReference(); + final AtomicReference 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() { } - }