From 2068f667f38cd206e3e9116d0f82d3ffe4faca3b Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 5 Jul 2016 11:10:36 -0400 Subject: [PATCH] Expose getStatusCode from ServerHttpResponse --- .../http/server/reactive/AbstractServerHttpResponse.java | 3 ++- .../http/server/reactive/ServerHttpResponse.java | 7 ++++++- .../http/server/reactive/MockServerHttpResponse.java | 2 +- .../web/reactive/DispatcherHandlerErrorTests.java | 4 ++-- .../web/reactive/ResponseStatusExceptionHandlerTests.java | 2 +- .../annotation/ResponseEntityResultHandlerTests.java | 6 +++--- .../server/handler/ExceptionHandlingHttpHandlerTests.java | 8 ++++---- .../web/server/handler/FilteringWebHandlerTests.java | 2 +- 8 files changed, 20 insertions(+), 14 deletions(-) diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java index 2aafef5d7a..a19b875c43 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java @@ -97,7 +97,8 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse { return false; } - protected HttpStatus getStatusCode() { + @Override + public HttpStatus getStatusCode() { return this.statusCode; } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java index c458cfcc7e..777b36defa 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java @@ -40,8 +40,13 @@ public interface ServerHttpResponse extends ReactiveHttpOutputMessage { boolean setStatusCode(HttpStatus status); /** - * Return a mutable map with the cookies to send to the server. + * Return the HTTP status code or {@code null} if not set. */ + HttpStatus getStatusCode(); + + /** + * Return a mutable map with the cookies to send to the server. + */ MultiValueMap getCookies(); /** diff --git a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java index c12ba69f94..3ffafd090c 100644 --- a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java +++ b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java @@ -54,7 +54,7 @@ public class MockServerHttpResponse implements ServerHttpResponse { return true; } - public HttpStatus getStatus() { + public HttpStatus getStatusCode() { return this.status; } diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java index e6ba0b2163..3657fd2fc4 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java @@ -192,7 +192,7 @@ public class DispatcherHandlerErrorTests { Mono publisher = webHandler.handle(this.exchange); publisher.block(); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatus()); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatusCode()); } @Test @@ -204,7 +204,7 @@ public class DispatcherHandlerErrorTests { Mono publisher = webHandler.handle(this.exchange); publisher.block(); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatus()); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatusCode()); } diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/ResponseStatusExceptionHandlerTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/ResponseStatusExceptionHandlerTests.java index d916a81c96..c44553b96f 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/ResponseStatusExceptionHandlerTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/ResponseStatusExceptionHandlerTests.java @@ -67,7 +67,7 @@ public class ResponseStatusExceptionHandlerTests { Mono publisher = this.handler.handle(this.exchange, ex); publisher.block(); - assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatus()); + assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatusCode()); } @Test diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java index b54994f170..546c1bd0b4 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java @@ -145,7 +145,7 @@ public class ResponseEntityResultHandlerTests { HandlerResult result = handlerResult(value, type); this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5)); - assertEquals(HttpStatus.NO_CONTENT, this.response.getStatus()); + assertEquals(HttpStatus.NO_CONTENT, this.response.getStatusCode()); assertEquals(0, this.response.getHeaders().size()); assertNull(this.response.getBody()); } @@ -158,7 +158,7 @@ public class ResponseEntityResultHandlerTests { HandlerResult result = handlerResult(value, type); this.resultHandler.handleResult(this.exchange, result).block(Duration.ofSeconds(5)); - assertEquals(HttpStatus.CREATED, this.response.getStatus()); + assertEquals(HttpStatus.CREATED, this.response.getStatusCode()); assertEquals(1, this.response.getHeaders().size()); assertEquals(location, this.response.getHeaders().getLocation()); assertNull(this.response.getBody()); @@ -188,7 +188,7 @@ public class ResponseEntityResultHandlerTests { HandlerResult result = handlerResult(returnValue, type); this.resultHandler.handleResult(this.exchange, result).block(Duration.ofSeconds(5)); - assertEquals(HttpStatus.OK, this.response.getStatus()); + assertEquals(HttpStatus.OK, this.response.getStatusCode()); assertEquals("text/plain;charset=UTF-8", this.response.getHeaders().getFirst("Content-Type")); assertResponseBody("abc"); } diff --git a/spring-web-reactive/src/test/java/org/springframework/web/server/handler/ExceptionHandlingHttpHandlerTests.java b/spring-web-reactive/src/test/java/org/springframework/web/server/handler/ExceptionHandlingHttpHandlerTests.java index 6152a48e2f..c3b9aef394 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/server/handler/ExceptionHandlingHttpHandlerTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/server/handler/ExceptionHandlingHttpHandlerTests.java @@ -64,7 +64,7 @@ public class ExceptionHandlingHttpHandlerTests { WebExceptionHandler exceptionHandler = new BadRequestExceptionHandler(); createWebHandler(exceptionHandler).handle(this.exchange).block(); - assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatus()); + assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatusCode()); } @Test @@ -77,7 +77,7 @@ public class ExceptionHandlingHttpHandlerTests { }; createWebHandler(exceptionHandlers).handle(this.exchange).block(); - assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatus()); + assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatusCode()); } @Test @@ -85,7 +85,7 @@ public class ExceptionHandlingHttpHandlerTests { WebExceptionHandler exceptionHandler = new UnresolvedExceptionHandler(); createWebHandler(exceptionHandler).handle(this.exchange).block(); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatus()); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatusCode()); } @Test @@ -93,7 +93,7 @@ public class ExceptionHandlingHttpHandlerTests { WebExceptionHandler exceptionHandler = new BadRequestExceptionHandler(); createWebHandler(exceptionHandler).handle(this.exchange).block(); - assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatus()); + assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatusCode()); } private WebHandler createWebHandler(WebExceptionHandler... handlers) { diff --git a/spring-web-reactive/src/test/java/org/springframework/web/server/handler/FilteringWebHandlerTests.java b/spring-web-reactive/src/test/java/org/springframework/web/server/handler/FilteringWebHandlerTests.java index 206c03e8b2..4f6d54b9f0 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/server/handler/FilteringWebHandlerTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/server/handler/FilteringWebHandlerTests.java @@ -117,7 +117,7 @@ public class FilteringWebHandlerTests { .filters(new ExceptionFilter()).exceptionHandlers(exceptionHandler).build(); handler.handle(this.request, this.response).block(); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatus()); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatusCode()); Throwable savedException = exceptionHandler.ex; assertNotNull(savedException);