Added support for a "header-mapper" attribute on the <jms-source/> and <jms-target/> elements (INT-205).
This commit is contained in:
@@ -58,12 +58,19 @@
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="jms-source" type="jmsInboundAdapterType">
|
||||
<xsd:element name="jms-source">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a JMS-based source channel adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="jmsInboundAdapterType">
|
||||
<xsd:attribute name="header-mapper" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="jms-gateway">
|
||||
@@ -86,12 +93,19 @@
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="jms-target" type="jmsAdapterType">
|
||||
<xsd:element name="jms-target">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a target that sends JMS Messages.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="jmsAdapterType">
|
||||
<xsd:attribute name="header-mapper" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:complexType name="jmsInboundAdapterType">
|
||||
|
||||
@@ -46,6 +46,10 @@ public abstract class JmsAdapterParserUtils {
|
||||
|
||||
public static final String DESTINATION_NAME_PROPERTY = "destinationName";
|
||||
|
||||
public static final String HEADER_MAPPER_ATTRIBUTE = "header-mapper";
|
||||
|
||||
public static final String HEADER_MAPPER_PROPERTY = "headerMapper";
|
||||
|
||||
public static final String MESSAGE_CONVERTER_ATTRIBUTE = "message-converter";
|
||||
|
||||
public static final String MESSAGE_CONVERTER_PROPERTY = "messageConverter";
|
||||
|
||||
@@ -47,6 +47,7 @@ public class JmsSourceParser extends AbstractBeanDefinitionParser {
|
||||
String jmsTemplate = element.getAttribute(JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE);
|
||||
String destination = element.getAttribute(JmsAdapterParserUtils.DESTINATION_ATTRIBUTE);
|
||||
String destinationName = element.getAttribute(JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE);
|
||||
String headerMapper = element.getAttribute(JmsAdapterParserUtils.HEADER_MAPPER_ATTRIBUTE);
|
||||
if (StringUtils.hasText(jmsTemplate)) {
|
||||
if (element.hasAttribute(JmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE) ||
|
||||
element.hasAttribute(JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE) ||
|
||||
@@ -73,6 +74,9 @@ public class JmsSourceParser extends AbstractBeanDefinitionParser {
|
||||
JmsAdapterParserUtils.DESTINATION_ATTRIBUTE + "' or '" + JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE +
|
||||
"' attributes must be provided for a polling JMS adapter");
|
||||
}
|
||||
if (StringUtils.hasText(headerMapper)) {
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper);
|
||||
}
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ public class JmsTargetParser extends AbstractSingleBeanDefinitionParser {
|
||||
String jmsTemplate = element.getAttribute(JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE);
|
||||
String destination = element.getAttribute(JmsAdapterParserUtils.DESTINATION_ATTRIBUTE);
|
||||
String destinationName = element.getAttribute(JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE);
|
||||
String headerMapper = element.getAttribute(JmsAdapterParserUtils.HEADER_MAPPER_ATTRIBUTE);
|
||||
if (StringUtils.hasText(jmsTemplate)) {
|
||||
if (element.hasAttribute(JmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE) ||
|
||||
element.hasAttribute(JmsAdapterParserUtils.DESTINATION_ATTRIBUTE) ||
|
||||
@@ -71,6 +72,9 @@ public class JmsTargetParser extends AbstractSingleBeanDefinitionParser {
|
||||
throw new BeanCreationException("Either a 'jms-template' reference or " +
|
||||
"one of 'destination' or 'destination-name' attributes must be provided.");
|
||||
}
|
||||
if (StringUtils.hasText(headerMapper)) {
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -114,6 +114,18 @@ public class JmsSourceParserTests {
|
||||
assertEquals("polling-test", message.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourceWithHeaderMapper() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"jmsSourceWithHeaderMapper.xml", this.getClass());
|
||||
JmsSource source = (JmsSource) context.getBean("jmsSource");
|
||||
Message<?> message = source.receive();
|
||||
assertNotNull("message should not be null", message);
|
||||
assertEquals("polling-test", message.getPayload());
|
||||
assertEquals("foo", message.getHeader().getProperty("testProperty"));
|
||||
assertEquals(new Integer(123), message.getHeader().getAttribute("testAttribute"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourceEndpoint() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.MessageHeaderMapper;
|
||||
import org.springframework.integration.adapter.jms.JmsTarget;
|
||||
|
||||
/**
|
||||
@@ -59,6 +60,19 @@ public class JmsTargetParserTests {
|
||||
assertNotNull(accessor.getPropertyValue("jmsTemplate"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testTargetWithHeaderMapper() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"targetWithHeaderMapper.xml", this.getClass());
|
||||
JmsTarget target = (JmsTarget) context.getBean("target");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(target);
|
||||
MessageHeaderMapper headerMapper = (MessageHeaderMapper)
|
||||
accessor.getPropertyValue("headerMapper");
|
||||
assertNotNull(headerMapper);
|
||||
assertEquals(TestMessageHeaderMapper.class, headerMapper.getClass());
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testTargetWithEmptyConnectionFactory() {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.adapter.jms.config;
|
||||
|
||||
import javax.jms.Message;
|
||||
|
||||
import org.springframework.integration.adapter.MessageHeaderMapper;
|
||||
import org.springframework.integration.message.MessageHeader;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TestMessageHeaderMapper implements MessageHeaderMapper<Message> {
|
||||
|
||||
public void mapFromMessageHeader(MessageHeader header, Message target) {
|
||||
}
|
||||
|
||||
public void mapToMessageHeader(Message source, MessageHeader header) {
|
||||
header.setProperty("testProperty", "foo");
|
||||
header.setAttribute("testAttribute", new Integer(123));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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"
|
||||
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">
|
||||
|
||||
<si:jms-source id="jmsSource" jms-template="jmsTemplate" header-mapper="mapper"/>
|
||||
|
||||
<bean id="mapper" class="org.springframework.integration.adapter.jms.config.TestMessageHeaderMapper"/>
|
||||
|
||||
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
|
||||
<property name="connectionFactory" ref="connectionFactory"/>
|
||||
<property name="defaultDestinationName" value="test"/>
|
||||
</bean>
|
||||
|
||||
<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.adapter.jms.StubConnection">
|
||||
<constructor-arg value="polling-test"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +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:si="http://www.springframework.org/schema/integration"
|
||||
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">
|
||||
|
||||
<si:jms-target id="target" destination="testDestination" header-mapper="mapper"/>
|
||||
|
||||
<bean id="mapper" class="org.springframework.integration.adapter.jms.config.TestMessageHeaderMapper"/>
|
||||
|
||||
<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.adapter.jms.StubConnection">
|
||||
<constructor-arg value="target-test"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="testDestination" class="org.springframework.integration.adapter.jms.StubDestination"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user