From 4d2e00d6c81def7e6822a92bb43d8d0dc17c3b3f Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 31 May 2018 12:23:26 -0400 Subject: [PATCH] Fix LambdaMessageProcessor for Map payload JIRA: https://jira.spring.io/browse/INT-4478 When we use a `GenericHandler` and an incoming payload is a `Map`, we copy it into both arguments into the `Object` for the payload and `Map` for the headers. This way we lose headers in the target lambda * Check a size of arguments on the target lambda and don't set a payload into the `Map` argument if we have more than 1 arguments **Cherry-pick to 5.0.x** --- .../integration/handler/LambdaMessageProcessor.java | 2 +- .../integration/webflux/dsl/WebFluxDslTests.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/LambdaMessageProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/LambdaMessageProcessor.java index 81f0e6e9cb..0deef01ef0 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/LambdaMessageProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/LambdaMessageProcessor.java @@ -100,7 +100,7 @@ public class LambdaMessageProcessor implements MessageProcessor, BeanFac args[i] = message; } else if (Map.class.isAssignableFrom(parameterType)) { - if (message.getPayload() instanceof Map) { + if (message.getPayload() instanceof Map && this.parameterTypes.length == 1) { args[i] = message.getPayload(); } else { diff --git a/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/dsl/WebFluxDslTests.java b/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/dsl/WebFluxDslTests.java index 741407fe7a..9e8b61d7a8 100644 --- a/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/dsl/WebFluxDslTests.java +++ b/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/dsl/WebFluxDslTests.java @@ -299,8 +299,10 @@ public class WebFluxDslTests { public IntegrationFlow sseFlow() { return IntegrationFlows .from(WebFlux.inboundGateway("/sse") - .requestMapping(m -> m.produces(MediaType.TEXT_EVENT_STREAM_VALUE))) - .handle((p, h) -> Flux.just("foo", "bar", "baz")) + .requestMapping(m -> m.produces(MediaType.TEXT_EVENT_STREAM_VALUE)) + .mappedResponseHeaders("*")) + .enrichHeaders(Collections.singletonMap("aHeader", new String[] { "foo", "bar", "baz" })) + .handle((p, h) -> Flux.fromArray((String[]) h.get("aHeader"))) .get(); }