Class 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]
    • 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 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, 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)
      Creates a new HookHandler.
    • 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,
                           org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler,
                           String userProfilePath,
                           String hookRootUri)
        Creates a new HookHandler.
        Parameters:
        vertx - vertx
        selfClient - selfClient
        storage - storage
        loggingResourceManager - loggingResourceManager
        monitoringHandler - monitoringHandler
        userProfilePath - userProfilePath
        hookRootUri - 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,
                           org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler,
                           String userProfilePath,
                           String hookRootUri,
                           RequestQueue requestQueue)
        Creates a new HookHandler.
        Parameters:
        vertx - vertx
        selfClient - selfClient
        storage - storage
        loggingResourceManager - loggingResourceManager
        monitoringHandler - monitoringHandler
        userProfilePath - userProfilePath
        hookRootUri - hookRootUri
        requestQueue - 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,
                           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,
                           org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler,
                           String userProfilePath,
                           String hookRootUri,
                           RequestQueue requestQueue,
                           boolean listableRoutes,
                           ReducedPropagationManager reducedPropagationManager)
        Creates a new HookHandler.
        Parameters:
        vertx - vertx
        selfClient - selfClient
        storage - storage
        loggingResourceManager - loggingResourceManager
        monitoringHandler - monitoringHandler
        userProfilePath - userProfilePath
        hookRootUri - hookRootUri
        requestQueue - requestQueue
        listableRoutes - listableRoutes
        reducedPropagationManager - reducedPropagationManager
      • 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,
                           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

        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,
                           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)
        Creates a new HookHandler.
        Parameters:
        vertx - vertx
        selfClient - selfClient
        userProfileStorage - userProfileStorage - where the user profiles are stored
        loggingResourceManager - loggingResourceManager
        monitoringHandler - monitoringHandler
        userProfilePath - userProfilePath
        hookRootUri - hookRootUri
        requestQueue - requestQueue
        listableRoutes - listableRoutes
        reducedPropagationManager - reducedPropagationManager
        doneHandler - doneHandler
        hookStorage - hookStorage - where the hooks are stored
        routeMultiplier - 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 of Router instances within a cluster
    • Method Detail

      • init

        public void init()
      • enableResourceLogging

        public void enableResourceLogging​(boolean resourceLoggingEnabled)
        Specified by:
        enableResourceLogging in interface org.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.
      • getUniqueListenerId

        protected String getUniqueListenerId​(String requestUrl)
        Creates a listener id, which is unique for the given service, and the monitored url.
        Parameters:
        requestUrl - requestUrl
        Returns:
        String