Class HookHandler

  • All Implemented Interfaces:
    org.swisspush.gateleen.core.logging.LoggableResource

    public class HookHandler
    extends java.lang.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.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
      void enableResourceLogging​(boolean resourceLoggingEnabled)  
      protected java.lang.String getUniqueListenerId​(java.lang.String requestUrl)
      Creates a listener id, which is unique for the given service, and the monitored url.
      boolean handle​(io.vertx.core.http.HttpServerRequest request)
      Handles requests, which are either listener or route related.
      void init()  
      boolean isHookJsonInvalid​(io.vertx.core.http.HttpServerRequest request, io.vertx.core.buffer.Buffer hookData)  
      boolean isRequestAlreadyHooked​(io.vertx.core.http.HttpServerRequest request)
      Checks if the original Request was already hooked.
      void registerListenerRegistrationHandler​(io.vertx.core.Handler<java.lang.Void> readyHandler)
      Registers all needed handlers for the listener registration / unregistration.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 - 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.monitoring.MonitoringHandler monitoringHandler,
                           java.lang.String userProfilePath,
                           java.lang.String hookRootUri,
                           org.swisspush.gateleen.queue.queuing.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.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 - 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 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 - 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
    • 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<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