Replaced <jms:source/> with <jms:inbound-channel-adapter/>, refactored parser, and adjusted tests.

This commit is contained in:
Mark Fisher
2008-10-12 00:19:19 +00:00
parent 04fe19c91e
commit 998ca827d7
14 changed files with 106 additions and 101 deletions

View File

@@ -19,19 +19,19 @@ package org.springframework.integration.jms.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser;
import org.springframework.integration.jms.JmsSource;
import org.springframework.util.StringUtils;
/**
* Parser for the &lt;jms-source/&gt; element.
* Parser for the &lt;inbound-channel-adapter/&gt; element of the 'jms' namespace.
*
* @author Mark Fisher
*/
public class JmsSourceParser extends AbstractBeanDefinitionParser {
public class JmsInboundChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser {
protected boolean shouldGenerateId() {
return false;
@@ -42,7 +42,7 @@ public class JmsSourceParser extends AbstractBeanDefinitionParser {
}
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
protected String parseSource(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(JmsSource.class);
String jmsTemplate = element.getAttribute(JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE);
String destination = element.getAttribute(JmsAdapterParserUtils.DESTINATION_ATTRIBUTE);
@@ -77,7 +77,7 @@ public class JmsSourceParser extends AbstractBeanDefinitionParser {
if (StringUtils.hasText(headerMapper)) {
builder.addPropertyReference(JmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper);
}
return builder.getBeanDefinition();
return BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry());
}
}

View File

@@ -27,7 +27,7 @@ public class JmsNamespaceHandler extends NamespaceHandlerSupport {
public void init() {
this.registerBeanDefinitionParser("jms-gateway", new JmsGatewayParser());
this.registerBeanDefinitionParser("jms-source", new JmsSourceParser());
this.registerBeanDefinitionParser("inbound-channel-adapter", new JmsInboundChannelAdapterParser());
this.registerBeanDefinitionParser("jms-target", new JmsTargetParser());
}

View File

@@ -15,15 +15,17 @@
Defines the configuration elements for Spring Integration's JMS adapters.
]]></xsd:documentation>
</xsd:annotation>
<xsd:element name="jms-source">
<xsd:element name="inbound-channel-adapter">
<xsd:annotation>
<xsd:documentation>
Defines a JMS-based source channel adapter.
Defines a JMS-based inbound Channel Adapter.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="jmsInboundAdapterType">
<xsd:attribute name="channel" type="xsd:string"/>
<xsd:attribute name="header-mapper" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>

View File

@@ -26,50 +26,49 @@ import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.jms.JmsSource;
import org.springframework.integration.message.Message;
/**
* @author Mark Fisher
*/
public class JmsSourceParserTests {
public class JmsInboundChannelAdapterParserTests {
@Test
public void testSourceWithJmsTemplate() {
public void adapterWithJmsTemplate() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"jmsSourceWithJmsTemplate.xml", this.getClass());
JmsSource source = (JmsSource) context.getBean("jmsSource");
Message<?> message = source.receive();
"jmsInboundWithJmsTemplate.xml", this.getClass());
PollableChannel output = (PollableChannel) context.getBean("output");
Message<?> message = output.receive(1000);
assertNotNull("message should not be null", message);
assertEquals("polling-test", message.getPayload());
}
@Test
public void testSourceWithConnectionFactoryAndDestination() {
public void adapterWithConnectionFactoryAndDestination() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"jmsSourceWithConnectionFactoryAndDestination.xml", this.getClass());
JmsSource source = (JmsSource) context.getBean("jmsSource");
Message<?> message = source.receive();
"jmsInboundWithConnectionFactoryAndDestination.xml", this.getClass());
PollableChannel output = (PollableChannel) context.getBean("output");
Message<?> message = output.receive(1000);
assertNotNull("message should not be null", message);
assertEquals("polling-test", message.getPayload());
context.stop();
}
@Test
public void testSourceWithConnectionFactoryAndDestinationName() {
public void adapterWithConnectionFactoryAndDestinationName() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"jmsSourceWithConnectionFactoryAndDestinationName.xml", this.getClass());
JmsSource source = (JmsSource) context.getBean("jmsSource");
Message<?> message = source.receive();
"jmsInboundWithConnectionFactoryAndDestinationName.xml", this.getClass());
PollableChannel output = (PollableChannel) context.getBean("output");
Message<?> message = output.receive(1000);
assertNotNull("message should not be null", message);
assertEquals("polling-test", message.getPayload());
context.stop();
}
@Test(expected=BeanDefinitionStoreException.class)
public void testSourceWithConnectionFactoryOnly() {
@Test(expected = BeanDefinitionStoreException.class)
public void adapterWithConnectionFactoryOnly() {
try {
new ClassPathXmlApplicationContext("jmsSourceWithConnectionFactoryOnly.xml", this.getClass());
new ClassPathXmlApplicationContext("jmsInboundWithConnectionFactoryOnly.xml", this.getClass());
}
catch (RuntimeException e) {
assertEquals(BeanCreationException.class, e.getCause().getClass());
@@ -77,10 +76,10 @@ public class JmsSourceParserTests {
}
}
@Test(expected=BeanCreationException.class)
public void testSourceWithDestinationOnly() {
@Test(expected = BeanCreationException.class)
public void adapterWithDestinationOnly() {
try {
new ClassPathXmlApplicationContext("jmsSourceWithDestinationOnly.xml", this.getClass());
new ClassPathXmlApplicationContext("jmsInboundWithDestinationOnly.xml", this.getClass());
}
catch (RuntimeException e) {
assertEquals(NoSuchBeanDefinitionException.class, e.getCause().getClass());
@@ -89,53 +88,41 @@ public class JmsSourceParserTests {
}
@Test
public void testSourceWithDestinationAndDefaultConnectionFactory() {
public void adpaterWithDestinationAndDefaultConnectionFactory() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"jmsSourceWithDestinationAndDefaultConnectionFactory.xml", this.getClass());
JmsSource source = (JmsSource) context.getBean("jmsSource");
Message<?> message = source.receive();
"jmsInboundWithDestinationAndDefaultConnectionFactory.xml", this.getClass());
PollableChannel output = (PollableChannel) context.getBean("output");
Message<?> message = output.receive(1000);
assertNotNull("message should not be null", message);
assertEquals("polling-test", message.getPayload());
context.stop();
}
@Test(expected=BeanCreationException.class)
public void testSourceWithDestinationNameOnly() {
new ClassPathXmlApplicationContext("jmsSourceWithDestinationNameOnly.xml", this.getClass());
public void adapterWithDestinationNameOnly() {
new ClassPathXmlApplicationContext("jmsInboundWithDestinationNameOnly.xml", this.getClass());
}
@Test
public void testSourceWithDestinationNameAndDefaultConnectionFactory() {
public void adapterWithDestinationNameAndDefaultConnectionFactory() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"jmsSourceWithDestinationNameAndDefaultConnectionFactory.xml", this.getClass());
JmsSource source = (JmsSource) context.getBean("jmsSource");
Message<?> message = source.receive();
"jmsInboundWithDestinationNameAndDefaultConnectionFactory.xml", this.getClass());
PollableChannel output = (PollableChannel) context.getBean("output");
Message<?> message = output.receive(1000);
assertNotNull("message should not be null", message);
assertEquals("polling-test", message.getPayload());
}
@Test
public void testSourceWithHeaderMapper() {
public void adapterWithHeaderMapper() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"jmsSourceWithHeaderMapper.xml", this.getClass());
JmsSource source = (JmsSource) context.getBean("jmsSource");
Message<?> message = source.receive();
"jmsInboundWithHeaderMapper.xml", this.getClass());
PollableChannel output = (PollableChannel) context.getBean("output");
Message<?> message = output.receive(1000);
assertNotNull("message should not be null", message);
assertEquals("polling-test", message.getPayload());
assertEquals("foo", message.getHeaders().get("testProperty"));
assertEquals(new Integer(123), message.getHeaders().get("testAttribute"));
}
@Test
public void testSourceEndpoint() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"jmsSourceEndpoint.xml", this.getClass());
context.start();
PollableChannel channel = (PollableChannel) context.getBean("channel");
Message<?> message = channel.receive(3000);
assertNotNull("message should not be null", message);
assertEquals("polling-test", message.getPayload());
context.stop();
}
}

