diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/AsyncWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/async/AsyncWebRequest.java index 1e89d1a2fc..9cf4fda6f0 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/AsyncWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/AsyncWebRequest.java @@ -46,6 +46,7 @@ public interface AsyncWebRequest extends NativeWebRequest { /** * Add a handler to invoke when an error occurred while concurrent * handling of a request. + * @since 5.0 */ void addErrorHandler(Consumer exceptionHandler); diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/CallableProcessingInterceptor.java b/spring-web/src/main/java/org/springframework/web/context/request/async/CallableProcessingInterceptor.java index 8b6fba962d..4a43b4526c 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/CallableProcessingInterceptor.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/CallableProcessingInterceptor.java @@ -102,17 +102,18 @@ public interface CallableProcessingInterceptor { Object handleTimeout(NativeWebRequest request, Callable task) throws Exception; /** - * Invoked from a container thread when an error occurred while processing the async request - * before the {@code Callable} task completes. Implementations may return a value, - * including an {@link Exception}, to use instead of the value the - * {@link Callable} did not return in time. + * Invoked from a container thread when an error occurred while processing + * the async request before the {@code Callable} task completes. + * Implementations may return a value, including an {@link Exception}, to + * use instead of the value the {@link Callable} did not return in time. * @param request the current request * @param task the task for the current async request - * @paramt t the error that occurred while request processing + * @param t the error that occurred while request processing * @return a concurrent result value; if the value is anything other than * {@link #RESULT_NONE} or {@link #RESPONSE_HANDLED}, concurrent processing * is resumed and subsequent interceptors are not invoked * @throws Exception in case of errors + * @since 5.0 */ Object handleError(NativeWebRequest request, Callable task, Throwable t) throws Exception; diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java index 8667871d34..0d5b76086d 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java @@ -154,11 +154,13 @@ public class DeferredResult { } /** - * Register code to invoke when an error occurred while processing the async request. - *

This method is called from a container thread when an error occurred while - * processing an async request before the {@code DeferredResult} has been populated. - * It may invoke {@link DeferredResult#setResult setResult} or - * {@link DeferredResult#setErrorResult setErrorResult} to resume processing. + * Register code to invoke when an error occurred during the async request. + *

This method is called from a container thread when an error occurs + * while processing an async request before the {@code DeferredResult} has + * been populated. It may invoke {@link DeferredResult#setResult setResult} + * or {@link DeferredResult#setErrorResult setErrorResult} to resume + * processing. + * @since 5.0 */ public void onError(Consumer callback) { this.errorCallback = callback; diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/ErrorCallableProcessingInterceptor.java b/spring-web/src/main/java/org/springframework/web/context/request/async/ErrorCallableProcessingInterceptor.java index 2f7b7f80ca..a8cffce575 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/ErrorCallableProcessingInterceptor.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/ErrorCallableProcessingInterceptor.java @@ -27,7 +27,7 @@ import org.springframework.web.context.request.NativeWebRequest; * @author Violeta Georgieva * @since 5.0 */ -public class ErrorCallableProcessingInterceptor extends CallableProcessingInterceptorAdapter { +class ErrorCallableProcessingInterceptor extends CallableProcessingInterceptorAdapter { @Override public Object handleError(NativeWebRequest request, Callable task, Throwable t) throws Exception { diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java index dadb0fea31..31d2311121 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java @@ -143,23 +143,17 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements @Override public void onError(AsyncEvent event) throws IOException { - for (Consumer handler : this.exceptionHandlers) { - handler.accept(event.getThrowable()); - } + this.exceptionHandlers.forEach(consumer -> consumer.accept(event.getThrowable())); } @Override public void onTimeout(AsyncEvent event) throws IOException { - for (Runnable handler : this.timeoutHandlers) { - handler.run(); - } + this.timeoutHandlers.forEach(Runnable::run); } @Override public void onComplete(AsyncEvent event) throws IOException { - for (Runnable handler : this.completionHandlers) { - handler.run(); - } + this.completionHandlers.forEach(Runnable::run); this.asyncContext = null; this.asyncCompleted.set(true); } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncTask.java b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncTask.java index 9ef0b89b1e..9e91060a59 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncTask.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncTask.java @@ -153,12 +153,14 @@ public class WebAsyncTask implements BeanFactoryAware { } /** - * Register code to invoke when an error occurred while processing the async request. - *

This method is called from a container thread when an error occurred while processing - * an async request before the {@code Callable} has completed. The callback is executed in - * the same thread and therefore should return without blocking. It may return - * an alternative value to use, including an {@link Exception} or return + * Register code to invoke for an error during async request processing. + *

This method is called from a container thread when an error occurred + * while processing an async request before the {@code Callable} has + * completed. The callback is executed in the same thread and therefore + * should return without blocking. It may return an alternative value to + * use, including an {@link Exception} or return * {@link CallableProcessingInterceptor#RESULT_NONE RESULT_NONE}. + * @since 5.0 */ public void onError(Callable callback) { this.errorCallback = callback; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java index 6a8cc2dbaa..e59a8b07e0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java @@ -217,9 +217,10 @@ public class ResponseBodyEmitter { } /** - * Register code to invoke when an error occurred while processing the async request. - * This method is called from a container thread when an error occurred while processing - * an async request. + * Register code to invoke for an error during async request processing. + * This method is called from a container thread when an error occurred + * while processing an async request. + * @since 5.0 */ public synchronized void onError(Consumer callback) { this.errorCallback.setDelegate(callback);