diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/rx/SingleReturnValueHandler.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/rx/SingleReturnValueHandler.java index 1db91b76..a875e511 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/rx/SingleReturnValueHandler.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/rx/SingleReturnValueHandler.java @@ -100,6 +100,10 @@ public class SingleReturnValueHandler implements AsyncHandlerMethodReturnValueHa .map(new Func1>() { @Override public ResponseEntity call(Object object) { + if (object instanceof ResponseEntity){ + return (ResponseEntity) object; + } + return new ResponseEntity(object, getHttpHeaders(responseEntity), getHttpStatus(responseEntity)); diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/rx/SingleReturnValueHandlerTest.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/rx/SingleReturnValueHandlerTest.java index 8c7f0c45..e35ee000 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/rx/SingleReturnValueHandlerTest.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/rx/SingleReturnValueHandlerTest.java @@ -69,6 +69,11 @@ public class SingleReturnValueHandlerTest { return new ResponseEntity<>(Single.just("single value"), HttpStatus.NOT_FOUND); } + + @RequestMapping(method = RequestMethod.GET, value = "/singleCreatedWithResponse") + public Single> singleOuterWithResponse() { + return Single.just(new ResponseEntity<>("single value", HttpStatus.CREATED)); + } @RequestMapping(method = RequestMethod.GET, value = "/throw") public Single error() { @@ -114,6 +119,19 @@ public class SingleReturnValueHandlerTest { assertNotNull(response); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); } + + @Test + public void shouldRetrieveSingleValueWithCreatedCode() { + + // when + ResponseEntity response = restTemplate.getForEntity(path("/singleCreatedWithResponse"), + String.class); + + // then + assertNotNull(response); + assertEquals(HttpStatus.CREATED, response.getStatusCode()); + assertEquals("single value", response.getBody()); + } private String path(String context) { return String.format("http://localhost:%d%s", port, context);