From 35c7ef1131cdc9fe7b777f9437a2770f8bba6592 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 1 Jun 2018 12:15:51 -0400 Subject: [PATCH] INT-4387: Fix incorrect contentType mapping JIRA: https://jira.spring.io/browse/INT-4387 Don't put a copy in the message properties headers map. --- .../amqp/support/DefaultAmqpHeaderMapper.java | 3 ++- .../support/DefaultAmqpHeaderMapperTests.java | 4 ++-- src/reference/asciidoc/amqp.adoc | 17 ++++++++++++++++- src/reference/asciidoc/whats-new.adoc | 3 +++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/DefaultAmqpHeaderMapper.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/DefaultAmqpHeaderMapper.java index 35840c20b6..1bcf174fc5 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/DefaultAmqpHeaderMapper.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/DefaultAmqpHeaderMapper.java @@ -359,7 +359,8 @@ public class DefaultAmqpHeaderMapper extends AbstractHeaderMapper headerKeys = amqpProperties.getHeaders().keySet(); for (String headerKey : headerKeys) { - if (headerKey.startsWith(AmqpHeaders.PREFIX)) { - fail(); + if (headerKey.startsWith(AmqpHeaders.PREFIX) || headerKey.equals("contentType")) { + fail("Unexpected header in properties.headers: " + headerKey); } } assertEquals("test.appId", amqpProperties.getAppId()); diff --git a/src/reference/asciidoc/amqp.adoc b/src/reference/asciidoc/amqp.adoc index 6da0e9a935..fccdf74c00 100644 --- a/src/reference/asciidoc/amqp.adoc +++ b/src/reference/asciidoc/amqp.adoc @@ -1388,6 +1388,8 @@ public IntegrationFlow pubSubInFlow(ConnectionFactory connectionFactory) { [[amqp-message-headers]] === AMQP Message Headers +==== Overview + The Spring Integration AMQP Adapters will map all AMQP properties and headers automatically. (This is a change in 4.3 - previously, only standard headers were mapped). These properties will be copied by default to and from Spring Integration `MessageHeaders` using the @@ -1423,7 +1425,7 @@ Class `org.springframework.amqp.support.AmqpHeaders` identifies the default head * amqp_contentLength -* content-type +* content-type (see <>) * amqp_correlationId @@ -1508,6 +1510,19 @@ NOTE: Starting with _version 5.1_, the `DefaultAmqpHeaderMapper` will fall back Inbound properties will be mapped to the `amqp_*` headers as before. It is useful to populate the `messageId` property when message consumers are using stateful retry. +[[amqp-content-type]] +==== contentType Header + +Unlike other headers, the `AmqpHeaders.CONTENT_TYPE` is not prefixed with `amqp_`; this allows transparent passing of the contentType header across different technologies. +E.g. an inbound HTTP message sent to a RabbitMQ queue. + +The `contentType` header is mapped to Spring AMQP's `MessageProperties.contentType` property and that is subsequently mapped to RabbitMQ's `content_type` property. + +Prior to _version 5.1_, this header was also mapped as an entry in the `MessageProperties.headers` map; this was incorrect and, furthermore, the value could be wrong since the underlying Spring AMQP message converter might have changed the content type. +Such a change would be reflected in the first-class `content_type` property, but not in the RabbitMQ headers map. +Inbound mapping ignored the headers map value. +`contentType` is no longer mapped to an entry in the headers map. + [[amqp-strict-ordering]] === Strict Message Ordering diff --git a/src/reference/asciidoc/whats-new.adoc b/src/reference/asciidoc/whats-new.adoc index a733a02d1e..fb09e0f043 100644 --- a/src/reference/asciidoc/whats-new.adoc +++ b/src/reference/asciidoc/whats-new.adoc @@ -55,3 +55,6 @@ See <> for more information. `ID` and `Timestamp` header mapping changes in the `DefaultAmqpHeaderMapper`. See the note near the bottom of <> for more information. + +The `contentType` header is no longer incorrectly mapped as an entry in the general headers map. +See <> for more information.