spring-projects / spring-integration

Spring Integration provides an extension of the Spring programming model to support the well-known Enterprise Integration Patterns (EIP)
http://projects.spring.io/spring-integration/
Apache License 2.0
1.54k stars 1.11k forks source link

MappingUtils overrides the contentType set by the DefaultAmqpHeaderMapper [INT-4359] #8301

Closed spring-operator closed 6 years ago

spring-operator commented 6 years ago

Oleg Zhurakousky opened INT-4359 and commented

While working on semi-relevant issue in Spring Cloud Stream, I've discovered that there is some voodoo in MappingUtils.mapMessage(..). Here is the relevant code snippet:

1: MessageProperties amqpMessageProperties = new MessageProperties();
2: org.springframework.amqp.core.Message amqpMessage;
3: if (!headersMappedLast) {
4:     headerMapper.fromHeadersToRequest(requestMessage.getHeaders(), amqpMessageProperties);
5: }
. . .
6: amqpMessage = converter.toMessage(requestMessage.getPayload(), amqpMessageProperties);

Line 1; MessageProperties are created with contentType "application/octet-stream" Line 4: It is changed to "text/plain" by getting it from MessageHeaders Line 6; It is back to "application/octet-stream" simply based on the payload type (which is byte[] - always in the case of SCSt)

I see there were significant changes in MappingUtils between SI 4 and 5 and this appears to be a regression


Affects: 5.0 M7

Issue Links:

spring-operator commented 6 years ago

Gary Russell commented

This was changed in 5.0 to be consistent; previously the order of header mapping was inconsistent, depending on which message converter was being used. This was made the default to avoid unexpected header propagation from upstream endpoints.

Set headersMappedLast to ensure headers in the outbound message take precedence over those set by the message converter.

Although this was covered in the what's new and a note in this section I have now added a mention of the behavior change to the 5.0 migration guide.