提交 7e907c1e 编写于 作者: A Arjen Poutsma

Align web.reactive.function with WebClient

This commit changes web.reactive.function to reflect the introduction of
the new WebClient. Changes include:

- Request -> ServerRequest
- Response -> ServerResponse
- FilterFunction -> HandlerFilterFunction
- StrategiesSupplier -> HandlerStrategies
上级 0cfb6b37
......@@ -40,22 +40,22 @@ import org.springframework.util.ClassUtils;
import org.springframework.web.reactive.result.view.ViewResolver;
/**
* Default implementation of {@link StrategiesSupplier.Builder}.
* Default implementation of {@link HandlerStrategies.Builder}.
*
* @author Arjen Poutsma
* @since 5.0
*/
class DefaultStrategiesSupplierBuilder implements StrategiesSupplier.Builder {
class DefaultHandlerStrategiesBuilder implements HandlerStrategies.Builder {
private static final boolean jackson2Present =
ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper",
DefaultStrategiesSupplierBuilder.class.getClassLoader()) &&
DefaultHandlerStrategiesBuilder.class.getClassLoader()) &&
ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator",
DefaultStrategiesSupplierBuilder.class.getClassLoader());
DefaultHandlerStrategiesBuilder.class.getClassLoader());
private static final boolean jaxb2Present =
ClassUtils.isPresent("javax.xml.bind.Binder",
DefaultStrategiesSupplierBuilder.class.getClassLoader());
DefaultHandlerStrategiesBuilder.class.getClassLoader());
private final List<HttpMessageReader<?>> messageReaders = new ArrayList<>();
......@@ -86,33 +86,33 @@ class DefaultStrategiesSupplierBuilder implements StrategiesSupplier.Builder {
}
@Override
public StrategiesSupplier.Builder messageReader(HttpMessageReader<?> messageReader) {
public HandlerStrategies.Builder messageReader(HttpMessageReader<?> messageReader) {
Assert.notNull(messageReader, "'messageReader' must not be null");
this.messageReaders.add(messageReader);
return this;
}
@Override
public StrategiesSupplier.Builder messageWriter(HttpMessageWriter<?> messageWriter) {
public HandlerStrategies.Builder messageWriter(HttpMessageWriter<?> messageWriter) {
Assert.notNull(messageWriter, "'messageWriter' must not be null");
this.messageWriters.add(messageWriter);
return this;
}
@Override
public StrategiesSupplier.Builder viewResolver(ViewResolver viewResolver) {
public HandlerStrategies.Builder viewResolver(ViewResolver viewResolver) {
Assert.notNull(viewResolver, "'viewResolver' must not be null");
this.viewResolvers.add(viewResolver);
return this;
}
@Override
public StrategiesSupplier build() {
return new DefaultStrategiesSupplier(this.messageReaders, this.messageWriters,
public HandlerStrategies build() {
return new DefaultHandlerStrategies(this.messageReaders, this.messageWriters,
this.viewResolvers);
}
private static class DefaultStrategiesSupplier implements StrategiesSupplier {
private static class DefaultHandlerStrategies implements HandlerStrategies {
private final List<HttpMessageReader<?>> messageReaders;
......@@ -120,7 +120,7 @@ class DefaultStrategiesSupplierBuilder implements StrategiesSupplier.Builder {
private final List<ViewResolver> viewResolvers;
public DefaultStrategiesSupplier(
public DefaultHandlerStrategies(
List<HttpMessageReader<?>> messageReaders,
List<HttpMessageWriter<?>> messageWriters,
List<ViewResolver> viewResolvers) {
......
......@@ -37,19 +37,19 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.ServerWebExchange;
/**
* {@code Request} implementation based on a {@link ServerWebExchange}.
* {@code ServerRequest} implementation based on a {@link ServerWebExchange}.
* @author Arjen Poutsma
*/
class DefaultRequest implements Request {
class DefaultServerRequest implements ServerRequest {
private final ServerWebExchange exchange;
private final Headers headers;
private final StrategiesSupplier strategies;
private final HandlerStrategies strategies;
DefaultRequest(ServerWebExchange exchange, StrategiesSupplier strategies) {
DefaultServerRequest(ServerWebExchange exchange, HandlerStrategies strategies) {
this.exchange = exchange;
this.strategies = strategies;
this.headers = new DefaultHeaders();
......@@ -77,7 +77,7 @@ class DefaultRequest implements Request {
new BodyExtractor.Context() {
@Override
public Supplier<Stream<HttpMessageReader<?>>> messageReaders() {
return DefaultRequest.this.strategies.messageReaders();
return DefaultServerRequest.this.strategies.messageReaders();
}
});
}
......
......@@ -26,7 +26,6 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -36,12 +35,14 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.Conventions;
import org.springframework.core.ResolvableType;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.codec.BodyInserter;
import org.springframework.http.codec.BodyInserters;
import org.springframework.http.codec.HttpMessageWriter;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.util.Assert;
......@@ -50,22 +51,22 @@ import org.springframework.web.reactive.result.view.ViewResolver;
import org.springframework.web.server.ServerWebExchange;
/**
* Default {@link Response.BodyBuilder} implementation.
* Default {@link ServerResponse.BodyBuilder} implementation.
*
* @author Arjen Poutsma
*/
class DefaultResponseBuilder implements Response.BodyBuilder {
class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
private final int statusCode;
private final HttpHeaders headers = new HttpHeaders();
public DefaultResponseBuilder(int statusCode) {
public DefaultServerResponseBuilder(int statusCode) {
this.statusCode = statusCode;
}
@Override
public Response.BodyBuilder header(String headerName, String... headerValues) {
public ServerResponse.BodyBuilder header(String headerName, String... headerValues) {
for (String headerValue : headerValues) {
this.headers.add(headerName, headerValue);
}
......@@ -73,7 +74,7 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
}
@Override
public Response.BodyBuilder headers(HttpHeaders headers) {
public ServerResponse.BodyBuilder headers(HttpHeaders headers) {
if (headers != null) {
this.headers.putAll(headers);
}
......@@ -81,25 +82,25 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
}
@Override
public Response.BodyBuilder allow(HttpMethod... allowedMethods) {
public ServerResponse.BodyBuilder allow(HttpMethod... allowedMethods) {
this.headers.setAllow(new LinkedHashSet<>(Arrays.asList(allowedMethods)));
return this;
}
@Override
public Response.BodyBuilder contentLength(long contentLength) {
public ServerResponse.BodyBuilder contentLength(long contentLength) {
this.headers.setContentLength(contentLength);
return this;
}
@Override
public Response.BodyBuilder contentType(MediaType contentType) {
public ServerResponse.BodyBuilder contentType(MediaType contentType) {
this.headers.setContentType(contentType);
return this;
}
@Override
public Response.BodyBuilder eTag(String eTag) {
public ServerResponse.BodyBuilder eTag(String eTag) {
if (eTag != null) {
if (!eTag.startsWith("\"") && !eTag.startsWith("W/\"")) {
eTag = "\"" + eTag;
......@@ -113,7 +114,7 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
}
@Override
public Response.BodyBuilder lastModified(ZonedDateTime lastModified) {
public ServerResponse.BodyBuilder lastModified(ZonedDateTime lastModified) {
ZonedDateTime gmt = lastModified.withZoneSameInstant(ZoneId.of("GMT"));
String headerValue = DateTimeFormatter.RFC_1123_DATE_TIME.format(gmt);
this.headers.set(HttpHeaders.LAST_MODIFIED, headerValue);
......@@ -121,13 +122,13 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
}
@Override
public Response.BodyBuilder location(URI location) {
public ServerResponse.BodyBuilder location(URI location) {
this.headers.setLocation(location);
return this;
}
@Override
public Response.BodyBuilder cacheControl(CacheControl cacheControl) {
public ServerResponse.BodyBuilder cacheControl(CacheControl cacheControl) {
String ccValue = cacheControl.getHeaderValue();
if (ccValue != null) {
this.headers.setCacheControl(cacheControl.getHeaderValue());
......@@ -136,20 +137,20 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
}
@Override
public Response.BodyBuilder varyBy(String... requestHeaders) {
public ServerResponse.BodyBuilder varyBy(String... requestHeaders) {
this.headers.setVary(Arrays.asList(requestHeaders));
return this;
}
@Override
public Response<Void> build() {
public ServerResponse<Void> build() {
return body(BodyInserter.of(
(response, context) -> response.setComplete(),
() -> null));
}
@Override
public <T extends Publisher<Void>> Response<T> build(T voidPublisher) {
public <T extends Publisher<Void>> ServerResponse<T> build(T voidPublisher) {
Assert.notNull(voidPublisher, "'voidPublisher' must not be null");
return body(BodyInserter.of(
(response, context) -> Flux.from(voidPublisher).then(response.setComplete()),
......@@ -157,19 +158,23 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
}
@Override
public <T> Response<T> body(BiFunction<ServerHttpResponse, BodyInserter.Context, Mono<Void>> writer,
Supplier<T> supplier) {
return body(BodyInserter.of(writer, supplier));
public <T> ServerResponse<T> body(BodyInserter<T, ? super ServerHttpResponse> inserter) {
Assert.notNull(inserter, "'inserter' must not be null");
return new BodyInserterServerResponse<T>(this.statusCode, this.headers, inserter);
}
@Override
public <T> Response<T> body(BodyInserter<T, ? super ServerHttpResponse> inserter) {
Assert.notNull(inserter, "'inserter' must not be null");
return new BodyInserterResponse<T>(this.statusCode, this.headers, inserter);
public <S extends Publisher<T>, T> ServerResponse<S> body(S publisher, Class<T> elementClass) {
return body(BodyInserters.fromPublisher(publisher, elementClass));
}
@Override
public <S extends Publisher<T>, T> ServerResponse<S> body(S publisher, ResolvableType elementType) {
return body(BodyInserters.fromPublisher(publisher, elementType));
}
@Override
public Response<Rendering> render(String name, Object... modelAttributes) {
public ServerResponse<Rendering> render(String name, Object... modelAttributes) {
Assert.hasLength(name, "'name' must not be empty");
return render(name, toModelMap(modelAttributes));
}
......@@ -190,24 +195,24 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
}
@Override
public Response<Rendering> render(String name, Map<String, ?> model) {
public ServerResponse<Rendering> render(String name, Map<String, ?> model) {
Assert.hasLength(name, "'name' must not be empty");
Map<String, Object> modelMap = new LinkedHashMap<>();
if (model != null) {
modelMap.putAll(model);
}
return new RenderingResponse(this.statusCode, this.headers, name, modelMap);
return new RenderingServerResponse(this.statusCode, this.headers, name, modelMap);
}
private static abstract class AbstractResponse<T> implements Response<T> {
private static abstract class AbstractServerResponse<T> implements ServerResponse<T> {
private final int statusCode;
private final HttpHeaders headers;
protected AbstractResponse(int statusCode, HttpHeaders headers) {
protected AbstractServerResponse(int statusCode, HttpHeaders headers) {
this.statusCode = statusCode;
this.headers = HttpHeaders.readOnlyHttpHeaders(headers);
}
......@@ -235,12 +240,12 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
}
}
private static final class BodyInserterResponse<T> extends AbstractResponse<T> {
private static final class BodyInserterServerResponse<T> extends AbstractServerResponse<T> {
private final BodyInserter<T, ? super ServerHttpResponse> inserter;
public BodyInserterResponse(int statusCode, HttpHeaders headers,
public BodyInserterServerResponse(int statusCode, HttpHeaders headers,
BodyInserter<T, ? super ServerHttpResponse> inserter) {
super(statusCode, headers);
......@@ -253,7 +258,7 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
}
@Override
public Mono<Void> writeTo(ServerWebExchange exchange, StrategiesSupplier strategies) {
public Mono<Void> writeTo(ServerWebExchange exchange, HandlerStrategies strategies) {
ServerHttpResponse response = exchange.getResponse();
writeStatusAndHeaders(response);
return this.inserter.insert(response, new BodyInserter.Context() {
......@@ -267,7 +272,7 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
}
private static final class RenderingResponse extends AbstractResponse<Rendering> {
private static final class RenderingServerResponse extends AbstractServerResponse<Rendering> {
private final String name;
......@@ -275,7 +280,7 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
private final Rendering rendering;
public RenderingResponse(int statusCode, HttpHeaders headers, String name,
public RenderingServerResponse(int statusCode, HttpHeaders headers, String name,
Map<String, Object> model) {
super(statusCode, headers);
this.name = name;
......@@ -289,7 +294,7 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
}
@Override
public Mono<Void> writeTo(ServerWebExchange exchange, StrategiesSupplier strategies) {
public Mono<Void> writeTo(ServerWebExchange exchange, HandlerStrategies strategies) {
ServerHttpResponse response = exchange.getResponse();
writeStatusAndHeaders(response);
MediaType contentType = exchange.getResponse().getHeaders().getContentType();
......
......@@ -16,7 +16,7 @@
package org.springframework.web.reactive.function;
import org.springframework.web.reactive.function.support.RequestWrapper;
import org.springframework.web.reactive.function.support.ServerRequestWrapper;
/**
* Represents a function that filters a {@linkplain HandlerFunction handler function}.
......@@ -25,22 +25,22 @@ import org.springframework.web.reactive.function.support.RequestWrapper;
* @param <R> the type of the response of the function
* @author Arjen Poutsma
* @since 5.0
* @see RouterFunction#filter(FilterFunction)
* @see RouterFunction#filter(HandlerFilterFunction)
*/
@FunctionalInterface
public interface FilterFunction<T, R> {
public interface HandlerFilterFunction<T, R> {
/**
* Apply this filter to the given handler function. The given
* {@linkplain HandlerFunction handler function} represents the next entity in the
* chain, and can be {@linkplain HandlerFunction#handle(Request) invoked} in order
* chain, and can be {@linkplain HandlerFunction#handle(ServerRequest) invoked} in order
* to proceed to this entity, or not invoked to block the chain.
*
* @param request the request
* @param next the next handler or filter function in the chain
* @return the filtered response
* @see RequestWrapper
* @see ServerRequestWrapper
*/
Response<R> filter(Request request, HandlerFunction<T> next);
ServerResponse<R> filter(ServerRequest request, HandlerFunction<T> next);
}
......@@ -17,7 +17,7 @@
package org.springframework.web.reactive.function;
/**
* Represents a function that handles a {@linkplain Request request}.
* Represents a function that handles a {@linkplain ServerRequest request}.
*
* @param <T> the type of the response of the function
* @author Arjen Poutsma
......@@ -31,6 +31,6 @@ public interface HandlerFunction<T> {
* @param request the request to handle
* @return the response
*/
Response<T> handle(Request request);
ServerResponse<T> handle(ServerRequest request);
}
......@@ -29,16 +29,16 @@ import org.springframework.web.reactive.result.view.ViewResolver;
* Defines the strategies to be used for processing {@link HandlerFunction}s. An instance of
* this class is immutable; instances are typically created through the mutable {@link Builder}:
* either through {@link #builder()} to set up default strategies, or {@link #empty()} to start from
* scratch. Alternatively, {@code StrategiesSupplier} instances can be created through
* scratch. Alternatively, {@code HandlerStrategies} instances can be created through
* {@link #of(Supplier, Supplier, Supplier)}.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @since 5.0
* @see RouterFunctions#toHttpHandler(RouterFunction, StrategiesSupplier)
* @see RouterFunctions#toHandlerMapping(RouterFunction, StrategiesSupplier)
* @see RouterFunctions#toHttpHandler(RouterFunction, HandlerStrategies)
* @see RouterFunctions#toHandlerMapping(RouterFunction, HandlerStrategies)
*/
public interface StrategiesSupplier {
public interface HandlerStrategies {
// Instance methods
......@@ -67,41 +67,41 @@ public interface StrategiesSupplier {
// Static methods
/**
* Return a new {@code StrategiesSupplier} with default initialization.
* @return the new {@code StrategiesSupplier}
* Return a new {@code HandlerStrategies} with default initialization.
* @return the new {@code HandlerStrategies}
*/
static StrategiesSupplier withDefaults() {
static HandlerStrategies withDefaults() {
return builder().build();
}
/**
* Return a new {@code StrategiesSupplier} based on the given
* Return a new {@code HandlerStrategies} based on the given
* {@linkplain ApplicationContext application context}.
* The returned supplier will search for all {@link HttpMessageReader}, {@link HttpMessageWriter},
* and {@link ViewResolver} instances in the given application context and return them for
* {@link #messageReaders()}, {@link #messageWriters()}, and {@link #viewResolvers()}
* respectively.
* @param applicationContext the application context to base the strategies on
* @return the new {@code StrategiesSupplier}
* @return the new {@code HandlerStrategies}
*/
static StrategiesSupplier of(ApplicationContext applicationContext) {
static HandlerStrategies of(ApplicationContext applicationContext) {
return builder(applicationContext).build();
}
/**
* Return a new {@code StrategiesSupplier} described by the given supplier functions.
* Return a new {@code HandlerStrategies} described by the given supplier functions.
* All provided supplier function parameters can be {@code null} to indicate an empty
* stream is to be returned.
* @param messageReaders the supplier function for {@link HttpMessageReader} instances (can be {@code null})
* @param messageWriters the supplier function for {@link HttpMessageWriter} instances (can be {@code null})
* @param viewResolvers the supplier function for {@link ViewResolver} instances (can be {@code null})
* @return the new {@code StrategiesSupplier}
* @return the new {@code HandlerStrategies}
*/
static StrategiesSupplier of(Supplier<Stream<HttpMessageReader<?>>> messageReaders,
static HandlerStrategies of(Supplier<Stream<HttpMessageReader<?>>> messageReaders,
Supplier<Stream<HttpMessageWriter<?>>> messageWriters,
Supplier<Stream<ViewResolver>> viewResolvers) {
return new StrategiesSupplier() {
return new HandlerStrategies() {
@Override
public Supplier<Stream<HttpMessageReader<?>>> messageReaders() {
return checkForNull(messageReaders);
......@@ -124,11 +124,11 @@ public interface StrategiesSupplier {
// Builder methods
/**
* Return a mutable builder for a {@code StrategiesSupplier} with default initialization.
* Return a mutable builder for a {@code HandlerStrategies} with default initialization.
* @return the builder
*/
static Builder builder() {
DefaultStrategiesSupplierBuilder builder = new DefaultStrategiesSupplierBuilder();
DefaultHandlerStrategiesBuilder builder = new DefaultHandlerStrategiesBuilder();
builder.defaultConfiguration();
return builder;
}
......@@ -144,22 +144,22 @@ public interface StrategiesSupplier {
*/
static Builder builder(ApplicationContext applicationContext) {
Assert.notNull(applicationContext, "ApplicationContext must not be null");
DefaultStrategiesSupplierBuilder builder = new DefaultStrategiesSupplierBuilder();
DefaultHandlerStrategiesBuilder builder = new DefaultHandlerStrategiesBuilder();
builder.applicationContext(applicationContext);
return builder;
}
/**
* Return a mutable, empty builder for a {@code StrategiesSupplier}.
* Return a mutable, empty builder for a {@code HandlerStrategies}.
* @return the builder
*/
static Builder empty() {
return new DefaultStrategiesSupplierBuilder();
return new DefaultHandlerStrategiesBuilder();
}
/**
* A mutable builder for a {@link StrategiesSupplier}.
* A mutable builder for a {@link HandlerStrategies}.
*/
interface Builder {
......@@ -185,10 +185,10 @@ public interface StrategiesSupplier {
Builder viewResolver(ViewResolver viewResolver);
/**
* Builds the {@link StrategiesSupplier}.
* Builds the {@link HandlerStrategies}.
* @return the built strategies
*/
StrategiesSupplier build();
HandlerStrategies build();
}
}
......@@ -19,7 +19,7 @@ package org.springframework.web.reactive.function;
import org.springframework.util.Assert;
/**
* Represents a function that evaluates on a given {@link Request}.
* Represents a function that evaluates on a given {@link ServerRequest}.
* Instances of this function that evaluate on common request properties can be found in {@link RequestPredicates}.
*
* @author Arjen Poutsma
......@@ -38,7 +38,7 @@ public interface RequestPredicate {
* @param request the request to match against
* @return {@code true} if the request matches the predicate; {@code false} otherwise
*/
boolean test(Request request);
boolean test(ServerRequest request);
/**
* Returns a composed request predicate that tests against both this predicate AND the {@code other} predicate.
......@@ -52,12 +52,12 @@ public interface RequestPredicate {
Assert.notNull(other, "'other' must not be null");
return new RequestPredicate() {
@Override
public boolean test(Request t) {
public boolean test(ServerRequest t) {
return RequestPredicate.this.test(t) && other.test(t);
}
@Override
public Request subRequest(Request request) {
public ServerRequest subRequest(ServerRequest request) {
return other.subRequest(RequestPredicate.this.subRequest(request));
}
};
......@@ -85,7 +85,7 @@ public interface RequestPredicate {
return (t) -> test(t) || other.test(t);
}
default Request subRequest(Request request) {
default ServerRequest subRequest(ServerRequest request) {
return request;
}
}
......@@ -90,13 +90,13 @@ public abstract class RequestPredicates {
* @param headersPredicate a predicate that tests against the request headers
* @return a predicate that tests against the given header predicate
*/
public static RequestPredicate headers(Predicate<Request.Headers> headersPredicate) {
public static RequestPredicate headers(Predicate<ServerRequest.Headers> headersPredicate) {
return new HeaderPredicates(headersPredicate);
}
/**
* Return a {@code RequestPredicate} that tests if the request's
* {@linkplain Request.Headers#contentType() content type} is {@linkplain MediaType#includes(MediaType) included}
* {@linkplain ServerRequest.Headers#contentType() content type} is {@linkplain MediaType#includes(MediaType) included}
* by any of the given media types.
*
* @param mediaTypes the media types to match the request's content type against
......@@ -115,7 +115,7 @@ public abstract class RequestPredicates {
/**
* Return a {@code RequestPredicate} that tests if the request's
* {@linkplain Request.Headers#accept() accept} header is
* {@linkplain ServerRequest.Headers#accept() accept} header is
* {@linkplain MediaType#isCompatibleWith(MediaType) compatible} with any of the given media types.
*
* @param mediaTypes the media types to match the request's accept header against
......@@ -227,7 +227,7 @@ public abstract class RequestPredicates {
}
@Override
public boolean test(Request request) {
public boolean test(ServerRequest request) {
return this.httpMethod == request.method();
}
}
......@@ -246,11 +246,11 @@ public abstract class RequestPredicates {
}
@Override
public boolean test(Request request) {
public boolean test(ServerRequest request) {
String path = request.path();
if (this.pathMatcher.match(this.pattern, path)) {
if (request instanceof DefaultRequest) {
DefaultRequest defaultRequest = (DefaultRequest) request;
if (request instanceof DefaultServerRequest) {
DefaultServerRequest defaultRequest = (DefaultServerRequest) request;
Map<String, String> uriTemplateVariables = this.pathMatcher.extractUriTemplateVariables(this.pattern, path);
defaultRequest.exchange().getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVariables);
}
......@@ -262,35 +262,35 @@ public abstract class RequestPredicates {
}
@Override
public Request subRequest(Request request) {
public ServerRequest subRequest(ServerRequest request) {
String requestPath = request.path();
String subPath = this.pathMatcher.extractPathWithinPattern(this.pattern, requestPath);
return new SubPathRequestWrapper(request, subPath);
return new SubPathServerRequestWrapper(request, subPath);
}
}
private static class HeaderPredicates implements RequestPredicate {
private final Predicate<Request.Headers> headersPredicate;
private final Predicate<ServerRequest.Headers> headersPredicate;
public HeaderPredicates(Predicate<Request.Headers> headersPredicate) {
public HeaderPredicates(Predicate<ServerRequest.Headers> headersPredicate) {
Assert.notNull(headersPredicate, "'headersPredicate' must not be null");
this.headersPredicate = headersPredicate;
}
@Override
public boolean test(Request request) {
public boolean test(ServerRequest request) {
return this.headersPredicate.test(request.headers());
}
}
private static class SubPathRequestWrapper implements Request {
private static class SubPathServerRequestWrapper implements ServerRequest {
private final Request request;
private final ServerRequest request;
private final String subPath;
public SubPathRequestWrapper(Request request, String subPath) {
public SubPathServerRequestWrapper(ServerRequest request, String subPath) {
this.request = request;
this.subPath = subPath;
}
......
......@@ -35,7 +35,7 @@ public interface RouterFunction<T> {
* @return an {@code Optional} describing the {@code HandlerFunction} that matches this request,
* or an empty {@code Optional} if there is no match
*/
Optional<HandlerFunction<T>> route(Request request);
Optional<HandlerFunction<T>> route(ServerRequest request);
/**
* Return a composed routing function that first invokes this function,
......@@ -73,13 +73,13 @@ public interface RouterFunction<T> {
/**
* Filter all {@linkplain HandlerFunction handler functions} routed by this function with the given
* {@linkplain FilterFunction filter function}.
* {@linkplain HandlerFilterFunction filter function}.
*
* @param filterFunction the filter to apply
* @param <S> the filter return type
* @return the filtered routing function
*/
default <S> RouterFunction<S> filter(FilterFunction<T, S> filterFunction) {
default <S> RouterFunction<S> filter(HandlerFilterFunction<T, S> filterFunction) {
return request -> this.route(request)
.map(handlerFunction -> filterRequest -> filterFunction.filter(filterRequest, handlerFunction));
}
......
......@@ -38,7 +38,7 @@ import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
* <p>Additionally, this class can {@linkplain #toHttpHandler(RouterFunction) transform} a
* {@code RouterFunction} into an {@code HttpHandler}, which can be run in Servlet 3.1+,
* Reactor, RxNetty, or Undertow.
* And it can {@linkplain #toHandlerMapping(RouterFunction, StrategiesSupplier) transform} a
* And it can {@linkplain #toHandlerMapping(RouterFunction, HandlerStrategies) transform} a
* {@code RouterFunction} into an {@code HandlerMapping}, which can be run in a
* {@code DispatcherHandler}.
*
......@@ -48,7 +48,7 @@ import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
public abstract class RouterFunctions {
/**
* Name of the {@link ServerWebExchange} attribute that contains the {@link Request}.
* Name of the {@link ServerWebExchange} attribute that contains the {@link ServerRequest}.
*/
public static final String REQUEST_ATTRIBUTE = RouterFunctions.class.getName() + ".request";
......@@ -59,7 +59,7 @@ public abstract class RouterFunctions {
public static final String URI_TEMPLATE_VARIABLES_ATTRIBUTE =
RouterFunctions.class.getName() + ".uriTemplateVariables";
private static final HandlerFunction<Void> NOT_FOUND_HANDLER = request -> Response.notFound().build();
private static final HandlerFunction<Void> NOT_FOUND_HANDLER = request -> ServerResponse.notFound().build();
/**
......@@ -93,7 +93,7 @@ public abstract class RouterFunctions {
return request -> {
if (predicate.test(request)) {
Request subRequest = predicate.subRequest(request);
ServerRequest subRequest = predicate.subRequest(request);
return routerFunction.route(subRequest);
}
else {
......@@ -104,7 +104,7 @@ public abstract class RouterFunctions {
/**
* Convert the given {@linkplain RouterFunction routing function} into a {@link HttpHandler}.
* This conversion uses {@linkplain StrategiesSupplier#builder() default strategies}.
* This conversion uses {@linkplain HandlerStrategies#builder() default strategies}.
* <p>The returned {@code HttpHandler} can be adapted to run in
* <ul>
* <li>Servlet 3.1+ using the
......@@ -120,7 +120,7 @@ public abstract class RouterFunctions {
* @return an http handler that handles HTTP request using the given routing function
*/
public static HttpHandler toHttpHandler(RouterFunction<?> routerFunction) {
return toHttpHandler(routerFunction, StrategiesSupplier.withDefaults());
return toHttpHandler(routerFunction, HandlerStrategies.withDefaults());
}
/**
......@@ -141,31 +141,31 @@ public abstract class RouterFunctions {
* @param strategies the strategies to use
* @return an http handler that handles HTTP request using the given routing function
*/
public static HttpHandler toHttpHandler(RouterFunction<?> routerFunction, StrategiesSupplier strategies) {
public static HttpHandler toHttpHandler(RouterFunction<?> routerFunction, HandlerStrategies strategies) {
Assert.notNull(routerFunction, "RouterFunction must not be null");
Assert.notNull(strategies, "StrategiesSupplier must not be null");
Assert.notNull(strategies, "HandlerStrategies must not be null");
return new HttpWebHandlerAdapter(exchange -> {
Request request = new DefaultRequest(exchange, strategies);
ServerRequest request = new DefaultServerRequest(exchange, strategies);
addAttributes(exchange, request);
HandlerFunction<?> handlerFunction = routerFunction.route(request).orElse(notFound());
Response<?> response = handlerFunction.handle(request);
ServerResponse<?> response = handlerFunction.handle(request);
return response.writeTo(exchange, strategies);
});
}
/**
* Convert the given {@code RouterFunction} into a {@code HandlerMapping}.
* This conversion uses {@linkplain StrategiesSupplier#builder() default strategies}.
* This conversion uses {@linkplain HandlerStrategies#builder() default strategies}.
* <p>The returned {@code HandlerMapping} can be run in a
* {@link org.springframework.web.reactive.DispatcherHandler}.
* @param routerFunction the routing function to convert
* @return an handler mapping that maps HTTP request to a handler using the given routing function
* @see org.springframework.web.reactive.function.support.HandlerFunctionAdapter
* @see org.springframework.web.reactive.function.support.ResponseResultHandler
* @see org.springframework.web.reactive.function.support.ServerResponseResultHandler
*/
public static HandlerMapping toHandlerMapping(RouterFunction<?> routerFunction) {
return toHandlerMapping(routerFunction, StrategiesSupplier.withDefaults());
return toHandlerMapping(routerFunction, HandlerStrategies.withDefaults());
}
/**
......@@ -177,14 +177,14 @@ public abstract class RouterFunctions {
* @param strategies the strategies to use
* @return an handler mapping that maps HTTP request to a handler using the given routing function
* @see org.springframework.web.reactive.function.support.HandlerFunctionAdapter
* @see org.springframework.web.reactive.function.support.ResponseResultHandler
* @see org.springframework.web.reactive.function.support.ServerResponseResultHandler
*/
public static HandlerMapping toHandlerMapping(RouterFunction<?> routerFunction, StrategiesSupplier strategies) {
public static HandlerMapping toHandlerMapping(RouterFunction<?> routerFunction, HandlerStrategies strategies) {
Assert.notNull(routerFunction, "RouterFunction must not be null");
Assert.notNull(strategies, "StrategiesSupplier must not be null");
Assert.notNull(strategies, "HandlerStrategies must not be null");
return exchange -> {
Request request = new DefaultRequest(exchange, strategies);
ServerRequest request = new DefaultServerRequest(exchange, strategies);
addAttributes(exchange, request);
Optional<? extends HandlerFunction<?>> route = routerFunction.route(request);
return Mono.justOrEmpty(route);
......@@ -192,7 +192,7 @@ public abstract class RouterFunctions {
}
private static void addAttributes(ServerWebExchange exchange, Request request) {
private static void addAttributes(ServerWebExchange exchange, ServerRequest request) {
Map<String, Object> attributes = exchange.getAttributes();
attributes.put(REQUEST_ATTRIBUTE, request);
}
......
......@@ -32,14 +32,14 @@ import org.springframework.http.codec.BodyExtractor;
import org.springframework.http.server.reactive.ServerHttpRequest;
/**
* Represents an HTTP request, as handled by a {@code HandlerFunction}.
* Represents a server-side HTTP request, as handled by a {@code HandlerFunction}.
* Access to headers and body is offered by {@link Headers} and
* {@link #body(BodyExtractor)} respectively.
*
* @author Arjen Poutsma
* @since 5.0
*/
public interface Request {
public interface ServerRequest {
/**
* Return the HTTP method.
......@@ -115,7 +115,7 @@ public interface Request {
/**
* Represents the headers of the HTTP request.
* @see Request#headers()
* @see ServerRequest#headers()
*/
interface Headers {
......
......@@ -21,31 +21,31 @@ import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
import org.springframework.core.ResolvableType;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.codec.BodyInserter;
import org.springframework.http.codec.BodyInserters;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.util.Assert;
import org.springframework.web.server.ServerWebExchange;
/**
* Represents a typed HTTP response, as returned by a {@linkplain HandlerFunction handler function} or
* {@linkplain FilterFunction filter function}.
* Represents a typed, server-side HTTP response, as returned by a
* {@linkplain HandlerFunction handler function} or {@linkplain HandlerFilterFunction filter function}.
*
* @author Arjen Poutsma
* @since 5.0
* @param <T> the type of the body that this response contains
*/
public interface Response<T> {
public interface ServerResponse<T> {
// Instance methods
......@@ -69,9 +69,9 @@ public interface Response<T> {
*
* @param exchange the web exchange to write to
* @param strategies the strategies to use when writing
* @return {@code Mono<Void>} to indicate when request handling is complete
* @return {@code Mono<Void>} to indicate when writing is complete
*/
Mono<Void> writeTo(ServerWebExchange exchange, StrategiesSupplier strategies);
Mono<Void> writeTo(ServerWebExchange exchange, HandlerStrategies strategies);
// Static builder methods
......@@ -81,9 +81,9 @@ public interface Response<T> {
* @param other the response to copy the status and headers from
* @return the created builder
*/
static BodyBuilder from(Response<?> other) {
static BodyBuilder from(ServerResponse<?> other) {
Assert.notNull(other, "'other' must not be null");
DefaultResponseBuilder builder = new DefaultResponseBuilder(other.statusCode().value());
DefaultServerResponseBuilder builder = new DefaultServerResponseBuilder(other.statusCode().value());
return builder.headers(other.headers());
}
......@@ -95,7 +95,7 @@ public interface Response<T> {
*/
static BodyBuilder status(HttpStatus status) {
Assert.notNull(status, "HttpStatus must not be null");
return new DefaultResponseBuilder(status.value());
return new DefaultServerResponseBuilder(status.value());
}
/**
......@@ -105,7 +105,7 @@ public interface Response<T> {
* @return the created builder
*/
static BodyBuilder status(int status) {
return new DefaultResponseBuilder(status);
return new DefaultServerResponseBuilder(status);
}
/**
......@@ -271,7 +271,7 @@ public interface Response<T> {
*
* @return the built response
*/
Response<Void> build();
ServerResponse<Void> build();
/**
* Build the response entity with no body.
......@@ -280,7 +280,7 @@ public interface Response<T> {
* @param voidPublisher publisher publisher to indicate when the response should be committed
* @return the built response
*/
<T extends Publisher<Void>> Response<T> build(T voidPublisher);
<T extends Publisher<Void>> ServerResponse<T> build(T voidPublisher);
}
......@@ -310,23 +310,36 @@ public interface Response<T> {
BodyBuilder contentType(MediaType contentType);
/**
* Set the body with the given {@code supplier} function, and write it with the given
* {@code writer} function.
* @param writer a function that writes the body to the {@code ServerHttpResponse}
* @param supplier a function that returns the body instance
* Set the body of the response to the given {@code BodyInserter} and return it.
* @param inserter the {@code BodyInserter} that writes to the response
* @param <T> the type contained in the body
* @return the built response
*/
<T> Response<T> body(BiFunction<ServerHttpResponse, BodyInserter.Context, Mono<Void>> writer,
Supplier<T> supplier);
<T> ServerResponse<T> body(BodyInserter<T, ? super ServerHttpResponse> inserter);
/**
* Set the body of the response to the given {@code BodyInserter} and return it.
* @param inserter the {@code BodyInserter} that writes to the response
* @param <T> the type contained in the body
* @return the built response
* Set the body of the response to the given {@code Publisher} and return it. This
* convenience method combines {@link #body(BodyInserter)} and
* {@link BodyInserters#fromPublisher(Publisher, Class)}.
* @param publisher the {@code Publisher} to write to the response
* @param elementClass the class of elements contained in the publisher
* @param <T> the type of the elements contained in the publisher
* @param <S> the type of the {@code Publisher}
* @return the built request
*/
<S extends Publisher<T>, T> ServerResponse<S> body(S publisher, Class<T> elementClass);
/**
* Set the body of the response to the given {@code Publisher} and return it. This
* convenience method combines {@link #body(BodyInserter)} and
* {@link BodyInserters#fromPublisher(Publisher, ResolvableType)}.
* @param publisher the {@code Publisher} to write to the response
* @param elementType the type of elements contained in the publisher
* @param <T> the type of the elements contained in the publisher
* @param <S> the type of the {@code Publisher}
* @return the built request
*/
<T> Response<T> body(BodyInserter<T, ? super ServerHttpResponse> inserter);
<S extends Publisher<T>, T> ServerResponse<S> body(S publisher, ResolvableType elementType);
/**
* Render the template with the given {@code name} using the given {@code modelAttributes}.
......@@ -339,7 +352,7 @@ public interface Response<T> {
* @param modelAttributes the modelAttributes used to render the template
* @return the built response
*/
Response<Rendering> render(String name, Object... modelAttributes);
ServerResponse<Rendering> render(String name, Object... modelAttributes);
/**
* Render the template with the given {@code name} using the given {@code model}.
......@@ -347,7 +360,7 @@ public interface Response<T> {
* @param model the model used to render the template
* @return the built response
*/
Response<Rendering> render(String name, Map<String, ?> model);
ServerResponse<Rendering> render(String name, Map<String, ?> model);
}
......
......@@ -24,9 +24,9 @@ import org.springframework.core.MethodParameter;
import org.springframework.web.reactive.HandlerAdapter;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.reactive.function.HandlerFunction;
import org.springframework.web.reactive.function.Request;
import org.springframework.web.reactive.function.Response;
import org.springframework.web.reactive.function.RouterFunctions;
import org.springframework.web.reactive.function.ServerRequest;
import org.springframework.web.reactive.function.ServerResponse;
import org.springframework.web.server.ServerWebExchange;
/**
......@@ -41,7 +41,7 @@ public class HandlerFunctionAdapter implements HandlerAdapter {
static {
try {
Method method = HandlerFunction.class.getMethod("handle", Request.class);
Method method = HandlerFunction.class.getMethod("handle", ServerRequest.class);
HANDLER_FUNCTION_RETURN_TYPE = new MethodParameter(method, -1);
}
catch (NoSuchMethodException ex) {
......@@ -57,11 +57,12 @@ public class HandlerFunctionAdapter implements HandlerAdapter {
@Override
public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) {
HandlerFunction<?> handlerFunction = (HandlerFunction<?>) handler;
Request request =
exchange.<Request>getAttribute(RouterFunctions.REQUEST_ATTRIBUTE)
.orElseThrow(() -> new IllegalStateException("Could not find Request in exchange attributes"));
ServerRequest request =
exchange.<ServerRequest>getAttribute(RouterFunctions.REQUEST_ATTRIBUTE)
.orElseThrow(() -> new IllegalStateException(
"Could not find ServerRequest in exchange attributes"));
Response<?> response = handlerFunction.handle(request);
ServerResponse<?> response = handlerFunction.handle(request);
HandlerResult handlerResult =
new HandlerResult(handlerFunction, response, HANDLER_FUNCTION_RETURN_TYPE);
return Mono.just(handlerResult);
......
......@@ -32,18 +32,18 @@ import org.springframework.http.codec.BodyExtractor;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.util.Assert;
import org.springframework.web.reactive.function.HandlerFunction;
import org.springframework.web.reactive.function.Request;
import org.springframework.web.reactive.function.ServerRequest;
/**
* Implementation of the {@link Request} interface that can be subclassed to adapt the request to a
* Implementation of the {@link ServerRequest} interface that can be subclassed to adapt the request to a
* {@link HandlerFunction handler function}. All methods default to calling through to the wrapped request.
*
* @author Arjen Poutsma
* @since 5.0
*/
public class RequestWrapper implements Request {
public class ServerRequestWrapper implements ServerRequest {
private final Request request;
private final ServerRequest request;
/**
......@@ -51,7 +51,7 @@ public class RequestWrapper implements Request {
*
* @param request the request to wrap
*/
public RequestWrapper(Request request) {
public ServerRequestWrapper(ServerRequest request) {
Assert.notNull(request, "'request' must not be null");
this.request = request;
}
......@@ -59,7 +59,7 @@ public class RequestWrapper implements Request {
/**
* Return the wrapped request.
*/
public Request request() {
public ServerRequest request() {
return this.request;
}
......@@ -117,7 +117,7 @@ public class RequestWrapper implements Request {
* Implementation of the {@link Headers} interface that can be subclassed to adapt the headers to a
* {@link HandlerFunction handler function}. All methods default to calling through to the wrapped headers.
*/
public static class HeadersWrapper implements Request.Headers {
public static class HeadersWrapper implements ServerRequest.Headers {
private final Headers headers;
......
......@@ -21,31 +21,31 @@ import reactor.core.publisher.Mono;
import org.springframework.util.Assert;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.reactive.HandlerResultHandler;
import org.springframework.web.reactive.function.Response;
import org.springframework.web.reactive.function.StrategiesSupplier;
import org.springframework.web.reactive.function.ServerResponse;
import org.springframework.web.reactive.function.HandlerStrategies;
import org.springframework.web.server.ServerWebExchange;
/**
* {@code HandlerResultHandler} implementation that supports {@link Response}s.
* {@code HandlerResultHandler} implementation that supports {@link ServerResponse}s.
*
* @author Arjen Poutsma
* @since 5.0
*/
public class ResponseResultHandler implements HandlerResultHandler {
public class ServerResponseResultHandler implements HandlerResultHandler {
private final StrategiesSupplier strategies;
private final HandlerStrategies strategies;
/**
* Create a {@code ResponseResultHandler} with default strategies.
*/
public ResponseResultHandler() {
this(StrategiesSupplier.builder().build());
public ServerResponseResultHandler() {
this(HandlerStrategies.builder().build());
}
/**
* Create a {@code ResponseResultHandler} with the given strategies.
*/
public ResponseResultHandler(StrategiesSupplier strategies) {
public ServerResponseResultHandler(HandlerStrategies strategies) {
Assert.notNull(strategies, "'strategies' must not be null");
this.strategies = strategies;
}
......@@ -53,13 +53,13 @@ public class ResponseResultHandler implements HandlerResultHandler {
@Override
public boolean supports(HandlerResult result) {
return result.getReturnValue()
.filter(o -> o instanceof Response)
.filter(o -> o instanceof ServerResponse)
.isPresent();
}
@Override
public Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
Response<?> response = (Response<?>) result.getReturnValue().orElseThrow(
ServerResponse<?> response = (ServerResponse<?>) result.getReturnValue().orElseThrow(
IllegalStateException::new);
return response.writeTo(exchange, this.strategies);
}
......
/**
* Classes supporting the {@code org.springframework.web.reactive.function} package.
* Contains a {@code HandlerAdapter} that supports {@code HandlerFunction}s,
* a {@code HandlerResultHandler} that supports {@code Response}s, and
* a {@code Request} wrapper to adapt a request.
* a {@code HandlerResultHandler} that supports {@code ServerResponse}s, and
* a {@code ServerRequest} wrapper to adapt a request.
*/
package org.springframework.web.reactive.function.support;
\ No newline at end of file
......@@ -57,7 +57,7 @@ import static org.springframework.http.codec.BodyExtractors.toMono;
/**
* @author Arjen Poutsma
*/
public class DefaultRequestTests {
public class DefaultServerRequestTests {
private ServerHttpRequest mockRequest;
......@@ -65,9 +65,9 @@ public class DefaultRequestTests {
private ServerWebExchange mockExchange;
private StrategiesSupplier mockStrategiesSupplier;
private HandlerStrategies mockHandlerStrategies;
private DefaultRequest defaultRequest;
private DefaultServerRequest defaultRequest;
@Before
public void createMocks() {
......@@ -77,9 +77,9 @@ public class DefaultRequestTests {
mockExchange = mock(ServerWebExchange.class);
when(mockExchange.getRequest()).thenReturn(mockRequest);
when(mockExchange.getResponse()).thenReturn(mockResponse);
mockStrategiesSupplier = mock(StrategiesSupplier.class);
mockHandlerStrategies = mock(HandlerStrategies.class);
defaultRequest = new DefaultRequest(mockExchange, mockStrategiesSupplier);
defaultRequest = new DefaultServerRequest(mockExchange, mockHandlerStrategies);
}
@Test
......@@ -149,7 +149,7 @@ public class DefaultRequestTests {
when(mockRequest.getHeaders()).thenReturn(httpHeaders);
Request.Headers headers = defaultRequest.headers();
ServerRequest.Headers headers = defaultRequest.headers();
assertEquals(accept, headers.accept());
assertEquals(acceptCharset, headers.acceptCharset());
assertEquals(OptionalLong.of(contentLength), headers.contentLength());
......@@ -171,7 +171,7 @@ public class DefaultRequestTests {
Set<HttpMessageReader<?>> messageReaders = Collections
.singleton(new DecoderHttpMessageReader<String>(new StringDecoder()));
when(mockStrategiesSupplier.messageReaders()).thenReturn(messageReaders::stream);
when(mockHandlerStrategies.messageReaders()).thenReturn(messageReaders::stream);
Mono<String> resultMono = defaultRequest.body(toMono(String.class));
assertEquals("foo", resultMono.block());
......
......@@ -61,137 +61,137 @@ import static org.mockito.Mockito.when;
/**
* @author Arjen Poutsma
*/
public class DefaultResponseBuilderTests {
public class DefaultServerResponseBuilderTests {
@Test
public void from() throws Exception {
Response<Void> other = Response.ok().header("foo", "bar").build();
Response<Void> result = Response.from(other).build();
ServerResponse<Void> other = ServerResponse.ok().header("foo", "bar").build();
ServerResponse<Void> result = ServerResponse.from(other).build();
assertEquals(HttpStatus.OK, result.statusCode());
assertEquals("bar", result.headers().getFirst("foo"));
}
@Test
public void status() throws Exception {
Response<Void> result = Response.status(HttpStatus.CREATED).build();
ServerResponse<Void> result = ServerResponse.status(HttpStatus.CREATED).build();
assertEquals(HttpStatus.CREATED, result.statusCode());
}
@Test
public void statusInt() throws Exception {
Response<Void> result = Response.status(201).build();
ServerResponse<Void> result = ServerResponse.status(201).build();
assertEquals(HttpStatus.CREATED, result.statusCode());
}
@Test
public void ok() throws Exception {
Response<Void> result = Response.ok().build();
ServerResponse<Void> result = ServerResponse.ok().build();
assertEquals(HttpStatus.OK, result.statusCode());
}
@Test
public void created() throws Exception {
URI location = URI.create("http://example.com");
Response<Void> result = Response.created(location).build();
ServerResponse<Void> result = ServerResponse.created(location).build();
assertEquals(HttpStatus.CREATED, result.statusCode());
assertEquals(location, result.headers().getLocation());
}
@Test
public void accepted() throws Exception {
Response<Void> result = Response.accepted().build();
ServerResponse<Void> result = ServerResponse.accepted().build();
assertEquals(HttpStatus.ACCEPTED, result.statusCode());
}
@Test
public void noContent() throws Exception {
Response<Void> result = Response.noContent().build();
ServerResponse<Void> result = ServerResponse.noContent().build();
assertEquals(HttpStatus.NO_CONTENT, result.statusCode());
}
@Test
public void badRequest() throws Exception {
Response<Void> result = Response.badRequest().build();
ServerResponse<Void> result = ServerResponse.badRequest().build();
assertEquals(HttpStatus.BAD_REQUEST, result.statusCode());
}
@Test
public void notFound() throws Exception {
Response<Void> result = Response.notFound().build();
ServerResponse<Void> result = ServerResponse.notFound().build();
assertEquals(HttpStatus.NOT_FOUND, result.statusCode());
}
@Test
public void unprocessableEntity() throws Exception {
Response<Void> result = Response.unprocessableEntity().build();
ServerResponse<Void> result = ServerResponse.unprocessableEntity().build();
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, result.statusCode());
}
@Test
public void allow() throws Exception {
Response<Void> result = Response.ok().allow(HttpMethod.GET).build();
ServerResponse<Void> result = ServerResponse.ok().allow(HttpMethod.GET).build();
assertEquals(Collections.singleton(HttpMethod.GET), result.headers().getAllow());
}
@Test
public void contentLength() throws Exception {
Response<Void> result = Response.ok().contentLength(42).build();
ServerResponse<Void> result = ServerResponse.ok().contentLength(42).build();
assertEquals(42, result.headers().getContentLength());
}
@Test
public void contentType() throws Exception {
Response<Void> result = Response.ok().contentType(MediaType.APPLICATION_JSON).build();
ServerResponse<Void> result = ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).build();
assertEquals(MediaType.APPLICATION_JSON, result.headers().getContentType());
}
@Test
public void eTag() throws Exception {
Response<Void> result = Response.ok().eTag("foo").build();
ServerResponse<Void> result = ServerResponse.ok().eTag("foo").build();
assertEquals("\"foo\"", result.headers().getETag());
}
@Test
public void lastModified() throws Exception {
ZonedDateTime now = ZonedDateTime.now();
Response<Void> result = Response.ok().lastModified(now).build();
ServerResponse<Void> result = ServerResponse.ok().lastModified(now).build();
assertEquals(now.toInstant().toEpochMilli()/1000, result.headers().getLastModified()/1000);
}
@Test
public void cacheControlTag() throws Exception {
Response<Void> result = Response.ok().cacheControl(CacheControl.noCache()).build();
ServerResponse<Void> result = ServerResponse.ok().cacheControl(CacheControl.noCache()).build();
assertEquals("no-cache", result.headers().getCacheControl());
}
@Test
public void varyBy() throws Exception {
Response<Void> result = Response.ok().varyBy("foo").build();
ServerResponse<Void> result = ServerResponse.ok().varyBy("foo").build();
assertEquals(Collections.singletonList("foo"), result.headers().getVary());
}
@Test
public void statusCode() throws Exception {
HttpStatus statusCode = HttpStatus.ACCEPTED;
Response<Void> result = Response.status(statusCode).build();
ServerResponse<Void> result = ServerResponse.status(statusCode).build();
assertSame(statusCode, result.statusCode());
}
@Test
public void headers() throws Exception {
HttpHeaders headers = new HttpHeaders();
Response<Void> result = Response.ok().headers(headers).build();
ServerResponse<Void> result = ServerResponse.ok().headers(headers).build();
assertEquals(headers, result.headers());
}
@Test
public void build() throws Exception {
Response<Void> result = Response.status(201).header("MyKey", "MyValue").build();
ServerResponse<Void> result = ServerResponse.status(201).header("MyKey", "MyValue").build();
ServerWebExchange exchange = mock(ServerWebExchange.class);
MockServerHttpResponse response = new MockServerHttpResponse();
when(exchange.getResponse()).thenReturn(response);
StrategiesSupplier strategies = mock(StrategiesSupplier.class);
HandlerStrategies strategies = mock(HandlerStrategies.class);
result.writeTo(exchange, strategies).block();
assertEquals(201, response.getStatusCode().value());
......@@ -203,12 +203,12 @@ public class DefaultResponseBuilderTests {
@Test
public void buildVoidPublisher() throws Exception {
Mono<Void> mono = Mono.empty();
Response<Mono<Void>> result = Response.ok().build(mono);
ServerResponse<Mono<Void>> result = ServerResponse.ok().build(mono);
ServerWebExchange exchange = mock(ServerWebExchange.class);
MockServerHttpResponse response = new MockServerHttpResponse();
when(exchange.getResponse()).thenReturn(response);
StrategiesSupplier strategies = mock(StrategiesSupplier.class);
HandlerStrategies strategies = mock(HandlerStrategies.class);
result.writeTo(exchange, strategies).block();
assertNull(response.getBody());
......@@ -227,7 +227,7 @@ public class DefaultResponseBuilderTests {
return response.writeWith(Mono.just(buffer));
};
Response<String> result = Response.ok().body(writer, supplier);
ServerResponse<String> result = ServerResponse.ok().body(BodyInserter.of(writer, supplier));
assertEquals(body, result.body());
MockServerHttpRequest request =
......@@ -239,7 +239,7 @@ public class DefaultResponseBuilderTests {
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
messageWriters.add(new EncoderHttpMessageWriter<CharSequence>(new CharSequenceEncoder()));
StrategiesSupplier strategies = mock(StrategiesSupplier.class);
HandlerStrategies strategies = mock(HandlerStrategies.class);
when(strategies.messageWriters()).thenReturn(messageWriters::stream);
result.writeTo(exchange, strategies).block();
......@@ -249,7 +249,7 @@ public class DefaultResponseBuilderTests {
@Test
public void render() throws Exception {
Map<String, Object> model = Collections.singletonMap("foo", "bar");
Response<Rendering> result = Response.ok().render("view", model);
ServerResponse<Rendering> result = ServerResponse.ok().render("view", model);
assertEquals("view", result.body().name());
assertEquals(model, result.body().model());
......@@ -265,7 +265,7 @@ public class DefaultResponseBuilderTests {
List<ViewResolver> viewResolvers = new ArrayList<>();
viewResolvers.add(viewResolver);
StrategiesSupplier mockConfig = mock(StrategiesSupplier.class);
HandlerStrategies mockConfig = mock(HandlerStrategies.class);
when(mockConfig.viewResolvers()).thenReturn(viewResolvers::stream);
result.writeTo(exchange, mockConfig).block();
......@@ -273,11 +273,11 @@ public class DefaultResponseBuilderTests {
@Test
public void renderObjectArray() throws Exception {
Response<Rendering> result =
Response.ok().render("name", this, Collections.emptyList(), "foo");
ServerResponse<Rendering> result =
ServerResponse.ok().render("name", this, Collections.emptyList(), "foo");
Map<String, Object> model = result.body().model();
assertEquals(2, model.size());
assertEquals(this, model.get("defaultResponseBuilderTests"));
assertEquals(this, model.get("defaultServerResponseBuilderTests"));
assertEquals("foo", model.get("string"));
}
......
......@@ -45,7 +45,7 @@ import org.springframework.web.reactive.HandlerAdapter;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.reactive.config.WebReactiveConfigurationSupport;
import org.springframework.web.reactive.function.support.HandlerFunctionAdapter;
import org.springframework.web.reactive.function.support.ResponseResultHandler;
import org.springframework.web.reactive.function.support.ServerResponseResultHandler;
import org.springframework.web.reactive.result.view.ViewResolver;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
......@@ -121,7 +121,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
public HandlerMapping handlerMapping(RouterFunction<?> routerFunction,
ApplicationContext applicationContext) {
return RouterFunctions.toHandlerMapping(routerFunction,
new StrategiesSupplier() {
new HandlerStrategies() {
@Override
public Supplier<Stream<HttpMessageReader<?>>> messageReaders() {
return () -> getMessageReaders().stream();
......@@ -147,22 +147,22 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
}
@Bean
public ResponseResultHandler responseResultHandler() {
return new ResponseResultHandler();
public ServerResponseResultHandler responseResultHandler() {
return new ServerResponseResultHandler();
}
}
private static class PersonHandler {
public Response<Publisher<Person>> mono(Request request) {
public ServerResponse<Publisher<Person>> mono(ServerRequest request) {
Person person = new Person("John");
return Response.ok().body(fromPublisher(Mono.just(person), Person.class));
return ServerResponse.ok().body(fromPublisher(Mono.just(person), Person.class));
}
public Response<Publisher<Person>> flux(Request request) {
public ServerResponse<Publisher<Person>> flux(ServerRequest request) {
Person person1 = new Person("John");
Person person2 = new Person("Jane");
return Response.ok().body(
return ServerResponse.ok().body(
fromPublisher(Flux.just(person1, person2), Person.class));
}
......
......@@ -41,11 +41,11 @@ import static org.junit.Assert.*;
/**
* @author Arjen Poutsma
*/
public class StrategiesSupplierTests {
public class HandlerStrategiesTests {
@Test
public void empty() {
StrategiesSupplier strategies = StrategiesSupplier.empty().build();
HandlerStrategies strategies = HandlerStrategies.empty().build();
assertEquals(Optional.empty(), strategies.messageReaders().get().findFirst());
assertEquals(Optional.empty(), strategies.messageWriters().get().findFirst());
assertEquals(Optional.empty(), strategies.viewResolvers().get().findFirst());
......@@ -56,7 +56,7 @@ public class StrategiesSupplierTests {
HttpMessageReader<?> messageReader = new DummyMessageReader();
HttpMessageWriter<?> messageWriter = new DummyMessageWriter();
StrategiesSupplier strategies = StrategiesSupplier.of(
HandlerStrategies strategies = HandlerStrategies.of(
() -> Stream.of(messageReader),
() -> Stream.of(messageWriter),
null);
......@@ -77,7 +77,7 @@ public class StrategiesSupplierTests {
applicationContext.registerSingleton("messageReader", DummyMessageReader.class);
applicationContext.refresh();
StrategiesSupplier strategies = StrategiesSupplier.of(applicationContext);
HandlerStrategies strategies = HandlerStrategies.of(applicationContext);
assertTrue(strategies.messageReaders().get()
.allMatch(r -> r instanceof DummyMessageReader));
assertTrue(strategies.messageWriters().get()
......
......@@ -30,7 +30,7 @@ import org.junit.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRange;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.support.RequestWrapper;
import org.springframework.web.reactive.function.support.ServerRequestWrapper;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
......@@ -41,15 +41,15 @@ import static org.mockito.Mockito.when;
*/
public class HeadersWrapperTest {
private Request.Headers mockHeaders;
private ServerRequest.Headers mockHeaders;
private RequestWrapper.HeadersWrapper wrapper;
private ServerRequestWrapper.HeadersWrapper wrapper;
@Before
public void createWrapper() {
mockHeaders = mock(Request.Headers.class);
wrapper = new RequestWrapper.HeadersWrapper(mockHeaders);
mockHeaders = mock(ServerRequest.Headers.class);
wrapper = new ServerRequestWrapper.HeadersWrapper(mockHeaders);
}
@Test
......
......@@ -42,7 +42,7 @@ import org.springframework.util.MultiValueMap;
/**
* @author Arjen Poutsma
*/
public class MockRequest<T> implements Request {
public class MockServerRequest<T> implements ServerRequest {
private final HttpMethod method;
......@@ -58,7 +58,7 @@ public class MockRequest<T> implements Request {
private final Map<String, String> pathVariables;
private MockRequest(HttpMethod method, URI uri,
private MockServerRequest(HttpMethod method, URI uri,
MockHeaders headers, T body, Map<String, Object> attributes,
MultiValueMap<String, String> queryParams,
Map<String, String> pathVariables) {
......@@ -134,9 +134,9 @@ public class MockRequest<T> implements Request {
Builder<T> pathVariables(Map<String, String> pathVariables);
MockRequest<T> body(T body);
MockServerRequest<T> body(T body);
MockRequest<Void> build();
MockServerRequest<Void> build();
}
......@@ -231,15 +231,15 @@ public class MockRequest<T> implements Request {
}
@Override
public MockRequest<T> body(T body) {
public MockServerRequest<T> body(T body) {
this.body = body;
return new MockRequest<T>(this.method, this.uri, this.headers, this.body,
return new MockServerRequest<T>(this.method, this.uri, this.headers, this.body,
this.attributes, this.queryParams, this.pathVariables);
}
@Override
public MockRequest<Void> build() {
return new MockRequest<Void>(this.method, this.uri, this.headers, null,
public MockServerRequest<Void> build() {
return new MockServerRequest<Void>(this.method, this.uri, this.headers, null,
this.attributes, this.queryParams, this.pathVariables);
}
......
......@@ -97,20 +97,20 @@ public class PublisherHandlerFunctionIntegrationTests
private static class PersonHandler {
public Response<Publisher<Person>> mono(Request request) {
public ServerResponse<Publisher<Person>> mono(ServerRequest request) {
Person person = new Person("John");
return Response.ok().body(fromPublisher(Mono.just(person), Person.class));
return ServerResponse.ok().body(fromPublisher(Mono.just(person), Person.class));
}
public Response<Publisher<Person>> postMono(Request request) {
public ServerResponse<Publisher<Person>> postMono(ServerRequest request) {
Mono<Person> personMono = request.body(toMono(Person.class));
return Response.ok().body(fromPublisher(personMono, Person.class));
return ServerResponse.ok().body(fromPublisher(personMono, Person.class));
}
public Response<Publisher<Person>> flux(Request request) {
public ServerResponse<Publisher<Person>> flux(ServerRequest request) {
Person person1 = new Person("John");
Person person2 = new Person("Jane");
return Response.ok().body(
return ServerResponse.ok().body(
fromPublisher(Flux.just(person1, person2), Person.class));
}
......
......@@ -32,7 +32,7 @@ public class RequestPredicateTests {
RequestPredicate predicate2 = request -> true;
RequestPredicate predicate3 = request -> false;
MockRequest request = MockRequest.builder().build();
MockServerRequest request = MockServerRequest.builder().build();
assertTrue(predicate1.and(predicate2).test(request));
assertTrue(predicate2.and(predicate1).test(request));
assertFalse(predicate1.and(predicate3).test(request));
......@@ -43,7 +43,7 @@ public class RequestPredicateTests {
RequestPredicate predicate = request -> false;
RequestPredicate negated = predicate.negate();
MockRequest mockRequest = MockRequest.builder().build();
MockServerRequest mockRequest = MockServerRequest.builder().build();
assertTrue(negated.test(mockRequest));
predicate = request -> true;
......@@ -58,7 +58,7 @@ public class RequestPredicateTests {
RequestPredicate predicate2 = request -> false;
RequestPredicate predicate3 = request -> false;
MockRequest request = MockRequest.builder().build();
MockServerRequest request = MockServerRequest.builder().build();
assertTrue(predicate1.or(predicate2).test(request));
assertTrue(predicate2.or(predicate1).test(request));
assertFalse(predicate2.or(predicate3).test(request));
......
......@@ -35,7 +35,7 @@ public class RequestPredicatesTests {
@Test
public void all() throws Exception {
RequestPredicate predicate = RequestPredicates.all();
MockRequest request = MockRequest.builder().build();
MockServerRequest request = MockServerRequest.builder().build();
assertTrue(predicate.test(request));
}
......@@ -43,10 +43,10 @@ public class RequestPredicatesTests {
public void method() throws Exception {
HttpMethod httpMethod = HttpMethod.GET;
RequestPredicate predicate = RequestPredicates.method(httpMethod);
MockRequest request = MockRequest.builder().method(httpMethod).build();
MockServerRequest request = MockServerRequest.builder().method(httpMethod).build();
assertTrue(predicate.test(request));
request = MockRequest.builder().method(HttpMethod.POST).build();
request = MockServerRequest.builder().method(HttpMethod.POST).build();
assertFalse(predicate.test(request));
}
......@@ -55,31 +55,31 @@ public class RequestPredicatesTests {
URI uri = URI.create("http://localhost/path");
RequestPredicate predicate = RequestPredicates.GET("/p*");
MockRequest request = MockRequest.builder().method(HttpMethod.GET).uri(uri).build();
MockServerRequest request = MockServerRequest.builder().method(HttpMethod.GET).uri(uri).build();
assertTrue(predicate.test(request));
predicate = RequestPredicates.HEAD("/p*");
request = MockRequest.builder().method(HttpMethod.HEAD).uri(uri).build();
request = MockServerRequest.builder().method(HttpMethod.HEAD).uri(uri).build();
assertTrue(predicate.test(request));
predicate = RequestPredicates.POST("/p*");
request = MockRequest.builder().method(HttpMethod.POST).uri(uri).build();
request = MockServerRequest.builder().method(HttpMethod.POST).uri(uri).build();
assertTrue(predicate.test(request));
predicate = RequestPredicates.PUT("/p*");
request = MockRequest.builder().method(HttpMethod.PUT).uri(uri).build();
request = MockServerRequest.builder().method(HttpMethod.PUT).uri(uri).build();
assertTrue(predicate.test(request));
predicate = RequestPredicates.PATCH("/p*");
request = MockRequest.builder().method(HttpMethod.PATCH).uri(uri).build();
request = MockServerRequest.builder().method(HttpMethod.PATCH).uri(uri).build();
assertTrue(predicate.test(request));
predicate = RequestPredicates.DELETE("/p*");
request = MockRequest.builder().method(HttpMethod.DELETE).uri(uri).build();
request = MockServerRequest.builder().method(HttpMethod.DELETE).uri(uri).build();
assertTrue(predicate.test(request));
predicate = RequestPredicates.OPTIONS("/p*");
request = MockRequest.builder().method(HttpMethod.OPTIONS).uri(uri).build();
request = MockServerRequest.builder().method(HttpMethod.OPTIONS).uri(uri).build();
assertTrue(predicate.test(request));
}
......@@ -88,10 +88,10 @@ public class RequestPredicatesTests {
public void path() throws Exception {
URI uri = URI.create("http://localhost/path");
RequestPredicate predicate = RequestPredicates.path("/p*");
MockRequest request = MockRequest.builder().uri(uri).build();
MockServerRequest request = MockServerRequest.builder().uri(uri).build();
assertTrue(predicate.test(request));
request = MockRequest.builder().build();
request = MockServerRequest.builder().build();
assertFalse(predicate.test(request));
}
......@@ -104,10 +104,10 @@ public class RequestPredicatesTests {
return headers.header(name).equals(
Collections.singletonList(value));
});
MockRequest request = MockRequest.builder().header(name, value).build();
MockServerRequest request = MockServerRequest.builder().header(name, value).build();
assertTrue(predicate.test(request));
request = MockRequest.builder().build();
request = MockServerRequest.builder().build();
assertFalse(predicate.test(request));
}
......@@ -115,10 +115,11 @@ public class RequestPredicatesTests {
public void contentType() throws Exception {
MediaType json = MediaType.APPLICATION_JSON;
RequestPredicate predicate = RequestPredicates.contentType(json);
MockRequest request = MockRequest.builder().header("Content-Type", json.toString()).build();
MockServerRequest
request = MockServerRequest.builder().header("Content-Type", json.toString()).build();
assertTrue(predicate.test(request));
request = MockRequest.builder().build();
request = MockServerRequest.builder().build();
assertFalse(predicate.test(request));
}
......@@ -126,10 +127,10 @@ public class RequestPredicatesTests {
public void accept() throws Exception {
MediaType json = MediaType.APPLICATION_JSON;
RequestPredicate predicate = RequestPredicates.accept(json);
MockRequest request = MockRequest.builder().header("Accept", json.toString()).build();
MockServerRequest request = MockServerRequest.builder().header("Accept", json.toString()).build();
assertTrue(predicate.test(request));
request = MockRequest.builder().build();
request = MockServerRequest.builder().build();
assertFalse(predicate.test(request));
}
......
......@@ -33,14 +33,14 @@ public class RouterFunctionTests {
@Test
public void andSame() throws Exception {
HandlerFunction<Void> handlerFunction = request -> Response.ok().build();
HandlerFunction<Void> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<Void> routerFunction1 = request -> Optional.empty();
RouterFunction<Void> routerFunction2 = request -> Optional.of(handlerFunction);
RouterFunction<Void> result = routerFunction1.andSame(routerFunction2);
assertNotNull(result);
MockRequest request = MockRequest.builder().build();
MockServerRequest request = MockServerRequest.builder().build();
Optional<HandlerFunction<Void>> resultHandlerFunction = result.route(request);
assertTrue(resultHandlerFunction.isPresent());
assertEquals(handlerFunction, resultHandlerFunction.get());
......@@ -48,14 +48,14 @@ public class RouterFunctionTests {
@Test
public void and() throws Exception {
HandlerFunction<String> handlerFunction = request -> Response.ok().body(fromObject("42"));
HandlerFunction<String> handlerFunction = request -> ServerResponse.ok().body(fromObject("42"));
RouterFunction<Void> routerFunction1 = request -> Optional.empty();
RouterFunction<String> routerFunction2 = request -> Optional.of(handlerFunction);
RouterFunction<?> result = routerFunction1.and(routerFunction2);
assertNotNull(result);
MockRequest request = MockRequest.builder().build();
MockServerRequest request = MockServerRequest.builder().build();
Optional<? extends HandlerFunction<?>> resultHandlerFunction = result.route(request);
assertTrue(resultHandlerFunction.isPresent());
assertEquals(handlerFunction, resultHandlerFunction.get());
......@@ -63,21 +63,21 @@ public class RouterFunctionTests {
@Test
public void filter() throws Exception {
HandlerFunction<String> handlerFunction = request -> Response.ok().body(fromObject("42"));
HandlerFunction<String> handlerFunction = request -> ServerResponse.ok().body(fromObject("42"));
RouterFunction<String> routerFunction = request -> Optional.of(handlerFunction);
FilterFunction<String, Integer> filterFunction = (request, next) -> {
Response<String> response = next.handle(request);
HandlerFilterFunction<String, Integer> filterFunction = (request, next) -> {
ServerResponse<String> response = next.handle(request);
int i = Integer.parseInt(response.body());
return Response.ok().body(fromObject(i));
return ServerResponse.ok().body(fromObject(i));
};
RouterFunction<Integer> result = routerFunction.filter(filterFunction);
assertNotNull(result);
MockRequest request = MockRequest.builder().build();
MockServerRequest request = MockServerRequest.builder().build();
Optional<? extends HandlerFunction<?>> resultHandlerFunction = result.route(request);
assertTrue(resultHandlerFunction.isPresent());
Response<?> resultResponse = resultHandlerFunction.get().handle(request);
ServerResponse<?> resultResponse = resultHandlerFunction.get().handle(request);
assertEquals(42, resultResponse.body());
}
......
......@@ -48,9 +48,9 @@ public class RouterFunctionsTests {
@Test
public void routeMatch() throws Exception {
HandlerFunction<Void> handlerFunction = request -> Response.ok().build();
HandlerFunction<Void> handlerFunction = request -> ServerResponse.ok().build();
MockRequest request = MockRequest.builder().build();
MockServerRequest request = MockServerRequest.builder().build();
RequestPredicate requestPredicate = mock(RequestPredicate.class);
when(requestPredicate.test(request)).thenReturn(true);
......@@ -64,9 +64,9 @@ public class RouterFunctionsTests {
@Test
public void routeNoMatch() throws Exception {
HandlerFunction<Void> handlerFunction = request -> Response.ok().build();
HandlerFunction<Void> handlerFunction = request -> ServerResponse.ok().build();
MockRequest request = MockRequest.builder().build();
MockServerRequest request = MockServerRequest.builder().build();
RequestPredicate requestPredicate = mock(RequestPredicate.class);
when(requestPredicate.test(request)).thenReturn(false);
......@@ -79,10 +79,10 @@ public class RouterFunctionsTests {
@Test
public void subrouteMatch() throws Exception {
HandlerFunction<Void> handlerFunction = request -> Response.ok().build();
HandlerFunction<Void> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<Void> routerFunction = request -> Optional.of(handlerFunction);
MockRequest request = MockRequest.builder().build();
MockServerRequest request = MockServerRequest.builder().build();
RequestPredicate requestPredicate = mock(RequestPredicate.class);
when(requestPredicate.test(request)).thenReturn(true);
......@@ -96,10 +96,10 @@ public class RouterFunctionsTests {
@Test
public void subrouteNoMatch() throws Exception {
HandlerFunction<Void> handlerFunction = request -> Response.ok().build();
HandlerFunction<Void> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<Void> routerFunction = request -> Optional.of(handlerFunction);
MockRequest request = MockRequest.builder().build();
MockServerRequest request = MockServerRequest.builder().build();
RequestPredicate requestPredicate = mock(RequestPredicate.class);
when(requestPredicate.test(request)).thenReturn(false);
......@@ -112,7 +112,7 @@ public class RouterFunctionsTests {
@Test
public void toHttpHandler() throws Exception {
StrategiesSupplier strategies = mock(StrategiesSupplier.class);
HandlerStrategies strategies = mock(HandlerStrategies.class);
when(strategies.messageReaders()).thenReturn(
() -> Collections.<HttpMessageReader<?>>emptyList().stream());
when(strategies.messageWriters()).thenReturn(
......@@ -120,15 +120,15 @@ public class RouterFunctionsTests {
when(strategies.viewResolvers()).thenReturn(
() -> Collections.<ViewResolver>emptyList().stream());
Request request = mock(Request.class);
Response response = mock(Response.class);
ServerRequest request = mock(ServerRequest.class);
ServerResponse response = mock(ServerResponse.class);
when(response.writeTo(any(ServerWebExchange.class), eq(strategies))).thenReturn(Mono.empty());
HandlerFunction handlerFunction = mock(HandlerFunction.class);
when(handlerFunction.handle(any(Request.class))).thenReturn(response);
when(handlerFunction.handle(any(ServerRequest.class))).thenReturn(response);
RouterFunction routerFunction = mock(RouterFunction.class);
when(routerFunction.route(any(Request.class))).thenReturn(Optional.of(handlerFunction));
when(routerFunction.route(any(ServerRequest.class))).thenReturn(Optional.of(handlerFunction));
RequestPredicate requestPredicate = mock(RequestPredicate.class);
when(requestPredicate.test(request)).thenReturn(false);
......
......@@ -129,25 +129,25 @@ public class SseHandlerFunctionIntegrationTests
private static class SseHandler {
public Response<Publisher<String>> string(Request request) {
public ServerResponse<Publisher<String>> string(ServerRequest request) {
Flux<String> flux = Flux.interval(Duration.ofMillis(100)).map(l -> "foo " + l).take(2);
return Response.ok().body(fromServerSentEvents(flux, String.class));
return ServerResponse.ok().body(fromServerSentEvents(flux, String.class));
}
public Response<Publisher<Person>> person(Request request) {
public ServerResponse<Publisher<Person>> person(ServerRequest request) {
Flux<Person> flux = Flux.interval(Duration.ofMillis(100))
.map(l -> new Person("foo " + l)).take(2);
return Response.ok().body(fromServerSentEvents(flux, Person.class));
return ServerResponse.ok().body(fromServerSentEvents(flux, Person.class));
}
public Response<Publisher<ServerSentEvent<String>>> sse(Request request) {
public ServerResponse<Publisher<ServerSentEvent<String>>> sse(ServerRequest request) {
Flux<ServerSentEvent<String>> flux = Flux.interval(Duration.ofMillis(100))
.map(l -> ServerSentEvent.<String>builder().data("foo")
.id(Long.toString(l))
.comment("bar")
.build()).take(2);
return Response.ok().body(fromServerSentEvents(flux));
return ServerResponse.ok().body(fromServerSentEvents(flux));
}
}
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.web.reactive.function;
package org.springframework.web.reactive.function.support;
import java.net.URI;
import java.util.Collections;
......@@ -26,7 +26,7 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.http.HttpMethod;
import org.springframework.web.reactive.function.support.RequestWrapper;
import org.springframework.web.reactive.function.ServerRequest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
......@@ -36,16 +36,16 @@ import static org.mockito.Mockito.when;
/**
* @author Arjen Poutsma
*/
public class RequestWrapperTests {
public class ServerRequestWrapperTests {
private Request mockRequest;
private ServerRequest mockRequest;
private RequestWrapper wrapper;
private ServerRequestWrapper wrapper;
@Before
public void createWrapper() {
mockRequest = mock(Request.class);
wrapper = new RequestWrapper(mockRequest);
mockRequest = mock(ServerRequest.class);
wrapper = new ServerRequestWrapper(mockRequest);
}
@Test
......@@ -79,7 +79,7 @@ public class RequestWrapperTests {
@Test
public void headers() throws Exception {
Request.Headers headers = mock(Request.Headers.class);
ServerRequest.Headers headers = mock(ServerRequest.Headers.class);
when(mockRequest.headers()).thenReturn(headers);
assertSame(headers, wrapper.headers());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册