#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:
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user