Package org.swisspush.gateleen.expansion
Class ExpansionHandler
- java.lang.Object
-
- org.swisspush.gateleen.expansion.ExpansionHandler
-
- All Implemented Interfaces:
RuleProvider.RuleChangesObserver
public class ExpansionHandler extends Object implements RuleProvider.RuleChangesObserver
TheExpansionHandlerallows to fetch multiple a collection of multiple resources in a single GET request. To use theExpansionHandlerthe parameterexpand=xhas 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]
-
-
Field Summary
Fields Modifier and Type Field Description static StringEXPAND_PARAMstatic StringMAX_EXPANSION_LEVEL_HARD_PROPERTYstatic StringMAX_EXPANSION_LEVEL_SOFT_PROPERTYstatic StringMAX_SUBREQUEST_PROPERTYstatic StringSERIOUS_EXCEPTIONstatic StringZIP_PARAM
-
Constructor Summary
Constructors Constructor Description ExpansionHandler(io.vertx.core.Vertx vertx, org.swisspush.gateleen.core.storage.ResourceStorage storage, io.vertx.core.http.HttpClient httpClient, Map<String,Object> properties, String serverRoot, String rulesPath)Creates a new instance of the ExpansionHandler.ExpansionHandler(RuleProvider ruleProvider, io.vertx.core.http.HttpClient httpClient, Map<String,Object> properties, String serverRoot)Creates a new instance of the ExpansionHandler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetMaxExpansionLevelHard()intgetMaxExpansionLevelSoft()intgetMaxSubRequestCount()voidhandleExpansionRecursion(io.vertx.core.http.HttpServerRequest request)Handles the request as if it is a recursive expansion.voidhandleZipRecursion(io.vertx.core.http.HttpServerRequest request)Handles the request as if it is a request for a zip stream.protected booleanisBackendExpand(String uri)Check to see whether this request will be expanded by the backend (and therefore the expansionhandler won't do anything).booleanisCollection(String target)Returns true if the given name or path belongs to a collection.booleanisExpansionRequest(io.vertx.core.http.HttpServerRequest request)Returns true when theExpansionHandlercan deal with the given request.protected booleanisStorageExpand(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).booleanisZipRequest(io.vertx.core.http.HttpServerRequest request)Returns true when theExpansionHandlercan deal with the given request.voidrulesChanged(List<Rule> rules)
-
-
-
Field Detail
-
SERIOUS_EXCEPTION
public static final String SERIOUS_EXCEPTION
- See Also:
- Constant Field Values
-
EXPAND_PARAM
public static final String EXPAND_PARAM
- See Also:
- Constant Field Values
-
ZIP_PARAM
public static final String ZIP_PARAM
- See Also:
- Constant Field Values
-
MAX_EXPANSION_LEVEL_SOFT_PROPERTY
public static final String MAX_EXPANSION_LEVEL_SOFT_PROPERTY
- See Also:
- Constant Field Values
-
MAX_EXPANSION_LEVEL_HARD_PROPERTY
public static final String MAX_EXPANSION_LEVEL_HARD_PROPERTY
- See Also:
- Constant Field Values
-
MAX_SUBREQUEST_PROPERTY
public static final String MAX_SUBREQUEST_PROPERTY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ExpansionHandler
public ExpansionHandler(RuleProvider ruleProvider, io.vertx.core.http.HttpClient httpClient, Map<String,Object> properties, String serverRoot)
Creates a new instance of the ExpansionHandler.- Parameters:
ruleProvider-RuleProviderhttpClient- httpClientproperties- propertiesserverRoot- serverRoot
-
ExpansionHandler
public ExpansionHandler(io.vertx.core.Vertx vertx, org.swisspush.gateleen.core.storage.ResourceStorage storage, io.vertx.core.http.HttpClient httpClient, Map<String,Object> properties, String serverRoot, String rulesPath)Creates a new instance of the ExpansionHandler.- Parameters:
vertx- vertxstorage- storagehttpClient- httpClientproperties- propertiesserverRoot- serverRootrulesPath- rulesPath
-
-
Method Detail
-
rulesChanged
public void rulesChanged(List<Rule> rules)
- Specified by:
rulesChangedin interfaceRuleProvider.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 theExpansionHandlercan deal with the given request. The request must be a GET request and must have the parameterexpand=x. The method called after this check must behandleExpansionRecursion( ... ).- Parameters:
request- request- Returns:
- boolean
-
isBackendExpand
protected boolean isBackendExpand(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(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 theExpansionHandlercan deal with the given request. The request must be a GET request and must have the parameterexpand=x&zip=true. The method called after this check must behandleZipRecursion( ... ).- 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(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
-
-