From 2b8e7afbf39d6630dde64310c6fce00d5b83448d Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Mon, 9 Dec 2019 10:21:13 +0100 Subject: [PATCH] DATAREST-1463 - Adapt to API changes in LinkBuilderSupport. --- .../data/rest/webmvc/BaseUri.java | 21 +++++++++++++++---- .../webmvc/support/RepositoryLinkBuilder.java | 17 +++++++-------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/BaseUri.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/BaseUri.java index 43b8cf696..9cc6ba523 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/BaseUri.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/BaseUri.java @@ -23,10 +23,12 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; +import org.springframework.data.rest.core.Path; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; +import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UrlPathHelper; @@ -152,10 +154,21 @@ public class BaseUri { */ public UriComponentsBuilder getUriComponentsBuilder() { - if (baseUri.isAbsolute()) { - return UriComponentsBuilder.fromUri(baseUri); - } + return baseUri.isAbsolute() // + ? UriComponentsBuilder.fromUri(baseUri) // + : ServletUriComponentsBuilder.fromCurrentServletMapping().path(baseUri.toString()); + } - return ServletUriComponentsBuilder.fromCurrentServletMapping().path(baseUri.toString()); + /** + * Returns the {@link UriComponents} for the given {@link Path} appended to the current {@link BaseUri}. + * + * @param path must not be {@literal null}. + * @return + */ + public UriComponents appendPath(Path path) { + + Assert.notNull(path, "Path must not be null!"); + + return getUriComponentsBuilder().path(path.toString()).build(); } } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/RepositoryLinkBuilder.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/RepositoryLinkBuilder.java index 0d44e5fab..8f2fc553e 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/RepositoryLinkBuilder.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/RepositoryLinkBuilder.java @@ -27,7 +27,7 @@ import org.springframework.hateoas.Link; import org.springframework.hateoas.server.LinkBuilder; import org.springframework.hateoas.server.core.LinkBuilderSupport; import org.springframework.util.Assert; -import org.springframework.web.util.UriComponentsBuilder; +import org.springframework.web.util.UriComponents; /** * {@link LinkBuilder} to be able to create links pointing to repositories. @@ -45,19 +45,18 @@ public class RepositoryLinkBuilder extends LinkBuilderSupport affordances) { + private RepositoryLinkBuilder(ResourceMetadata metadata, UriComponents components, List affordances) { - super(builder, affordances); + super(components, affordances); Assert.notNull(metadata, "ResourceMetadata must not be null!"); @@ -89,8 +88,8 @@ public class RepositoryLinkBuilder extends LinkBuilderSupport affordances) { - return new RepositoryLinkBuilder(this.metadata, builder, affordances); + protected RepositoryLinkBuilder createNewInstance(UriComponents components, List affordances) { + return new RepositoryLinkBuilder(this.metadata, components, affordances); } /*