Class HttpHandler
java.lang.Object
eu.cloudnetservice.driver.network.http.HttpHandler
- Direct Known Subclasses:
MethodHttpHandlerInvoker
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final Deque<HttpContextPreprocessor>static final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddPreProcessorHead(@NonNull HttpContextPreprocessor preprocessor) Adds a preprocessor which is applied to the context before calling this handler.addPreProcessorTail(@NonNull HttpContextPreprocessor preprocessor) Adds a preprocessor which is applied to the context before calling this handler.abstract voidhandle(@NonNull String path, @NonNull HttpContext context) Handles a http request whose path (and other supplied attributes) while registering is matching the requested path of the client.Gets all preprocessors which were added to this http handler.
-
Field Details
-
PRIORITY_HIGH
public static final int PRIORITY_HIGH- See Also:
-
PRIORITY_NORMAL
public static final int PRIORITY_NORMAL- See Also:
-
PRIORITY_LOW
public static final int PRIORITY_LOW- See Also:
-
PRIORITY_LOWEST
public static final int PRIORITY_LOWEST- See Also:
-
preprocessors
-
-
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.
-