Added AbstractConsumerFactoryBean and SplitterFactoryBean to support different consumer types that can only be initialized after the "ref" Object's type is known (for example, see INT-397).
This commit is contained in:
@@ -33,22 +33,60 @@ import org.springframework.integration.message.StringMessage;
|
||||
public class SplitterParserTests {
|
||||
|
||||
@Test
|
||||
public void testSplitter() {
|
||||
public void splitterAdapterWithRefAndMethod() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"splitterParserTests.xml", this.getClass());
|
||||
context.start();
|
||||
MessageChannel channel1 = (MessageChannel) context.getBean("channel1");
|
||||
PollableChannel channel2 = (PollableChannel) context.getBean("channel2");
|
||||
channel1.send(new StringMessage("this.is.a.test"));
|
||||
Message<?> result1 = channel2.receive(1000);
|
||||
MessageChannel input = (MessageChannel) context.getBean("splitterAdapterWithRefAndMethodInput");
|
||||
PollableChannel output = (PollableChannel) context.getBean("output");
|
||||
input.send(new StringMessage("this.is.a.test"));
|
||||
Message<?> result1 = output.receive(1000);
|
||||
assertEquals("this", result1.getPayload());
|
||||
Message<?> result2 = channel2.receive(1000);
|
||||
Message<?> result2 = output.receive(1000);
|
||||
assertEquals("is", result2.getPayload());
|
||||
Message<?> result3 = channel2.receive(1000);
|
||||
Message<?> result3 = output.receive(1000);
|
||||
assertEquals("a", result3.getPayload());
|
||||
Message<?> result4 = channel2.receive(1000);
|
||||
Message<?> result4 = output.receive(1000);
|
||||
assertEquals("test", result4.getPayload());
|
||||
assertNull(channel2.receive(0));
|
||||
assertNull(output.receive(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitterAdapterWithRefOnly() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"splitterParserTests.xml", this.getClass());
|
||||
context.start();
|
||||
MessageChannel input = (MessageChannel) context.getBean("splitterAdapterWithRefOnlyInput");
|
||||
PollableChannel output = (PollableChannel) context.getBean("output");
|
||||
input.send(new StringMessage("this.is.a.test"));
|
||||
Message<?> result1 = output.receive(1000);
|
||||
assertEquals("this", result1.getPayload());
|
||||
Message<?> result2 = output.receive(1000);
|
||||
assertEquals("is", result2.getPayload());
|
||||
Message<?> result3 = output.receive(1000);
|
||||
assertEquals("a", result3.getPayload());
|
||||
Message<?> result4 = output.receive(1000);
|
||||
assertEquals("test", result4.getPayload());
|
||||
assertNull(output.receive(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitterImplementation() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"splitterParserTests.xml", this.getClass());
|
||||
context.start();
|
||||
MessageChannel input = (MessageChannel) context.getBean("splitterImplementationInput");
|
||||
PollableChannel output = (PollableChannel) context.getBean("output");
|
||||
input.send(new StringMessage("this.is.a.test"));
|
||||
Message<?> result1 = output.receive(1000);
|
||||
assertEquals("this", result1.getPayload());
|
||||
Message<?> result2 = output.receive(1000);
|
||||
assertEquals("is", result2.getPayload());
|
||||
Message<?> result3 = output.receive(1000);
|
||||
assertEquals("a", result3.getPayload());
|
||||
Message<?> result4 = output.receive(1000);
|
||||
assertEquals("test", result4.getPayload());
|
||||
assertNull(output.receive(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.integration.router.config;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TestSplitter {
|
||||
public class TestSplitterBean {
|
||||
|
||||
public String[] split(String input) {
|
||||
return input.split("\\.");
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.router.config;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.splitter.AbstractMessageSplitter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TestSplitterImpl extends AbstractMessageSplitter {
|
||||
|
||||
|
||||
@Override
|
||||
protected Object splitMessage(Message<?> message) {
|
||||
return message.getPayload().toString().split("\\.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,15 +9,28 @@
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="channel1"/>
|
||||
|
||||
<channel id="channel2">
|
||||
<queue capacity="5"/>
|
||||
<channel id="output">
|
||||
<queue capacity="10"/>
|
||||
</channel>
|
||||
|
||||
<splitter id="splitter" ref="pojo" method="split"
|
||||
input-channel="channel1" output-channel="channel2"/>
|
||||
<splitter id="splitterAdapterWithRefAndMethod"
|
||||
ref="splitterBean"
|
||||
method="split"
|
||||
input-channel="splitterAdapterWithRefAndMethodInput"
|
||||
output-channel="output"/>
|
||||
|
||||
<beans:bean id="pojo" class="org.springframework.integration.router.config.TestSplitter"/>
|
||||
<splitter id="splitterAdapterWithRefOnly"
|
||||
ref="splitterBean"
|
||||
input-channel="splitterAdapterWithRefOnlyInput"
|
||||
output-channel="output"/>
|
||||
|
||||
<splitter id="splitterImplementation"
|
||||
ref="splitterImpl"
|
||||
input-channel="splitterImplementationInput"
|
||||
output-channel="output"/>
|
||||
|
||||
<beans:bean id="splitterBean" class="org.springframework.integration.router.config.TestSplitterBean"/>
|
||||
|
||||
<beans:bean id="splitterImpl" class="org.springframework.integration.router.config.TestSplitterImpl"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
Reference in New Issue
Block a user