public static Map<String, String> decodePathParams(String pathTemplate, String path) { // Ignore trailing slashes on either the template or path. if (pathTemplate.endsWith("/")) pathTemplate = pathTemplate.substring(0, pathTemplate.length() - 1); if (path.endsWith("/")) path = path.substring(0, path.length() - 1); if (!pathParamExtractor.match(pathTemplate, path)) { throw new PathParameterMatchingException( "Cannot decode path params - path template and URI path do not match.", pathTemplate, path); } return pathParamExtractor.extractUriTemplateVariables(pathTemplate, path); }
/** * @return Returns the first pattern found in the collection that matches the given request if one exists. Order of * paths can be significant so when creating a MultiMatcher use an ordered collection if some path may match * multiple patterns. */ @Override public Optional<String> matchesPath(RequestInfo<?> request) { if (request == null || request.getPath() == null) return Optional.empty(); // Ignore trailing slashes on the actual path. String path = MatcherUtil.stripEndSlash(request.getPath()); return matchingPathTemplates .stream() // Ignore trailing slashes on the template. .filter(pathTemplate -> pathParamExtractor.match(pathTemplate, path)) .findFirst(); }
/** * {@inheritDoc} */ public Optional<String> matchesPath(RequestInfo<?> request) { if (request == null || request.getPath() == null) return Optional.empty(); // Ignore trailing slashes on actual path. String path = MatcherUtil.stripEndSlash(request.getPath()); if (pathParamExtractor.match(matchingPathTemplate, path)) { return cachedMatchesPathResponse; } else { return Optional.empty(); } }
if (!pattern1.equals(pattern2) && !pattern1ContainsUriVar && match(pattern1, pattern2)) { // /* + /hotel -> /hotel ; "/*.*" + "/*.html" -> /*.html
@Test @DataProvider(value = { "/some/{path}/foo | /some/bar/foo | true", "/some/{path}/f?o | /some/bar/fio | true", "/some/{:path}/foo | /some/bar/foo | false", "some/{path}/foo | /some/bar/foo | false", "/some/{path}/foo | some/bar/foo | false", "/some/{path}/foo/ | /some/bar/foo | false", "/some/{path}/foo | /some/bar/foo/ | false", "/some/{path}/foo/ | /some/bar/foo/ | true", "/some/{path}/foo | /some/bar/foo/no | false", "/bef{path}aft | /befTHINGaft | true", "/bef{path}aft | /befTHINGaft/whoops | false", "/foo/all.{the}.things | /foo/all.bar.things | true", "/foo/all.{the}.things | /foo/no/all.bar.things | false", "/foo/all.{the}.*/** | /foo/all..bar.aa/ee/oo | true", "/foo/all.{the}.*/** | /foo/all..bar. | true", "/foo/**/bar/** | /foo/it/bar/stuff/whee | true", "/foo/**/bar/** | /foo/it/barwhoops/it | false", "/foo/**/bar/**/whee | /foo/it/bar/stuff/whee | true", "/foo/**/bar/**baz** | /foo/it/bar/1baz2 | true", "/foo/**/bar/**baz** | /foo/it/bar/baz2 | true", "/foo/**/bar/**baz** | /foo/it/bar/1baz | true", "/foo/**/bar/**baz** | /foo/it/bar/blegh | false" }, splitBy = "\\|") public void match_method_works_as_expected_for_known_data(String pattern, String path, boolean expectedMatchValue) { // expect assertThat(matcher.match(pattern, path), is(expectedMatchValue)); }