View File

@@ -1,15 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms-1.0.xsd">
<jms:jms-source id="jmsSource"
connection-factory="testConnectionFactory"
destination="testDestination"/>
<integration:message-bus/>
<jms:inbound-channel-adapter channel="output"
connection-factory="testConnectionFactory"
destination="testDestination"/>
<integration:channel id="output">
<integration:queue capacity="1"/>
</integration:channel>
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<constructor-arg>

View File

@@ -1,15 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms-1.0.xsd">
<jms:jms-source id="jmsSource"
connection-factory="testConnectionFactory"
destination-name="testDestinationName"/>
<integration:message-bus/>
<jms:inbound-channel-adapter channel="output"
connection-factory="testConnectionFactory"
destination-name="testDestinationName"/>
<integration:channel id="output">
<integration:queue capacity="1"/>
</integration:channel>
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<constructor-arg>

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms-1.0.xsd">
<jms:jms-source id="adapter" connection-factory="testConnectionFactory"/>
<jms:inbound-channel-adapter id="adapter" connection-factory="testConnectionFactory"/>
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<constructor-arg>

View File

@@ -1,13 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms-1.0.xsd">
<jms:jms-source id="jmsSource" destination="testDestination"/>
<integration:message-bus/>
<jms:inbound-channel-adapter channel="output" destination="testDestination"/>
<integration:channel id="output">
<integration:queue capacity="1"/>
</integration:channel>
<bean id="testDestination" class="org.springframework.integration.jms.StubDestination"/>

