From afb53e166d8483fc10c902a942e02465cfb2c6de Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Thu, 24 Dec 2009 02:37:54 +0000 Subject: [PATCH] INT-851 Added method name to the "name" property of the MessageHistory.Event for a gateway. --- .../integration/core/MessageHistory.java | 2 +- .../handler/ArgumentArrayMessageMapper.java | 7 ++++- .../gateway/GatewayProxyFactoryBeanTests.java | 31 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/core/MessageHistory.java b/org.springframework.integration/src/main/java/org/springframework/integration/core/MessageHistory.java index 208abbb819..47de477007 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/core/MessageHistory.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/core/MessageHistory.java @@ -45,7 +45,7 @@ public class MessageHistory implements Iterable, Serializa public static enum ComponentType { - channel, endpoint; + channel, endpoint, gateway; } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/handler/ArgumentArrayMessageMapper.java b/org.springframework.integration/src/main/java/org/springframework/integration/handler/ArgumentArrayMessageMapper.java index 1c1d560029..1bb79fbc40 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/handler/ArgumentArrayMessageMapper.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/handler/ArgumentArrayMessageMapper.java @@ -44,6 +44,7 @@ import org.springframework.integration.annotation.Headers; import org.springframework.integration.annotation.Payload; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessagingException; +import org.springframework.integration.core.MessageHistory.ComponentType; import org.springframework.integration.message.InboundMessageMapper; import org.springframework.integration.message.MessageBuilder; import org.springframework.integration.message.MessageHandlingException; @@ -154,7 +155,11 @@ public class ArgumentArrayMessageMapper implements InboundMessageMapper message = this.mapArgumentsToMessage(arguments); + if (message != null) { + message.getHeaders().getHistory().add(ComponentType.gateway, this.method.getName()); + } + return message; } private Object[] mapMessageToArguments(Message message) { diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayProxyFactoryBeanTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayProxyFactoryBeanTests.java index 02ca05f99a..dfbf988fab 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayProxyFactoryBeanTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayProxyFactoryBeanTests.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.lang.reflect.Method; +import java.util.Iterator; import java.util.Random; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; @@ -34,7 +35,10 @@ import org.springframework.integration.channel.PollableChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; +import org.springframework.integration.core.MessageHistory.ComponentType; +import org.springframework.integration.core.MessageHistory.Event; import org.springframework.integration.endpoint.EventDrivenConsumer; +import org.springframework.integration.handler.BridgeHandler; import org.springframework.integration.message.MessageHandler; import org.springframework.integration.message.StringMessage; import org.springframework.util.ReflectionUtils; @@ -249,12 +253,39 @@ public class GatewayProxyFactoryBeanTests { }).start(); } + @Test + public void testMethodNameInHistory() throws Exception { + GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean(); + DirectChannel channel = new DirectChannel(); + channel.setBeanName("testChannel"); + EventDrivenConsumer consumer = new EventDrivenConsumer(channel, new BridgeHandler()); + consumer.start(); + proxyFactory.setDefaultRequestChannel(channel); + proxyFactory.setServiceInterface(TestEchoService.class); + proxyFactory.afterPropertiesSet(); + TestEchoService proxy = (TestEchoService) proxyFactory.getObject(); + Message message = proxy.echo("test"); + Iterator historyIterator = message.getHeaders().getHistory().iterator(); + Event event1 = historyIterator.next(); + Event event2 = historyIterator.next(); + assertEquals(ComponentType.gateway, event1.getComponentType()); + assertEquals("echo", event1.getComponentName()); + assertEquals(ComponentType.channel, event2.getComponentType()); + assertEquals("testChannel", event2.getComponentName()); + } + public static void throwTestException() throws TestException { throw new TestException(); } + static interface TestEchoService { + + Message echo(String s); + } + + static interface TestExceptionThrowingInterface { String throwCheckedException(String s) throws TestException;