INT-4500: Fix DefAmqpHeaderMapper correlationId

JIRA https://jira.spring.io/browse/INT-4500

The `correlationId` condition was against a `contentType` by mistake

* Code style polishing, add `@author`
This commit is contained in:
Steve Singer
2018-07-12 17:52:23 -04:00
committed by Artem Bilan
parent e40e2a4238
commit 0dcbde0642
2 changed files with 20 additions and 2 deletions

View File

@@ -53,11 +53,13 @@ import org.springframework.util.StringUtils;
* @author Gary Russell
* @author Artem Bilan
* @author Stephane Nicoll
* @author Steve Singer
*
* @since 2.1
*/
public class DefaultAmqpHeaderMapper extends AbstractHeaderMapper<MessageProperties> implements AmqpHeaderMapper {
private static final List<String> STANDARD_HEADER_NAMES = new ArrayList<String>();
private static final List<String> STANDARD_HEADER_NAMES = new ArrayList<>();
static {
STANDARD_HEADER_NAMES.add(AmqpHeaders.APP_ID);
@@ -126,7 +128,7 @@ public class DefaultAmqpHeaderMapper extends AbstractHeaderMapper<MessagePropert
headers.put(AmqpHeaders.CONTENT_TYPE, contentType);
}
String correlationId = amqpMessageProperties.getCorrelationId();
if (StringUtils.hasText(contentType)) {
if (StringUtils.hasText(correlationId)) {
headers.put(AmqpHeaders.CORRELATION_ID, correlationId);
}
MessageDeliveryMode receivedDeliveryMode = amqpMessageProperties.getReceivedDeliveryMode();

View File

@@ -48,6 +48,8 @@ import org.springframework.util.MimeTypeUtils;
* @author Oleg Zhurakousky
* @author Stephane Nicoll
* @author Artem Bilan
* @author Steve Singer
*
* @since 2.1
*/
public class DefaultAmqpHeaderMapperTests {
@@ -213,6 +215,20 @@ public class DefaultAmqpHeaderMapperTests {
assertEquals("test.replyTo2", headerMap.get(AmqpHeaders.SPRING_REPLY_TO_STACK));
}
@Test
public void toHeadersNonContenType() {
DefaultAmqpHeaderMapper headerMapper = DefaultAmqpHeaderMapper.inboundMapper();
MessageProperties amqpProperties = new MessageProperties();
amqpProperties.setAppId("test.appId");
amqpProperties.setClusterId("test.clusterId");
amqpProperties.setContentType(null);
String testCorrelationId = "foo";
amqpProperties.setCorrelationId(testCorrelationId);
Map<String, Object> headerMap = headerMapper.toHeadersFromReply(amqpProperties);
assertEquals(testCorrelationId, headerMap.get(AmqpHeaders.CORRELATION_ID));
}
@Test
public void testToHeadersConsumerMetadata() {
DefaultAmqpHeaderMapper headerMapper = DefaultAmqpHeaderMapper.inboundMapper();