diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignAutoConfiguration.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignAutoConfiguration.java index d3dcdf9b..a68f3d81 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignAutoConfiguration.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignAutoConfiguration.java @@ -94,7 +94,8 @@ public class FeignAutoConfiguration { @Bean @ConditionalOnMissingBean(PageJacksonModule.class) @ConditionalOnClass(name = "org.springframework.data.domain.Page") - @ConditionalOnProperty(value = "feign.autoconfiguration.jackson.enabled", havingValue = "true") + @ConditionalOnProperty(value = "feign.autoconfiguration.jackson.enabled", + havingValue = "true") public Module pageJacksonModule() { return new PageJacksonModule(); } @@ -102,7 +103,8 @@ public class FeignAutoConfiguration { @Bean @ConditionalOnMissingBean(SortJacksonModule.class) @ConditionalOnClass(name = "org.springframework.data.domain.Sort") - @ConditionalOnProperty(value = "feign.autoconfiguration.jackson.enabled", havingValue = "true") + @ConditionalOnProperty(value = "feign.autoconfiguration.jackson.enabled", + havingValue = "true") public Module sortModule() { return new SortJacksonModule(); } diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/ResponseEntityDecoder.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/ResponseEntityDecoder.java index 4d8532fc..13329fe8 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/ResponseEntityDecoder.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/ResponseEntityDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 the original author or authors. + * Copyright 2013-2021 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. @@ -26,16 +26,16 @@ import feign.Response; import feign.codec.Decoder; import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; /** * Decoder adds compatibility for Spring MVC's ResponseEntity to any other decoder via * composition. * * @author chad jaros + * @author Olga Maciaszek-Sharma */ public class ResponseEntityDecoder implements Decoder { @@ -81,7 +81,7 @@ public class ResponseEntityDecoder implements Decoder { @SuppressWarnings("unchecked") private ResponseEntity createResponse(Object instance, Response response) { - MultiValueMap headers = new LinkedMultiValueMap<>(); + HttpHeaders headers = new HttpHeaders(); for (String key : response.headers().keySet()) { headers.put(key, new LinkedList<>(response.headers().get(key))); } diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/SpringDecoderTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/SpringDecoderTests.java index f6288b5f..d979611b 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/SpringDecoderTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/SpringDecoderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 the original author or authors. + * Copyright 2013-2021 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. @@ -32,7 +32,9 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.cloud.openfeign.test.NoSecurityConfiguration; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -45,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Spencer Gibb + * @author Olga Maciaszek-Sharma */ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = SpringDecoderTests.Application.class, @@ -152,6 +155,14 @@ public class SpringDecoderTests extends FeignClientFactoryBean { assertThat(response.getBody()).as("response body was not null").isNull(); } + @Test + // Issue: https://github.com/spring-cloud/spring-cloud-openfeign/issues/456 + public void testResponseEntityHeaders() { + ResponseEntity response = testClient().getContentType(); + assertThat(response.getHeaders().getContentType()) + .isEqualTo(MediaType.APPLICATION_JSON); + } + protected interface TestClient { @RequestMapping(method = RequestMethod.GET, value = "/helloresponse") @@ -175,6 +186,9 @@ public class SpringDecoderTests extends FeignClientFactoryBean { @GetMapping("/helloWildcard") ResponseEntity getWildcard(); + @GetMapping(path = "/contentType", produces = MediaType.APPLICATION_JSON_VALUE) + ResponseEntity getContentType(); + } public static class Hello { @@ -262,6 +276,13 @@ public class SpringDecoderTests extends FeignClientFactoryBean { return ResponseEntity.ok(new Hello("wildcard")); } + @Override + public ResponseEntity getContentType() { + return ResponseEntity.ok() + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .body("test"); + } + } }