Skip to content

Commit ae2be1b

Browse files
artembilangaryrussell
authored andcommitted
Fix deprecations according latest SF
Use as much as possible SF API for proxies and their classes
1 parent 62f576b commit ae2be1b

File tree

2 files changed

+17
-32
lines changed

2 files changed

+17
-32
lines changed

spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java

+12-14
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.commons.logging.LogFactory;
4242

4343
import org.springframework.aop.framework.Advised;
44+
import org.springframework.aop.framework.AopProxyUtils;
4445
import org.springframework.aop.support.AopUtils;
4546
import org.springframework.beans.factory.BeanFactory;
4647
import org.springframework.beans.factory.config.BeanExpressionContext;
@@ -978,23 +979,20 @@ private String resolve(String value) {
978979
}
979980

980981
private Class<?> getTargetClass(Object targetObject) {
981-
Class<?> targetClass = targetObject.getClass();
982-
if (AopUtils.isAopProxy(targetObject)) {
983-
targetClass = AopUtils.getTargetClass(targetObject);
984-
if (targetClass == targetObject.getClass()) {
985-
try {
986-
// Maybe a proxy with no target - e.g. gateway
987-
Class<?>[] interfaces = ((Advised) targetObject).getProxiedInterfaces();
988-
if (interfaces.length == 1) {
989-
targetClass = interfaces[0];
990-
}
991-
}
992-
catch (Exception e) {
993-
LOGGER.debug("Exception trying to extract interface", e);
982+
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(targetObject);
983+
if (targetClass == targetObject.getClass()) {
984+
try {
985+
// Maybe a proxy with no target - e.g. gateway
986+
Class<?>[] interfaces = ((Advised) targetObject).getProxiedInterfaces();
987+
if (interfaces.length == 1) {
988+
targetClass = interfaces[0];
994989
}
995990
}
991+
catch (Exception e) {
992+
LOGGER.debug("Exception trying to extract interface", e);
993+
}
996994
}
997-
else if (ClassUtils.isCglibProxyClass(targetClass) || targetClass.getSimpleName().contains("$MockitoMock$")) {
995+
if (targetClass.getSimpleName().contains("$MockitoMock$")) {
998996
Class<?> superClass = targetObject.getClass().getSuperclass();
999997
if (!Object.class.equals(superClass)) {
1000998
targetClass = superClass;

spring-integration-core/src/main/java/org/springframework/integration/util/MessagingAnnotationUtils.java

+5-18
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.List;
2222
import java.util.concurrent.atomic.AtomicReference;
2323

24-
import org.springframework.aop.support.AopUtils;
24+
import org.springframework.aop.framework.AopProxyUtils;
2525
import org.springframework.core.annotation.AnnotatedElementUtils;
2626
import org.springframework.core.annotation.AnnotationUtils;
2727
import org.springframework.integration.annotation.EndpointId;
@@ -30,7 +30,6 @@
3030
import org.springframework.messaging.handler.annotation.Header;
3131
import org.springframework.messaging.handler.annotation.Headers;
3232
import org.springframework.messaging.handler.annotation.Payload;
33-
import org.springframework.util.ClassUtils;
3433
import org.springframework.util.ReflectionUtils;
3534
import org.springframework.util.StringUtils;
3635

@@ -42,6 +41,7 @@
4241
* @author Gunnar Hillert
4342
* @author Soby Chacko
4443
* @author Artem Bilan
44+
*
4545
* @since 4.0
4646
*/
4747
public final class MessagingAnnotationUtils {
@@ -77,9 +77,9 @@ public static boolean hasValue(Object value) {
7777
}
7878

7979
public static Method findAnnotatedMethod(Object target, final Class<? extends Annotation> annotationType) {
80-
final AtomicReference<Method> reference = new AtomicReference<Method>();
80+
final AtomicReference<Method> reference = new AtomicReference<>();
8181

82-
ReflectionUtils.doWithMethods(getTargetClass(target),
82+
ReflectionUtils.doWithMethods(AopProxyUtils.ultimateTargetClass(target),
8383
method -> reference.compareAndSet(null, method),
8484
method -> ReflectionUtils.USER_DECLARED_METHODS.matches(method) &&
8585
AnnotatedElementUtils.isAnnotated(method, annotationType.getName()));
@@ -129,20 +129,7 @@ public static String endpointIdValue(Method method) {
129129
return endpointId != null ? endpointId.value() : null;
130130
}
131131

132-
private static Class<?> getTargetClass(Object targetObject) {
133-
Class<?> targetClass = targetObject.getClass();
134-
if (AopUtils.isAopProxy(targetObject)) {
135-
targetClass = AopUtils.getTargetClass(targetObject);
136-
}
137-
else if (ClassUtils.isCglibProxyClass(targetClass)) {
138-
Class<?> superClass = targetObject.getClass().getSuperclass();
139-
if (!Object.class.equals(superClass)) {
140-
targetClass = superClass;
141-
}
142-
}
143-
return targetClass;
132+
private MessagingAnnotationUtils() {
144133
}
145134

146-
private MessagingAnnotationUtils() { }
147-
148135
}

0 commit comments

Comments
 (0)