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.
@@ -50,7 +50,7 @@ import org.springframework.web.servlet.LocaleContextResolver;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.ThemeResolver;
import org.springframework.web.util.HtmlUtils;
import org.springframework.web.util.UriTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.web.util.UrlPathHelper;
import org.springframework.web.util.WebUtils;
@@ -563,8 +563,7 @@ public class RequestContext {
*/
public String getContextUrl(String relativeUrl, Map<String, ?> params) {
String url = getContextPath() + relativeUrl;
UriTemplate template = new UriTemplate(url);
url = template.expand(params).toASCIIString();
url = UriComponentsBuilder.fromUriString(url).buildAndExpand(params).encode().toUri().toASCIIString();
if (this.response != null) {
url = this.response.encodeURL(url);
}