Class MethodHttpHandlerInvoker
java.lang.Object
eu.cloudnetservice.driver.network.http.HttpHandler
eu.cloudnetservice.driver.network.http.annotation.parser.MethodHttpHandlerInvoker
A http handler which delegates its calls to a method invocation, resolving the parameters for that from the
preprocessed http context.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MethodHandleprivate final Class<?>[]private final Objectprivate final Collection<String>Fields inherited from class eu.cloudnetservice.driver.network.http.HttpHandler
PRIORITY_HIGH, PRIORITY_LOW, PRIORITY_LOWEST, PRIORITY_NORMAL -
Constructor Summary
ConstructorsConstructorDescriptionMethodHttpHandlerInvoker(@NonNull Object handlerInstance, @NonNull Method handlerMethod, @NonNull Collection<String> supportedMethods) Constructs a new MethodHttpHandlerInvoker instance. -
Method Summary
Modifier and TypeMethodDescriptionbuildInvocationArguments(@NonNull String path, @NonNull HttpContext context) Constructs the arguments array which will be passed to the method which is actually handling the associated request.private static @NonNull MethodHandlegenericHandleForMethod(@NonNull Method method) Converts the given method into a generic method handle which can be used to invoke the method without the exact arguments or return type known to the caller.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.Methods inherited from class eu.cloudnetservice.driver.network.http.HttpHandler
addPreProcessorHead, addPreProcessorTail, preprocessors
-
Field Details
-
instance
-
handlerMethod
-
handlerParameterTypes
-
supportedMethods
-
-
Constructor Details
-
MethodHttpHandlerInvoker
public MethodHttpHandlerInvoker(@NonNull @NonNull Object handlerInstance, @NonNull @NonNull Method handlerMethod, @NonNull @NonNull Collection<String> supportedMethods) throws IllegalAccessException Constructs a new MethodHttpHandlerInvoker instance.- Parameters:
handlerInstance- the instance in which the http handler method is located.handlerMethod- the method to delegate matching http calls to.supportedMethods- the supported http requests methods by this handler.- Throws:
NullPointerException- if the given instance, method or methods collection is null.IllegalAccessException- if method access checking fails.
-
-
Method Details
-
genericHandleForMethod
@NonNull private static @NonNull MethodHandle genericHandleForMethod(@NonNull @NonNull Method method) throws IllegalAccessException Converts the given method into a generic method handle which can be used to invoke the method without the exact arguments or return type known to the caller.- Parameters:
method- the method to convert.- Returns:
- a method generic method handle for the given method.
- Throws:
IllegalAccessException- if method access checking fails.
-
handle
public 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.- Specified by:
handlein classHttpHandler- 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.
-
buildInvocationArguments
@NonNull private @NonNull Object[] buildInvocationArguments(@NonNull @NonNull String path, @NonNull @NonNull HttpContext context) Constructs the arguments array which will be passed to the method which is actually handling the associated request.- Parameters:
path- the full path of the client request.context- the current context of the request.- Throws:
NullPointerException- if the given path or context is null.AnnotationHttpHandleException- if any exception occurs while resolving the arguments.
-