Search in sources :

Example 11 with ApiService

use of com.bluenimble.platform.api.ApiService in project serverless by bluenimble.

the class ApiImpl method lockup.

protected ApiService lockup(final ApiVerb verb, String[] endpoint) {
    if (servicesManager.isEmpty(verb)) {
        return null;
    }
    String path = Lang.SLASH;
    if (endpoint != null && endpoint.length > 0) {
        path += Lang.join(endpoint, Lang.SLASH);
    }
    ApiService service = servicesManager.get(verb, path);
    if (service != null) {
        return service;
    }
    final String wildcard = path;
    final ValueHolder<ApiService> holder = new ValueHolder<ApiService>();
    servicesManager.list(new Selector() {

        @Override
        public boolean select(ApiService service) {
            WildcardMatcher matcher = new WildcardMatcher(WildcardCompiler.compile(service.getEndpoint()), wildcard);
            if (matcher.find() && service.getVerb().equals(verb)) {
                holder.set(service);
                return true;
            }
            return false;
        }
    });
    return holder.get();
}
Also used : ApiService(com.bluenimble.platform.api.ApiService) WildcardMatcher(com.bluenimble.platform.regex.WildcardMatcher) ValueHolder(com.bluenimble.platform.ValueHolder) Selector(com.bluenimble.platform.api.ApiServicesManager.Selector)

Aggregations

ApiService (com.bluenimble.platform.api.ApiService)11 ApiServicesManagerException (com.bluenimble.platform.api.ApiServicesManagerException)4 ApiServiceExecutionException (com.bluenimble.platform.api.ApiServiceExecutionException)3 Selector (com.bluenimble.platform.api.ApiServicesManager.Selector)3 JsonArray (com.bluenimble.platform.json.JsonArray)3 JsonObject (com.bluenimble.platform.json.JsonObject)3 ValueHolder (com.bluenimble.platform.ValueHolder)2 ApiVerb (com.bluenimble.platform.api.ApiVerb)2 JsonApiOutput (com.bluenimble.platform.api.impls.JsonApiOutput)2 ApiServiceValidatorException (com.bluenimble.platform.api.validation.ApiServiceValidatorException)2 ApiServiceSet (com.bluenimble.platform.server.impls.fs.ApiServiceSet)2 Recyclable (com.bluenimble.platform.Recyclable)1 Api (com.bluenimble.platform.api.Api)1 ApiAccessDeniedException (com.bluenimble.platform.api.ApiAccessDeniedException)1 ApiContext (com.bluenimble.platform.api.ApiContext)1 ApiManagementException (com.bluenimble.platform.api.ApiManagementException)1 ApiOutput (com.bluenimble.platform.api.ApiOutput)1 ApiResourcesManagerException (com.bluenimble.platform.api.ApiResourcesManagerException)1 ApiResponse (com.bluenimble.platform.api.ApiResponse)1 ApiStatus (com.bluenimble.platform.api.ApiStatus)1