diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundGatewayParser.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundGatewayParser.java index 563e0edda3..c52101c27c 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundGatewayParser.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundGatewayParser.java @@ -16,6 +16,10 @@ package org.springframework.integration.jms.config; +import javax.jms.DeliveryMode; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.w3c.dom.Element; import org.springframework.beans.factory.support.BeanDefinitionBuilder; @@ -28,8 +32,10 @@ import org.springframework.util.StringUtils; * Parser for the <outbound-gateway> element of the integration 'jms' namespace. * * @author Mark Fisher + * @author Oleg Zhurakousky */ public class JmsOutboundGatewayParser extends AbstractConsumerEndpointParser { + private static final Log logger = LogFactory.getLog(JmsOutboundGatewayParser.class); @Override protected String getInputChannelAttributeName() { @@ -64,10 +70,31 @@ public class JmsOutboundGatewayParser extends AbstractConsumerEndpointParser { IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-reply-payload"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "receive-timeout"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "pub-sub-domain"); - IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "delivery-mode"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "time-to-live"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "priority"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "explicit-qos-enabled"); + + String deliveryMode = element.getAttribute("delivery-mode"); + String deliveryPersistent = element.getAttribute("delivery-persistent"); + + if (StringUtils.hasText(deliveryMode) && StringUtils.hasText(deliveryPersistent)){ + parserContext.getReaderContext(). + error("Exactly one of the 'delivery-mode' attribute or 'delivery-persistent' attribute is allowed", element); + return null; + } + if (StringUtils.hasText(deliveryMode)){ + logger.warn("'delivery-mode' attribute is deprecated. Use 'delivery-persistent' instead"); + builder.addPropertyValue("deliveryMode", deliveryMode); + } + else if (StringUtils.hasText(deliveryPersistent)){ + boolean persistentValue = Boolean.parseBoolean(deliveryPersistent); + if (persistentValue){ + builder.addPropertyValue("deliveryMode", DeliveryMode.PERSISTENT); + } + else { + builder.addPropertyValue("deliveryMode", DeliveryMode.NON_PERSISTENT); + } + } return builder; } diff --git a/spring-integration-jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd b/spring-integration-jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd index d4d8d97e2d..260ecc8a40 100644 --- a/spring-integration-jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd +++ b/spring-integration-jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd @@ -729,7 +729,24 @@ - + + + + + + + + + Specify a boolean value indicating whether the delivery mode should be + DeliveryMode.PERSISTENT (true) or DeliveryMode.NON_PERSISTENT (false). + This setting will only take effect if 'explicit-qos-enabled' is true. + + + diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsOutboundGatewayParserTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsOutboundGatewayParserTests.java index 08d0339815..ab6725b134 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsOutboundGatewayParserTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsOutboundGatewayParserTests.java @@ -24,8 +24,11 @@ import static org.mockito.Mockito.verify; import java.util.Properties; +import javax.jms.DeliveryMode; + import org.junit.Test; import org.mockito.Mockito; + import org.springframework.beans.DirectFieldAccessor; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.Message; @@ -47,6 +50,18 @@ import org.springframework.jms.support.converter.MessageConverter; * @author Oleg Zhurakousky */ public class JmsOutboundGatewayParserTests { + + @Test + public void testWithDelivertPersistentAttribute(){ + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( + "jmsOutboundGatewayWithDeliveryPersistent.xml", this.getClass()); + EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("jmsGateway"); + DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint); + JmsOutboundGateway gateway = (JmsOutboundGateway) accessor.getPropertyValue("handler"); + accessor = new DirectFieldAccessor(gateway); + int deliveryMode = (Integer)accessor.getPropertyValue("deliveryMode"); + assertEquals(DeliveryMode.PERSISTENT, deliveryMode); + } @Test public void testDefault(){