Interface ServerController<A extends ExchangeContext,B extends Exchange<A>,C extends ErrorExchange<A>>
- Type Parameters:
A
- the type of the exchange contextB
- the type of exchange handled by the controllerC
- the type of error exchange handled by the controller
- All Superinterfaces:
ReactiveServerController<A,
B, C>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A server controller defines how server exchanges and server error exchanges are handled, within the HTTP server.
When receiving a request from a client, the HTTP server creates an Exchange
and invokes the server controller to actually process that request and provide a response to the client. In case
of error during that process, it creates an ErrorExchange
from the original exchange and invokes the controller again to handle the error and provide an error response to the client.
The HTTP server shall only rely on the defer(io.inverno.mod.http.server.Exchange)
and defer(io.inverno.mod.http.server.ErrorExchange)
methods in order to remain reactive, the
server controller only exposes non-reactive handling methods to facilitate the definition of the controller using lambdas.
The createContext()
method is used by the server to create the exchange context associated to an Exchange.
- Since:
- 1.5
- Author:
- Jeremy Kuhn
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault A
Creates the context that is eventually attached to the exchange.By default, returns a Mono that defers the execution ofhandle(io.inverno.mod.http.server.Exchange)
.By default, returns a Mono that defers the execution ofhandle(io.inverno.mod.http.server.ErrorExchange)
.static <U extends ExchangeContext,
V extends Exchange<U>, W extends ErrorExchange<U>>
ServerController<U, V, W> from
(ExchangeHandler<U, V> handler) Returns a server controller that delegates to the specified exchange handler.static <U extends ExchangeContext,
V extends Exchange<U>, W extends ErrorExchange<U>>
ServerController<U, V, W> from
(ExchangeHandler<U, V> handler, ExchangeHandler<U, W> errorHandler) Returns a server controller that delegates to the specified exchange handler and error exchange handler.static <U extends ExchangeContext,
V extends Exchange<U>, W extends ErrorExchange<U>>
ServerController<U, V, W> from
(ExchangeHandler<U, V> handler, ExchangeHandler<U, W> errorHandler, Supplier<U> contextSupplier) Returns a server controller that delegates to the specified exchange handler and error exchange handler and uses the specified context supplier to create exchange contexts.static <U extends ExchangeContext,
V extends Exchange<U>, W extends ErrorExchange<U>>
ServerController<U, V, W> from
(ReactiveExchangeHandler<U, V> handler) Returns a server controller that delegates to the specified reactive exchange handler.static <U extends ExchangeContext,
V extends Exchange<U>, W extends ErrorExchange<U>>
ServerController<U, V, W> from
(ReactiveExchangeHandler<U, V> handler, ReactiveExchangeHandler<U, W> errorHandler) Returns a server controller that delegates to the specified reactive exchange handler and error exchange handler.static <U extends ExchangeContext,
V extends Exchange<U>, W extends ErrorExchange<U>>
ServerController<U, V, W> from
(ReactiveExchangeHandler<U, V> handler, ReactiveExchangeHandler<U, W> errorHandler, Supplier<U> contextSupplier) Returns a server controller that delegates to the specified reactive exchange handler and error exchange handler and uses the specified context supplier to create exchange contexts.void
Processes the specified server exchange.default void
Processes the specified server error exchange.
-
Method Details
-
defer
By default, returns a Mono that defers the execution of
handle(io.inverno.mod.http.server.Exchange)
.- Specified by:
defer
in interfaceReactiveServerController<A extends ExchangeContext,
B extends Exchange<A>, C extends ErrorExchange<A>> - Parameters:
exchange
- the exchange to process- Returns:
- an empty mono that completes when the exchange has been processed
- Throws:
HttpException
- See Also:
-
handle
Processes the specified server exchange.
This method is more convenient than
defer(io.inverno.mod.http.server.Exchange)
when the handling logic does not need to be reactive.- Parameters:
exchange
- the exchange to process- Throws:
HttpException
- if an error occurs during the processing of the exchange
-
defer
By default, returns a Mono that defers the execution of
handle(io.inverno.mod.http.server.ErrorExchange)
.- Specified by:
defer
in interfaceReactiveServerController<A extends ExchangeContext,
B extends Exchange<A>, C extends ErrorExchange<A>> - Parameters:
errorExchange
- the error exchange to process- Returns:
- an empty mono that completes when the error exchange has been processed
- Throws:
HttpException
- See Also:
-
handle
Processes the specified server error exchange.
The purpose of this method is to eventually inject a
ResponseBody
in the response which basically completes the exchange.- Parameters:
errorExchange
- the exchange to process- Throws:
HttpException
- if an error occurs during the processing of the exchange
-
createContext
Creates the context that is eventually attached to the exchange.
This method returns null by default.
- Returns:
- a new exchange context
-
from
static <U extends ExchangeContext,V extends Exchange<U>, ServerController<U,W extends ErrorExchange<U>> V, fromW> (ReactiveExchangeHandler<U, V> handler) Returns a server controller that delegates to the specified reactive exchange handler.
- Type Parameters:
U
- the type of the exchange contextV
- the type of exchange handled by the controllerW
- the type of error exchange handled by the controller- Parameters:
handler
- a reactive exchange handler- Returns:
- a server controller
-
from
static <U extends ExchangeContext,V extends Exchange<U>, ServerController<U,W extends ErrorExchange<U>> V, fromW> (ExchangeHandler<U, V> handler) Returns a server controller that delegates to the specified exchange handler.
- Type Parameters:
U
- the type of the exchange contextV
- the type of exchange handled by the controllerW
- the type of error exchange handled by the controller- Parameters:
handler
- an exchange handler- Returns:
- a server controller
-
from
static <U extends ExchangeContext,V extends Exchange<U>, ServerController<U,W extends ErrorExchange<U>> V, fromW> (ReactiveExchangeHandler<U, V> handler, ReactiveExchangeHandler<U, W> errorHandler) Returns a server controller that delegates to the specified reactive exchange handler and error exchange handler.
- Type Parameters:
U
- the type of the exchange contextV
- the type of exchange handled by the controllerW
- the type of error exchange handled by the controller- Parameters:
handler
- a reactive exchange handlererrorHandler
- a reactive error exchange handler- Returns:
- a server controller
-
from
static <U extends ExchangeContext,V extends Exchange<U>, ServerController<U,W extends ErrorExchange<U>> V, fromW> (ExchangeHandler<U, V> handler, ExchangeHandler<U, W> errorHandler) Returns a server controller that delegates to the specified exchange handler and error exchange handler.
- Type Parameters:
U
- the type of the exchange contextV
- the type of exchange handled by the controllerW
- the type of error exchange handled by the controller- Parameters:
handler
- an exchange handlererrorHandler
- an error exchange handler- Returns:
- a server controller
-
from
static <U extends ExchangeContext,V extends Exchange<U>, ServerController<U,W extends ErrorExchange<U>> V, fromW> (ReactiveExchangeHandler<U, V> handler, ReactiveExchangeHandler<U, W> errorHandler, Supplier<U> contextSupplier) Returns a server controller that delegates to the specified reactive exchange handler and error exchange handler and uses the specified context supplier to create exchange contexts.
- Type Parameters:
U
- the type of the exchange contextV
- the type of exchange handled by the controllerW
- the type of error exchange handled by the controller- Parameters:
handler
- an exchange handlererrorHandler
- a reactive error exchange handlercontextSupplier
- a reactive exchange context supplier- Returns:
- a server controller
-
from
static <U extends ExchangeContext,V extends Exchange<U>, ServerController<U,W extends ErrorExchange<U>> V, fromW> (ExchangeHandler<U, V> handler, ExchangeHandler<U, W> errorHandler, Supplier<U> contextSupplier) Returns a server controller that delegates to the specified exchange handler and error exchange handler and uses the specified context supplier to create exchange contexts.
- Type Parameters:
U
- the type of the exchange contextV
- the type of exchange handled by the controllerW
- the type of error exchange handled by the controller- Parameters:
handler
- an exchange handlererrorHandler
- an error exchange handlercontextSupplier
- an exchange context supplier- Returns:
- a server controller
-