Package org.swisspush.gateleen.hook
Class HookHandler
- java.lang.Object
-
- org.swisspush.gateleen.hook.HookHandler
-
- All Implemented Interfaces:
org.swisspush.gateleen.core.logging.LoggableResource
public class HookHandler extends Object implements org.swisspush.gateleen.core.logging.LoggableResource
The HookHandler is responsible for un- and registering hooks (listener, as well as routes). He also handles forwarding requests to listeners / routes.- Author:
- https://github.com/ljucam [Mario Ljuca]
-
-
Field Summary
Fields Modifier and Type Field Description static StringCOLLECTIONstatic StringDESTINATIONstatic StringDISCARD_PAYLOADstatic StringEXPIRATION_TIMEstatic StringFILTERstatic StringFULL_URLstatic StringHEADERS_FILTERstatic StringHOOKstatic StringHOOK_ROUTES_LISTEDstatic StringHOOK_TRIGGER_TYPEstatic StringHOOKED_HEADERstatic StringHOOKS_LISTENERS_URI_PARTstatic StringHOOKS_ROUTE_URI_PARTstatic StringLISTABLEstatic StringLISTENER_QUEUE_PREFIXstatic StringMETHODSstatic StringQUEUE_EXPIRE_AFTERstatic StringREQUESTURLstatic StringSTATIC_HEADERSstatic StringTRANSLATE_STATUS
-
Constructor Summary
Constructors Constructor Description HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage storage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri)Creates a new HookHandler.HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage storage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri, RequestQueue requestQueue)Creates a new HookHandler.HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage storage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri, RequestQueue requestQueue, boolean listableRoutes)HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage storage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri, RequestQueue requestQueue, boolean listableRoutes, ReducedPropagationManager reducedPropagationManager)Creates a new HookHandler.HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage userProfileStorage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri, RequestQueue requestQueue, boolean listableRoutes, ReducedPropagationManager reducedPropagationManager, io.vertx.core.Handler doneHandler, org.swisspush.gateleen.core.storage.ResourceStorage hookStorage)HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage userProfileStorage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri, RequestQueue requestQueue, boolean listableRoutes, ReducedPropagationManager reducedPropagationManager, io.vertx.core.Handler doneHandler, org.swisspush.gateleen.core.storage.ResourceStorage hookStorage, int routeMultiplier)HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage userProfileStorage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri, RequestQueue requestQueue, boolean listableRoutes, ReducedPropagationManager reducedPropagationManager, io.vertx.core.Handler doneHandler, org.swisspush.gateleen.core.storage.ResourceStorage hookStorage, int routeMultiplier, QueueSplitter queueSplitter)Creates a new HookHandler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidenableResourceLogging(boolean resourceLoggingEnabled)protected StringgetUniqueListenerId(String requestUrl)Creates a listener id, which is unique for the given service, and the monitored url.booleanhandle(io.vertx.ext.web.RoutingContext ctx)Handles requests, which are either listener or route related.voidinit()booleanisHookJsonInvalid(io.vertx.core.http.HttpServerRequest request, io.vertx.core.buffer.Buffer hookData)booleanisRequestAlreadyHooked(io.vertx.core.http.HttpServerRequest request)Checks if the original Request was already hooked.voidregisterListenerRegistrationHandler(io.vertx.core.Handler<Void> readyHandler)Registers all needed handlers for the listener registration / unregistration.voidsetMeterRegistry(io.micrometer.core.instrument.MeterRegistry meterRegistry)
-
-
-
Field Detail
-
HOOKED_HEADER
public static final String HOOKED_HEADER
- See Also:
- Constant Field Values
-
HOOK_ROUTES_LISTED
public static final String HOOK_ROUTES_LISTED
- See Also:
- Constant Field Values
-
HOOKS_LISTENERS_URI_PART
public static final String HOOKS_LISTENERS_URI_PART
- See Also:
- Constant Field Values
-
LISTENER_QUEUE_PREFIX
public static final String LISTENER_QUEUE_PREFIX
- See Also:
- Constant Field Values
-
HOOKS_ROUTE_URI_PART
public static final String HOOKS_ROUTE_URI_PART
- See Also:
- Constant Field Values
-
REQUESTURL
public static final String REQUESTURL
- See Also:
- Constant Field Values
-
EXPIRATION_TIME
public static final String EXPIRATION_TIME
- See Also:
- Constant Field Values
-
HOOK
public static final String HOOK
- See Also:
- Constant Field Values
-
TRANSLATE_STATUS
public static final String TRANSLATE_STATUS
- See Also:
- Constant Field Values
-
METHODS
public static final String METHODS
- See Also:
- Constant Field Values
-
HEADERS_FILTER
public static final String HEADERS_FILTER
- See Also:
- Constant Field Values
-
DESTINATION
public static final String DESTINATION
- See Also:
- Constant Field Values
-
FILTER
public static final String FILTER
- See Also:
- Constant Field Values
-
QUEUE_EXPIRE_AFTER
public static final String QUEUE_EXPIRE_AFTER
- See Also:
- Constant Field Values
-
STATIC_HEADERS
public static final String STATIC_HEADERS
- See Also:
- Constant Field Values
-
FULL_URL
public static final String FULL_URL
- See Also:
- Constant Field Values
-
DISCARD_PAYLOAD
public static final String DISCARD_PAYLOAD
- See Also:
- Constant Field Values
-
HOOK_TRIGGER_TYPE
public static final String HOOK_TRIGGER_TYPE
- See Also:
- Constant Field Values
-
LISTABLE
public static final String LISTABLE
- See Also:
- Constant Field Values
-
COLLECTION
public static final String COLLECTION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HookHandler
public HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage storage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, @Nullable org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri)Creates a new HookHandler.- Parameters:
vertx- vertxselfClient- selfClientstorage- storageloggingResourceManager- loggingResourceManagermonitoringHandler- monitoringHandleruserProfilePath- userProfilePathhookRootUri- hookRootUri
-
HookHandler
public HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage storage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, @Nullable org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri, RequestQueue requestQueue)Creates a new HookHandler.- Parameters:
vertx- vertxselfClient- selfClientstorage- storageloggingResourceManager- loggingResourceManagermonitoringHandler- monitoringHandleruserProfilePath- userProfilePathhookRootUri- hookRootUrirequestQueue- requestQueue
-
HookHandler
public HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage storage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, @Nullable org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri, RequestQueue requestQueue, boolean listableRoutes)
-
HookHandler
public HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage storage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, @Nullable org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri, RequestQueue requestQueue, boolean listableRoutes, @Nullable ReducedPropagationManager reducedPropagationManager)Creates a new HookHandler.- Parameters:
vertx- vertxselfClient- selfClientstorage- storageloggingResourceManager- loggingResourceManagermonitoringHandler- monitoringHandleruserProfilePath- userProfilePathhookRootUri- hookRootUrirequestQueue- requestQueuelistableRoutes- listableRoutesreducedPropagationManager- reducedPropagationManager
-
HookHandler
public HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage userProfileStorage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, @Nullable org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri, RequestQueue requestQueue, boolean listableRoutes, ReducedPropagationManager reducedPropagationManager, @Nullable io.vertx.core.Handler doneHandler, org.swisspush.gateleen.core.storage.ResourceStorage hookStorage)
-
HookHandler
public HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage userProfileStorage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, @Nullable org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri, RequestQueue requestQueue, boolean listableRoutes, ReducedPropagationManager reducedPropagationManager, @Nullable io.vertx.core.Handler doneHandler, org.swisspush.gateleen.core.storage.ResourceStorage hookStorage, int routeMultiplier)
-
HookHandler
public HookHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage userProfileStorage, org.swisspush.gateleen.logging.LoggingResourceManager loggingResourceManager, org.swisspush.gateleen.logging.LogAppenderRepository logAppenderRepository, @Nullable org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, String userProfilePath, String hookRootUri, RequestQueue requestQueue, boolean listableRoutes, ReducedPropagationManager reducedPropagationManager, @Nullable io.vertx.core.Handler doneHandler, org.swisspush.gateleen.core.storage.ResourceStorage hookStorage, int routeMultiplier, @Nonnull QueueSplitter queueSplitter)Creates a new HookHandler.- Parameters:
vertx- vertxselfClient- selfClientuserProfileStorage- userProfileStorage - where the user profiles are storedloggingResourceManager- loggingResourceManagermonitoringHandler- monitoringHandleruserProfilePath- userProfilePathhookRootUri- hookRootUrirequestQueue- requestQueuelistableRoutes- listableRoutesreducedPropagationManager- reducedPropagationManagerdoneHandler- doneHandlerhookStorage- hookStorage - where the hooks are storedrouteMultiplier- the multiplier that is applied to routes, this is typically the number of nodes in a cluster multiplied by the number of router instances within a node. Or in other words the number ofRouterinstances within a clusterqueueSplitter- Configured QueueSplitter or NoOpQueueSplitter which dispatches to subqueues for parallel operation.
-
-
Method Detail
-
init
public void init()
-
setMeterRegistry
public void setMeterRegistry(io.micrometer.core.instrument.MeterRegistry meterRegistry)
-
enableResourceLogging
public void enableResourceLogging(boolean resourceLoggingEnabled)
- Specified by:
enableResourceLoggingin interfaceorg.swisspush.gateleen.core.logging.LoggableResource
-
registerListenerRegistrationHandler
public void registerListenerRegistrationHandler(io.vertx.core.Handler<Void> readyHandler)
Registers all needed handlers for the listener registration / unregistration.
-
handle
public boolean handle(io.vertx.ext.web.RoutingContext ctx)
Handles requests, which are either listener or route related. Takes on:- hook un-/registration
- enqueueing a request for the registered listeners
- forwarding a request to the reistered listeners
- creating a self request for the original request (if necessary)
- Parameters:
ctx- routing context- Returns:
- true if a request is processed by the handler, otherwise false
-
isHookJsonInvalid
public boolean isHookJsonInvalid(io.vertx.core.http.HttpServerRequest request, io.vertx.core.buffer.Buffer hookData)
-
isRequestAlreadyHooked
public boolean isRequestAlreadyHooked(io.vertx.core.http.HttpServerRequest request)
Checks if the original Request was already hooked. Eg. After a request is processed by the hook handler (register), the handler creates a self request with a copy of the original request. Therefore it's necessary to mark the request as already hooked.- Parameters:
request- request- Returns:
- true if the original request was already hooked.
-
-