INT-1203 The "jms-template" reference on a JMS <outbound-channel-adapter> is now properly configured by the parser.

This commit is contained in:
Mark Fisher
2010-07-21 19:16:27 +00:00
parent 13356b2d96
commit 5c9780cd71
4 changed files with 54 additions and 1 deletions

View File

@@ -35,6 +35,18 @@ public class JmsSendingMessageHandler extends AbstractJmsTemplateBasedAdapter im
private volatile int order = Ordered.LOWEST_PRECEDENCE;
public JmsSendingMessageHandler(JmsTemplate jmsTemplate) {
super(jmsTemplate);
}
/**
* No-arg constructor provided for convenience when configuring with
* setters. Note that the initialization callback will validate.
*/
public JmsSendingMessageHandler() {
super();
}
/**
* Specify whether the payload should be extracted from each Spring
* Integration Message to be converted to the body of a JMS Message.

View File

@@ -49,7 +49,7 @@ public class JmsOutboundChannelAdapterParser extends AbstractOutboundChannelAdap
throw new BeanCreationException("When providing a 'jms-template' reference, none of " +
"'connection-factory', 'destination', or 'destination-name' should be provided.");
}
builder.addPropertyReference(JmsAdapterParserUtils.JMS_TEMPLATE_PROPERTY, jmsTemplate);
builder.addConstructorArgReference(jmsTemplate);
}
else if (hasDestinationRef ^ hasDestinationName) {
builder.addPropertyReference(JmsAdapterParserUtils.CONNECTION_FACTORY_PROPERTY,

View File

@@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.jms.JmsHeaderMapper;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.converter.MessageConverter;
/**
@@ -89,6 +90,17 @@ public class JmsOutboundChannelAdapterParserTests {
assertEquals(TestJmsHeaderMapper.class, headerMapper.getClass());
}
@Test
public void adapterWithJmsTemplate() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"jmsOutboundWithJmsTemplate.xml", this.getClass());
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("adapter");
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(new DirectFieldAccessor(endpoint).getPropertyValue("handler"));
JmsTemplate jmsTemplate = (JmsTemplate) handlerAccessor.getPropertyValue("jmsTemplate");
assertNotNull(jmsTemplate);
assertEquals(context.getBean("template"), jmsTemplate);
}
@Test
public void adapterWithMessageConverter() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(

View File

@@ -0,0 +1,29 @@
<?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.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd">
<integration:channel id="input"/>
<jms:outbound-channel-adapter id="adapter" channel="input" jms-template="template"/>
<bean id="template" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<bean class="org.springframework.jms.connection.SingleConnectionFactory">
<constructor-arg>
<bean class="org.springframework.integration.jms.StubConnection">
<constructor-arg value="target-test"/>
</bean>
</constructor-arg>
</bean>
</property>
</bean>
</beans>