diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsAdapterParserUtils.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsAdapterParserUtils.java index c0a8d3d365..fce101b8ee 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsAdapterParserUtils.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsAdapterParserUtils.java @@ -52,6 +52,10 @@ abstract class JmsAdapterParserUtils { static final String HEADER_MAPPER_PROPERTY = "headerMapper"; + private static final String[] JMS_TEMPLATE_ATTRIBUTES = { "destination", "destination-name", + "connection-factory", "message-converter", "time-to-live", "priority", "delivery-persistent", "explicit-qos-enabled" }; + + /* * The following constants match those of javax.jms.Session. * They are duplicated here to avoid a dependency in tooling. @@ -102,4 +106,13 @@ abstract class JmsAdapterParserUtils { } } + static void verifyNoJmsTemplateAttributes(Element element, ParserContext parserContext) { + for (String attributeName : JMS_TEMPLATE_ATTRIBUTES) { + if (element.hasAttribute(attributeName)) { + parserContext.getReaderContext().error("When providing a 'jms-template' reference, the '" + + attributeName + "' attribute is not allowed", parserContext.extractSource(element)); + } + } + } + } diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParser.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParser.java index b952fbfa06..3ba23c5e6b 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParser.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParser.java @@ -60,15 +60,7 @@ public class JmsInboundChannelAdapterParser extends AbstractPollingInboundChanne boolean hasDestinationRef = StringUtils.hasText(destination); boolean hasDestinationName = StringUtils.hasText(destinationName); if (StringUtils.hasText(jmsTemplate)) { - if (element.hasAttribute(JmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE) || - hasDestinationRef || hasDestinationName) { - parserContext.getReaderContext().error( - "When providing '" + JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE + - "', none of '" + JmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE + - "', '" + JmsAdapterParserUtils.DESTINATION_ATTRIBUTE + "', or '" + - JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE + "' are allowed.", - source); - } + JmsAdapterParserUtils.verifyNoJmsTemplateAttributes(element, parserContext); builder.addConstructorArgReference(jmsTemplate); } else if (hasDestinationRef || hasDestinationName) { diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParser.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParser.java index 16624af905..e1c221ac53 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParser.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParser.java @@ -18,7 +18,6 @@ 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.ParserContext; @@ -44,11 +43,7 @@ public class JmsOutboundChannelAdapterParser extends AbstractOutboundChannelAdap boolean hasDestinationRef = StringUtils.hasText(destination); boolean hasDestinationName = StringUtils.hasText(destinationName); if (StringUtils.hasText(jmsTemplate)) { - if (element.hasAttribute(JmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE) || - hasDestinationRef || hasDestinationName) { - throw new BeanCreationException("When providing a 'jms-template' reference, none of " + - "'connection-factory', 'destination', or 'destination-name' should be provided."); - } + JmsAdapterParserUtils.verifyNoJmsTemplateAttributes(element, parserContext); builder.addConstructorArgReference(jmsTemplate); } else if (hasDestinationRef ^ hasDestinationName) { @@ -64,8 +59,8 @@ public class JmsOutboundChannelAdapterParser extends AbstractOutboundChannelAdap } } else { - throw new BeanCreationException("Either a 'jms-template' reference " + - "or one of 'destination' or 'destination-name' must be provided."); + parserContext.getReaderContext().error("Either a 'jms-template' reference " + + "or one of 'destination' or 'destination-name' must be provided.", parserContext.extractSource(element)); } if (StringUtils.hasText(headerMapper)) { builder.addPropertyReference(JmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper);