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:
Gary Russell
2014-01-29 18:18:15 -05:00
committed by Artem Bilan
parent ad1035c33a
commit c0637b6e99
4 changed files with 61 additions and 3 deletions

View File

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

View File

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