Remove the few remaining usages of UriTemplate

Also update Javadoc of UriTemplate to point to UriComponentsBuilder and
UriBuilderFactory as more flexible options.

See gh-24094
This commit is contained in:
Rossen Stoyanchev
2019-11-28 11:28:49 +00:00
parent df2ed75df0
commit b44daa8b71
7 changed files with 38 additions and 29 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ import org.springframework.validation.Errors;
import org.springframework.web.bind.EscapedErrors;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.util.HtmlUtils;
import org.springframework.web.util.UriTemplate;
import org.springframework.web.util.UriComponentsBuilder;
/**
* Context holder for request-specific state, like the {@link MessageSource} to
@@ -218,8 +218,7 @@ public class RequestContext {
*/
public String getContextUrl(String relativeUrl, Map<String, ?> params) {
String url = StringUtils.applyRelativePath(getContextPath() + "/", relativeUrl);
UriTemplate template = new UriTemplate(url);
url = template.expand(params).toASCIIString();
url = UriComponentsBuilder.fromUriString(url).buildAndExpand(params).encode().toUri().toASCIIString();
return getExchange().transformUrl(url);
}