Fix HttpHeaderMapper to support MimeType
It turns out that `contentType` header (as well as `Accept`) may be converted into `MimeType` upstream before the message is sent into HTTP Outbound Channel Adapter meanwhile the logic is only to support String and MediaType * Change the `DefaultHttpHeaderMapper` to support more generic `MimeType` for the `Content-Type` and `Accept` HTTP headers which can simply be converted to the expected `MediaType` **Cherry-pick to 5.1.x & 5.0.x**
This commit is contained in:
committed by
Gary Russell
parent
f04962301d
commit
a75f0808fd
@@ -40,6 +40,7 @@ import org.springframework.integration.mapping.HeaderMapper;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
@@ -343,6 +344,18 @@ public class DefaultHttpHeaderMapperFromMessageOutboundTests {
|
||||
assertThat(headers.getContentType().getSubtype()).isEqualTo("html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateContentTypeAsMimeType() {
|
||||
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.outboundMapper();
|
||||
Map<String, Object> messageHeaders = new HashMap<>();
|
||||
messageHeaders.put(MessageHeaders.CONTENT_TYPE, new MimeType("text", "plain"));
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
|
||||
assertThat(headers.getContentType().getType()).isEqualTo("text");
|
||||
assertThat(headers.getContentType().getSubtype()).isEqualTo("plain");
|
||||
}
|
||||
|
||||
// Date test
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user