#527 - Revert a glitch introduced in move to Spring's UriComponentsBuilder API.

Our migration to the header handling for #509 (47cefe) unfortunately moved from starting with the servlet mapping for URI creation to using the full URI from the start.

This is now fixed by switching back by creating a UriComponentsBuilder from the current servlet mapping.

Related ticket: #509.
This commit is contained in:
Oliver Gierke
2016-12-22 12:08:32 +01:00
parent 61528d3242
commit fb0ba255a6
2 changed files with 14 additions and 2 deletions

View File

@@ -32,7 +32,6 @@ import org.springframework.hateoas.core.AnnotationMappingDiscoverer;
import org.springframework.hateoas.core.DummyInvocationUtils;
import org.springframework.hateoas.core.LinkBuilderSupport;
import org.springframework.hateoas.core.MappingDiscoverer;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -264,7 +263,7 @@ public class ControllerLinkBuilder extends LinkBuilderSupport<ControllerLinkBuil
static UriComponentsBuilder getBuilder() {
HttpServletRequest request = getCurrentRequest();
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpRequest(new ServletServerHttpRequest(request));
UriComponentsBuilder builder = ServletUriComponentsBuilder.fromServletMapping(request);
// special case handling for X-Forwarded-Ssl:
// apply it, but only if X-Forwarded-Proto is unset.

View File

@@ -557,6 +557,19 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
assertThat(linkTo(PersonControllerImpl.class).withSelfRel().getHref(), startsWith("http://"));
}
/**
* @see #527
*/
@Test
public void createsLinkRelativeToContextRoot() {
request.setContextPath("/ctx");
request.setServletPath("/foo");
request.setRequestURI("/ctx/foo");
assertThat(linkTo(PersonControllerImpl.class).withSelfRel().getHref(), endsWith("/ctx/people"));
}
private static UriComponents toComponents(Link link) {
return UriComponentsBuilder.fromUriString(link.expand().getHref()).build();
}