INT-1363 JmsOutboundChannelAdapterParser now allows a JmsTemplate reference along with a Destination or destinationName (but the latter 2 are still mutually exclusive)
This commit is contained in:
@@ -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.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
@@ -71,17 +70,17 @@ public class JmsInboundChannelAdapterParser extends AbstractPollingInboundChanne
|
||||
parserContext.getReaderContext().error("The 'destination-name' " +
|
||||
"and 'destination' attributes are mutually exclusive.", parserContext.extractSource(element));
|
||||
}
|
||||
builder.addPropertyReference("destination", destination);
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.DESTINATION_PROPERTY, destination);
|
||||
}
|
||||
else if (hasDestinationName) {
|
||||
builder.addPropertyValue("destinationName", destinationName);
|
||||
builder.addPropertyValue(JmsAdapterParserUtils.DESTINATION_NAME_PROPERTY, destinationName);
|
||||
}
|
||||
}
|
||||
else if (!hasJmsTemplate) {
|
||||
throw new BeanCreationException("either a '" + JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE +
|
||||
parserContext.getReaderContext().error("either a '" + JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE +
|
||||
"' or one of '" + JmsAdapterParserUtils.DESTINATION_ATTRIBUTE + "' or '"
|
||||
+ JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE +
|
||||
"' attributes must be provided for a polling JMS adapter");
|
||||
"' attributes must be provided for a polling JMS adapter", parserContext.extractSource(element));
|
||||
}
|
||||
if (StringUtils.hasText(headerMapper)) {
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper);
|
||||
|
||||
@@ -40,26 +40,33 @@ public class JmsOutboundChannelAdapterParser extends AbstractOutboundChannelAdap
|
||||
String destination = element.getAttribute(JmsAdapterParserUtils.DESTINATION_ATTRIBUTE);
|
||||
String destinationName = element.getAttribute(JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE);
|
||||
String headerMapper = element.getAttribute(JmsAdapterParserUtils.HEADER_MAPPER_ATTRIBUTE);
|
||||
boolean hasJmsTemplate = StringUtils.hasText(jmsTemplate);
|
||||
boolean hasDestinationRef = StringUtils.hasText(destination);
|
||||
boolean hasDestinationName = StringUtils.hasText(destinationName);
|
||||
if (StringUtils.hasText(jmsTemplate)) {
|
||||
if (hasJmsTemplate) {
|
||||
JmsAdapterParserUtils.verifyNoJmsTemplateAttributes(element, parserContext);
|
||||
builder.addConstructorArgReference(jmsTemplate);
|
||||
}
|
||||
else if (hasDestinationRef ^ hasDestinationName) {
|
||||
else {
|
||||
builder.addConstructorArgValue(JmsAdapterParserUtils.parseJmsTemplateBeanDefinition(element, parserContext));
|
||||
if (StringUtils.hasText(destination)) {
|
||||
}
|
||||
if (hasDestinationRef || hasDestinationName) {
|
||||
if (hasDestinationRef) {
|
||||
if (hasDestinationName) {
|
||||
parserContext.getReaderContext().error("The 'destination-name' " +
|
||||
"and 'destination' attributes are mutually exclusive.", parserContext.extractSource(element));
|
||||
}
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.DESTINATION_PROPERTY, destination);
|
||||
}
|
||||
else {
|
||||
else if (hasDestinationName) {
|
||||
builder.addPropertyValue(JmsAdapterParserUtils.DESTINATION_NAME_PROPERTY, destinationName);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(
|
||||
builder, element, JmsAdapterParserUtils.PUB_SUB_DOMAIN_ATTRIBUTE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
parserContext.getReaderContext().error("Either a 'jms-template' reference " +
|
||||
"or one of 'destination' or 'destination-name' must be provided.", parserContext.extractSource(element));
|
||||
else if (!hasJmsTemplate) {
|
||||
parserContext.getReaderContext().error("either a '" + JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE +
|
||||
"' or one of '" + JmsAdapterParserUtils.DESTINATION_ATTRIBUTE + "' or '"
|
||||
+ JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE +
|
||||
"' attributes must be provided", parserContext.extractSource(element));
|
||||
}
|
||||
if (StringUtils.hasText(headerMapper)) {
|
||||
builder.addPropertyReference(JmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -69,13 +69,7 @@ public class JmsInboundChannelAdapterParserTests {
|
||||
|
||||
@Test(expected = BeanDefinitionStoreException.class)
|
||||
public void adapterWithConnectionFactoryOnly() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("jmsInboundWithConnectionFactoryOnly.xml", this.getClass());
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals(BeanCreationException.class, e.getCause().getClass());
|
||||
throw e;
|
||||
}
|
||||
new ClassPathXmlApplicationContext("jmsInboundWithConnectionFactoryOnly.xml", this.getClass());
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
|
||||
Reference in New Issue
Block a user