DATAREST-276 - Yet another round of trailing slash handling.

We need to proactively strip trailing slashes during base URI handling as even on a successful match (which previously left trailing slashes intact) this might subsequently on the resolving of the repository metadata when evaluating the left-over lookup path against the @RequestMapping methods (which keeps trailing slashes).
This commit is contained in:
Oliver Gierke
2014-05-02 11:19:44 +02:00
parent 358ff1bda8
commit b458378bbc
3 changed files with 7 additions and 5 deletions

View File

@@ -103,6 +103,8 @@ public class BaseUri {
Assert.notNull(lookupPath, "Lookup path must not be null!");
lookupPath = trimTrailingCharacter(lookupPath, '/');
if (!baseUri.isAbsolute()) {
String uri = baseUri.toString();

View File

@@ -94,6 +94,6 @@ public class ResourceMetadataHandlerMethodArgumentResolver implements HandlerMet
}
}
return null;
throw new IllegalArgumentException(String.format("Could not resolve repository metadata for %s.", repositoryKey));
}
}

View File

@@ -59,7 +59,7 @@ public class BaseUriUnitTests {
BaseUri uri = new BaseUri(URI.create("foo/"));
assertThat(uri.getRepositoryLookupPath("/foo"), isEmptyString());
assertThat(uri.getRepositoryLookupPath("/foo/"), is("/"));
assertThat(uri.getRepositoryLookupPath("/foo/"), isEmptyString());
}
/**
@@ -71,7 +71,7 @@ public class BaseUriUnitTests {
BaseUri uri = new BaseUri(URI.create("/foo"));
assertThat(uri.getRepositoryLookupPath("/foo"), isEmptyString());
assertThat(uri.getRepositoryLookupPath("/foo/"), is("/"));
assertThat(uri.getRepositoryLookupPath("/foo/"), isEmptyString());
}
/**
@@ -83,8 +83,8 @@ public class BaseUriUnitTests {
BaseUri uri = new BaseUri(URI.create("http://localhost:8080/foo/"));
assertThat(uri.getRepositoryLookupPath("/foo"), isEmptyString());
assertThat(uri.getRepositoryLookupPath("/foo/"), is("/"));
assertThat(uri.getRepositoryLookupPath("/foo/"), isEmptyString());
assertThat(uri.getRepositoryLookupPath("/foo/people"), is("/people"));
assertThat(uri.getRepositoryLookupPath("/foo/people/"), is("/people/"));
assertThat(uri.getRepositoryLookupPath("/foo/people/"), is("/people"));
}
}