Class ExpansionHandler

  • All Implemented Interfaces:
    org.swisspush.gateleen.routing.RuleProvider.RuleChangesObserver

    public class ExpansionHandler
    extends java.lang.Object
    implements org.swisspush.gateleen.routing.RuleProvider.RuleChangesObserver
    The ExpansionHandler allows to fetch multiple a collection of multiple resources in a single GET request. To use the ExpansionHandler the parameter expand=x has to be added. Having a request to a resource defining a collection of resources like this:
     {"acls":["admin","developer"]}
     
    Would lead to a result like this:
     {
      "acls" : {
        "admin" : {
          "all.edit": {
            "methods": [
              "GET",
              "PUT",
              "POST",
              "DELETE"
            ],
            "path": "/.*"
          }
        },
        "developer" : {
          "role_1.menu.display": {},
          "role_2.menu.display": {},
          "gateleen.admin.menu": {}
        }
      }
     }
     
    Author:
    https://github.com/mcweba [Marc-Andre Weber], https://github.com/ljucam [Mario Ljuca]
    • Constructor Summary

      Constructors 
      Constructor Description
      ExpansionHandler​(io.vertx.core.Vertx vertx, org.swisspush.gateleen.core.storage.ResourceStorage storage, io.vertx.core.http.HttpClient httpClient, java.util.Map<java.lang.String,​java.lang.Object> properties, java.lang.String serverRoot, java.lang.String rulesPath)
      Creates a new instance of the ExpansionHandler.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getMaxExpansionLevelHard()  
      int getMaxExpansionLevelSoft()  
      int getMaxSubRequestCount()  
      void handleExpansionRecursion​(io.vertx.core.http.HttpServerRequest request)
      Handles the request as if it is a recursive expansion.
      void handleZipRecursion​(io.vertx.core.http.HttpServerRequest request)
      Handles the request as if it is a request for a zip stream.
      protected boolean isBackendExpand​(java.lang.String uri)
      Check to see whether this request will be expanded by the backend (and therefore the expansionhandler won't do anything).
      boolean isCollection​(java.lang.String target)
      Returns true if the given name or path belongs to a collection.
      boolean isExpansionRequest​(io.vertx.core.http.HttpServerRequest request)
      Returns true when the ExpansionHandler can deal with the given request.
      protected boolean isStorageExpand​(java.lang.String uri)
      Check to see whether this request is a storageExpand request (will be expanded by in the storage) (and therefore the expansionhandler won't do the subrequests by itself).
      boolean isZipRequest​(io.vertx.core.http.HttpServerRequest request)
      Returns true when the ExpansionHandler can deal with the given request.
      void rulesChanged​(java.util.List<org.swisspush.gateleen.routing.Rule> rules)  
      • Methods inherited from class java.lang.Object

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

      • SERIOUS_EXCEPTION

        public static final java.lang.String SERIOUS_EXCEPTION
        See Also:
        Constant Field Values
      • MAX_EXPANSION_LEVEL_SOFT_PROPERTY

        public static final java.lang.String MAX_EXPANSION_LEVEL_SOFT_PROPERTY
        See Also:
        Constant Field Values
      • MAX_EXPANSION_LEVEL_HARD_PROPERTY

        public static final java.lang.String MAX_EXPANSION_LEVEL_HARD_PROPERTY
        See Also:
        Constant Field Values
      • MAX_SUBREQUEST_PROPERTY

        public static final java.lang.String MAX_SUBREQUEST_PROPERTY
        See Also:
        Constant Field Values
    • Constructor Detail

      • ExpansionHandler

        public ExpansionHandler​(io.vertx.core.Vertx vertx,
                                org.swisspush.gateleen.core.storage.ResourceStorage storage,
                                io.vertx.core.http.HttpClient httpClient,
                                java.util.Map<java.lang.String,​java.lang.Object> properties,
                                java.lang.String serverRoot,
                                java.lang.String rulesPath)
        Creates a new instance of the ExpansionHandler.
        Parameters:
        vertx - vertx
        storage - storage
        httpClient - httpClient
        properties - properties
        serverRoot - serverRoot
        rulesPath - rulesPath
    • Method Detail

      • rulesChanged

        public void rulesChanged​(java.util.List<org.swisspush.gateleen.routing.Rule> rules)
        Specified by:
        rulesChanged in interface org.swisspush.gateleen.routing.RuleProvider.RuleChangesObserver
      • getMaxExpansionLevelSoft

        public int getMaxExpansionLevelSoft()
      • getMaxExpansionLevelHard

        public int getMaxExpansionLevelHard()
      • getMaxSubRequestCount

        public int getMaxSubRequestCount()
      • isExpansionRequest

        public boolean isExpansionRequest​(io.vertx.core.http.HttpServerRequest request)
        Returns true when the ExpansionHandler can deal with the given request. The request must be a GET request and must have the parameter expand=x. The method called after this check must be handleExpansionRecursion( ... ).
        Parameters:
        request - request
        Returns:
        boolean
      • isBackendExpand

        protected boolean isBackendExpand​(java.lang.String uri)
        Check to see whether this request will be expanded by the backend (and therefore the expansionhandler won't do anything).
        Parameters:
        uri - uri to check against the internal list of expandOnBackend urls
        Returns:
        boolean and true if the expand should be done by the backend
      • isStorageExpand

        protected boolean isStorageExpand​(java.lang.String uri)
        Check to see whether this request is a storageExpand request (will be expanded by in the storage) (and therefore the expansionhandler won't do the subrequests by itself).
        Parameters:
        uri - uri to check against the internal list of storageExpand urls
        Returns:
        boolean and true if the expand should be done in the storage
      • isZipRequest

        public boolean isZipRequest​(io.vertx.core.http.HttpServerRequest request)
        Returns true when the ExpansionHandler can deal with the given request. The request must be a GET request and must have the parameter expand=x&zip=true. The method called after this check must be handleZipRecursion( ... ).
        Parameters:
        request - request
        Returns:
        boolean
      • handleExpansionRecursion

        public void handleExpansionRecursion​(io.vertx.core.http.HttpServerRequest request)
        Handles the request as if it is a recursive expansion.
        Parameters:
        request - request
      • handleZipRecursion

        public void handleZipRecursion​(io.vertx.core.http.HttpServerRequest request)
        Handles the request as if it is a request for a zip stream.
        Parameters:
        request - request
      • isCollection

        public boolean isCollection​(java.lang.String target)
        Returns true if the given name or path belongs to a collection. In this case ends with a slash.
        Parameters:
        target - target
        Returns:
        boolean