Interface ServerController<A extends ExchangeContext,B extends Exchange<A>,C extends ErrorExchange<A>>

Type Parameters:
A - the type of the exchange context
B - the type of exchange handled by the controller
C - 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.

@FunctionalInterface public interface ServerController<A extends ExchangeContext,B extends Exchange<A>,C extends ErrorExchange<A>> extends ReactiveServerController<A,B,C>

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 Details

    • defer

      default Mono<Void> defer(B exchange) throws HttpException

      By default, returns a Mono that defers the execution of handle(io.inverno.mod.http.server.Exchange).

      Specified by:
      defer in interface ReactiveServerController<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

      void handle(B exchange) throws HttpException

      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

      default Mono<Void> defer(C errorExchange) throws HttpException

      By default, returns a Mono that defers the execution of handle(io.inverno.mod.http.server.ErrorExchange).

      Specified by:
      defer in interface ReactiveServerController<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

      default void handle(C errorExchange) throws HttpException

      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

      default A 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>, W extends ErrorExchange<U>> ServerController<U,V,W> from(ExchangeHandler<U,V> handler)

      Returns a server controller that delegates to the specified exchange handler.

      Type Parameters:
      U - the type of the exchange context
      V - the type of exchange handled by the controller
      W - 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>, 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.

      Type Parameters:
      U - the type of the exchange context
      V - the type of exchange handled by the controller
      W - the type of error exchange handled by the controller
      Parameters:
      handler - an exchange handler
      errorHandler - an error exchange handler
      Returns:
      a server controller
    • from

      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.

      Type Parameters:
      U - the type of the exchange context
      V - the type of exchange handled by the controller
      W - the type of error exchange handled by the controller
      Parameters:
      handler - an exchange handler
      errorHandler - an error exchange handler
      contextSupplier - an exchange context supplier
      Returns:
      a server controller