From 1c8da6f251666af5a1d0f032b1635ffb182719f2 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 25 Aug 2010 19:25:26 +0000 Subject: [PATCH] INT-1257, INT-1263 Refactoring Message History (work in progress): Removed MessageHistoryWriter. Added MessageHistory. --- .../channel/AbstractMessageChannel.java | 4 +- .../context/MessageHistoryWriter.java | 71 ------ .../integration/core/MessageHistory.java | 222 ++++++++++++++++++ .../endpoint/MessageProducerSupport.java | 4 +- .../gateway/SimpleMessagingGateway.java | 4 +- .../handler/AbstractMessageHandler.java | 4 +- .../MessageHistoryIntegrationTests.java | 64 ++--- .../messageHistoryWithHistoryWriter-fail.xml | 4 +- .../ChannelPublishingJmsMessageListener.java | 4 +- .../jms/JmsDestinationPollingSource.java | 4 +- .../jms/JmsSendingMessageHandler.java | 4 +- .../jms/config/JmsMessageHistoryTests.java | 46 ++-- 12 files changed, 293 insertions(+), 142 deletions(-) delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/context/MessageHistoryWriter.java create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/core/MessageHistory.java diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java index d5fd89b954..28423ff44b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java @@ -31,9 +31,9 @@ import org.springframework.integration.MessageDeliveryException; import org.springframework.integration.MessagingException; import org.springframework.integration.context.HistoryProvider; import org.springframework.integration.context.IntegrationObjectSupport; -import org.springframework.integration.context.MessageHistoryWriter; import org.springframework.integration.core.MessageBuilder; import org.springframework.integration.core.MessageChannel; +import org.springframework.integration.core.MessageHistory; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -170,7 +170,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im Assert.notNull(message, "message must not be null"); Assert.notNull(message.getPayload(), "message payload must not be null"); if (this.shouldIncludeInHistory) { - message = MessageHistoryWriter.writeHistory(this, message); + message = MessageHistory.addComponentToHistory(message, this); } message = this.convertPayloadIfNecessary(message); message = this.interceptors.preSend(message, this); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/context/MessageHistoryWriter.java b/spring-integration-core/src/main/java/org/springframework/integration/context/MessageHistoryWriter.java deleted file mode 100644 index b1ffc90cc5..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/context/MessageHistoryWriter.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.context; - -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import org.springframework.integration.Message; -import org.springframework.integration.MessageHeaders; -import org.springframework.integration.core.MessageBuilder; -import org.springframework.integration.core.MessageChannel; -import org.springframework.integration.core.MessageHandler; -import org.springframework.util.StringUtils; - -/** - * This component is responsible for maintaining the history of {@link MessageChannel}s and - * {@link MessageHandler}s. There can only be one instance of this class per ApplicationContext - * hierarchy otherwise an Exception will be thrown. - * - * @author Oleg Zhurakousky - * @author Mark Fisher - * @since 2.0 - */ -public abstract class MessageHistoryWriter { - - public static final String NAME_PROPERTY = "name"; - - public static final String TYPE_PROPERTY = "type"; - - public static final String TIMESTAMP_PROPERTY = "timestamp"; - - - @SuppressWarnings({"unchecked", "rawtypes"}) - public static Message writeHistory(NamedComponent component, Message message) { - if (component != null && message != null) { - String componentName = component.getComponentName(); - if (componentName != null && !componentName.startsWith("org.springframework.integration")) { - Properties historyEvent = new Properties(); - String componentType = component.getComponentType(); - if (StringUtils.hasText(componentType)) { - historyEvent.setProperty(TYPE_PROPERTY, componentType); - } - historyEvent.setProperty(NAME_PROPERTY, componentName); - historyEvent.setProperty(TIMESTAMP_PROPERTY, "" + System.currentTimeMillis()); - List history = message.getHeaders().get(MessageHeaders.HISTORY, List.class); - if (history == null) { - history = new ArrayList(); - } - history.add(historyEvent); - message = MessageBuilder.fromMessage(message).setHeader(MessageHeaders.HISTORY, history).build(); - } - } - return message; - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/core/MessageHistory.java b/spring-integration-core/src/main/java/org/springframework/integration/core/MessageHistory.java new file mode 100644 index 0000000000..fb9a4e2ffc --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/core/MessageHistory.java @@ -0,0 +1,222 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.core; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Properties; + +import org.springframework.integration.Message; +import org.springframework.integration.MessageHeaders; +import org.springframework.integration.context.NamedComponent; +import org.springframework.util.Assert; + +/** + * @author Mark Fisher + * @since 2.0 + */ +public class MessageHistory implements List { + + public static final String HEADER_NAME = MessageHeaders.PREFIX + "history"; + + public static final String NAME_PROPERTY = "name"; + + public static final String TYPE_PROPERTY = "type"; + + public static final String TIMESTAMP_PROPERTY = "timestamp"; + + + private final List components; + + + public static Message addComponentToHistory(Message message, NamedComponent component) { + Assert.notNull(message, "Message must not be null"); + Assert.notNull(component, "Component must not be null"); + Properties metadata = extractMetadata(component); + if (!metadata.isEmpty()) { + MessageHistory previousHistory = message.getHeaders().get(HEADER_NAME, MessageHistory.class); + List components = (previousHistory != null) ? + new ArrayList(previousHistory) : new ArrayList(); + components.add(metadata); + MessageHistory history = new MessageHistory(components); + message = MessageBuilder.fromMessage(message).setHeader(HEADER_NAME, history).build(); + } + return message; + } + + + private MessageHistory(List components) { + Assert.notEmpty(components, "component list must not be empty"); + this.components = components; + } + + + public int size() { + return this.components.size(); + } + + public boolean isEmpty() { + return this.components.isEmpty(); + } + + public boolean contains(Object o) { + return this.components.contains(o); + } + + public boolean containsAll(Collection c) { + return this.components.containsAll(c); + } + + public Properties get(int index) { + return this.components.get(index); + } + + public Iterator iterator() { + return Collections.unmodifiableList(this.components).iterator(); + } + + public ListIterator listIterator() { + return Collections.unmodifiableList(this.components).listIterator(); + } + + public ListIterator listIterator(int index) { + return Collections.unmodifiableList(this.components).listIterator(index); + } + + public List subList(int fromIndex, int toIndex) { + return Collections.unmodifiableList(this.components).subList(fromIndex, toIndex); + } + + public Object[] toArray() { + return this.components.toArray(); + } + + public T[] toArray(T[] a) { + return this.components.toArray(a); + } + + public int indexOf(Object o) { + return this.components.indexOf(o); + } + + public int lastIndexOf(Object o) { + return this.components.lastIndexOf(o); + } + + public String toString() { + return this.components.toString(); + } + + + /* + * Unsupported Operations + */ + + public boolean add(Properties e) { + throw new UnsupportedOperationException("MessageHistory is immutable."); + } + + public void add(int index, Properties element) { + throw new UnsupportedOperationException("MessageHistory is immutable."); + } + + public boolean addAll(Collection c) { + throw new UnsupportedOperationException("MessageHistory is immutable."); + } + + public boolean addAll(int index, Collection c) { + throw new UnsupportedOperationException("MessageHistory is immutable."); + } + + public Properties set(int index, Properties element) { + throw new UnsupportedOperationException("MessageHistory is immutable."); + } + + public Properties remove(int index) { + throw new UnsupportedOperationException("MessageHistory is immutable."); + } + + public boolean remove(Object o) { + throw new UnsupportedOperationException("MessageHistory is immutable."); + } + + public boolean removeAll(Collection c) { + throw new UnsupportedOperationException("MessageHistory is immutable."); + } + + public boolean retainAll(Collection c) { + throw new UnsupportedOperationException("MessageHistory is immutable."); + } + + public void clear() { + throw new UnsupportedOperationException("MessageHistory is immutable."); + } + + + private static Properties extractMetadata(NamedComponent component) { + Entry entry = new Entry(); + String name = component.getComponentName(); + String type = component.getComponentType(); + if (name != null && !name.startsWith("org.springframework.integration")) { + entry.setName(name); + if (type != null) { + entry.setType(type); + } + } + if (!entry.isEmpty()) { + entry.setTimestamp(Long.toString(System.currentTimeMillis())); + } + return entry; + } + + + /** + * Inner class for each Entry in the history. + */ + @SuppressWarnings("serial") + public static class Entry extends Properties { + + public String getName() { + return this.getProperty(NAME_PROPERTY); + } + + private void setName(String name) { + this.setProperty(NAME_PROPERTY, name); + } + + public String getType() { + return this.getProperty(TYPE_PROPERTY); + } + + private void setType(String type) { + this.setProperty(TYPE_PROPERTY, type); + } + + public String getTimestamp() { + return this.getProperty(TIMESTAMP_PROPERTY); + } + + private void setTimestamp(String timestamp) { + this.setProperty(TIMESTAMP_PROPERTY, timestamp); + } + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java index c472bedb23..1f069b5279 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java @@ -17,8 +17,8 @@ package org.springframework.integration.endpoint; import org.springframework.integration.Message; -import org.springframework.integration.context.MessageHistoryWriter; import org.springframework.integration.core.MessageChannel; +import org.springframework.integration.core.MessageHistory; import org.springframework.integration.core.MessageProducer; import org.springframework.integration.core.MessagingTemplate; import org.springframework.util.Assert; @@ -51,7 +51,7 @@ public abstract class MessageProducerSupport extends AbstractEndpoint implements protected void sendMessage(Message message) { if (message != null) { - message = MessageHistoryWriter.writeHistory(this, message); + message = MessageHistory.addComponentToHistory(message, this); } this.messagingTemplate.send(this.outputChannel, message); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java index b55433d588..c606a94df9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java @@ -19,7 +19,7 @@ package org.springframework.integration.gateway; import org.springframework.integration.Message; import org.springframework.integration.MessagingException; import org.springframework.integration.context.HistoryProvider; -import org.springframework.integration.context.MessageHistoryWriter; +import org.springframework.integration.core.MessageHistory; import org.springframework.integration.mapping.InboundMessageMapper; import org.springframework.integration.mapping.OutboundMessageMapper; import org.springframework.util.Assert; @@ -90,7 +90,7 @@ public class SimpleMessagingGateway extends AbstractMessagingGateway implements try { message = this.inboundMapper.toMessage(object); if (this.shouldIncludeInHistory) { - message = MessageHistoryWriter.writeHistory(this, message); + message = MessageHistory.addComponentToHistory(message, this); } } catch (Exception e) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java index 400ab20d0a..360eb661e6 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java @@ -25,8 +25,8 @@ import org.springframework.integration.MessageHandlingException; import org.springframework.integration.MessagingException; import org.springframework.integration.context.HistoryProvider; import org.springframework.integration.context.IntegrationObjectSupport; -import org.springframework.integration.context.MessageHistoryWriter; import org.springframework.integration.core.MessageHandler; +import org.springframework.integration.core.MessageHistory; import org.springframework.util.Assert; /** @@ -72,7 +72,7 @@ public abstract class AbstractMessageHandler extends IntegrationObjectSupport im } try { if (message != null && this.shouldIncludeInHistory) { - message = MessageHistoryWriter.writeHistory(this, message); + message = MessageHistory.addComponentToHistory(message, this); } this.handleMessageInternal(message); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/history/MessageHistoryIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/history/MessageHistoryIntegrationTests.java index 04bef9dbab..eb8573c6b5 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/history/MessageHistoryIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/history/MessageHistoryIntegrationTests.java @@ -38,9 +38,9 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.Message; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.config.ConsumerEndpointFactoryBean; -import org.springframework.integration.context.MessageHistoryWriter; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.core.MessageHandler; +import org.springframework.integration.core.MessageHistory; /** * @author Oleg Zhurakousky @@ -79,60 +79,60 @@ public class MessageHistoryIntegrationTests { Iterator historyIterator = message.getHeaders().getHistory().iterator(); Properties event1 = historyIterator.next(); - assertEquals("sampleGateway", event1.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("gateway", event1.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("sampleGateway", event1.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("gateway", event1.getProperty(MessageHistory.TYPE_PROPERTY)); Properties event2 = historyIterator.next(); - assertEquals("bridgeInChannel", event2.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("channel", event2.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("bridgeInChannel", event2.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("channel", event2.getProperty(MessageHistory.TYPE_PROPERTY)); Properties event3 = historyIterator.next(); - assertEquals("testBridge", event3.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("bridge", event3.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("testBridge", event3.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("bridge", event3.getProperty(MessageHistory.TYPE_PROPERTY)); Properties event4 = historyIterator.next(); - assertEquals("headerEnricherChannel", event4.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("channel", event4.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("headerEnricherChannel", event4.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("channel", event4.getProperty(MessageHistory.TYPE_PROPERTY)); Properties event5 = historyIterator.next(); - assertEquals("testHeaderEnricher", event5.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("transformer", event5.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("testHeaderEnricher", event5.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("transformer", event5.getProperty(MessageHistory.TYPE_PROPERTY)); Properties event6 = historyIterator.next(); - assertEquals("chainChannel", event6.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("channel", event6.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("chainChannel", event6.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("channel", event6.getProperty(MessageHistory.TYPE_PROPERTY)); Properties event7 = historyIterator.next(); - assertEquals("sampleChain", event7.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("chain", event7.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("sampleChain", event7.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("chain", event7.getProperty(MessageHistory.TYPE_PROPERTY)); Properties event8 = historyIterator.next(); - assertEquals("filterChannel", event8.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("channel", event8.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("filterChannel", event8.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("channel", event8.getProperty(MessageHistory.TYPE_PROPERTY)); Properties event9 = historyIterator.next(); - assertEquals("testFilter", event9.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("filter", event9.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("testFilter", event9.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("filter", event9.getProperty(MessageHistory.TYPE_PROPERTY)); Properties event10 = historyIterator.next(); - assertEquals("splitterChannel", event10.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("channel", event10.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("splitterChannel", event10.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("channel", event10.getProperty(MessageHistory.TYPE_PROPERTY)); Properties event11 = historyIterator.next(); - assertEquals("testSplitter", event11.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("splitter", event11.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("testSplitter", event11.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("splitter", event11.getProperty(MessageHistory.TYPE_PROPERTY)); Properties event12 = historyIterator.next(); - assertEquals("aggregatorChannel", event12.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("channel", event12.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("aggregatorChannel", event12.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("channel", event12.getProperty(MessageHistory.TYPE_PROPERTY)); Properties event13 = historyIterator.next(); - assertEquals("testAggregator", event13.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("aggregator", event13.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("testAggregator", event13.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("aggregator", event13.getProperty(MessageHistory.TYPE_PROPERTY)); Properties event14 = historyIterator.next(); - assertEquals("endOfThePipeChannel", event14.getProperty(MessageHistoryWriter.NAME_PROPERTY)); - assertEquals("channel", event14.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); + assertEquals("endOfThePipeChannel", event14.getProperty(MessageHistory.NAME_PROPERTY)); + assertEquals("channel", event14.getProperty(MessageHistory.TYPE_PROPERTY)); MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel(); replyChannel.send(message); @@ -181,12 +181,12 @@ public class MessageHistoryIntegrationTests { } @Test(expected=BeanDefinitionParsingException.class) - public void testMessageHistoryMoreThenOneNamespaceFail() { + public void testMessageHistoryMoreThanOneNamespaceFail() { new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriterNamespace-fail.xml", MessageHistoryIntegrationTests.class); } - @Test(expected=BeanCreationException.class) - public void testMessageHistoryMoreThenOneFail() { + @Test(expected=BeanCreationException.class) @Ignore + public void testMessageHistoryMoreThanOneFail() { new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriter-fail.xml", MessageHistoryIntegrationTests.class); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter-fail.xml b/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter-fail.xml index dccb0e5e9b..8d92ebeb69 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter-fail.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter-fail.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd"> - - + + diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java index be7a0ec53c..c3bdf8bfc5 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java @@ -27,8 +27,8 @@ import javax.jms.Session; import org.springframework.beans.factory.InitializingBean; import org.springframework.integration.Message; -import org.springframework.integration.context.MessageHistoryWriter; import org.springframework.integration.core.MessageBuilder; +import org.springframework.integration.core.MessageHistory; import org.springframework.integration.gateway.AbstractMessagingGateway; import org.springframework.jms.listener.SessionAwareMessageListener; import org.springframework.jms.support.converter.MessageConverter; @@ -223,7 +223,7 @@ public class ChannelPublishingJmsMessageListener extends AbstractMessagingGatewa Message requestMessage = (object instanceof Message) ? MessageBuilder.fromMessage((Message) object).copyHeaders(headers).build() : MessageBuilder.withPayload(object).copyHeaders(headers).build(); - requestMessage = MessageHistoryWriter.writeHistory(this, requestMessage); + requestMessage = MessageHistory.addComponentToHistory(requestMessage, this); if (!this.expectReply) { this.send(requestMessage); } diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsDestinationPollingSource.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsDestinationPollingSource.java index bf42851eb6..2b007b7779 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsDestinationPollingSource.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsDestinationPollingSource.java @@ -23,8 +23,8 @@ import javax.jms.Destination; import org.springframework.integration.Message; import org.springframework.integration.MessagingException; -import org.springframework.integration.context.MessageHistoryWriter; import org.springframework.integration.core.MessageBuilder; +import org.springframework.integration.core.MessageHistory; import org.springframework.integration.core.MessageSource; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.support.converter.MessageConverter; @@ -88,7 +88,7 @@ public class JmsDestinationPollingSource extends AbstractJmsTemplateBasedAdapter MessageBuilder builder = (convertedObject instanceof Message) ? MessageBuilder.fromMessage((Message) convertedObject) : MessageBuilder.withPayload(convertedObject); convertedMessage = builder.copyHeadersIfAbsent(mappedHeaders).build(); - convertedMessage = MessageHistoryWriter.writeHistory(this, convertedMessage); + convertedMessage = MessageHistory.addComponentToHistory(convertedMessage, this); } catch (Exception e) { throw new MessagingException(e.getMessage(), e); diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsSendingMessageHandler.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsSendingMessageHandler.java index 0c8710a5f6..2d0b0fd507 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsSendingMessageHandler.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsSendingMessageHandler.java @@ -20,8 +20,8 @@ import javax.jms.JMSException; import org.springframework.core.Ordered; import org.springframework.integration.Message; -import org.springframework.integration.context.MessageHistoryWriter; import org.springframework.integration.core.MessageHandler; +import org.springframework.integration.core.MessageHistory; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.MessagePostProcessor; @@ -63,7 +63,7 @@ public class JmsSendingMessageHandler extends AbstractJmsTemplateBasedAdapter im if (message == null) { throw new IllegalArgumentException("message must not be null"); } - final Message messageToSend = MessageHistoryWriter.writeHistory(this, message); + final Message messageToSend = MessageHistory.addComponentToHistory(message, this); this.getJmsTemplate().convertAndSend(messageToSend, new MessagePostProcessor() { public javax.jms.Message postProcessMessage(javax.jms.Message jmsMessage) throws JMSException { diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java index 3ff080c3fe..fb6bc3e9bf 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java @@ -35,10 +35,10 @@ import org.springframework.integration.Message; import org.springframework.integration.MessageHeaders; import org.springframework.integration.MessagingException; import org.springframework.integration.channel.DirectChannel; -import org.springframework.integration.context.MessageHistoryWriter; import org.springframework.integration.context.NamedComponent; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.core.MessageHandler; +import org.springframework.integration.core.MessageHistory; import org.springframework.integration.core.PollableChannel; import org.springframework.integration.core.StringMessage; import org.springframework.integration.core.SubscribableChannel; @@ -61,11 +61,11 @@ public class JmsMessageHistoryTests { Message message = jmsInputChannel.receive(5000); Iterator historyIterator = message.getHeaders().getHistory().iterator(); Properties event = historyIterator.next(); - assertEquals("jms:inbound-channel-adapter", event.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); - assertEquals("sampleJmsInboundAdapter", event.getProperty(MessageHistoryWriter.NAME_PROPERTY)); + assertEquals("jms:inbound-channel-adapter", event.getProperty(MessageHistory.TYPE_PROPERTY)); + assertEquals("sampleJmsInboundAdapter", event.getProperty(MessageHistory.NAME_PROPERTY)); event = historyIterator.next(); - assertEquals("channel", event.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); - assertEquals("jmsInputChannel", event.getProperty(MessageHistoryWriter.NAME_PROPERTY)); + assertEquals("channel", event.getProperty(MessageHistory.TYPE_PROPERTY)); + assertEquals("jmsInputChannel", event.getProperty(MessageHistory.NAME_PROPERTY)); } @Test @Ignore @@ -78,17 +78,17 @@ public class JmsMessageHistoryTests { Message message = jmsInputChannel.receive(50000); Iterator historyIterator = message.getHeaders().getHistory().iterator(); Properties event = historyIterator.next(); - assertEquals("channel", event.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); - assertEquals("outbound-channel", event.getProperty(MessageHistoryWriter.NAME_PROPERTY)); + assertEquals("channel", event.getProperty(MessageHistory.TYPE_PROPERTY)); + assertEquals("outbound-channel", event.getProperty(MessageHistory.NAME_PROPERTY)); event = historyIterator.next(); - assertEquals("jms:outbound-channel-adapter", event.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); - assertEquals("jmsOutbound", event.getProperty(MessageHistoryWriter.NAME_PROPERTY)); + assertEquals("jms:outbound-channel-adapter", event.getProperty(MessageHistory.TYPE_PROPERTY)); + assertEquals("jmsOutbound", event.getProperty(MessageHistory.NAME_PROPERTY)); event = historyIterator.next(); - assertEquals("jms:inbound-channel-adapter", event.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); - assertEquals("sampleJmsInboundAdapter", event.getProperty(MessageHistoryWriter.NAME_PROPERTY)); + assertEquals("jms:inbound-channel-adapter", event.getProperty(MessageHistory.TYPE_PROPERTY)); + assertEquals("sampleJmsInboundAdapter", event.getProperty(MessageHistory.NAME_PROPERTY)); event = historyIterator.next(); - assertEquals("channel", event.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); - assertEquals("jmsInputChannel", event.getProperty(MessageHistoryWriter.NAME_PROPERTY)); + assertEquals("channel", event.getProperty(MessageHistory.TYPE_PROPERTY)); + assertEquals("jmsInputChannel", event.getProperty(MessageHistory.NAME_PROPERTY)); } @Test @Ignore @@ -101,20 +101,20 @@ public class JmsMessageHistoryTests { public void handleMessage(Message message) { Iterator historyIterator = message.getHeaders().getHistory().iterator(); Properties event = historyIterator.next(); - assertEquals("gateway", event.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); - assertEquals("sampleGateway", event.getProperty(MessageHistoryWriter.NAME_PROPERTY)); + assertEquals("gateway", event.getProperty(MessageHistory.TYPE_PROPERTY)); + assertEquals("sampleGateway", event.getProperty(MessageHistory.NAME_PROPERTY)); event = historyIterator.next(); - assertEquals("publish-subscribe-channel", event.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); - assertEquals("channel-a", event.getProperty(MessageHistoryWriter.NAME_PROPERTY)); + assertEquals("publish-subscribe-channel", event.getProperty(MessageHistory.TYPE_PROPERTY)); + assertEquals("channel-a", event.getProperty(MessageHistory.NAME_PROPERTY)); event = historyIterator.next(); - assertEquals("jms:outbound-gateway", event.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); - assertEquals("jmsOutbound", event.getProperty(MessageHistoryWriter.NAME_PROPERTY)); + assertEquals("jms:outbound-gateway", event.getProperty(MessageHistory.TYPE_PROPERTY)); + assertEquals("jmsOutbound", event.getProperty(MessageHistory.NAME_PROPERTY)); event = historyIterator.next(); - assertEquals("jms:inbound-gateway", event.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); - assertEquals("jmsInbound", event.getProperty(MessageHistoryWriter.NAME_PROPERTY)); + assertEquals("jms:inbound-gateway", event.getProperty(MessageHistory.TYPE_PROPERTY)); + assertEquals("jmsInbound", event.getProperty(MessageHistory.NAME_PROPERTY)); event = historyIterator.next(); - assertEquals("publish-subscribe-channel", event.getProperty(MessageHistoryWriter.TYPE_PROPERTY)); - assertEquals("inbound-jms-channel", event.getProperty(MessageHistoryWriter.NAME_PROPERTY)); + assertEquals("publish-subscribe-channel", event.getProperty(MessageHistory.TYPE_PROPERTY)); + assertEquals("inbound-jms-channel", event.getProperty(MessageHistory.NAME_PROPERTY)); MessageChannel channel = (MessageChannel) message.getHeaders().getReplyChannel(); channel.send(new StringMessage("OK"));