From 64a37381e0c1bdaddfd7f1195335b8db9ee6bb88 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 20 Mar 2018 16:32:49 -0400 Subject: [PATCH] INT-4437: Scatter-Gather: reinstate replyChannel JIRA: https://jira.spring.io/browse/INT-4437 The `ScatterGatherHandler` overrides a `replyChannel` header for the scatter message to its internal queue and doesn't reinstate the original `replyChannel` header when producer a gather result message * Rebuild gather result message with population a proper `replyChannel` header from the request message and removing a `gatherResultChannel` header **Cherry-pick to 5.0.3 and 4.3.x** Polishing --- .../integration/scattergather/ScatterGatherHandler.java | 8 ++++++-- .../scattergather/config/ScatterGatherTests-context.xml | 6 ++++-- .../scattergather/config/ScatterGatherTests.java | 4 +++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/scattergather/ScatterGatherHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/scattergather/ScatterGatherHandler.java index 96d0d92f74..87853491bd 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/scattergather/ScatterGatherHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/scattergather/ScatterGatherHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -147,7 +147,11 @@ public class ScatterGatherHandler extends AbstractReplyProducingMessageHandler i Message gatherResult = gatherResultChannel.receive(this.gatherTimeout); if (gatherResult != null) { - return gatherResult; + return getMessageBuilderFactory() + .fromMessage(gatherResult) + .removeHeader(GATHER_RESULT_CHANNEL) + .setHeader(MessageHeaders.REPLY_CHANNEL, requestMessage.getHeaders().getReplyChannel()) + .build(); } return null; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests-context.xml index e50f4df0c1..8dfeca0b08 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests-context.xml @@ -52,12 +52,14 @@ - + - + + + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests.java b/spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests.java index 75b4991660..50d22a7f24 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Artem Bilan + * @author Gary Russell * @since 4.1 */ @ContextConfiguration @@ -81,6 +82,7 @@ public class ScatterGatherTests { @Test public void testGatewayScatterGather() { Message bestQuoteMessage = this.gateway.exchange(new GenericMessage("foo")); + assertNotNull(bestQuoteMessage); Object payload = bestQuoteMessage.getPayload(); assertThat(payload, instanceOf(List.class)); assertThat(((List) payload).size(), greaterThanOrEqualTo(1));