diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2020-12-21 12:25:26 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2020-12-21 12:25:26 +0100 |
commit | 057e333efb8b8efb967c048900505362726fa547 (patch) | |
tree | d1b73f5942a46284102be346033c9f09311591d9 /jdisc_core | |
parent | 3b021b169f7836efd215e7c4bc0302715b3e56cc (diff) |
Deprecate unused and complicating "priority"
Diffstat (limited to 'jdisc_core')
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java | 15 | ||||
-rw-r--r-- | jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java | 6 |
2 files changed, 18 insertions, 3 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java index 350d8170987..a626b789fae 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java @@ -37,6 +37,8 @@ public class UriPattern implements Comparable<UriPattern> { private final GlobPattern host; private final int port; private final GlobPattern path; + + // TODO Vespa 8 jonmv remove private final int priority; /** @@ -48,7 +50,16 @@ public class UriPattern implements Comparable<UriPattern> { * @throws IllegalArgumentException If the pattern could not be parsed. */ public UriPattern(String uri) { - this(uri, DEFAULT_PRIORITY); + Matcher matcher = PATTERN.matcher(uri); + if ( ! matcher.find()) + throw new IllegalArgumentException(uri); + + scheme = GlobPattern.compile(normalizeScheme(resolvePatternComponent(matcher.group(1)))); + host = GlobPattern.compile(resolvePatternComponent(matcher.group(2))); + port = resolvePortPattern(matcher.group(4)); + path = GlobPattern.compile(resolvePatternComponent(matcher.group(7))); + pattern = scheme + "://" + host + ":" + (port > 0 ? port : "*") + "/" + path; + this.priority = DEFAULT_PRIORITY; } /** @@ -56,10 +67,12 @@ public class UriPattern implements Comparable<UriPattern> { * input string must be on the form <code><scheme>://<host>[:<port>]<path></code>, where * '*' can be used as a wildcard character at any position.</p> * + * @deprecated Use {@link #UriPattern(String)} and let's avoid another complication here. * @param uri The pattern to parse. * @param priority The priority of this pattern. * @throws IllegalArgumentException If the pattern could not be parsed. */ + @Deprecated(forRemoval = true, since = "7") public UriPattern(String uri, int priority) { Matcher matcher = PATTERN.matcher(uri); if (!matcher.find()) { diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java index d2499bbf369..4b5ff271dfa 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java @@ -173,12 +173,14 @@ public class UriPatternTestCase { } @Test + @SuppressWarnings("removal") public void requireThatPrioritiesAreOrderedDescending() { assertCompareLt(new UriPattern("scheme://host:69/path", 1), new UriPattern("scheme://host:69/path", 0)); } @Test + @SuppressWarnings("removal") public void requireThatPriorityOrdersBeforeScheme() { assertCompareLt(new UriPattern("*://host:69/path", 1), new UriPattern("scheme://host:69/path", 0)); @@ -314,7 +316,7 @@ public class UriPatternTestCase { } private static void assertCompareLt(String lhs, String rhs) { - assertCompareLt(new UriPattern(lhs, 0), new UriPattern(rhs, 0)); + assertCompareLt(new UriPattern(lhs), new UriPattern(rhs)); } private static void assertCompareLt(UriPattern lhs, UriPattern rhs) { @@ -322,7 +324,7 @@ public class UriPatternTestCase { } private static void assertCompareEq(String lhs, String rhs) { - assertCompareEq(new UriPattern(lhs, 0), new UriPattern(rhs, 0)); + assertCompareEq(new UriPattern(lhs), new UriPattern(rhs)); } private static void assertCompareEq(UriPattern lhs, UriPattern rhs) { |