Deprecate DefaultUriTemplate handler
Following on the introduction of the UriBuilderFactory and its DefaultUriBuilderFactory implementation, this commit deprecates DefaultUriTemplate (and AbstractUriTemplateHandler). The new DefaultUriBuilderFactory has comparable functionality and is more flexible but cannot be merged into the existing hierarchy and be backwards compatible with regards to protected methods. Issue: SPR-15124
This commit is contained in:
@@ -45,6 +45,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureAdapter;
|
||||
import org.springframework.web.util.AbstractUriTemplateHandler;
|
||||
import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||
import org.springframework.web.util.UriTemplateHandler;
|
||||
|
||||
/**
|
||||
@@ -163,9 +164,16 @@ public class AsyncRestTemplate extends InterceptingAsyncHttpAccessor implements
|
||||
*/
|
||||
public void setDefaultUriVariables(Map<String, ?> defaultUriVariables) {
|
||||
UriTemplateHandler handler = this.syncTemplate.getUriTemplateHandler();
|
||||
Assert.isInstanceOf(AbstractUriTemplateHandler.class, handler,
|
||||
"Can only use this property in conjunction with a DefaultUriTemplateHandler");
|
||||
((AbstractUriTemplateHandler) handler).setDefaultUriVariables(defaultUriVariables);
|
||||
if (handler instanceof DefaultUriBuilderFactory) {
|
||||
((DefaultUriBuilderFactory) handler).setDefaultUriVariables(defaultUriVariables);
|
||||
}
|
||||
else if (handler instanceof AbstractUriTemplateHandler) {
|
||||
((AbstractUriTemplateHandler) handler).setDefaultUriVariables(defaultUriVariables);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"This property is not supported with the configured UriTemplateHandler.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,7 +53,7 @@ import org.springframework.http.converter.xml.SourceHttpMessageConverter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.web.util.AbstractUriTemplateHandler;
|
||||
import org.springframework.web.util.DefaultUriTemplateHandler;
|
||||
import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||
import org.springframework.web.util.UriTemplateHandler;
|
||||
|
||||
/**
|
||||
@@ -149,7 +149,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
|
||||
private ResponseErrorHandler errorHandler = new DefaultResponseErrorHandler();
|
||||
|
||||
private UriTemplateHandler uriTemplateHandler = new DefaultUriTemplateHandler();
|
||||
private UriTemplateHandler uriTemplateHandler = new DefaultUriBuilderFactory();
|
||||
|
||||
private final ResponseExtractor<HttpHeaders> headersExtractor = new HeadersExtractor();
|
||||
|
||||
@@ -254,24 +254,31 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
/**
|
||||
* Configure default URI variable values. This is a shortcut for:
|
||||
* <pre class="code">
|
||||
* DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
|
||||
* DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory();
|
||||
* handler.setDefaultUriVariables(...);
|
||||
*
|
||||
* RestTemplate restTemplate = new RestTemplate();
|
||||
* restTemplate.setUriTemplateHandler(handler);
|
||||
* </pre>
|
||||
* @param defaultUriVariables the default URI variable values
|
||||
* @param uriVars the default URI variable values
|
||||
* @since 4.3
|
||||
*/
|
||||
public void setDefaultUriVariables(Map<String, ?> defaultUriVariables) {
|
||||
Assert.isInstanceOf(AbstractUriTemplateHandler.class, this.uriTemplateHandler,
|
||||
"Can only use this property in conjunction with an AbstractUriTemplateHandler");
|
||||
((AbstractUriTemplateHandler) this.uriTemplateHandler).setDefaultUriVariables(defaultUriVariables);
|
||||
public void setDefaultUriVariables(Map<String, ?> uriVars) {
|
||||
if (this.uriTemplateHandler instanceof DefaultUriBuilderFactory) {
|
||||
((DefaultUriBuilderFactory) this.uriTemplateHandler).setDefaultUriVariables(uriVars);
|
||||
}
|
||||
else if (this.uriTemplateHandler instanceof AbstractUriTemplateHandler) {
|
||||
((AbstractUriTemplateHandler) this.uriTemplateHandler).setDefaultUriVariables(uriVars);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"This property is not supported with the configured UriTemplateHandler.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the {@link UriTemplateHandler} to use to expand URI templates.
|
||||
* By default the {@link DefaultUriTemplateHandler} is used which relies on
|
||||
* By default the {@link DefaultUriBuilderFactory} is used which relies on
|
||||
* Spring's URI template support and exposes several useful properties that
|
||||
* customize its behavior for encoding and for prepending a common base URL.
|
||||
* An alternative implementation may be used to plug an external URI
|
||||
|
||||
@@ -33,7 +33,9 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.3
|
||||
* @deprecated as of 5.0 in favor of {@link DefaultUriBuilderFactory}
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractUriTemplateHandler implements UriTemplateHandler {
|
||||
|
||||
private String baseUrl;
|
||||
|
||||
@@ -33,7 +33,9 @@ import java.util.Map;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.2
|
||||
* @deprecated as of 5.0 in favor of {@link DefaultUriBuilderFactory}
|
||||
*/
|
||||
@Deprecated
|
||||
public class DefaultUriTemplateHandler extends AbstractUriTemplateHandler {
|
||||
|
||||
private boolean parsePath;
|
||||
|
||||
@@ -455,8 +455,9 @@ final class HierarchicalUriComponents extends UriComponents {
|
||||
if (getHost() != null) {
|
||||
builder.host(getHost());
|
||||
}
|
||||
if (getPort() != -1) {
|
||||
builder.port(getPort());
|
||||
// Avoid parsing the port, may have URI variable..
|
||||
if (this.port != null) {
|
||||
builder.port(this.port);
|
||||
}
|
||||
if (getPath() != null) {
|
||||
this.path.copyToUriComponentsBuilder(builder);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -20,18 +20,14 @@ import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Strategy for expanding a URI template with full control over the URI template
|
||||
* syntax and the encoding of variables. Also a convenient central point for
|
||||
* pre-processing all URI templates for example to insert a common base path.
|
||||
* Strategy for expanding a URI template.
|
||||
*
|
||||
* <p>Supported as a property on the {@code RestTemplate} as well as the
|
||||
* {@code AsyncRestTemplate}. The {@link DefaultUriTemplateHandler} is built
|
||||
* on Spring's URI template support via {@link UriComponentsBuilder}. An
|
||||
* alternative implementation may be used to plug external URI template libraries.
|
||||
* {@code AsyncRestTemplate}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.2
|
||||
* @see org.springframework.web.client.RestTemplate#setUriTemplateHandler
|
||||
* @see DefaultUriBuilderFactory
|
||||
*/
|
||||
public interface UriTemplateHandler {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user