Search in sources :

Example 1 with BindingMatch

use of com.yahoo.jdisc.application.BindingMatch in project vespa by vespa-engine.

the class HttpConfigRequests method getBindingMatch.

/**
 * 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());
}
Also used : UriPattern(com.yahoo.jdisc.application.UriPattern) URI(java.net.URI) BindingMatch(com.yahoo.jdisc.application.BindingMatch) Match(com.yahoo.jdisc.application.UriPattern.Match)

Aggregations

BindingMatch (com.yahoo.jdisc.application.BindingMatch)1 UriPattern (com.yahoo.jdisc.application.UriPattern)1 Match (com.yahoo.jdisc.application.UriPattern.Match)1 URI (java.net.URI)1