Search in sources :

Example 1 with WildcardMatcher

use of com.bluenimble.platform.regex.WildcardMatcher 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

ValueHolder (com.bluenimble.platform.ValueHolder)1 ApiService (com.bluenimble.platform.api.ApiService)1 Selector (com.bluenimble.platform.api.ApiServicesManager.Selector)1 WildcardMatcher (com.bluenimble.platform.regex.WildcardMatcher)1