INT-3221: Deprecate MessageTransformingCI
JIRA: https://jira.springsource.org/browse/INT-3221
This commit is contained in:
committed by
Gary Russell
parent
c2004f1ab3
commit
9971ace2ad
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,11 +17,7 @@
|
||||
<channel id="channelWithInterceptorInnerBean">
|
||||
<queue capacity="5"/>
|
||||
<interceptors>
|
||||
<beans:bean class="org.springframework.integration.transformer.MessageTransformingChannelInterceptor">
|
||||
<beans:constructor-arg>
|
||||
<beans:bean class="org.springframework.integration.channel.config.TestTransformer"/>
|
||||
</beans:constructor-arg>
|
||||
</beans:bean>
|
||||
<beans:bean class="org.springframework.integration.channel.config.ChannelParserTests$TestInterceptor"/>
|
||||
</interceptors>
|
||||
</channel>
|
||||
|
||||
|
||||
@@ -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<String> message;
|
||||
|
||||
private TestTransformer transformer;
|
||||
|
||||
private MessageTransformingChannelInterceptor channelInterceptor;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
channel = new QueueChannel();
|
||||
message = new GenericMessage<String>("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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -340,12 +340,8 @@
|
||||
<interfacename><ulink url="http://static.springsource.org/spring-integration/api/org/springframework/integration/transformer/Transformer.html">Transformer</ulink></interfacename>.
|
||||
When configuring XML transformers as beans in Spring Integration,
|
||||
you would normally configure the <emphasis>Transformer</emphasis>
|
||||
in conjunction with either a
|
||||
<classname><ulink url="http://static.springsource.org/spring-integration/api/org/springframework/integration/transformer/MessageTransformingChannelInterceptor.html">MessageTransformingChannelInterceptor</ulink></classname>
|
||||
or a <classname><ulink url="http://static.springsource.org/spring-integration/api/org/springframework/integration/transformer/MessageTransformingHandler.html">MessageTransformingHandler</ulink></classname>.
|
||||
This allows the transformer to be used as either an interceptor,
|
||||
which transforms the message as it is sent or received to the
|
||||
<emphasis>Channel</emphasis>, or as an <emphasis>Endpoint</emphasis>.
|
||||
in conjunction with a <classname><ulink url="http://static.springsource.org/spring-integration/api/org/springframework/integration/transformer/MessageTransformingHandler.html">MessageTransformingHandler</ulink></classname>.
|
||||
This allows the transformer to be used as an <emphasis>Endpoint</emphasis>.
|
||||
Finally, the namespace support will be discussed, which allows for
|
||||
the simple configuration of the transformers as elements in XML.
|
||||
</para>
|
||||
|
||||
Reference in New Issue
Block a user