diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingChannelInterceptor.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingChannelInterceptor.java index 44e1038023..8bee7cd959 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingChannelInterceptor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingChannelInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2013 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. @@ -24,9 +24,13 @@ import org.springframework.integration.channel.interceptor.ChannelInterceptorAda /** * A {@link ChannelInterceptor} which invokes a {@link Transformer} * when either sending-to or receiving-from a channel. - * + * + * @deprecated It is not generally recommended to perform functions + * such as transformation in a channel interceptor. + * * @author Jonas Partner */ +@Deprecated public class MessageTransformingChannelInterceptor extends ChannelInterceptorAdapter { private final Transformer transformer; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/config/ChannelParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/config/ChannelParserTests.java index 86b930e6de..eed9231008 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/config/ChannelParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/config/ChannelParserTests.java @@ -39,6 +39,8 @@ import org.springframework.integration.MessageDeliveryException; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.PublishSubscribeChannel; import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter; +import org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests; import org.springframework.integration.config.TestChannelInterceptor; import org.springframework.integration.core.PollableChannel; import org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy; @@ -259,4 +261,13 @@ public class ChannelParserTests { assertTrue(threwException); } + public static class TestInterceptor extends ChannelInterceptorAdapter { + + @Override + public Message preSend(Message message, MessageChannel channel) { + return MessageBuilder.withPayload(message.getPayload().toString().toUpperCase()).build(); + } + + } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/config/channelInterceptorParserTests.xml b/spring-integration-core/src/test/java/org/springframework/integration/channel/config/channelInterceptorParserTests.xml index b2230679d5..077975d0eb 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/config/channelInterceptorParserTests.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/config/channelInterceptorParserTests.xml @@ -17,11 +17,7 @@ - - - - - + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/transformer/MessageTransformingChannelInterceptorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/transformer/MessageTransformingChannelInterceptorTests.java deleted file mode 100644 index f05502583a..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/transformer/MessageTransformingChannelInterceptorTests.java +++ /dev/null @@ -1,89 +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.transformer; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; - -import org.springframework.integration.Message; -import org.springframework.integration.channel.QueueChannel; -import org.springframework.integration.message.GenericMessage; - -/** - * @author Jonas Partner - */ -public class MessageTransformingChannelInterceptorTests { - - private QueueChannel channel; - - private GenericMessage message; - - private TestTransformer transformer; - - private MessageTransformingChannelInterceptor channelInterceptor; - - - @Before - public void setUp() { - channel = new QueueChannel(); - message = new GenericMessage("test"); - transformer = new TestTransformer(); - channelInterceptor = new MessageTransformingChannelInterceptor(transformer); - channel.addInterceptor(channelInterceptor); - } - - - @Test - public void testTransformOnReceive() { - channelInterceptor.setTransformOnSend(false); - channel.send(message); - assertFalse("Transformer incorrectly invoked on send", transformer.invoked); - Message msg = channel.receive(1); - assertEquals("Wrong message", message, msg); - assertTrue("Transformer not invoked on receive", transformer.invoked); - } - - @Test - public void testTransformOnSend() { - channelInterceptor.setTransformOnSend(true); - channel.send(message); - assertTrue("Transformer not invoked on send", transformer.invoked); - Message msg = channel.receive(1); - assertEquals("Wrong message", message, msg); - assertEquals("Transformer invoked on receive", 1, transformer.invokedCount); - } - - - private static class TestTransformer implements Transformer { - - boolean invoked = false; - - int invokedCount = 0; - - public Message transform(Message message) { - invoked = true; - invokedCount++; - return message; - } - - } - -} diff --git a/src/reference/docbook/xml.xml b/src/reference/docbook/xml.xml index 5ee55ef17a..6bd803a776 100644 --- a/src/reference/docbook/xml.xml +++ b/src/reference/docbook/xml.xml @@ -340,12 +340,8 @@ Transformer. When configuring XML transformers as beans in Spring Integration, you would normally configure the Transformer - in conjunction with either a - MessageTransformingChannelInterceptor - or a MessageTransformingHandler. - This allows the transformer to be used as either an interceptor, - which transforms the message as it is sent or received to the - Channel, or as an Endpoint. + in conjunction with a MessageTransformingHandler. + This allows the transformer to be used as an Endpoint. Finally, the namespace support will be discussed, which allows for the simple configuration of the transformers as elements in XML.