Refine names in web.server and polish Javadoc

WebServerExchange -> ServerWebExchange

Follows the same convention as in the http package also better allowing
the possibility for a client equivalent in the future.

WebToHttpHandlerBuilder -> WebHttpHandlerBuilder
WebToHttpHandlerAdapter -> WebHttpHandlerAdapter

More consistent with Spring conventions.
This commit is contained in:
Rossen Stoyanchev 2016-01-27 17:05:07 -05:00
parent e59b927fd1
commit 381855aaf3
41 changed files with 310 additions and 245 deletions

View File

@ -33,7 +33,7 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
* Central dispatcher for HTTP request handlers/controllers. Dispatches to registered
@ -112,7 +112,7 @@ public class DispatcherHandler implements WebHandler, ApplicationContextAware {
@Override
public Mono<Void> handle(WebServerExchange exchange) {
public Mono<Void> handle(ServerWebExchange exchange) {
if (logger.isDebugEnabled()) {
ServerHttpRequest request = exchange.getRequest();
logger.debug("Processing " + request.getMethod() + " request for [" + request.getURI() + "]");
@ -125,7 +125,7 @@ public class DispatcherHandler implements WebHandler, ApplicationContextAware {
.otherwise(ex -> Mono.error(this.errorMapper.apply(ex)));
}
private Mono<HandlerResult> invokeHandler(WebServerExchange exchange, Object handler) {
private Mono<HandlerResult> invokeHandler(ServerWebExchange exchange, Object handler) {
for (HandlerAdapter handlerAdapter : this.handlerAdapters) {
if (handlerAdapter.supports(handler)) {
return handlerAdapter.handle(exchange, handler);
@ -134,7 +134,7 @@ public class DispatcherHandler implements WebHandler, ApplicationContextAware {
return Mono.error(new IllegalStateException("No HandlerAdapter: " + handler));
}
private Mono<Void> handleResult(WebServerExchange exchange, HandlerResult result) {
private Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
return getResultHandler(result).handleResult(exchange, result)
.otherwise(ex -> result.applyExceptionHandler(ex).then(exceptionResult ->
getResultHandler(result).handleResult(exchange, exceptionResult)));
@ -157,7 +157,7 @@ public class DispatcherHandler implements WebHandler, ApplicationContextAware {
@Override
public Mono<Object> getHandler(WebServerExchange exchange) {
public Mono<Object> getHandler(ServerWebExchange exchange) {
return Mono.error(HANDLER_NOT_FOUND_EXCEPTION);
}
}

View File

@ -20,7 +20,7 @@ import java.util.function.Function;
import reactor.core.publisher.Mono;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
* Contract that decouples the {@link DispatcherHandler} from the details of
@ -58,6 +58,6 @@ public interface HandlerAdapter {
* @return {@link Mono} that emits a single {@code HandlerResult} or none if
* the request has been fully handled and doesn't require further handling.
*/
Mono<HandlerResult> handle(WebServerExchange exchange, Object handler);
Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler);
}

View File

@ -18,7 +18,7 @@ package org.springframework.web.reactive;
import reactor.core.publisher.Mono;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
* Interface to be implemented by objects that define a mapping between
@ -35,6 +35,6 @@ public interface HandlerMapping {
* @return A {@link Mono} that emits one value or none in case the request
* cannot be resolved to a handler
*/
Mono<Object> getHandler(WebServerExchange exchange);
Mono<Object> getHandler(ServerWebExchange exchange);
}

View File

@ -18,7 +18,7 @@ package org.springframework.web.reactive;
import reactor.core.publisher.Mono;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
* Process the {@link HandlerResult}, usually returned by an {@link HandlerAdapter}.
@ -44,6 +44,6 @@ public interface HandlerResultHandler {
* @param result the result from the handling
* @return {@code Mono<Void>} to indicate when request handling is complete.
*/
Mono<Void> handleResult(WebServerExchange exchange, HandlerResult result);
Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result);
}

View File

@ -19,7 +19,7 @@ import reactor.core.publisher.Mono;
import org.springframework.web.ResponseStatusException;
import org.springframework.web.server.WebExceptionHandler;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
* Handle {@link ResponseStatusException} by setting the response status.
@ -30,7 +30,7 @@ public class ResponseStatusExceptionHandler implements WebExceptionHandler {
@Override
public Mono<Void> handle(WebServerExchange exchange, Throwable ex) {
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
if (ex instanceof ResponseStatusException) {
exchange.getResponse().setStatusCode(((ResponseStatusException) ex).getHttpStatus());
return Mono.empty();

View File

@ -24,7 +24,7 @@ import org.springframework.web.reactive.DispatcherHandler;
import org.springframework.web.reactive.HandlerAdapter;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
* Support use of {@link org.springframework.web.server.WebHandler} through the
@ -45,7 +45,7 @@ public class HttpHandlerHandlerAdapter implements HandlerAdapter {
}
@Override
public Mono<HandlerResult> handle(WebServerExchange exchange, Object handler) {
public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) {
WebHandler webHandler = (WebHandler) handler;
Mono<Void> completion = webHandler.handle(exchange);
return Mono.just(new HandlerResult(webHandler, completion, PUBLISHER_VOID));

View File

@ -25,7 +25,7 @@ import org.springframework.core.convert.ConversionService;
import org.springframework.util.Assert;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.reactive.HandlerResultHandler;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
* Supports {@link HandlerResult} with a {@code void} or {@code Publisher<Void>} value.
@ -74,7 +74,7 @@ public class SimpleHandlerResultHandler implements Ordered, HandlerResultHandler
@SuppressWarnings("unchecked")
@Override
public Mono<Void> handleResult(WebServerExchange exchange, HandlerResult result) {
public Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
Object value = result.getResult();
if (Void.TYPE.equals(result.getResultType().getRawClass())) {
return Mono.empty();

View File

@ -23,7 +23,7 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
* @author Rossen Stoyanchev
@ -42,7 +42,7 @@ public class SimpleUrlHandlerMapping implements HandlerMapping {
@Override
public Mono<Object> getHandler(WebServerExchange exchange) {
public Mono<Object> getHandler(ServerWebExchange exchange) {
return Flux.create(subscriber -> {
String path = exchange.getRequest().getURI().getPath();
Object handler = this.handlerMap.get(path);

View File

@ -19,7 +19,7 @@ package org.springframework.web.reactive.method;
import reactor.core.publisher.Mono;
import org.springframework.core.MethodParameter;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
@ -35,6 +35,6 @@ public interface HandlerMethodArgumentResolver {
* does not resolve to any value, which will result in {@code null} passed
* as the argument value.
*/
Mono<Object> resolveArgument(MethodParameter parameter, WebServerExchange exchange);
Mono<Object> resolveArgument(MethodParameter parameter, ServerWebExchange exchange);
}

View File

@ -36,7 +36,7 @@ import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
@ -82,7 +82,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
* @return Publisher that produces a single HandlerResult or an error signal;
* never throws an exception
*/
public Mono<HandlerResult> invokeForRequest(WebServerExchange exchange, Object... providedArgs) {
public Mono<HandlerResult> invokeForRequest(ServerWebExchange exchange, Object... providedArgs) {
return resolveArguments(exchange, providedArgs).then(args -> {
try {
Object value = doInvoke(args);
@ -100,7 +100,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
});
}
private Mono<Object[]> resolveArguments(WebServerExchange exchange, Object... providedArgs) {
private Mono<Object[]> resolveArguments(ServerWebExchange exchange, Object... providedArgs) {
if (ObjectUtils.isEmpty(getMethodParameters())) {
return NO_ARGS;
}

View File

@ -31,7 +31,7 @@ import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.reactive.method.HandlerMethodArgumentResolver;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
* @author Sebastien Deleuze
@ -58,7 +58,7 @@ public class RequestBodyArgumentResolver implements HandlerMethodArgumentResolve
}
@Override
public Mono<Object> resolveArgument(MethodParameter parameter, WebServerExchange exchange) {
public Mono<Object> resolveArgument(MethodParameter parameter, ServerWebExchange exchange) {
MediaType mediaType = exchange.getRequest().getHeaders().getContentType();
if (mediaType == null) {
mediaType = MediaType.APPLICATION_OCTET_STREAM;

View File

@ -45,7 +45,7 @@ import org.springframework.web.reactive.HandlerAdapter;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.reactive.method.HandlerMethodArgumentResolver;
import org.springframework.web.reactive.method.InvocableHandlerMethod;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
@ -114,7 +114,7 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, Initializin
}
@Override
public Mono<HandlerResult> handle(WebServerExchange exchange, Object handler) {
public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
InvocableHandlerMethod invocable = new InvocableHandlerMethod(handlerMethod);
invocable.setHandlerMethodArgumentResolvers(this.argumentResolvers);
@ -125,7 +125,7 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, Initializin
}
private Mono<HandlerResult> handleException(Throwable ex, HandlerMethod handlerMethod,
WebServerExchange exchange) {
ServerWebExchange exchange) {
if (ex instanceof Exception) {
InvocableHandlerMethod invocable = findExceptionHandler(handlerMethod, (Exception) ex);

View File

@ -41,7 +41,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.method.HandlerMethodSelector;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
@ -93,7 +93,7 @@ public class RequestMappingHandlerMapping implements HandlerMapping,
}
@Override
public Mono<Object> getHandler(WebServerExchange exchange) {
public Mono<Object> getHandler(ServerWebExchange exchange) {
return Flux.create(subscriber -> {
for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : this.methodMap.entrySet()) {
RequestMappingInfo info = entry.getKey();

View File

@ -21,7 +21,7 @@ import reactor.core.publisher.Mono;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.reactive.method.HandlerMethodArgumentResolver;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
@ -41,7 +41,7 @@ public class RequestParamArgumentResolver implements HandlerMethodArgumentResolv
@Override
public Mono<Object> resolveArgument(MethodParameter param, WebServerExchange exchange) {
public Mono<Object> resolveArgument(MethodParameter param, ServerWebExchange exchange) {
RequestParam annotation = param.getParameterAnnotation(RequestParam.class);
String name = (annotation.value().length() != 0 ? annotation.value() : param.getParameterName());
UriComponents uriComponents = UriComponentsBuilder.fromUri(exchange.getRequest().getURI()).build();

View File

@ -45,7 +45,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.reactive.HandlerResultHandler;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
@ -130,7 +130,7 @@ public class ResponseBodyResultHandler implements HandlerResultHandler, Ordered
@Override
@SuppressWarnings("unchecked")
public Mono<Void> handleResult(WebServerExchange exchange, HandlerResult result) {
public Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
Object value = result.getResult();
if (value == null) {

View File

@ -29,7 +29,7 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
*
* @author Rossen Stoyanchev
*/
public interface WebServerExchange {
public interface ServerWebExchange {
/**
* Return the current HTTP request.
@ -47,7 +47,12 @@ public interface WebServerExchange {
Map<String, Object> getAttributes();
/**
*
* Return the web session for the current request. Always guaranteed to
* return an instance either matching to the session id requested by the
* client, or with a new session id either because the client did not
* specify one or because the underlying session had expired. Use of this
* method does not automatically create a session. See {@link WebSession}
* for more details.
*/
Mono<WebSession> getSession();

View File

@ -33,6 +33,6 @@ public interface WebExceptionHandler {
* @param ex the exception to handle
* @return {@code Mono<Void>} to indicate when exception handling is complete
*/
Mono<Void> handle(WebServerExchange exchange, Throwable ex);
Mono<Void> handle(ServerWebExchange exchange, Throwable ex);
}

View File

@ -35,6 +35,6 @@ public interface WebFilter {
* @param chain provides a way to delegate to the next filter
* @return {@code Mono<Void>} to indicate when request processing is complete
*/
Mono<Void> filter(WebServerExchange exchange, WebFilterChain chain);
Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain);
}

View File

@ -30,6 +30,6 @@ public interface WebFilterChain {
* @param exchange the current server exchange
* @return {@code Mono<Void>} to indicate when request handling is complete
*/
Mono<Void> filter(WebServerExchange exchange);
Mono<Void> filter(ServerWebExchange exchange);
}

View File

@ -18,19 +18,19 @@ package org.springframework.web.server;
import reactor.core.publisher.Mono;
import org.springframework.web.server.adapter.WebToHttpHandlerAdapter;
import org.springframework.web.server.adapter.WebToHttpHandlerBuilder;
import org.springframework.web.server.adapter.WebHttpHandlerAdapter;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
/**
* Contract to handle a web server exchange.
*
* <p>Use {@link WebToHttpHandlerAdapter} to adapt a {@code WebHandler} to an
* <p>Use {@link WebHttpHandlerAdapter} to adapt a {@code WebHandler} to an
* {@link org.springframework.http.server.reactive.HttpHandler HttpHandler}.
* The {@link WebToHttpHandlerBuilder} provides a convenient way to do that while
* The {@link WebHttpHandlerBuilder} provides a convenient way to do that while
* also optionally configuring one or more filters and/or exception handlers.
*
* @author Rossen Stoyanchev
* @see WebToHttpHandlerBuilder
* @see WebHttpHandlerBuilder
*/
public interface WebHandler {
@ -40,6 +40,6 @@ public interface WebHandler {
* @param exchange the current server exchange
* @return {@code Mono<Void>} to indicate when request handling is complete
*/
Mono<Void> handle(WebServerExchange exchange);
Mono<Void> handle(ServerWebExchange exchange);
}

View File

@ -25,16 +25,16 @@ import reactor.core.publisher.Processors;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.util.Assert;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebSession;
import org.springframework.web.server.session.WebSessionManager;
/**
* Default implementation of {@link WebServerExchange}.
* Default implementation of {@link ServerWebExchange}.
*
* @author Rossen Stoyanchev
*/
public class DefaultWebServerExchange implements WebServerExchange {
public class DefaultServerWebExchange implements ServerWebExchange {
private final ServerHttpRequest request;
@ -51,7 +51,7 @@ public class DefaultWebServerExchange implements WebServerExchange {
public DefaultWebServerExchange(ServerHttpRequest request, ServerHttpResponse response,
public DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response,
WebSessionManager sessionManager) {
Assert.notNull(request, "'request' is required.");

View File

@ -26,32 +26,37 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.util.Assert;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.handler.WebHandlerDecorator;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.session.DefaultWebSessionManager;
import org.springframework.web.server.session.WebSessionManager;
/**
* Adapt {@link WebHandler} to {@link HttpHandler} also creating the
* {@link WebServerExchange} before invoking the target {@code WebHandler}.
* Default adapter of {@link WebHandler} to the {@link HttpHandler} contract.
*
* <p>By default creates and configures a {@link DefaultServerWebExchange} and
* then invokes the target {@code WebHandler}.
*
* @author Rossen Stoyanchev
*/
public class WebToHttpHandlerAdapter extends WebHandlerDecorator implements HttpHandler {
public class WebHttpHandlerAdapter extends WebHandlerDecorator implements HttpHandler {
private static Log logger = LogFactory.getLog(WebToHttpHandlerAdapter.class);
private static Log logger = LogFactory.getLog(WebHttpHandlerAdapter.class);
private WebSessionManager sessionManager = new DefaultWebSessionManager();
public WebToHttpHandlerAdapter(WebHandler delegate) {
public WebHttpHandlerAdapter(WebHandler delegate) {
super(delegate);
}
/**
*
* @param sessionManager
* Configure a custom {@link WebSessionManager} to use for managing web
* sessions. The provided instance is set on each created
* {@link DefaultServerWebExchange}.
* <p>By default this is set to {@link DefaultWebSessionManager}.
* @param sessionManager the session manager to use
*/
public void setSessionManager(WebSessionManager sessionManager) {
Assert.notNull(sessionManager, "'sessionManager' must not be null.");
@ -68,7 +73,7 @@ public class WebToHttpHandlerAdapter extends WebHandlerDecorator implements Http
@Override
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
WebServerExchange exchange = createWebServerExchange(request, response);
ServerWebExchange exchange = createExchange(request, response);
return getDelegate().handle(exchange)
.otherwise(ex -> {
if (logger.isDebugEnabled()) {
@ -80,8 +85,8 @@ public class WebToHttpHandlerAdapter extends WebHandlerDecorator implements Http
.after(response::setComplete);
}
protected WebServerExchange createWebServerExchange(ServerHttpRequest request, ServerHttpResponse response) {
return new DefaultWebServerExchange(request, response, this.sessionManager);
protected ServerWebExchange createExchange(ServerHttpRequest request, ServerHttpResponse response) {
return new DefaultServerWebExchange(request, response, this.sessionManager);
}
}

View File

@ -0,0 +1,158 @@
/*
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.server.adapter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebExceptionHandler;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
import org.springframework.web.server.handler.FilteringWebHandler;
import org.springframework.web.server.session.WebSessionManager;
/**
* Build an {@link org.springframework.http.server.reactive.HttpHandler HttpHandler}
* to handle requests with a chain of {@link #filters(WebFilter...) web filters},
* a target {@link #webHandler(WebHandler) web handler}, and apply one or more
* {@link #exceptionHandlers(WebExceptionHandler...) exception handlers}.
*
* <p>Effective this sets up the following {@code WebHandler} delegation:<br>
* {@link WebHttpHandlerAdapter} {@code -->}
* {@link ExceptionHandlingWebHandler} {@code -->}
* {@link FilteringWebHandler} {@code -->}
* {@link WebHandler}
*
* <p>Example usage:
* <pre>
* WebFilter myFilter = ... ;
* WebHandler myHandler = ... ;
*
* HttpHandler httpHandler = WebToHttpHandlerBuilder.webHandler(myHandler)
* .filters(myFilter)
* .exceptionHandlers(new ResponseStatusExceptionHandler())
* .build();
*
* // Configure the HttpServer with the created httpHandler
* </pre>
*
* @author Rossen Stoyanchev
*/
public class WebHttpHandlerBuilder {
private final WebHandler targetHandler;
private final List<WebFilter> filters = new ArrayList<>();
private final List<WebExceptionHandler> exceptionHandlers = new ArrayList<>();
private WebSessionManager sessionManager;
/**
* Private constructor.
* See static factory method {@link #webHandler(WebHandler)}.
*/
private WebHttpHandlerBuilder(WebHandler targetHandler) {
Assert.notNull(targetHandler, "'targetHandler' must not be null");
this.targetHandler = targetHandler;
}
/**
* Factory method to create a new builder instance.
* @param targetHandler the target handler to process requests with
*/
public static WebHttpHandlerBuilder webHandler(WebHandler targetHandler) {
return new WebHttpHandlerBuilder(targetHandler);
}
/**
* Add the given filters to use for processing requests.
* @param filters the filters to add
*/
public WebHttpHandlerBuilder filters(WebFilter... filters) {
if (!ObjectUtils.isEmpty(filters)) {
this.filters.addAll(Arrays.asList(filters));
}
return this;
}
/**
* Add the given exception handler to apply at the end of request processing.
* @param exceptionHandlers the exception handlers
*/
public WebHttpHandlerBuilder exceptionHandlers(WebExceptionHandler... exceptionHandlers) {
if (!ObjectUtils.isEmpty(exceptionHandlers)) {
this.exceptionHandlers.addAll(Arrays.asList(exceptionHandlers));
}
return this;
}
/**
* Configure the {@link WebSessionManager} to set on the
* {@link ServerWebExchange WebServerExchange}
* created for each HTTP request.
* @param sessionManager the session manager
*/
public WebHttpHandlerBuilder sessionManager(WebSessionManager sessionManager) {
this.sessionManager = sessionManager;
return this;
}
/**
* Build the {@link HttpHandler}.
*/
public HttpHandler build() {
WebHandler handler = createWebHandler();
return adaptWebHandler(handler);
}
/**
* Create the final (decorated) {@link WebHandler} to use.
*/
protected WebHandler createWebHandler() {
WebHandler webHandler = this.targetHandler;
if (!this.exceptionHandlers.isEmpty()) {
WebExceptionHandler[] array = new WebExceptionHandler[this.exceptionHandlers.size()];
webHandler = new ExceptionHandlingWebHandler(webHandler, this.exceptionHandlers.toArray(array));
}
if (!this.filters.isEmpty()) {
WebFilter[] array = new WebFilter[this.filters.size()];
webHandler = new FilteringWebHandler(webHandler, this.filters.toArray(array));
}
return webHandler;
}
/**
* Adapt the {@link WebHandler} to {@link HttpHandler}.
*/
protected WebHttpHandlerAdapter adaptWebHandler(WebHandler handler) {
WebHttpHandlerAdapter adapter = new WebHttpHandlerAdapter(handler);
if (this.sessionManager != null) {
adapter.setSessionManager(this.sessionManager);
}
return adapter;
}
}

View File

@ -1,102 +0,0 @@
/*
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.server.adapter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.web.server.WebExceptionHandler;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
import org.springframework.web.server.handler.FilteringWebHandler;
import org.springframework.web.server.session.WebSessionManager;
/**
* Assist with building an
* {@link org.springframework.http.server.reactive.HttpHandler HttpHandler} to
* invoke a target {@link WebHandler} with an optional chain of
* {@link WebFilter}s and one or more {@link WebExceptionHandler}s.
*
* <p>Effective this sets up the following {@code WebHandler} delegation:<br>
* {@link WebToHttpHandlerAdapter} {@code -->}
* {@link ExceptionHandlingWebHandler} {@code -->}
* {@link FilteringWebHandler}
*
* @author Rossen Stoyanchev
*/
public class WebToHttpHandlerBuilder {
private final WebHandler targetHandler;
private final List<WebFilter> filters = new ArrayList<>();
private final List<WebExceptionHandler> exceptionHandlers = new ArrayList<>();
private WebSessionManager sessionManager;
private WebToHttpHandlerBuilder(WebHandler targetHandler) {
Assert.notNull(targetHandler, "'targetHandler' must not be null");
this.targetHandler = targetHandler;
}
public static WebToHttpHandlerBuilder webHandler(WebHandler webHandler) {
return new WebToHttpHandlerBuilder(webHandler);
}
public WebToHttpHandlerBuilder filters(WebFilter... filters) {
if (!ObjectUtils.isEmpty(filters)) {
this.filters.addAll(Arrays.asList(filters));
}
return this;
}
public WebToHttpHandlerBuilder exceptionHandlers(WebExceptionHandler... exceptionHandlers) {
if (!ObjectUtils.isEmpty(exceptionHandlers)) {
this.exceptionHandlers.addAll(Arrays.asList(exceptionHandlers));
}
return this;
}
public WebToHttpHandlerBuilder sessionManager(WebSessionManager sessionManager) {
this.sessionManager = sessionManager;
return this;
}
public HttpHandler build() {
WebHandler handler = this.targetHandler;
if (!this.exceptionHandlers.isEmpty()) {
WebExceptionHandler[] array = new WebExceptionHandler[this.exceptionHandlers.size()];
handler = new ExceptionHandlingWebHandler(handler, this.exceptionHandlers.toArray(array));
}
if (!this.filters.isEmpty()) {
WebFilter[] array = new WebFilter[this.filters.size()];
handler = new FilteringWebHandler(handler, this.filters.toArray(array));
}
WebToHttpHandlerAdapter adapter = new WebToHttpHandlerAdapter(handler);
if (this.sessionManager != null) {
adapter.setSessionManager(this.sessionManager);
}
return adapter;
}
}

View File

@ -26,11 +26,11 @@ import reactor.core.publisher.Mono;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.WebExceptionHandler;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
* {@code WebHandler} that decorates another with exception handling using one
* or more instances of {@link WebExceptionHandler}.
* WebHandler that can invoke a target {@link WebHandler} and then apply
* exception handling with one or more {@link WebExceptionHandler} instances.
*
* @author Rossen Stoyanchev
*/
@ -53,7 +53,7 @@ public class ExceptionHandlingWebHandler extends WebHandlerDecorator {
/**
* @return a read-only list of the configured exception handlers.
* Return a read-only list of the configured exception handlers.
*/
public List<WebExceptionHandler> getExceptionHandlers() {
return this.exceptionHandlers;
@ -61,7 +61,7 @@ public class ExceptionHandlingWebHandler extends WebHandlerDecorator {
@Override
public Mono<Void> handle(WebServerExchange exchange) {
public Mono<Void> handle(ServerWebExchange exchange) {
Mono<Void> mono;
try {
mono = getDelegate().handle(exchange);
@ -75,7 +75,7 @@ public class ExceptionHandlingWebHandler extends WebHandlerDecorator {
return mono.otherwise(ex -> handleUnresolvedException(exchange, ex));
}
private Mono<? extends Void> handleUnresolvedException(WebServerExchange exchange, Throwable ex) {
private Mono<? extends Void> handleUnresolvedException(ServerWebExchange exchange, Throwable ex) {
if (logger.isDebugEnabled()) {
logger.debug("Could not complete request", ex);
}

View File

@ -24,10 +24,11 @@ import reactor.core.publisher.Mono;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
* {@code WebHandler} that decorates another with a chain of {@link WebFilter}s.
* WebHandler that delegates to a chain of {@link WebFilter} instances followed
* by a target {@link WebHandler}.
*
* @author Rossen Stoyanchev
*/
@ -47,14 +48,14 @@ public class FilteringWebHandler extends WebHandlerDecorator {
/**
* @return a read-only list of the configured filters.
* Return a read-only list of the configured filters.
*/
public List<WebFilter> getFilters() {
return this.filters;
}
@Override
public Mono<Void> handle(WebServerExchange exchange) {
public Mono<Void> handle(ServerWebExchange exchange) {
return new DefaultWebFilterChain().filter(exchange);
}
@ -65,7 +66,7 @@ public class FilteringWebHandler extends WebHandlerDecorator {
@Override
public Mono<Void> filter(WebServerExchange exchange) {
public Mono<Void> filter(ServerWebExchange exchange) {
if (this.index < filters.size()) {
WebFilter filter = filters.get(this.index++);
return filter.filter(exchange, this);

View File

@ -19,10 +19,10 @@ import reactor.core.publisher.Mono;
import org.springframework.util.Assert;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
* Base class for a {@link WebHandler} that decorates and delegates to another.
* {@link WebHandler} that decorates and delegates to another.
*
* @author Rossen Stoyanchev
*/
@ -43,7 +43,7 @@ public class WebHandlerDecorator implements WebHandler {
@Override
public Mono<Void> handle(WebServerExchange exchange) {
public Mono<Void> handle(ServerWebExchange exchange) {
return this.delegate.handle(exchange);
}

View File

@ -25,7 +25,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
/**
* Cookie-based {@link WebSessionIdResolver}.
@ -75,7 +75,7 @@ public class CookieWebSessionIdResolver implements WebSessionIdResolver {
@Override
public Optional<String> resolveSessionId(WebServerExchange exchange) {
public Optional<String> resolveSessionId(ServerWebExchange exchange) {
HttpHeaders headers = exchange.getRequest().getHeaders();
List<HttpCookie> cookies = headers.getCookies().get(getCookieName());
return (CollectionUtils.isEmpty(cookies) ?
@ -83,7 +83,7 @@ public class CookieWebSessionIdResolver implements WebSessionIdResolver {
}
@Override
public void setSessionId(WebServerExchange exchange, String id) {
public void setSessionId(ServerWebExchange exchange, String id) {
Duration maxAge = (StringUtils.hasText(id) ? getCookieMaxAge() : Duration.ofSeconds(0));
HttpCookie cookie = HttpCookie.serverCookie(getCookieName(), id).maxAge(maxAge).build();
HttpHeaders headers = exchange.getResponse().getHeaders();

View File

@ -23,7 +23,7 @@ import java.util.UUID;
import reactor.core.publisher.Mono;
import org.springframework.util.Assert;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebSession;
@ -97,7 +97,7 @@ public class DefaultWebSessionManager implements WebSessionManager {
@Override
public Mono<WebSession> getSession(WebServerExchange exchange) {
public Mono<WebSession> getSession(ServerWebExchange exchange) {
return Mono.fromCallable(() -> getSessionIdResolver().resolveSessionId(exchange))
.where(Optional::isPresent)
.map(Optional::get)
@ -107,7 +107,7 @@ public class DefaultWebSessionManager implements WebSessionManager {
.map(session -> extendSession(exchange, session));
}
protected Mono<WebSession> validateSession(WebServerExchange exchange, WebSession session) {
protected Mono<WebSession> validateSession(ServerWebExchange exchange, WebSession session) {
if (session.isExpired()) {
this.sessionIdResolver.setSessionId(exchange, "");
return this.sessionStore.removeSession(session.getId()).after(Mono::empty);
@ -117,13 +117,13 @@ public class DefaultWebSessionManager implements WebSessionManager {
}
}
protected Mono<WebSession> createSession(WebServerExchange exchange) {
protected Mono<WebSession> createSession(ServerWebExchange exchange) {
String sessionId = UUID.randomUUID().toString();
WebSession session = new DefaultWebSession(sessionId, getClock());
return Mono.just(session);
}
protected WebSession extendSession(WebServerExchange exchange, WebSession session) {
protected WebSession extendSession(ServerWebExchange exchange, WebSession session) {
if (session instanceof ConfigurableWebSession) {
ConfigurableWebSession managed = (ConfigurableWebSession) session;
managed.setSaveOperation(() -> saveSession(exchange, session));
@ -133,7 +133,7 @@ public class DefaultWebSessionManager implements WebSessionManager {
return session;
}
protected Mono<Void> saveSession(WebServerExchange exchange, WebSession session) {
protected Mono<Void> saveSession(ServerWebExchange exchange, WebSession session) {
Assert.isTrue(!session.isExpired(), "Sessions are checked for expiration and have their " +
"access time updated when first accessed during request processing. " +

View File

@ -17,8 +17,7 @@ package org.springframework.web.server.session;
import java.util.Optional;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.WebSession;
import org.springframework.web.server.ServerWebExchange;
/**
@ -36,7 +35,7 @@ public interface WebSessionIdResolver {
* @param exchange the current exchange
* @return the session id if present
*/
Optional<String> resolveSessionId(WebServerExchange exchange);
Optional<String> resolveSessionId(ServerWebExchange exchange);
/**
* Send the given session id to the client or if the session id is "null"
@ -44,6 +43,6 @@ public interface WebSessionIdResolver {
* @param exchange the current exchange
* @param sessionId the session id
*/
void setSessionId(WebServerExchange exchange, String sessionId);
void setSessionId(ServerWebExchange exchange, String sessionId);
}

View File

@ -17,7 +17,7 @@ package org.springframework.web.server.session;
import reactor.core.publisher.Mono;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebSession;
/**
@ -43,6 +43,6 @@ public interface WebSessionManager {
* @param exchange the current exchange
* @return {@code Mono} for async access to the session
*/
Mono<WebSession> getSession(WebServerExchange exchange);
Mono<WebSession> getSession(ServerWebExchange exchange);
}

View File

@ -49,14 +49,14 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.reactive.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.reactive.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.reactive.method.annotation.ResponseBodyResultHandler;
import org.springframework.web.server.adapter.DefaultWebServerExchange;
import org.springframework.web.server.adapter.DefaultServerWebExchange;
import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
import org.springframework.web.server.handler.FilteringWebHandler;
import org.springframework.web.server.WebExceptionHandler;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.session.WebSessionManager;
import static org.hamcrest.CoreMatchers.startsWith;
@ -81,7 +81,7 @@ public class DispatcherHandlerErrorTests {
private MockServerHttpResponse response;
private WebServerExchange exchange;
private ServerWebExchange exchange;
@Before
@ -97,7 +97,7 @@ public class DispatcherHandlerErrorTests {
this.request = new MockServerHttpRequest(HttpMethod.GET, new URI("/"));
this.response = new MockServerHttpResponse();
this.exchange = new DefaultWebServerExchange(this.request, this.response, sessionManager);
this.exchange = new DefaultServerWebExchange(this.request, this.response, sessionManager);
}
@ -280,7 +280,7 @@ public class DispatcherHandlerErrorTests {
private static class ServerError500ExceptionHandler implements WebExceptionHandler {
@Override
public Mono<Void> handle(WebServerExchange exchange, Throwable ex) {
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
return Mono.empty();
}
@ -289,7 +289,7 @@ public class DispatcherHandlerErrorTests {
private static class TestWebFilter implements WebFilter {
@Override
public Mono<Void> filter(WebServerExchange exchange, WebFilterChain chain) {
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
return chain.filter(exchange);
}
}

View File

@ -29,8 +29,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.MockServerHttpRequest;
import org.springframework.http.server.reactive.MockServerHttpResponse;
import org.springframework.web.ResponseStatusException;
import org.springframework.web.server.adapter.DefaultWebServerExchange;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.adapter.DefaultServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.session.WebSessionManager;
import static org.junit.Assert.assertEquals;
@ -47,7 +47,7 @@ public class ResponseStatusExceptionHandlerTests {
private MockServerHttpResponse response;
private WebServerExchange exchange;
private ServerWebExchange exchange;
@Before
@ -56,7 +56,7 @@ public class ResponseStatusExceptionHandlerTests {
MockServerHttpRequest request = new MockServerHttpRequest(HttpMethod.GET, new URI("/path"));
WebSessionManager sessionManager = mock(WebSessionManager.class);
this.response = new MockServerHttpResponse();
this.exchange = new DefaultWebServerExchange(request, this.response, sessionManager);
this.exchange = new DefaultServerWebExchange(request, this.response, sessionManager);
}

View File

@ -39,8 +39,8 @@ import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.DispatcherHandler;
import org.springframework.web.reactive.ResponseStatusExceptionHandler;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.adapter.WebToHttpHandlerBuilder;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@ -66,7 +66,7 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
DispatcherHandler webHandler = new DispatcherHandler();
webHandler.setApplicationContext(wac);
return WebToHttpHandlerBuilder.webHandler(webHandler)
return WebHttpHandlerBuilder.webHandler(webHandler)
.exceptionHandlers(new ResponseStatusExceptionHandler())
.build();
}
@ -140,7 +140,7 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
private static class FooHandler implements WebHandler {
@Override
public Mono<Void> handle(WebServerExchange exchange) {
public Mono<Void> handle(ServerWebExchange exchange) {
DataBuffer buffer = new DefaultDataBufferAllocator().allocateBuffer()
.write("foo".getBytes(StandardCharsets.UTF_8));
return exchange.getResponse().setBody(Flux.just(buffer));
@ -150,7 +150,7 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
private static class BarHandler implements WebHandler {
@Override
public Mono<Void> handle(WebServerExchange exchange) {
public Mono<Void> handle(ServerWebExchange exchange) {
DataBuffer buffer = new DefaultDataBufferAllocator().allocateBuffer()
.write("bar".getBytes(StandardCharsets.UTF_8));
return exchange.getResponse().setBody(Flux.just(buffer));
@ -160,7 +160,7 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
private static class HeaderSettingHandler implements WebHandler {
@Override
public Mono<Void> handle(WebServerExchange exchange) {
public Mono<Void> handle(ServerWebExchange exchange) {
exchange.getResponse().getHeaders().add("foo", "bar");
return Mono.empty();
}

View File

@ -35,8 +35,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.reactive.method.annotation.RequestParamArgumentResolver;
import org.springframework.web.server.adapter.DefaultWebServerExchange;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.adapter.DefaultServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.session.WebSessionManager;
import static org.junit.Assert.assertEquals;
@ -52,14 +52,14 @@ public class InvocableHandlerMethodTests {
private ServerHttpRequest request;
private WebServerExchange exchange;
private ServerWebExchange exchange;
@Before
public void setUp() throws Exception {
WebSessionManager sessionManager = mock(WebSessionManager.class);
this.request = mock(ServerHttpRequest.class);
this.exchange = new DefaultWebServerExchange(request, mock(ServerHttpResponse.class), sessionManager);
this.exchange = new DefaultServerWebExchange(request, mock(ServerHttpResponse.class), sessionManager);
}

View File

@ -34,8 +34,8 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.server.adapter.DefaultWebServerExchange;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.adapter.DefaultServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.session.WebSessionManager;
import static java.util.stream.Collectors.toList;
@ -66,7 +66,7 @@ public class RequestMappingHandlerMappingTests {
ServerHttpRequest request = new MockServerHttpRequest(HttpMethod.GET, new URI("boo"));
MockServerHttpResponse response = new MockServerHttpResponse();
WebSessionManager sessionManager = mock(WebSessionManager.class);
WebServerExchange exchange = new DefaultWebServerExchange(request, response, sessionManager);
ServerWebExchange exchange = new DefaultServerWebExchange(request, response, sessionManager);
Publisher<?> handlerPublisher = this.mapping.getHandler(exchange);
HandlerMethod handlerMethod = toHandlerMethod(handlerPublisher);
assertEquals(TestController.class.getMethod("boo"), handlerMethod.getMethod());
@ -77,13 +77,13 @@ public class RequestMappingHandlerMappingTests {
ServerHttpRequest request = new MockServerHttpRequest(HttpMethod.POST, new URI("foo"));
MockServerHttpResponse response = new MockServerHttpResponse();
WebSessionManager sessionManager = mock(WebSessionManager.class);
WebServerExchange exchange = new DefaultWebServerExchange(request, response, sessionManager);
ServerWebExchange exchange = new DefaultServerWebExchange(request, response, sessionManager);
Publisher<?> handlerPublisher = this.mapping.getHandler(exchange);
HandlerMethod handlerMethod = toHandlerMethod(handlerPublisher);
assertEquals(TestController.class.getMethod("postFoo"), handlerMethod.getMethod());
request = new MockServerHttpRequest(HttpMethod.GET, new URI("foo"));
exchange = new DefaultWebServerExchange(request, new MockServerHttpResponse(), sessionManager);
exchange = new DefaultServerWebExchange(request, new MockServerHttpResponse(), sessionManager);
handlerPublisher = this.mapping.getHandler(exchange);
handlerMethod = toHandlerMethod(handlerPublisher);
assertEquals(TestController.class.getMethod("getFoo"), handlerMethod.getMethod());

View File

@ -64,7 +64,7 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.DispatcherHandler;
import org.springframework.web.reactive.handler.SimpleHandlerResultHandler;
import org.springframework.web.server.adapter.WebToHttpHandlerBuilder;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@ -88,7 +88,7 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
DispatcherHandler webHandler = new DispatcherHandler();
webHandler.setApplicationContext(this.wac);
return WebToHttpHandlerBuilder.webHandler(webHandler).build();
return WebHttpHandlerBuilder.webHandler(webHandler).build();
}
@Test

View File

@ -28,9 +28,8 @@ import org.springframework.http.server.reactive.MockServerHttpRequest;
import org.springframework.http.server.reactive.MockServerHttpResponse;
import org.springframework.web.server.WebExceptionHandler;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
import org.springframework.web.server.adapter.DefaultWebServerExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.adapter.DefaultServerWebExchange;
import org.springframework.web.server.session.WebSessionManager;
import static org.junit.Assert.assertEquals;
@ -44,7 +43,7 @@ public class ExceptionHandlingHttpHandlerTests {
private MockServerHttpResponse response;
private WebServerExchange exchange;
private ServerWebExchange exchange;
private WebHandler targetHandler;
@ -55,7 +54,7 @@ public class ExceptionHandlingHttpHandlerTests {
WebSessionManager sessionManager = mock(WebSessionManager.class);
MockServerHttpRequest request = new MockServerHttpRequest(HttpMethod.GET, uri);
this.response = new MockServerHttpResponse();
this.exchange = new DefaultWebServerExchange(request, this.response, sessionManager);
this.exchange = new DefaultServerWebExchange(request, this.response, sessionManager);
this.targetHandler = new StubWebHandler(new IllegalStateException("boo"));
}
@ -119,7 +118,7 @@ public class ExceptionHandlingHttpHandlerTests {
}
@Override
public Mono<Void> handle(WebServerExchange exchange) {
public Mono<Void> handle(ServerWebExchange exchange) {
if (this.raise) {
throw this.exception;
}
@ -130,7 +129,7 @@ public class ExceptionHandlingHttpHandlerTests {
private static class BadRequestExceptionHandler implements WebExceptionHandler {
@Override
public Mono<Void> handle(WebServerExchange exchange, Throwable ex) {
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
exchange.getResponse().setStatusCode(HttpStatus.BAD_REQUEST);
return Mono.empty();
}
@ -140,7 +139,7 @@ public class ExceptionHandlingHttpHandlerTests {
private static class UnresolvedExceptionHandler implements WebExceptionHandler {
@Override
public Mono<Void> handle(WebServerExchange exchange, Throwable ex) {
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
return Mono.error(ex);
}
}

View File

@ -33,8 +33,8 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.adapter.WebToHttpHandlerBuilder;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -109,7 +109,7 @@ public class FilteringWebHandlerTests {
}
private HttpHandler createHttpHandler(StubWebHandler webHandler, WebFilter... filters) {
return WebToHttpHandlerBuilder.webHandler(webHandler).filters(filters).build();
return WebHttpHandlerBuilder.webHandler(webHandler).filters(filters).build();
}
@ -123,12 +123,12 @@ public class FilteringWebHandlerTests {
}
@Override
public Mono<Void> filter(WebServerExchange exchange, WebFilterChain chain) {
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
this.invoked = true;
return doFilter(exchange, chain);
}
public Mono<Void> doFilter(WebServerExchange exchange, WebFilterChain chain) {
public Mono<Void> doFilter(ServerWebExchange exchange, WebFilterChain chain) {
return chain.filter(exchange);
}
}
@ -136,7 +136,7 @@ public class FilteringWebHandlerTests {
private static class ShortcircuitingFilter extends TestFilter {
@Override
public Mono<Void> doFilter(WebServerExchange exchange, WebFilterChain chain) {
public Mono<Void> doFilter(ServerWebExchange exchange, WebFilterChain chain) {
return Mono.empty();
}
}
@ -144,7 +144,7 @@ public class FilteringWebHandlerTests {
private static class AsyncFilter extends TestFilter {
@Override
public Mono<Void> doFilter(WebServerExchange exchange, WebFilterChain chain) {
public Mono<Void> doFilter(ServerWebExchange exchange, WebFilterChain chain) {
return doAsyncWork().then(asyncResult -> {
logger.debug("Async result: " + asyncResult);
return chain.filter(exchange);
@ -166,7 +166,7 @@ public class FilteringWebHandlerTests {
}
@Override
public Mono<Void> handle(WebServerExchange exchange) {
public Mono<Void> handle(ServerWebExchange exchange) {
logger.trace("StubHandler invoked.");
this.invoked = true;
return Mono.empty();

View File

@ -27,8 +27,8 @@ import org.junit.Test;
import org.springframework.http.HttpMethod;
import org.springframework.http.server.reactive.MockServerHttpRequest;
import org.springframework.http.server.reactive.MockServerHttpResponse;
import org.springframework.web.server.adapter.DefaultWebServerExchange;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.adapter.DefaultServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebSession;
import static org.junit.Assert.assertEquals;
@ -47,7 +47,7 @@ public class DefaultWebSessionManagerTests {
private TestWebSessionIdResolver idResolver;
private DefaultWebServerExchange exchange;
private DefaultServerWebExchange exchange;
@Before
@ -58,7 +58,7 @@ public class DefaultWebSessionManagerTests {
MockServerHttpRequest request = new MockServerHttpRequest(HttpMethod.GET, new URI("/path"));
MockServerHttpResponse response = new MockServerHttpResponse();
this.exchange = new DefaultWebServerExchange(request, response, this.manager);
this.exchange = new DefaultServerWebExchange(request, response, this.manager);
}
@ -140,12 +140,12 @@ public class DefaultWebSessionManagerTests {
}
@Override
public Optional<String> resolveSessionId(WebServerExchange exchange) {
public Optional<String> resolveSessionId(ServerWebExchange exchange) {
return this.idToResolve;
}
@Override
public void setSessionId(WebServerExchange exchange, String sessionId) {
public void setSessionId(ServerWebExchange exchange, String sessionId) {
this.id = sessionId;
}
}

View File

@ -36,8 +36,8 @@ import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.server.WebHandler;
import org.springframework.web.server.WebServerExchange;
import org.springframework.web.server.adapter.WebToHttpHandlerBuilder;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -72,7 +72,7 @@ public class WebSessionIntegrationTests extends AbstractHttpHandlerIntegrationTe
protected HttpHandler createHttpHandler() {
this.sessionManager = new DefaultWebSessionManager();
this.handler = new TestWebHandler();
return WebToHttpHandlerBuilder.webHandler(this.handler).sessionManager(this.sessionManager).build();
return WebHttpHandlerBuilder.webHandler(this.handler).sessionManager(this.sessionManager).build();
}
@Test
@ -152,7 +152,7 @@ public class WebSessionIntegrationTests extends AbstractHttpHandlerIntegrationTe
}
@Override
public Mono<Void> handle(WebServerExchange exchange) {
public Mono<Void> handle(ServerWebExchange exchange) {
return exchange.getSession().map(session -> {
Map<String, Object> map = session.getAttributes();
int value = (map.get("counter") != null ? (int) map.get("counter") : 0);