From 80ed25ebf308a28d383c119d480061d54873985a Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 16 Oct 2019 15:57:33 -0400 Subject: [PATCH] GH-3079: Use getMostSpecificMethod for SpEL calls (#3082) * GH-3079: Use getMostSpecificMethod for SpEL calls Fixes https://github.com/spring-projects/spring-integration/issues/3079 It turns out that we need to use a *most specific* method for the target to be called reflectively from the SpEL NOTE: We drop a *Method not found* error in case of wrong method source since now we find a right source via `ClassUtils.getMostSpecificMethod()` **Cherry-pick to 5.1.x** * * `@Ignore` `MethodInvokingMessageProcessorTests.testProcessMessageMethodNotFound()` instead of removal --- .../support/MessagingMethodInvokerHelper.java | 4 +++- .../dsl/flows/IntegrationFlowTests.java | 15 ++++++++++++--- .../MethodInvokingMessageProcessorTests.java | 2 ++ 3 files changed, 17 insertions(+), 4 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 7a2d685c8a..6fbdbe06d5 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 @@ -434,7 +434,9 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator StandardEvaluationContext context = getEvaluationContext(false); Class targetType = AopUtils.getTargetClass(this.targetObject); if (this.method != null) { - context.registerMethodFilter(targetType, new FixedMethodFilter(this.method)); + context.registerMethodFilter(targetType, + new FixedMethodFilter( + org.springframework.util.ClassUtils.getMostSpecificMethod(this.method, targetType))); if (this.expectedType != null) { Assert.state(context.getTypeConverter() .canConvert(TypeDescriptor.valueOf((this.method).getReturnType()), this.expectedType), diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java index cc5be97d24..01040704a8 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java @@ -83,6 +83,7 @@ import org.springframework.integration.store.MessageStore; import org.springframework.integration.store.SimpleMessageStore; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.support.MutableMessageBuilder; +import org.springframework.integration.transformer.GenericTransformer; import org.springframework.integration.transformer.PayloadSerializingTransformer; import org.springframework.integration.util.NoBeansOverrideAnnotationConfigContextLoader; import org.springframework.messaging.Message; @@ -386,10 +387,10 @@ public class IntegrationFlowTests { assertNotNull(out); assertEquals("bar", out.getPayload()); - this.tappedChannel5.send(new GenericMessage<>("foo")); + this.tappedChannel5.send(new GenericMessage<>("")); out = this.wireTapSubflowResult.receive(10000); assertNotNull(out); - assertEquals("FOO", out.getPayload()); + assertEquals("", out.getPayload()); } @Autowired @@ -724,7 +725,15 @@ public class IntegrationFlowTests { public IntegrationFlow wireTapFlow5() { return f -> f .wireTap(sf -> sf - .transform(String::toUpperCase) + .transform(// Must not be lambda for SpEL fallback behavior on empty payload + new GenericTransformer() { + + @Override + public String transform(String source) { + return source.toUpperCase(); + } + + }) .channel(MessageChannels.queue("wireTapSubflowResult"))) .channel("nullChannel"); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java index eb66438fb6..24d3ac8708 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java @@ -51,6 +51,7 @@ import org.apache.commons.logging.LogFactory; import org.hamcrest.Description; import org.hamcrest.Matchers; import org.hamcrest.TypeSafeMatcher; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -460,6 +461,7 @@ public class MethodInvokingMessageProcessorTests { } @Test + @Ignore("See https://github.com/spring-projects/spring-framework/issues/23824") public void testProcessMessageMethodNotFound() throws Exception { expected.expect(new ExceptionCauseMatcher(SpelEvaluationException.class)); TestDifferentErrorService service = new TestDifferentErrorService();