INT-712 Headers defined by 'header-enricher' elements are now configured as sub-elements rather than attributes. This applies to the "core" as well as the JMS and Mail namespace support.

This commit is contained in:
Mark Fisher
2009-11-03 00:14:28 +00:00
parent 543ec6f5f6
commit 33f593cf27
18 changed files with 550 additions and 215 deletions

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2002-2009 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.jms.config;
import org.springframework.integration.config.xml.HeaderEnricherParserSupport;
import org.springframework.integration.jms.JmsHeaders;
/**
* Header enricher for JMS specific values.
*
* @author Mark Fisher
* @since 2.0
*/
public class JmsHeaderEnricherParser extends HeaderEnricherParserSupport {
public JmsHeaderEnricherParser() {
this.addElementToHeaderMapping("correlation-id", JmsHeaders.CORRELATION_ID);
this.addElementToHeaderMapping("reply-to", JmsHeaders.REPLY_TO);
}
}

View File

@@ -18,8 +18,6 @@ package org.springframework.integration.jms.config;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler;
import org.springframework.integration.config.xml.SimpleHeaderEnricherParser;
import org.springframework.integration.jms.JmsHeaders;
/**
* Namespace handler for Spring Integration's <em>jms</em> namespace.
@@ -37,8 +35,7 @@ public class JmsNamespaceHandler extends AbstractIntegrationNamespaceHandler {
BeanDefinitionParser channelParser = new JmsChannelParser();
this.registerBeanDefinitionParser("channel", channelParser);
this.registerBeanDefinitionParser("publish-subscribe-channel", channelParser);
this.registerBeanDefinitionParser("header-enricher",
new SimpleHeaderEnricherParser(JmsHeaders.PREFIX, new String[] { "replyTo" }));
this.registerBeanDefinitionParser("header-enricher", new JmsHeaderEnricherParser());
}
}

View File

@@ -537,14 +537,44 @@
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="transformerType">
<xsd:attribute name="correlation-id" type="xsd:string"/>
<xsd:attribute name="reply-to" type="xsd:string"/>
<xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element name="reply-to" type="refOnlyHeaderType">
<xsd:annotation>
<xsd:documentation>
The ReplyTo Destination for the JMS Message.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="correlation-id" type="refOrValueHeaderType">
<xsd:annotation>
<xsd:documentation>
The Correlation ID for the JMS Message.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:choice>
<!--
<xsd:attribute name="overwrite" type="xsd:string"/>
-->
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="refOrValueHeaderType">
<xsd:complexContent>
<xsd:extension base="refOnlyHeaderType">
<xsd:attribute name="value" type="xsd:string" />
<!-- xsd:attribute name="expression" type="xsd:string" / -->
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="refOnlyHeaderType">
<xsd:attribute name="ref" type="xsd:string" />
<!-- TODO add 'overwrite' -->
</xsd:complexType>
<xsd:complexType name="jmsAdapterType">
<xsd:annotation>
<xsd:documentation>

View File

@@ -10,8 +10,10 @@
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd">
<jms:header-enricher input-channel="input" output-channel="output"
reply-to="testDestination"/>
<jms:header-enricher input-channel="input" output-channel="output">
<jms:reply-to ref="testDestination"/>
<jms:correlation-id value="ABC"/>
</jms:header-enricher>
<bean id="testDestination" class="org.springframework.integration.jms.StubDestination"/>

View File

@@ -60,4 +60,14 @@ public class JmsHeaderEnricherTests {
assertEquals(testDestination, jmsMessage.getJMSReplyTo());
}
@Test
public void verifyCorrelationId() throws Exception {
input.send(new StringMessage("test"));
Message<?> result = output.receive(0);
assertEquals("ABC", result.getHeaders().get(JmsHeaders.CORRELATION_ID));
HeaderMappingMessageConverter converter = new HeaderMappingMessageConverter();
javax.jms.Message jmsMessage = converter.toMessage(result, new StubSession("foo"));
assertEquals("ABC", jmsMessage.getJMSCorrelationID());
}
}