Skip to content

Commit 97f7733

Browse files
committed
GH-3079: Use getMostSpecificMethod for SpEL calls
Fixes #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**
1 parent 911cdc8 commit 97f7733

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ private void prepareEvaluationContext() {
417417
StandardEvaluationContext context = getEvaluationContext();
418418
Class<?> targetType = AopUtils.getTargetClass(this.targetObject);
419419
if (this.method != null) {
420-
context.registerMethodFilter(targetType, new FixedMethodFilter(this.method));
420+
context.registerMethodFilter(targetType,
421+
new FixedMethodFilter(ClassUtils.getMostSpecificMethod(this.method, targetType)));
421422
if (this.expectedType != null) {
422423
Assert.state(context.getTypeConverter()
423424
.canConvert(TypeDescriptor.valueOf((this.method).getReturnType()), this.expectedType),

spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import org.springframework.integration.store.SimpleMessageStore;
7575
import org.springframework.integration.support.MessageBuilder;
7676
import org.springframework.integration.support.MutableMessageBuilder;
77+
import org.springframework.integration.transformer.GenericTransformer;
7778
import org.springframework.integration.transformer.PayloadSerializingTransformer;
7879
import org.springframework.integration.util.NoBeansOverrideAnnotationConfigContextLoader;
7980
import org.springframework.messaging.Message;
@@ -362,10 +363,10 @@ public void testWireTap() {
362363
assertThat(out).isNotNull();
363364
assertThat(out.getPayload()).isEqualTo("bar");
364365

365-
this.tappedChannel5.send(new GenericMessage<>("foo"));
366+
this.tappedChannel5.send(new GenericMessage<>(""));
366367
out = this.wireTapSubflowResult.receive(10000);
367368
assertThat(out).isNotNull();
368-
assertThat(out.getPayload()).isEqualTo("FOO");
369+
assertThat(out.getPayload()).isEqualTo("");
369370
}
370371

371372
@Autowired
@@ -700,7 +701,15 @@ public IntegrationFlow wireTapFlow4() {
700701
public IntegrationFlow wireTapFlow5() {
701702
return f -> f
702703
.wireTap(sf -> sf
703-
.<String, String>transform(String::toUpperCase)
704+
.transform(// Must not be lambda for SpEL fallback behavior on empty payload
705+
new GenericTransformer<String, String>() {
706+
707+
@Override
708+
public String transform(String source) {
709+
return source.toUpperCase();
710+
}
711+
712+
})
704713
.channel(MessageChannels.queue("wireTapSubflowResult")))
705714
.channel("nullChannel");
706715
}

spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import org.springframework.core.MethodParameter;
5656
import org.springframework.expression.Expression;
5757
import org.springframework.expression.spel.SpelCompilerMode;
58-
import org.springframework.expression.spel.SpelEvaluationException;
5958
import org.springframework.expression.spel.SpelParserConfiguration;
6059
import org.springframework.expression.spel.standard.SpelExpressionParser;
6160
import org.springframework.expression.spel.support.StandardEvaluationContext;
@@ -449,18 +448,6 @@ public void testProcessMessageCheckedException() throws Exception {
449448
.withRootCauseInstanceOf(CheckedException.class);
450449
}
451450

452-
@Test
453-
public void testProcessMessageMethodNotFound() throws Exception {
454-
TestDifferentErrorService service = new TestDifferentErrorService();
455-
Method method = TestErrorService.class.getMethod("checked", String.class);
456-
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
457-
processor.setUseSpelInvoker(true);
458-
processor.setBeanFactory(mock(BeanFactory.class));
459-
assertThatExceptionOfType(MessageHandlingException.class)
460-
.isThrownBy(() -> processor.processMessage(new GenericMessage<>("foo")))
461-
.withCauseInstanceOf(SpelEvaluationException.class);
462-
}
463-
464451
@Test
465452
public void messageAndHeaderWithAnnotatedMethod() throws Exception {
466453
AnnotatedTestService service = new AnnotatedTestService();

0 commit comments

Comments
 (0)