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 java.lang.Object implements org.swisspush.gateleen.core.logging.LoggableResourceThe 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 java.lang.StringCOLLECTIONstatic java.lang.StringDESTINATIONstatic java.lang.StringDISCARD_PAYLOADstatic java.lang.StringEXPIRATION_TIMEstatic java.lang.StringFILTERstatic java.lang.StringFULL_URLstatic java.lang.StringHOOKstatic java.lang.StringHOOK_ROUTES_LISTEDstatic java.lang.StringHOOK_TRIGGER_TYPEstatic java.lang.StringHOOKED_HEADERstatic java.lang.StringHOOKS_LISTENERS_URI_PARTstatic java.lang.StringHOOKS_ROUTE_URI_PARTstatic java.lang.StringLISTABLEstatic java.lang.StringLISTENER_QUEUE_PREFIXstatic java.lang.StringMETHODSstatic java.lang.StringQUEUE_EXPIRE_AFTERstatic java.lang.StringREQUESTURLstatic java.lang.StringSTATIC_HEADERSstatic java.lang.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.monitoring.MonitoringHandler monitoringHandler, java.lang.String userProfilePath, java.lang.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.monitoring.MonitoringHandler monitoringHandler, java.lang.String userProfilePath, java.lang.String hookRootUri, org.swisspush.gateleen.queue.queuing.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.monitoring.MonitoringHandler monitoringHandler, java.lang.String userProfilePath, java.lang.String hookRootUri, org.swisspush.gateleen.queue.queuing.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.monitoring.MonitoringHandler monitoringHandler, java.lang.String userProfilePath, java.lang.String hookRootUri, org.swisspush.gateleen.queue.queuing.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.monitoring.MonitoringHandler monitoringHandler, java.lang.String userProfilePath, java.lang.String hookRootUri, org.swisspush.gateleen.queue.queuing.RequestQueue requestQueue, boolean listableRoutes, ReducedPropagationManager reducedPropagationManager, io.vertx.core.Handler doneHandler, org.swisspush.gateleen.core.storage.ResourceStorage hookStorage)Creates a new HookHandler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidenableResourceLogging(boolean resourceLoggingEnabled)protected java.lang.StringgetUniqueListenerId(java.lang.String requestUrl)Creates a listener id, which is unique for the given service, and the monitored url.booleanhandle(io.vertx.core.http.HttpServerRequest request)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<java.lang.Void> readyHandler)Registers all needed handlers for the listener registration / unregistration.
-
-
-
Field Detail
-
HOOKED_HEADER
public static final java.lang.String HOOKED_HEADER
- See Also:
- Constant Field Values
-
HOOK_ROUTES_LISTED
public static final java.lang.String HOOK_ROUTES_LISTED
- See Also:
- Constant Field Values
-
HOOKS_LISTENERS_URI_PART
public static final java.lang.String HOOKS_LISTENERS_URI_PART
- See Also:
- Constant Field Values
-
LISTENER_QUEUE_PREFIX
public static final java.lang.String LISTENER_QUEUE_PREFIX
- See Also:
- Constant Field Values
-
HOOKS_ROUTE_URI_PART
public static final java.lang.String HOOKS_ROUTE_URI_PART
- See Also:
- Constant Field Values
-
REQUESTURL
public static final java.lang.String REQUESTURL
- See Also:
- Constant Field Values
-
EXPIRATION_TIME
public static final java.lang.String EXPIRATION_TIME
- See Also:
- Constant Field Values
-
HOOK
public static final java.lang.String HOOK
- See Also:
- Constant Field Values
-
TRANSLATE_STATUS
public static final java.lang.String TRANSLATE_STATUS
- See Also:
- Constant Field Values
-
METHODS
public static final java.lang.String METHODS
- See Also:
- Constant Field Values
-
DESTINATION
public static final java.lang.String DESTINATION
- See Also:
- Constant Field Values
-
FILTER
public static final java.lang.String FILTER
- See Also:
- Constant Field Values
-
QUEUE_EXPIRE_AFTER
public static final java.lang.String QUEUE_EXPIRE_AFTER
- See Also:
- Constant Field Values
-
STATIC_HEADERS
public static final java.lang.String STATIC_HEADERS
- See Also:
- Constant Field Values
-
FULL_URL
public static final java.lang.String FULL_URL
- See Also:
- Constant Field Values
-
DISCARD_PAYLOAD
public static final java.lang.String DISCARD_PAYLOAD
- See Also:
- Constant Field Values
-
HOOK_TRIGGER_TYPE
public static final java.lang.String HOOK_TRIGGER_TYPE
- See Also:
- Constant Field Values
-
LISTABLE
public static final java.lang.String LISTABLE
- See Also:
- Constant Field Values
-
COLLECTION
public static final java.lang.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.monitoring.MonitoringHandler monitoringHandler, java.lang.String userProfilePath, java.lang.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.monitoring.MonitoringHandler monitoringHandler, java.lang.String userProfilePath, java.lang.String hookRootUri, org.swisspush.gateleen.queue.queuing.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.monitoring.MonitoringHandler monitoringHandler, java.lang.String userProfilePath, java.lang.String hookRootUri, org.swisspush.gateleen.queue.queuing.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.monitoring.MonitoringHandler monitoringHandler, java.lang.String userProfilePath, java.lang.String hookRootUri, org.swisspush.gateleen.queue.queuing.RequestQueue requestQueue, boolean listableRoutes, 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.monitoring.MonitoringHandler monitoringHandler, java.lang.String userProfilePath, java.lang.String hookRootUri, org.swisspush.gateleen.queue.queuing.RequestQueue requestQueue, boolean listableRoutes, ReducedPropagationManager reducedPropagationManager, io.vertx.core.Handler doneHandler, org.swisspush.gateleen.core.storage.ResourceStorage hookStorage)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 stored
-
-
Method Detail
-
init
public void init()
-
enableResourceLogging
public void enableResourceLogging(boolean resourceLoggingEnabled)
- Specified by:
enableResourceLoggingin interfaceorg.swisspush.gateleen.core.logging.LoggableResource
-
registerListenerRegistrationHandler
public void registerListenerRegistrationHandler(io.vertx.core.Handler<java.lang.Void> readyHandler)
Registers all needed handlers for the listener registration / unregistration.
-
handle
public boolean handle(io.vertx.core.http.HttpServerRequest request)
Handles requests, which are either listener or route related. Takes on:- hook un-/registration
- enqueueing a request for the registred listeners
- forwarding a request to the reistred listeners
- creating a self request for the original request (if necessary)
- Parameters:
request- request- 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.
-
getUniqueListenerId
protected java.lang.String getUniqueListenerId(java.lang.String requestUrl)
Creates a listener id, which is unique for the given service, and the monitored url.- Parameters:
requestUrl- requestUrl- Returns:
- String
-
-