View File

@@ -1,18 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms-1.0.xsd">
<jms:jms-source id="jmsSource" jms-template="jmsTemplate"/>
<integration:message-bus/>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="defaultDestinationName" value="test"/>
</bean>
<jms:inbound-channel-adapter channel="output" destination-name="testDestinationName"/>
<integration:channel id="output">
<integration:queue capacity="1"/>
</integration:channel>
<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<constructor-arg>

View File

@@ -7,6 +7,6 @@
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms-1.0.xsd">
<jms:jms-source id="jmsSource" destination-name="testDestinationName"/>
<jms:inbound-channel-adapter id="jmsSource" destination-name="testDestinationName"/>
</beans>

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms-1.0.xsd">
<jms:jms-source id="jmsSource" destination="testDestination"/>
<jms:inbound-channel-adapter id="jmsSource" destination="testDestination"/>
<bean id="testDestination" class="org.springframework.integration.jms.StubDestination"/>

View File

@@ -1,13 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms-1.0.xsd">
<jms:jms-source id="jmsSource" jms-template="jmsTemplate" header-mapper="mapper"/>
<integration:message-bus/>
<jms:inbound-channel-adapter channel="output" jms-template="jmsTemplate" header-mapper="mapper"/>
<integration:channel id="output">
<integration:queue capacity="1"/>
</integration:channel>
<bean id="mapper" class="org.springframework.integration.jms.config.TestMessageHeaderMapper"/>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
@@ -10,17 +10,13 @@
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms-1.0.xsd">
<si:message-bus/>
<integration:message-bus/>
<si:channel id="channel">
<si:queue capacity="10"/>
</si:channel>
<jms:inbound-channel-adapter jms-template="jmsTemplate" channel="output"/>
<si:inbound-channel-adapter ref="jmsSource" channel="channel">
<si:poller interval="5000" initial-delay="0" max-messages-per-poll="1"/>
</si:inbound-channel-adapter>
<jms:jms-source id="jmsSource" jms-template="jmsTemplate"/>
<integration:channel id="output">
<integration:queue capacity="1"/>
</integration:channel>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"/>

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms-1.0.xsd">
<jms:jms-source id="jmsSource" destination-name="testDestinationName"/>
<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<constructor-arg>
<bean class="org.springframework.integration.jms.StubConnection">
<constructor-arg value="polling-test"/>
</bean>
</constructor-arg>
</bean>
</beans>