Allow HandlerFunction to return Mono<ServerResponse>
This commit makes it possible for handler functions to return
asynchronous status codes and headers, by making HandlerFunction.handle
return a Mono<ServerResponse> instead of a ServerResponse. As a
consequence, all other types that deal with HandlerFunctions
(RouterFunction, HandlerFilterFunction, etc.) had to change as well.
However, when combining the above change with method references (a very
typical use case), resulting signatures would have been something like:
```
public Mono<ServerResponse<Mono<Person>>> getPerson(ServerRequest request)
```
which was too ugly to consider, especially the two uses of Mono. It was
considered to merge ServerResponse with the last Mono, essentialy making
ServerResponse always contain a Publisher, but this had unfortunate
consequences in view rendering.
It was therefore decided to drop the parameterization of ServerResponse,
as the only usage of the extra type information was to manipulate the
response objects in a filter. Even before the above change this was
suggested; it just made the change even more necessary.
As a consequence, `BodyInserter` could be turned into a real
`FunctionalInterface`, which resulted in changes in ClientRequest.
We did, however, make HandlerFunction.handle return a `Mono<? extends
ServerResponse>`, adding little complexity, but allowing for
future `ServerResponse` subtypes that do expose type information, if
it's needed. For instance, a RenderingResponse could expose the view
name and model.
Issue: SPR-14870
@ -62,9 +61,7 @@ public class HandlerFunctionAdapter implements HandlerAdapter {
@@ -62,9 +61,7 @@ public class HandlerFunctionAdapter implements HandlerAdapter {
.orElseThrow(()->newIllegalStateException(
"Could not find ServerRequest in exchange attributes"));
@ -59,7 +59,7 @@ public class ServerResponseResultHandler implements HandlerResultHandler {
@@ -59,7 +59,7 @@ public class ServerResponseResultHandler implements HandlerResultHandler {
@ -84,7 +83,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
@@ -84,7 +83,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
@ -94,7 +93,8 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
@@ -94,7 +93,8 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
@ -134,7 +134,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
@@ -134,7 +134,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
@ -154,18 +154,22 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
@@ -154,18 +154,22 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
@ -181,7 +185,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
@@ -181,7 +185,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
}
publicStringgetName(){
returnname;
returnthis.name;
}
publicvoidsetName(Stringname){
@ -209,7 +213,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
@@ -209,7 +213,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
@ -53,7 +53,7 @@ public class MockServerRequest<T> implements ServerRequest {
@@ -53,7 +53,7 @@ public class MockServerRequest<T> implements ServerRequest {
privatefinalMockHeadersheaders;
privatefinalTbody;
privatefinalObjectbody;
privatefinalMap<String,Object>attributes;
@ -62,7 +62,7 @@ public class MockServerRequest<T> implements ServerRequest {
@@ -62,7 +62,7 @@ public class MockServerRequest<T> implements ServerRequest {
@ -74,8 +74,8 @@ public class MockServerRequest<T> implements ServerRequest {
@@ -74,8 +74,8 @@ public class MockServerRequest<T> implements ServerRequest {
this.pathVariables=pathVariables;
}
publicstatic<T>Builder<T>builder(){
returnnewBuilderImpl<T>();
publicstaticBuilderbuilder(){
returnnewBuilderImpl();
}
@Override
@ -127,35 +127,35 @@ public class MockServerRequest<T> implements ServerRequest {
@@ -127,35 +127,35 @@ public class MockServerRequest<T> implements ServerRequest {
@ -163,7 +163,7 @@ public class MockServerRequest<T> implements ServerRequest {
@@ -163,7 +163,7 @@ public class MockServerRequest<T> implements ServerRequest {
@ -172,21 +172,21 @@ public class MockServerRequest<T> implements ServerRequest {
@@ -172,21 +172,21 @@ public class MockServerRequest<T> implements ServerRequest {
Assert.notNull(method,"'method' must not be null");
this.method=method;
returnthis;
}
@Override
publicBuilder<T>uri(URIuri){
publicBuilderuri(URIuri){
Assert.notNull(uri,"'uri' must not be null");
this.uri=uri;
returnthis;
}
@Override
publicBuilder<T>header(Stringkey,Stringvalue){
publicBuilderheader(Stringkey,Stringvalue){
Assert.notNull(key,"'key' must not be null");
Assert.notNull(value,"'value' must not be null");
this.headers.header(key,value);
@ -194,14 +194,14 @@ public class MockServerRequest<T> implements ServerRequest {
@@ -194,14 +194,14 @@ public class MockServerRequest<T> implements ServerRequest {
}
@Override
publicBuilder<T>headers(HttpHeadersheaders){
publicBuilderheaders(HttpHeadersheaders){
Assert.notNull(headers,"'headers' must not be null");
@ -209,14 +209,14 @@ public class MockServerRequest<T> implements ServerRequest {
@@ -209,14 +209,14 @@ public class MockServerRequest<T> implements ServerRequest {
@ -224,14 +224,14 @@ public class MockServerRequest<T> implements ServerRequest {
@@ -224,14 +224,14 @@ public class MockServerRequest<T> implements ServerRequest {
@ -239,22 +239,22 @@ public class MockServerRequest<T> implements ServerRequest {
@@ -239,22 +239,22 @@ public class MockServerRequest<T> implements ServerRequest {