Introduced MvcUriComponentsBuilder to create URIs pointing to controller methods.

MvcUriComponentsBuilder allows creating URIs that point to Spring MVC
controller methods annotated with @RequestMapping. It builds them by
exposing a mock method invocation API similar to Mockito, records the
method invocations and thus builds up the URI by inspecting the mapping
annotations and the parameters handed into the method invocations.

Introduced a new SPI UriComponentsContributor that should be implemented 
by HandlerMethodArgumentResolvers that actually contribute path segments 
or query parameters to a URI. While the newly introduced 
MvcUriComponentsBuilder looks up those UriComponentsContributor instances 
from the MVC configuration.

The MvcUriComponentsBuilderFactory (name to be discussed - MvcUris maybe?) 
prevents the multiple lookups by keeping the UriComponentsBuilder 
instances in an instance variable. So an instance of the factory could 
be exposed as Spring bean or through a HandlerMethodArgumentResolver to 
be injected into Controller methods.

Issue: SPR-10665, SPR-8826
This commit is contained in:
Oliver Gierke
2013-08-02 19:19:48 +02:00
committed by Rossen Stoyanchev
parent 92a48b72d7
commit 4fd27b12fc
18 changed files with 2036 additions and 1 deletions

View File

@@ -554,13 +554,42 @@ public class UriComponentsBuilder {
return this;
}
public UriComponentsBuilder with(UriComponentsBuilder builder) {
UriComponents components = builder.build().normalize();
if (StringUtils.hasText(components.getScheme())) {
scheme(components.getScheme());
}
if (StringUtils.hasText(components.getHost())) {
host(components.getHost());
}
if (components.getPort() != -1) {
port(components.getPort());
}
if (StringUtils.hasText(components.getPath())) {
path(components.getPath());
}
if (StringUtils.hasText(components.getQuery())) {
query(components.getQuery());
}
if (StringUtils.hasText(components.getFragment())) {
fragment(components.getFragment());
}
return this;
}
private interface PathComponentBuilder {
PathComponent build();
}
private static class CompositePathComponentBuilder implements PathComponentBuilder {
private final LinkedList<PathComponentBuilder> componentBuilders = new LinkedList<PathComponentBuilder>();