INT-3690: AMQP Content-Type Mapping for MimeType

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

**Cherry-pick to 4.0.x and 4.1.x**
This commit is contained in:
Artem Bilan
2015-03-31 21:36:52 +03:00
parent 90e7491d79
commit 5e4f9fca2c
2 changed files with 21 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -30,6 +30,7 @@ import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.integration.IntegrationMessageHeaderAccessor;
import org.springframework.integration.mapping.AbstractHeaderMapper;
import org.springframework.integration.mapping.support.JsonHeaders;
import org.springframework.util.MimeType;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.ReflectionUtils.FieldCallback;
import org.springframework.util.ReflectionUtils.FieldFilter;
@@ -359,7 +360,8 @@ public class DefaultAmqpHeaderMapper extends AbstractHeaderMapper<MessagePropert
if (contentType != null) {
String contentTypeClassName = contentType.getClass().getName();
if (contentTypeClassName.equals("org.springframework.http.MediaType")) { // see INT-2713
if (contentType instanceof MimeType ||
contentTypeClassName.equals("org.springframework.http.MediaType")) { // see INT-2713
contentTypeStringValue = contentType.toString();
}
else if (contentType instanceof String) {

View File

@@ -37,6 +37,7 @@ import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.http.MediaType;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.MimeType;
/**
* @author Mark Fisher
@@ -122,6 +123,22 @@ public class DefaultAmqpHeaderMapperTests {
assertEquals("text/html", amqpProperties.getContentType());
}
@Test
public void fromHeadersWithContentTypeAsMimeType() {
DefaultAmqpHeaderMapper headerMapper = new DefaultAmqpHeaderMapper();
Map<String, Object> headerMap = new HashMap<String, Object>();
MimeType contentType = MimeType.valueOf("text/html");
headerMap.put(AmqpHeaders.CONTENT_TYPE, contentType);
MessageHeaders integrationHeaders = new MessageHeaders(headerMap);
MessageProperties amqpProperties = new MessageProperties();
headerMapper.fromHeadersToRequest(integrationHeaders, amqpProperties);
assertEquals("text/html", amqpProperties.getContentType());
}
@Test
public void toHeaders() {
DefaultAmqpHeaderMapper headerMapper = new DefaultAmqpHeaderMapper();