diff options
6 files changed, 46 insertions, 13 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/Utils.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/Utils.java index 873a24b5f05..e5bf8e22020 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/Utils.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/Utils.java @@ -31,9 +31,10 @@ public class Utils { com.yahoo.jdisc.http.HttpRequest jDiscRequest = req.getJDiscRequest(); BindingMatch<?> bm = jDiscRequest.getBindingMatch(); if (bm == null) { + UriPattern pattern = new UriPattern(uriPattern); bm = new BindingMatch<>( - new UriPattern(uriPattern).match(URI.create(jDiscRequest.getUri().toString())), - new Object()); + pattern.match(URI.create(jDiscRequest.getUri().toString())), + new Object(), pattern); } return bm; } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpConfigRequests.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpConfigRequests.java index db92f53aacd..59270afd397 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpConfigRequests.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpConfigRequests.java @@ -39,7 +39,7 @@ public class HttpConfigRequests { UriPattern fullAppIdPattern = new UriPattern(pattern); URI uri = req.getUri(); Match match = fullAppIdPattern.match(uri); - if (match!=null) return new BindingMatch<>(match, new Object()); + if (match!=null) return new BindingMatch<>(match, new Object(), fullAppIdPattern); } throw new IllegalArgumentException("Illegal url for config request: " + req.getUri()); } diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingMatch.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingMatch.java index 5d4974f2dc4..7318b1b38ae 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingMatch.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingMatch.java @@ -15,6 +15,7 @@ public class BindingMatch<T> { private final UriPattern.Match match; private final T target; + private final UriPattern matched; /** * <p>Constructs a new instance of this class.</p> @@ -22,12 +23,27 @@ public class BindingMatch<T> { * @param match The match information for this instance. * @param target The target of this match. * @throws NullPointerException If any argument is null. + * @deprecated use BindingMatch(UriPattern.Match match, T target, UriPattern matched) */ + @Deprecated public BindingMatch(UriPattern.Match match, T target) { + this(match, target, null); + } + + /** + * <p>Constructs a new instance of this class.</p> + * + * @param match The match information for this instance. + * @param target The target of this match. + * @param matched The matched URI pattern + * @throws NullPointerException If any argument is null. + */ + public BindingMatch(UriPattern.Match match, T target, UriPattern matched) { Objects.requireNonNull(match, "match"); Objects.requireNonNull(target, "target"); this.match = match; this.target = target; + this.matched = matched; } /** @@ -61,4 +77,14 @@ public class BindingMatch<T> { public T target() { return target; } + + /** + * <p>Returns the URI pattern that was matched.</p> + * + * @return The matched pattern. + */ + public UriPattern matched() { + return matched; + } + } diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingSet.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingSet.java index 7a21e204dd3..1e25846f63c 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingSet.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingSet.java @@ -38,9 +38,10 @@ public class BindingSet<T> implements Iterable<Map.Entry<UriPattern, T>> { */ public BindingMatch<T> match(URI uri) { for (Map.Entry<UriPattern, T> entry : bindings) { - UriPattern.Match match = entry.getKey().match(uri); + UriPattern pattern = entry.getKey(); + UriPattern.Match match = pattern.match(uri); if (match != null) { - return new BindingMatch<>(match, entry.getValue()); + return new BindingMatch<>(match, entry.getValue(), pattern); } } return null; diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java index e00bdae153d..cd5e07f1224 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java @@ -297,9 +297,10 @@ public class RequestTestCase { public RequestHandler resolveHandler(Request request) { this.asServer = request.isServerRequest(); RequestHandler requestHandler = new MyRequestHandler(); - request.setBindingMatch(new BindingMatch<>( - new UriPattern("http://*/*").match(request.getUri()), - requestHandler)); + UriPattern pattern = new UriPattern("http://*/*"); + request.setBindingMatch(new BindingMatch<>(pattern.match(request.getUri()), + requestHandler, + pattern)); return requestHandler; } diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingMatchTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingMatchTestCase.java index 582a1c6685e..21a3ae08c49 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingMatchTestCase.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingMatchTestCase.java @@ -18,32 +18,36 @@ public class BindingMatchTestCase { @Test public void requireThatAccessorsWork() { Object obj = new Object(); + UriPattern pattern = new UriPattern("http://*/*"); BindingMatch<Object> match = new BindingMatch<>( - new UriPattern("http://*/*").match(URI.create("http://localhost:69/status.html")), - obj); + pattern.match(URI.create("http://localhost:69/status.html")), + obj, pattern); assertSame(obj, match.target()); assertEquals(3, match.groupCount()); assertEquals("localhost", match.group(0)); assertEquals("69", match.group(1)); assertEquals("status.html", match.group(2)); + assertEquals(pattern, match.matched()); } @Test public void requireThatConstructorArgumentsCanNotBeNull() { try { - new BindingMatch<>(null, null); + new BindingMatch<>(null, null, null); fail(); } catch (NullPointerException e) { } try { - new BindingMatch<>(new UriPattern("http://*/*").match(URI.create("http://localhost/")), null); + UriPattern pattern = new UriPattern("http://*/*"); + new BindingMatch<>(pattern.match(URI.create("http://localhost/")), null, pattern); fail(); } catch (NullPointerException e) { } try { - new BindingMatch<>(null, new Object()); + UriPattern pattern = new UriPattern("http://*/*"); + new BindingMatch<>(null, new Object(), pattern); fail(); } catch (NullPointerException e) { |