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**

Conflicts:
	spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/DefaultAmqpHeaderMapper.java
	spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/DefaultAmqpHeaderMapperTests.java

Resolved.
This commit is contained in:
Artem Bilan
2015-03-31 21:36:52 +03:00
committed by Gary Russell
parent 151431390d
commit ddf3919323
2 changed files with 22 additions and 3 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.
@@ -28,6 +28,7 @@ import org.springframework.integration.IntegrationMessageHeaderAccessor;
import org.springframework.integration.amqp.AmqpHeaders;
import org.springframework.integration.mapping.AbstractHeaderMapper;
import org.springframework.integration.mapping.support.JsonHeaders;
import org.springframework.util.MimeType;
import org.springframework.util.StringUtils;
/**
@@ -363,7 +364,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

@@ -25,13 +25,15 @@ import java.util.Map;
import java.util.Set;
import org.junit.Test;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.support.converter.JsonMessageConverter;
import org.springframework.http.MediaType;
import org.springframework.messaging.MessageHeaders;
import org.springframework.integration.amqp.AmqpHeaders;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.MimeType;
/**
* @author Mark Fisher
@@ -112,6 +114,21 @@ 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());
}
@SuppressWarnings("deprecation")
@Test
public void toHeaders() {