diff options
Diffstat (limited to 'configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/HttpConfigRequests.java')
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/HttpConfigRequests.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/HttpConfigRequests.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/HttpConfigRequests.java new file mode 100644 index 00000000000..d190ccaec12 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/request/HttpConfigRequests.java @@ -0,0 +1,54 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.http.v2.request; + +import java.net.URI; + +import com.yahoo.container.jdisc.HttpRequest; +import com.yahoo.jdisc.application.BindingMatch; +import com.yahoo.jdisc.application.UriPattern; +import com.yahoo.jdisc.application.UriPattern.Match; +import com.yahoo.vespa.config.server.RequestHandler; +import com.yahoo.vespa.config.server.tenant.Tenant; +import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.http.NotFoundException; + +/** + * Helpers for v2 config REST API + * + * @author vegardh + */ +public class HttpConfigRequests { + + static final String RECURSIVE_QUERY_PROPERTY = "recursive"; + + /** + * Produces the binding match for the request. If it's not available on the jDisc request, create one for + * testing using the long and short app id URL patterns given. + * @param req an {@link com.yahoo.container.jdisc.HttpRequest} + * @param patterns A list of patterns that should be matched if no match on binding. + * @return match + */ + public static BindingMatch<?> getBindingMatch(HttpRequest req, String ... patterns) { + com.yahoo.jdisc.http.HttpRequest jDiscRequest = req.getJDiscRequest(); + if (jDiscRequest==null) throw new IllegalArgumentException("No JDisc request for: " + req.getUri()); + BindingMatch<?> jdBm = jDiscRequest.getBindingMatch(); + if (jdBm!=null) return jdBm; + + // If not, use provided patterns + for (String pattern : patterns) { + UriPattern fullAppIdPattern = new UriPattern(pattern); + URI uri = req.getUri(); + Match match = fullAppIdPattern.match(uri); + if (match!=null) return new BindingMatch<>(match, new Object(), fullAppIdPattern); + } + throw new IllegalArgumentException("Illegal url for config request: " + req.getUri()); + } + + + public static RequestHandler getRequestHandler(TenantRepository tenantRepository, TenantRequest request) { + Tenant tenant = tenantRepository.getTenant(request.getApplicationId().tenant()); + if (tenant==null) throw new NotFoundException("No such tenant: "+request.getApplicationId().tenant()); + return tenant.getRequestHandler(); + } + +} |