diff --git a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsHeaderEnricherParser.java b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsHeaderEnricherParser.java new file mode 100644 index 0000000000..49d4766e6d --- /dev/null +++ b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsHeaderEnricherParser.java @@ -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); + } + +} diff --git a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsNamespaceHandler.java b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsNamespaceHandler.java index 3f8c5b97ef..8da780cdf0 100644 --- a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsNamespaceHandler.java +++ b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsNamespaceHandler.java @@ -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 jms 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()); } } diff --git a/org.springframework.integration.jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd b/org.springframework.integration.jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd index 02548e83e7..7e0371b153 100644 --- a/org.springframework.integration.jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd +++ b/org.springframework.integration.jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd @@ -537,14 +537,44 @@ - - + + + + + The ReplyTo Destination for the JMS Message. + + + + + + + The Correlation ID for the JMS Message. + + + + + + + + + + + + + + + + + + + diff --git a/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests-context.xml b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests-context.xml index 4fb2f41fab..0f1f85a58a 100644 --- a/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests-context.xml +++ b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests-context.xml @@ -10,8 +10,10 @@ http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd"> - + + + + diff --git a/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests.java b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests.java index 08ce07aa10..cd322e0f05 100644 --- a/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests.java +++ b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests.java @@ -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()); + } + } diff --git a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/MailHeaderEnricherParser.java b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/MailHeaderEnricherParser.java new file mode 100644 index 0000000000..68f0184838 --- /dev/null +++ b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/MailHeaderEnricherParser.java @@ -0,0 +1,37 @@ +/* + * 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.mail.config; + +import org.springframework.integration.config.xml.HeaderEnricherParserSupport; +import org.springframework.integration.mail.MailHeaders; + +/** + * @author Mark Fisher + * @since 2.0 + */ +public class MailHeaderEnricherParser extends HeaderEnricherParserSupport { + + public MailHeaderEnricherParser() { + this.addElementToHeaderMapping("subject", MailHeaders.SUBJECT); + this.addElementToHeaderMapping("to", MailHeaders.TO); + this.addElementToHeaderMapping("cc", MailHeaders.CC); + this.addElementToHeaderMapping("bcc", MailHeaders.BCC); + this.addElementToHeaderMapping("from", MailHeaders.FROM); + this.addElementToHeaderMapping("reply-to", MailHeaders.REPLY_TO); + } + +} diff --git a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/MailNamespaceHandler.java b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/MailNamespaceHandler.java index 1c48c2fd90..7e4e100d5b 100644 --- a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/MailNamespaceHandler.java +++ b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/MailNamespaceHandler.java @@ -17,8 +17,6 @@ package org.springframework.integration.mail.config; import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler; -import org.springframework.integration.config.xml.SimpleHeaderEnricherParser; -import org.springframework.integration.mail.MailHeaders; /** * Namespace handler for the 'mail' namespace. @@ -31,7 +29,7 @@ public class MailNamespaceHandler extends AbstractIntegrationNamespaceHandler { this.registerBeanDefinitionParser("outbound-channel-adapter", new MailOutboundChannelAdapterParser()); this.registerBeanDefinitionParser("inbound-channel-adapter", new MailInboundChannelAdapterParser()); this.registerBeanDefinitionParser("imap-idle-channel-adapter", new ImapIdleChannelAdapterParser()); - this.registerBeanDefinitionParser("header-enricher", new SimpleHeaderEnricherParser(MailHeaders.PREFIX)); + this.registerBeanDefinitionParser("header-enricher", new MailHeaderEnricherParser()); this.registerBeanDefinitionParser("mail-to-string-transformer", new MailToStringTransformerParser()); } diff --git a/org.springframework.integration.mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-2.0.xsd b/org.springframework.integration.mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-2.0.xsd index 1f58663f97..38a8f029fc 100644 --- a/org.springframework.integration.mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-2.0.xsd +++ b/org.springframework.integration.mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-2.0.xsd @@ -194,18 +194,26 @@ - - - - - - - + + + + + + + + + + + + + + + diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/MailHeaderEnricherTests-context.xml b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/MailHeaderEnricherTests-context.xml index 55f5a7e4f1..52fb4562e3 100644 --- a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/MailHeaderEnricherTests-context.xml +++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/MailHeaderEnricherTests-context.xml @@ -7,12 +7,13 @@ http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd"> - + + + + + + + + diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java index e9499f77d3..0d9c63ecc6 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java @@ -16,6 +16,10 @@ package org.springframework.integration.config.xml; +import java.util.List; + +import org.w3c.dom.Element; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -23,8 +27,8 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.CollectionUtils; import org.springframework.util.xml.DomUtils; -import org.w3c.dom.Element; /** * Base class parser for elements that create Message Endpoints. @@ -97,9 +101,13 @@ public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinit BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry()); } builder.addPropertyValue("inputChannelName", inputChannelName); - Element pollerElement = DomUtils.getChildElementByTagName(element, "poller"); - if (pollerElement != null) { - IntegrationNamespaceUtils.configurePollerMetadata(pollerElement, builder, parserContext); + List pollerElementList = DomUtils.getChildElementsByTagName(element, "poller"); + if (!CollectionUtils.isEmpty(pollerElementList)) { + if (pollerElementList.size() != 1) { + parserContext.getReaderContext().error( + "at most one poller element may be configured for an endpoint", element); + } + IntegrationNamespaceUtils.configurePollerMetadata(pollerElementList.get(0), builder, parserContext); } IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup"); return builder.getBeanDefinition(); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java new file mode 100644 index 0000000000..f4ec193c93 --- /dev/null +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java @@ -0,0 +1,127 @@ +/* + * 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.config.xml; + +import java.util.HashMap; +import java.util.Map; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.config.TypedStringValue; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.ManagedMap; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.ClassUtils; +import org.springframework.util.StringUtils; + +/** + * Base support class for 'header-enricher' parsers. + * + * @author Mark Fisher + * @since 2.0 + */ +public abstract class HeaderEnricherParserSupport extends AbstractTransformerParser { + + private final Map elementToNameMap = new HashMap(); + + private final Map> elementToTypeMap = new HashMap>(); + + + @Override + protected final String getTransformerClassName() { + return IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.HeaderEnricher"; + } + + protected boolean shouldOverwrite(Element element) { + return "true".equals(element.getAttribute("overwrite").toLowerCase()); + } + + protected final void addElementToHeaderMapping(String elementName, String headerName) { + this.addElementToHeaderMapping(elementName, headerName, null); + } + + protected final void addElementToHeaderMapping(String elementName, String headerName, Class headerType) { + this.elementToNameMap.put(elementName, headerName); + if (headerType != null) { + this.elementToTypeMap.put(elementName, headerType); + } + } + + @Override + @SuppressWarnings("unchecked") + protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + ManagedMap headers = new ManagedMap(); + this.processHeaders(element, headers, parserContext); + builder.addConstructorArgValue(headers); + builder.addPropertyValue("overwrite", this.shouldOverwrite(element)); // TODO: should be a per-header config setting + } + + protected void processHeaders(Element element, ManagedMap headers, ParserContext parserContext) { + NodeList childNodes = element.getChildNodes(); + for (int i = 0; i < childNodes.getLength(); i++) { + Node node = childNodes.item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + String headerName = null; + Element headerElement = (Element) node; + String elementName = node.getLocalName(); + Class headerType = null; + if ("header".equals(elementName)) { + headerName = headerElement.getAttribute("name"); + String headerTypeName = headerElement.getAttribute("type"); + if (StringUtils.hasText(headerTypeName)) { + ClassLoader classLoader = parserContext.getReaderContext().getBeanClassLoader(); + if (classLoader != null) { + try { + headerType = ClassUtils.forName(headerTypeName, classLoader); + } + catch (Exception e) { + parserContext.getReaderContext().error("unable to resolve type [" + + headerTypeName + "] for header '" + headerName + "'", element, e); + } + } + } + } + else { + headerName = elementToNameMap.get(elementName); + headerType = elementToTypeMap.get(elementName); + } + if (headerName != null) { + String value = headerElement.getAttribute("value"); + String ref = headerElement.getAttribute("ref"); + boolean isValue = StringUtils.hasText(value); + boolean isRef = StringUtils.hasText(ref); + if (!(isValue ^ isRef)) { + parserContext.getReaderContext().error( + "Exactly one of the 'value' or 'ref' attributes is required.", element); + } + if (isValue) { + Object headerValue = (headerType != null) ? + new TypedStringValue(value, headerType) : value; + headers.put(headerName, headerValue); + } + else { + headers.put(headerName, new RuntimeBeanReference(ref)); + } + } + } + } + } + +} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/SimpleHeaderEnricherParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/SimpleHeaderEnricherParser.java deleted file mode 100644 index c8d469f87d..0000000000 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/SimpleHeaderEnricherParser.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.config.xml; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.ManagedMap; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.core.Conventions; -import org.springframework.util.ObjectUtils; - -/** - * @author Mark Fisher - */ -public class SimpleHeaderEnricherParser extends AbstractTransformerParser { - - private static String[] ineligibleHeaderNames = new String[] { - "id", "input-channel", "output-channel", "overwrite" - }; - - - private final String prefix; - - private List referenceAttributes; - - - public SimpleHeaderEnricherParser() { - this(null, null); - } - - public SimpleHeaderEnricherParser(String prefix) { - this(prefix, null); - } - - public SimpleHeaderEnricherParser(String prefix, String[] referenceAttributes) { - this.prefix = prefix; - this.referenceAttributes = (referenceAttributes != null) - ? Arrays.asList(referenceAttributes) : Collections.emptyList(); - } - - - @Override - protected String getTransformerClassName() { - return IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.HeaderEnricher"; - } - - protected boolean isEligibleHeaderName(String headerName) { - return !(ObjectUtils.containsElement(ineligibleHeaderNames, headerName)); - } - - protected boolean shouldOverwrite(Element element) { - return "true".equals(element.getAttribute("overwrite").toLowerCase()); - } - - @Override - @SuppressWarnings("unchecked") - protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - ManagedMap headers = new ManagedMap(); - NamedNodeMap attributes = element.getAttributes(); - for (int i = 0; i < attributes.getLength(); i++) { - Node node = attributes.item(i); - String name = node.getNodeName(); - if (this.isEligibleHeaderName(name)) { - name = Conventions.attributeNameToPropertyName(name); - Object value = (this.referenceAttributes.contains(name)) - ? new RuntimeBeanReference(node.getNodeValue()) - : node.getNodeValue(); - if (this.prefix != null) { - name = this.prefix + name; - } - headers.put(name, value); - } - } - this.postProcessHeaders(element, headers, parserContext); - builder.addConstructorArgValue(headers); - builder.addPropertyValue("overwrite", this.shouldOverwrite(element)); - } - - /** - * Subclasses may implement this method to provide additional headers. - */ - protected void postProcessHeaders(Element element, ManagedMap headers, ParserContext parserContext) { - } - -} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/StandardHeaderEnricherParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/StandardHeaderEnricherParser.java index cee4ba0c00..b465360e10 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/StandardHeaderEnricherParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/StandardHeaderEnricherParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * 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. @@ -16,15 +16,8 @@ package org.springframework.integration.config.xml; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.support.ManagedMap; -import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.core.MessageHeaders; -import org.springframework.util.StringUtils; +import org.springframework.integration.core.MessagePriority; /** * Parser for the <header-enricher> element within the core integration @@ -35,43 +28,14 @@ import org.springframework.util.StringUtils; * * @author Mark Fisher */ -public class StandardHeaderEnricherParser extends SimpleHeaderEnricherParser { - - private static final String[] REFERENCE_ATTRIBUTES = new String[] { - "reply-channel", "error-channel" - }; - +public class StandardHeaderEnricherParser extends HeaderEnricherParserSupport { public StandardHeaderEnricherParser() { - super(MessageHeaders.PREFIX, REFERENCE_ATTRIBUTES); - } - - - @Override - @SuppressWarnings("unchecked") - protected void postProcessHeaders(Element element, ManagedMap headers, ParserContext parserContext) { - NodeList childNodes = element.getChildNodes(); - for (int i = 0; i < childNodes.getLength(); i++) { - Node node = childNodes.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE && node.getLocalName().equals("header")) { - Element headerElement = (Element) node; - String name = headerElement.getAttribute("name"); - String value = headerElement.getAttribute("value"); - String ref = headerElement.getAttribute("ref"); - boolean isValue = StringUtils.hasText(value); - boolean isRef = StringUtils.hasText(ref); - if (!(isValue ^ isRef)) { - parserContext.getReaderContext().error( - "Exactly one of the 'value' or 'ref' attributes is required.", element); - } - if (isValue) { - headers.put(name, value); - } - else { - headers.put(name, new RuntimeBeanReference(ref)); - } - } - } + this.addElementToHeaderMapping("reply-channel", MessageHeaders.REPLY_CHANNEL); + this.addElementToHeaderMapping("error-channel", MessageHeaders.ERROR_CHANNEL); + this.addElementToHeaderMapping("correlation-id", MessageHeaders.CORRELATION_ID); + this.addElementToHeaderMapping("expiration-date", MessageHeaders.EXPIRATION_DATE, Long.class); + this.addElementToHeaderMapping("priority", MessageHeaders.PRIORITY, MessagePriority.class); } } diff --git a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd index f0b1fb04af..d70975e696 100644 --- a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd +++ b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd @@ -878,25 +878,87 @@ - - - + + + + + + + + + + + + + + + + + + Element that accepts any user-defined header name/value pair. + + + + + - + + + + + + + + + + + - Defines a Message Header value or ref. + Defines a Message Header with a literal value or object reference. - - - + + + + + + Name of the header to be added. + + + + + + + + + + + + + + Literal value to be associated with the given header name. + + + + + + + + + + + + + Reference to be associated with the given header name. + + + @@ -906,29 +968,6 @@ MessageHeaders. - - - - - - - - - - - - - - - - - - - - - diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/ChainParserTests-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/ChainParserTests-context.xml index 595abe68e8..a0943d2682 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/ChainParserTests-context.xml +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/ChainParserTests-context.xml @@ -28,8 +28,9 @@ - + + +
diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/HeaderEnricherTests-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/HeaderEnricherTests-context.xml new file mode 100644 index 0000000000..b50cdeb571 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/HeaderEnricherTests-context.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/HeaderEnricherTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/HeaderEnricherTests.java new file mode 100644 index 0000000000..e7ac1a5f40 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/HeaderEnricherTests.java @@ -0,0 +1,118 @@ +/* + * 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.config.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.integration.channel.PollableChannel; +import org.springframework.integration.core.Message; +import org.springframework.integration.core.MessageChannel; +import org.springframework.integration.core.MessagePriority; +import org.springframework.integration.gateway.SimpleMessagingGateway; +import org.springframework.integration.message.StringMessage; +import org.springframework.integration.transformer.MessageTransformationException; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Mark Fisher + * @since 2.0 + */ +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class HeaderEnricherTests { + + @Autowired + private ApplicationContext context; + + @Test + public void replyChannel() { + PollableChannel replyChannel = context.getBean("testReplyChannel", PollableChannel.class); + MessageChannel inputChannel = context.getBean("replyChannelInput", MessageChannel.class); + inputChannel.send(new StringMessage("test")); + Message result = replyChannel.receive(0); + assertNotNull(result); + assertEquals("TEST", result.getPayload()); + assertEquals(replyChannel, result.getHeaders().getReplyChannel()); + } + + @Test + public void errorChannel() { + PollableChannel errorChannel = context.getBean("testErrorChannel", PollableChannel.class); + MessageChannel inputChannel = context.getBean("errorChannelInput", MessageChannel.class); + inputChannel.send(new StringMessage("test")); + Message errorMessage = errorChannel.receive(1000); + assertNotNull(errorMessage); + Object errorPayload = errorMessage.getPayload(); + assertEquals(MessageTransformationException.class, errorPayload.getClass()); + Message failedMessage = ((MessageTransformationException) errorPayload).getFailedMessage(); + assertEquals("test", failedMessage.getPayload()); + assertEquals(errorChannel, failedMessage.getHeaders().getErrorChannel()); + } + + @Test + public void correlationIdValue() { + SimpleMessagingGateway gateway = new SimpleMessagingGateway(); + gateway.setRequestChannel(context.getBean("correlationIdValueInput", MessageChannel.class)); + Message result = gateway.sendAndReceiveMessage("test"); + assertNotNull(result); + assertEquals("ABC", result.getHeaders().getCorrelationId()); + } + + @Test + public void correlationIdRef() { + SimpleMessagingGateway gateway = new SimpleMessagingGateway(); + gateway.setRequestChannel(context.getBean("correlationIdRefInput", MessageChannel.class)); + Message result = gateway.sendAndReceiveMessage("test"); + assertNotNull(result); + assertEquals(new Integer(123), result.getHeaders().getCorrelationId()); + } + + @Test + public void expirationDateValue() { + SimpleMessagingGateway gateway = new SimpleMessagingGateway(); + gateway.setRequestChannel(context.getBean("expirationDateValueInput", MessageChannel.class)); + Message result = gateway.sendAndReceiveMessage("test"); + assertNotNull(result); + assertEquals(new Long(1111), result.getHeaders().getExpirationDate()); + } + + @Test + public void expirationDateRef() { + SimpleMessagingGateway gateway = new SimpleMessagingGateway(); + gateway.setRequestChannel(context.getBean("expirationDateRefInput", MessageChannel.class)); + Message result = gateway.sendAndReceiveMessage("test"); + assertNotNull(result); + assertEquals(new Long(9999), result.getHeaders().getExpirationDate()); + } + + @Test + public void priority() { + SimpleMessagingGateway gateway = new SimpleMessagingGateway(); + gateway.setRequestChannel(context.getBean("priorityInput", MessageChannel.class)); + Message result = gateway.sendAndReceiveMessage("test"); + assertNotNull(result); + assertEquals(MessagePriority.HIGH, result.getHeaders().getPriority()); + } + +} diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/OrderedHandlersTests-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/OrderedHandlersTests-context.xml index 880e962332..33f69ec014 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/OrderedHandlersTests-context.xml +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/OrderedHandlersTests-context.xml @@ -11,7 +11,9 @@ - + +
+