INT-1447 raising an error if any JmsTemplate attributes are set when an explicit 'jms-template' reference is also specified
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user