Interface HandlerAdapter

All Known Implementing Classes:
HandlerFunctionAdapter, RequestMappingHandlerAdapter, simpleHandlerAdapter, WebsocketHandlerAdapter

public interface HandlerAdapter
Contract to abstract the details of invoking a handler of a given type.

An implementation can also choose to be an instance of DispatchExceptionHandler if it wants to handle exceptions that occur before the request is successfully mapped to a handler. This allows a HandlerAdapter to expose the same exception handling both for handler invocation errors and for errors before a handler is selected. In Reactive streams terms, handle(serverWebExchange, Object) handles the onNext signal, while DispatchExceptionHandler.handleError(serverWebExchange, Throwable) handles the onError signal from the dispatch processing chain.

since:
5.0
Author:
Rossen stoyanchev, sebastien Deleuze
  • Method summary

    Modifier and Type
    Method
    Description
    reactor.core.publisher.Mono<HandlerResult>
    handle(serverWebExchange&nbsp;exchange, Object&nbsp;handler)
    Handle the request with the given handler, previously checked via supports(Object).
    boolean
    supports(Object&nbsp;handler)
    Whether this HandlerAdapter supports the given handler.
  • Method Details

    • supports

      boolean&nbsp;supports(Object&nbsp;handler)
      Whether this HandlerAdapter supports the given handler.
      Parameters:
      handler - the handler object to check
      Returns:
      whether the handler is supported
    • handle

      reactor.core.publisher.Mono<HandlerResult>&nbsp;handle(serverWebExchange&nbsp;exchange, Object&nbsp;handler)
      Handle the request with the given handler, previously checked via supports(Object).

      Implementations should consider the following for exception handling:

      • Handle invocation exceptions within this method.
      • set an exception handler on the returned HandlerResult to handle deferred exceptions from asynchronous return values, and to handle exceptions from response rendering.
      • Implement DispatchExceptionHandler to extend exception handling to exceptions that occur before a handler is selected.
      Parameters:
      exchange - current server exchange
      handler - the selected handler which must have been previously checked via supports(Object)
      Returns:
      Mono that emits a HandlerResult, or completes empty if the request is fully handled; any error signal would not be handled within the DispatcherHandler, and would instead be processed by the chain of registered WebExceptionHandlers at the end of the WebFilter chain