Class DelegateHandler

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

    public class DelegateHandler
    extends java.lang.Object
    implements org.swisspush.gateleen.core.refresh.Refreshable, org.swisspush.gateleen.core.logging.LoggableResource
    Allows to create delegates. E.g.
    Definition of a delegate is stored in a resource called definition within the specified delegate.
    PUT /gateleen/server/delegate/v1/delegates/user-zip-copy/definition
        {
            "methods": [ "PUT", "DELETE" ],
            "pattern": "([^/]*)/(.*)",
            "requests": [
                {
                     "headers" : [],
                     "uri": "/gateleen/server/copy",
                     "method": "POST",
                     "payload": {
                        "source": "/gateleen/$1?expand=100&zip=true",
                        "destination": "/gateleen/zips/users/$1.zip"
                    }
                }
            ]
        }
    
     
    To trigger an execution, it suffice to perform a PUT request on the virtual collection execution within the specified delegate.
    PUT /gateleen/server/delegate/v1/delegates/user-zip-copy/execution/<...>
    Author:
    https://github.com/ljucam [Mario Ljuca]
    • Constructor Summary

      Constructors 
      Constructor Description
      DelegateHandler​(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpClient selfClient, org.swisspush.gateleen.core.storage.ResourceStorage delegateStorage, org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler, java.lang.String delegatesUri, java.util.Map<java.lang.String,​java.lang.Object> properties, io.vertx.core.Handler<java.lang.Void> doneHandler)
      Creates a new instance of the DelegateHandler.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void enableResourceLogging​(boolean resourceLoggingEnabled)  
      protected java.lang.String getDelegateName​(java.lang.String uri)
      Tries to extract the name of the delegate out of the incoming uri.
      boolean handle​(io.vertx.core.http.HttpServerRequest request)
      Checks if the DelegateHandler is responsible for this request.
      void init()
      This method initializes the Handler.
      void refresh()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DelegateHandler

        public DelegateHandler​(io.vertx.core.Vertx vertx,
                               io.vertx.core.http.HttpClient selfClient,
                               org.swisspush.gateleen.core.storage.ResourceStorage delegateStorage,
                               org.swisspush.gateleen.monitoring.MonitoringHandler monitoringHandler,
                               java.lang.String delegatesUri,
                               java.util.Map<java.lang.String,​java.lang.Object> properties,
                               io.vertx.core.Handler<java.lang.Void> doneHandler)
        Creates a new instance of the DelegateHandler.
        Parameters:
        vertx - vertx
        selfClient - selfClient
        delegateStorage - delegateStorage - only used for storing delegates
        monitoringHandler - monitoringHandler
        delegatesUri - delegate root
        properties - properties
        doneHandler - doneHandler
    • Method Detail

      • init

        public void init()
        This method initializes the Handler. It should be called after the router is successfully established.
      • getDelegateName

        protected java.lang.String getDelegateName​(java.lang.String uri)
        Tries to extract the name of the delegate out of the incoming uri.
        Parameters:
        uri - original request uri
        Returns:
        the name of the delegate or null if nothing matches
      • handle

        public boolean handle​(io.vertx.core.http.HttpServerRequest request)
        Checks if the DelegateHandler is responsible for this request. If so it processes the request and returns true, otherwise it returns false.
        Parameters:
        request - original request
        Returns:
        true if processed, false otherwise
      • refresh

        public void refresh()
        Specified by:
        refresh in interface org.swisspush.gateleen.core.refresh.Refreshable
      • enableResourceLogging

        public void enableResourceLogging​(boolean resourceLoggingEnabled)
        Specified by:
        enableResourceLogging in interface org.swisspush.gateleen.core.logging.LoggableResource