INT-1719 added delivery-persistent attribute to outbound-gateway, deprecated delivery-mode

This commit is contained in:
Oleg Zhurakousky
2011-01-20 16:58:47 -05:00
parent c3ea9d279a
commit 2cc182a667
3 changed files with 61 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -729,7 +729,24 @@
<xsd:attribute name="extract-request-payload" type="xsd:string" default="true"/>
<xsd:attribute name="extract-reply-payload" type="xsd:string" default="true"/>
<xsd:attribute name="receive-timeout" type="xsd:string"/>
<xsd:attribute name="delivery-mode" type="xsd:string"/>
<xsd:attribute name="delivery-mode" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
[DEPRECATED - use delivery-persistent attribute instead]
A reference to the MessageConverter strategy for converting between JMS Messages
and the Spring Integration Message payloads. Default is a SimpleMessageConverter.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="delivery-persistent" type="xsd:boolean" default="false">
<xsd:annotation>
<xsd:documentation>
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.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="time-to-live" type="xsd:string"/>
<xsd:attribute name="priority" type="xsd:string"/>
<xsd:attribute name="explicit-qos-enabled" type="xsd:string"/>

View File

@@ -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(){