INT-3259 Map Inbound JMSPriority to priority
JIRA: https://jira.springsource.org/browse/INT-3259 Add an option to suppress if needed. INT-3259: Polishing according PR comments
This commit is contained in:
committed by
Artem Bilan
parent
ad1035c33a
commit
c0637b6e99
@@ -29,6 +29,7 @@ import javax.jms.JMSException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -63,6 +64,16 @@ public class DefaultJmsHeaderMapper implements JmsHeaderMapper {
|
||||
|
||||
private volatile String outboundPrefix = "";
|
||||
|
||||
private volatile boolean mapInboundPriority = true;
|
||||
|
||||
/**
|
||||
* Suppress the mapping of inbound priority by using this setter with 'false'.
|
||||
*
|
||||
* @param mapInboundPriority 'false' to suppress mapping the inbound priority.
|
||||
*/
|
||||
public void setMapInboundPriority(boolean mapInboundPriority) {
|
||||
this.mapInboundPriority = mapInboundPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a prefix to be appended to the integration message header name
|
||||
@@ -205,9 +216,18 @@ public class DefaultJmsHeaderMapper implements JmsHeaderMapper {
|
||||
}
|
||||
try {
|
||||
headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.info("failed to read JMSTimestamp property, skipping", e);
|
||||
}
|
||||
if (this.mapInboundPriority) {
|
||||
try {
|
||||
headers.put(IntegrationMessageHeaderAccessor.PRIORITY, jmsMessage.getJMSPriority());
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.info("failed to read JMSPriority property, skipping", e);
|
||||
}
|
||||
}
|
||||
Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames();
|
||||
if (jmsPropertyNames != null) {
|
||||
while (jmsPropertyNames.hasMoreElements()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -28,9 +28,11 @@ import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -229,6 +231,28 @@ public class DefaultJmsHeaderMapperTests {
|
||||
assertEquals(timestamp, attrib);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJmsPriorityMappedToHeader() throws JMSException {
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
jmsMessage.setJMSPriority(5);
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
Map<String, Object> headers = mapper.toHeaders(jmsMessage);
|
||||
Object attrib = headers.get(IntegrationMessageHeaderAccessor.PRIORITY);
|
||||
assertNotNull(attrib);
|
||||
assertEquals(5, attrib);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJmsPriorityNotMappedToHeader() throws JMSException {
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
jmsMessage.setJMSPriority(5);
|
||||
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
|
||||
mapper.setMapInboundPriority(false);
|
||||
Map<String, Object> headers = mapper.toHeaders(jmsMessage);
|
||||
Object attrib = headers.get(IntegrationMessageHeaderAccessor.PRIORITY);
|
||||
assertNull(attrib);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContentTypePropertyMappedToHeader() throws JMSException {
|
||||
javax.jms.Message jmsMessage = new StubTextMessage();
|
||||
|
||||
@@ -521,6 +521,12 @@
|
||||
standard JMS API Headers as well as primitive/String Message Headers. Custom header mapper could also be
|
||||
provided via <code>header-mapper</code> attribute of inbound and outbound gateways.
|
||||
</para>
|
||||
<important>
|
||||
Since <emphasis>version 4.0</emphasis>, the <code>JMSPriority</code> header is mapped to the standard
|
||||
<code>priority</code> header for inbound messages (previously, the <code>priority</code> header was only used for
|
||||
outbound messages). To revert to the previous behavior (do not map inbound priority), use the
|
||||
<code>mapInboundPriority</code> property of <classname>DefaultJmsHeaderMapper</classname> with argument set to <code>false</code>.
|
||||
</important>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
@@ -50,5 +50,13 @@
|
||||
For more information see <xref linkend="transformer-xpath-spel-function"/>.
|
||||
</para>
|
||||
</section>
|
||||
<section id="4.0-jms-header-mapping">
|
||||
<title>JMS Header Mapping</title>
|
||||
<para>
|
||||
The <classname>DefaultJmsHeaderMapper</classname> now maps an incoming <code>JMSPriority</code> header to
|
||||
the Spring Integration <code>priority</code> header. Previously <code>priority</code> was only
|
||||
considered for outbound messages. For more information see <xref linkend="jms-header-mapping"/>.
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
Reference in New Issue
Block a user