ResponseStatusExceptionHandler in web.server.handler (plus related polishing)
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import org.springframework.core.NestedRuntimeException;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -29,7 +30,6 @@ public interface WebExceptionHandler {
|
||||
* Handle the given exception. A completion signal through the return value
|
||||
* indicates error handling is complete while an error signal indicates the
|
||||
* exception is still not handled.
|
||||
*
|
||||
* @param exchange the current exchange
|
||||
* @param ex the exception to handle
|
||||
* @return {@code Mono<Void>} to indicate when exception handling is complete
|
||||
|
||||
@@ -31,7 +31,6 @@ public interface WebFilter {
|
||||
/**
|
||||
* Process the Web request and (optionally) delegate to the next
|
||||
* {@code WebFilter} through the given {@link WebFilterChain}.
|
||||
*
|
||||
* @param exchange the current server exchange
|
||||
* @param chain provides a way to delegate to the next filter
|
||||
* @return {@code Mono<Void>} to indicate when request processing is complete
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -27,7 +28,6 @@ public interface WebFilterChain {
|
||||
|
||||
/**
|
||||
* Delegate to the next {@code WebFilter} in the chain.
|
||||
*
|
||||
* @param exchange the current server exchange
|
||||
* @return {@code Mono<Void>} to indicate when request handling is complete
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -36,7 +36,6 @@ public interface WebHandler {
|
||||
|
||||
/**
|
||||
* Handle the web server exchange.
|
||||
*
|
||||
* @param exchange the current server exchange
|
||||
* @return {@code Mono<Void>} to indicate when request handling is complete
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server.adapter;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -48,9 +49,9 @@ public class DefaultServerWebExchange implements ServerWebExchange {
|
||||
public DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response,
|
||||
WebSessionManager sessionManager) {
|
||||
|
||||
Assert.notNull(request, "'request' is required.");
|
||||
Assert.notNull(response, "'response' is required.");
|
||||
Assert.notNull(response, "'sessionManager' is required.");
|
||||
Assert.notNull(request, "'request' is required");
|
||||
Assert.notNull(response, "'response' is required");
|
||||
Assert.notNull(response, "'sessionManager' is required");
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
this.sessionMono = sessionManager.getSession(this).cache();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server.adapter;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -24,9 +25,9 @@ import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.handler.WebHandlerDecorator;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.session.DefaultWebSessionManager;
|
||||
import org.springframework.web.server.session.WebSessionManager;
|
||||
|
||||
@@ -43,7 +44,6 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
|
||||
|
||||
private static Log logger = LogFactory.getLog(HttpWebHandlerAdapter.class);
|
||||
|
||||
|
||||
private WebSessionManager sessionManager = new DefaultWebSessionManager();
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
|
||||
* @param sessionManager the session manager to use
|
||||
*/
|
||||
public void setSessionManager(WebSessionManager sessionManager) {
|
||||
Assert.notNull(sessionManager, "'sessionManager' must not be null.");
|
||||
Assert.notNull(sessionManager, "WebSessionManager must not be null");
|
||||
this.sessionManager = sessionManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public class WebHttpHandlerBuilder {
|
||||
* See factory method {@link #webHandler(WebHandler)}.
|
||||
*/
|
||||
private WebHttpHandlerBuilder(WebHandler targetHandler) {
|
||||
Assert.notNull(targetHandler, "'targetHandler' must not be null");
|
||||
Assert.notNull(targetHandler, "WebHandler must not be null");
|
||||
this.targetHandler = targetHandler;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server.handler;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -24,9 +25,9 @@ import org.apache.commons.logging.LogFactory;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebExceptionHandler;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
/**
|
||||
* WebHandler that can invoke a target {@link WebHandler} and then apply
|
||||
@@ -39,7 +40,6 @@ public class ExceptionHandlingWebHandler extends WebHandlerDecorator {
|
||||
|
||||
private static Log logger = LogFactory.getLog(ExceptionHandlingWebHandler.class);
|
||||
|
||||
|
||||
private final List<WebExceptionHandler> exceptionHandlers;
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server.handler;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -21,10 +22,10 @@ import java.util.List;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebFilter;
|
||||
import org.springframework.web.server.WebFilterChain;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
/**
|
||||
* WebHandler that delegates to a chain of {@link WebFilter} instances and then
|
||||
@@ -44,7 +45,7 @@ public class FilteringWebHandler extends WebHandlerDecorator {
|
||||
}
|
||||
|
||||
private static List<WebFilter> initList(WebFilter[] list) {
|
||||
return (list != null ? Collections.unmodifiableList(Arrays.asList(list)): Collections.emptyList());
|
||||
return (list != null ? Collections.unmodifiableList(Arrays.asList(list)) : Collections.emptyList());
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +66,6 @@ public class FilteringWebHandler extends WebHandlerDecorator {
|
||||
|
||||
private int index;
|
||||
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange) {
|
||||
if (this.index < filters.size()) {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2002-2016 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.handler;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebExceptionHandler;
|
||||
|
||||
/**
|
||||
* Handle {@link ResponseStatusException} by setting the response status.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
*/
|
||||
public class ResponseStatusExceptionHandler implements WebExceptionHandler {
|
||||
|
||||
@Override
|
||||
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
|
||||
if (ex instanceof ResponseStatusException) {
|
||||
exchange.getResponse().setStatusCode(((ResponseStatusException) ex).getStatus());
|
||||
return Mono.empty();
|
||||
}
|
||||
return Mono.error(ex);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -13,13 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server.handler;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
|
||||
/**
|
||||
* {@link WebHandler} that decorates and delegates to another.
|
||||
|
||||
Reference in New Issue
Block a user