21
21
import org .springframework .web .server .ServerWebExchange ;
22
22
23
23
/**
24
- * Contract that decouples the {@link DispatcherHandler} from the details of
25
- * invoking a handler and makes it possible to support any handler type.
24
+ * Contract to abstract the details of invoking a handler of a given type.
26
25
*
27
- * <p>A {@code HandlerAdapter} can implement {@link DispatchExceptionHandler}
28
- * if it wants to handle an exception that occurred before the request is mapped
29
- * to a handler. This allows the {@code HandlerAdapter} to expose a consistent
30
- * exception handling mechanism for any request handling error.
31
- * In Reactive Streams terms, {@link #handle} processes the onNext, while
32
- * {@link DispatchExceptionHandler#handleError} processes the onError signal
33
- * from the upstream.
26
+ * <p>An implementation can also choose to be an instance of
27
+ * {@link DispatchExceptionHandler} if it wants to handle exceptions that occur
28
+ * before the request is successfully mapped to a handler. This allows a
29
+ * {@code HandlerAdapter} to expose the same exception handling both for handler
30
+ * invocation errors and for errors before a handler is selected.
31
+ * In Reactive Streams terms, {@link #handle} handles the onNext signal, while
32
+ * {@link DispatchExceptionHandler#handleError} handles the onError signal
33
+ * from the dispatch processing chain.
34
34
*
35
35
* @author Rossen Stoyanchev
36
36
* @author Sebastien Deleuze
@@ -46,20 +46,27 @@ public interface HandlerAdapter {
46
46
boolean supports (Object handler );
47
47
48
48
/**
49
- * Handle the request with the given handler.
50
- * <p>Implementations are encouraged to handle exceptions resulting from the
51
- * invocation of a handler in order and if necessary to return an alternate
52
- * result that represents an error response.
53
- * <p>Furthermore since an async {@code HandlerResult} may produce an error
54
- * later during result handling implementations are also encouraged to
55
- * {@link HandlerResult#setExceptionHandler(DispatchExceptionHandler) set
56
- * an exception handler} on the {@code HandlerResult} so that may also be
57
- * applied later after result handling.
49
+ * Handle the request with the given handler, previously checked via
50
+ * {@link #supports(Object)}.
51
+ * <p>Implementations should consider the following for exception handling:
52
+ * <ul>
53
+ * <li>Handle invocation exceptions within this method.
54
+ * <li>{@link HandlerResult#setExceptionHandler(DispatchExceptionHandler)
55
+ * Set an exception handler} on the returned {@code HandlerResult} to handle
56
+ * deferred exceptions from asynchronous return values, and to handle
57
+ * exceptions from response rendering.
58
+ * <li>Implement {@link DispatchExceptionHandler} to extend exception
59
+ * handling to exceptions that occur before a handler is selected.
60
+ * </ul>
58
61
* @param exchange current server exchange
59
62
* @param handler the selected handler which must have been previously
60
63
* checked via {@link #supports(Object)}
61
- * @return {@link Mono} that emits a single {@code HandlerResult} or none if
62
- * the request has been fully handled and doesn't require further handling.
64
+ * @return {@link Mono} that emits a {@code HandlerResult}, or completes
65
+ * empty if the request is fully handled; any error signal would not be
66
+ * handled within the {@link DispatcherHandler}, and would instead be
67
+ * processed by the chain of registered
68
+ * {@link org.springframework.web.server.WebExceptionHandler}s at the end
69
+ * of the {@link org.springframework.web.server.WebFilter} chain
63
70
*/
64
71
Mono <HandlerResult > handle (ServerWebExchange exchange , Object handler );
65
72
0 commit comments