Class HttpHandler

java.lang.Object
eu.cloudnetservice.driver.network.http.HttpHandler
Direct Known Subclasses:
MethodHttpHandlerInvoker

public abstract class HttpHandler extends Object
A handler for a http request. Each request, matching the given attributes supplied when registering, will be called directly into this handler. A request is only processed by one handler at a time. Handlers with a high priority will get called before handlers with a low priority.
Since:
4.0
  • Field Details

  • Constructor Details

    • HttpHandler

      public HttpHandler()
  • Method Details

    • addPreProcessorHead

      @NonNull public @NonNull HttpHandler addPreProcessorHead(@NonNull @NonNull HttpContextPreprocessor preprocessor)
      Adds a preprocessor which is applied to the context before calling this handler. The pre-processors are called in the order they were added, using this method the handler is put at the head of the listeners, meaning that all other previously added handlers will be called after.
      Parameters:
      preprocessor - the context preprocessor to register.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given preprocessor is null.
    • addPreProcessorTail

      @NonNull public @NonNull HttpHandler addPreProcessorTail(@NonNull @NonNull HttpContextPreprocessor preprocessor)
      Adds a preprocessor which is applied to the context before calling this handler. The pre-processors are called in the order they were added, using this method the handler is put at the tail of the listeners, meaning that all other previously added handlers will be called first.
      Parameters:
      preprocessor - the context preprocessor to register.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given preprocessor is null.
    • preprocessors

      Gets all preprocessors which were added to this http handler.
      Returns:
      all registered preprocessors.
    • handle

      public abstract void handle(@NonNull @NonNull String path, @NonNull @NonNull HttpContext context) throws Throwable
      Handles a http request whose path (and other supplied attributes) while registering is matching the requested path of the client. A request is only processed by one handler at a time, giving the handler full control about changing the context. Changes to the context will be reflected into other handlers and vise-versa.
      Parameters:
      path - the full path of the client request.
      context - the current context of the request.
      Throws:
      Throwable - if any exception occurs during the request handling.
      NullPointerException - if the given path or context is null.