From 05d351cf6d52d7ab666d0713b3b1cf3a2ac01a77 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sat, 8 May 2010 19:32:30 +0000 Subject: [PATCH] INT-1133 AbstractReplyProducingMessageHandler no longer copies headers from the request Message into the reply Message IF the return value from the handler implementation is already a Message instance. --- .../gateway/AbstractRemotingOutboundGateway.java | 6 +++++- .../AbstractReplyProducingMessageHandler.java | 13 ++++--------- .../integration/config/TestHandler.java | 7 +++---- .../integration/filter/MessageFilterTests.java | 5 ++--- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/AbstractRemotingOutboundGateway.java b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/AbstractRemotingOutboundGateway.java index 5f21f31b91..bbeb6b8293 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/AbstractRemotingOutboundGateway.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/AbstractRemotingOutboundGateway.java @@ -59,7 +59,11 @@ public abstract class AbstractRemotingOutboundGateway extends AbstractReplyProdu } Message requestMessage = MessageBuilder.fromMessage(message).build(); try { - return this.proxy.exchange(requestMessage); + Message reply = this.proxy.exchange(requestMessage); + if (reply != null) { + reply = MessageBuilder.fromMessage(reply).copyHeadersIfAbsent(message.getHeaders()).build(); + } + return reply; } catch (RemoteAccessException e) { throw new MessageHandlingException(message, "remote failure in Messaging Gateway", e); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java b/org.springframework.integration/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java index 98a6d4af7c..439023b9bc 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java @@ -115,16 +115,11 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa @SuppressWarnings("unchecked") private Message createReplyMessage(Object reply, MessageHeaders requestHeaders) { - MessageBuilder builder = null; - if (reply instanceof MessageBuilder) { - builder = (MessageBuilder) reply; - } - else if (reply instanceof Message) { - builder = MessageBuilder.fromMessage((Message) reply); - } - else { - builder = MessageBuilder.withPayload(reply); + if (reply instanceof Message) { + return (Message) reply; } + MessageBuilder builder = (reply instanceof MessageBuilder) + ? (MessageBuilder) reply : MessageBuilder.withPayload(reply); builder.copyHeadersIfAbsent(requestHeaders); return builder.build(); } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/TestHandler.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/TestHandler.java index 074ef2b573..f6fd5766fb 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/TestHandler.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/TestHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 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. @@ -20,7 +20,6 @@ import java.util.concurrent.CountDownLatch; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.core.Message; -import org.springframework.integration.message.StringMessage; /** * @author Mark Fisher @@ -48,10 +47,10 @@ public class TestHandler { } @ServiceActivator - public Message handle(Message message) { + public String handle(Message message) { this.messageString = message.getPayload().toString(); this.latch.countDown(); - return (this.replyMessageText != null) ? new StringMessage(this.replyMessageText) : null; + return (this.replyMessageText != null) ? this.replyMessageText : null; } public String getMessageString() { diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/filter/MessageFilterTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/filter/MessageFilterTests.java index 7e0a4e3cd4..59bb1d421e 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/filter/MessageFilterTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/filter/MessageFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 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. @@ -18,7 +18,6 @@ package org.springframework.integration.filter; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -51,7 +50,7 @@ public class MessageFilterTests { filter.handleMessage(message); Message received = output.receive(0); assertEquals(message.getPayload(), received.getPayload()); - assertNotSame(message.getHeaders().getId(), received.getHeaders().getId()); + assertEquals(message.getHeaders().getId(), received.getHeaders().getId()); } @Test