Dropped RequestEntity's template variable methods in order to remove dependencies on org.springframework.web
Instead, as outlined in the revised javadoc, let's recommend manual UriTemplate usage for RequestEntity URI input. Issue: SPR-11752
This commit is contained in:
@@ -19,12 +19,10 @@ package org.springframework.http;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.util.UriTemplate;
|
||||
|
||||
/**
|
||||
* Extension of {@link HttpEntity} that adds a {@linkplain HttpMethod method} and
|
||||
@@ -35,10 +33,17 @@ import org.springframework.web.util.UriTemplate;
|
||||
* {@link org.springframework.web.client.RestTemplate#exchange(RequestEntity, Class) exchange()}:
|
||||
* <pre class="code">
|
||||
* MyRequest body = ...
|
||||
* RequestEntity<MyRequest> request = RequestEntity.post("http://example.com/{foo}", "bar").accept(MediaType.APPLICATION_JSON).body(body);
|
||||
* RequestEntity<MyRequest> request = RequestEntity.post(new URI("http://example.com/bar").accept(MediaType.APPLICATION_JSON).body(body);
|
||||
* ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
|
||||
* </pre>
|
||||
*
|
||||
* <p>If you would like to provide a URI template with variables, consider using
|
||||
* {@link org.springframework.web.util.UriTemplate}:
|
||||
* <pre class="code">
|
||||
* URI uri = new UriTemplate("http://example.com/{foo}"").expand("bar");
|
||||
* RequestEntity<MyRequest> request = RequestEntity.post(uri).accept(MediaType.APPLICATION_JSON).body(body);
|
||||
* </pre>
|
||||
*
|
||||
* <p>Can also be used in Spring MVC, as a parameter in a @Controller method:
|
||||
* <pre class="code">
|
||||
* @RequestMapping("/handle")
|
||||
@@ -169,32 +174,6 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
|
||||
// Static builder methods
|
||||
|
||||
/**
|
||||
* Create a builder with the given method, url, and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param method the HTTP method (GET, POST, etc)
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static BodyBuilder method(HttpMethod method, String url, Object... uriVariables) {
|
||||
URI expanded = new UriTemplate(url).expand(uriVariables);
|
||||
return new DefaultBodyBuilder(method, expanded);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder with the given method, url, and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param method the HTTP method (GET, POST, etc)
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static BodyBuilder method(HttpMethod method, String url, Map<String, ?> uriVariables) {
|
||||
URI expanded = new UriTemplate(url).expand(uriVariables);
|
||||
return new DefaultBodyBuilder(method, expanded);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder with the given method and url.
|
||||
* @param method the HTTP method (GET, POST, etc)
|
||||
@@ -205,31 +184,8 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
return new DefaultBodyBuilder(method, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a GET builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static HeadersBuilder<?> get(String url, Object... uriVariables) {
|
||||
return method(HttpMethod.GET, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP GET builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static HeadersBuilder<?> get(String url, Map<String, ?> uriVariables) {
|
||||
return method(HttpMethod.GET, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP GET builder with the given url.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @return the created builder
|
||||
*/
|
||||
@@ -237,28 +193,6 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
return method(HttpMethod.GET, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP HEAD builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static HeadersBuilder<?> head(String url, Object... uriVariables) {
|
||||
return method(HttpMethod.HEAD, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP HEAD builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static HeadersBuilder<?> head(String url, Map<String, ?> uriVariables) {
|
||||
return method(HttpMethod.HEAD, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP HEAD builder with the given url.
|
||||
* @param url the URL
|
||||
@@ -268,28 +202,6 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
return method(HttpMethod.HEAD, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP POST builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static BodyBuilder post(String url, Object... uriVariables) {
|
||||
return method(HttpMethod.POST, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP POST builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static BodyBuilder post(String url, Map<String, ?> uriVariables) {
|
||||
return method(HttpMethod.POST, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP POST builder with the given url.
|
||||
* @param url the URL
|
||||
@@ -299,28 +211,6 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
return method(HttpMethod.POST, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP PUT builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static BodyBuilder put(String url, Object... uriVariables) {
|
||||
return method(HttpMethod.PUT, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP PUT builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static BodyBuilder put(String url, Map<String, ?> uriVariables) {
|
||||
return method(HttpMethod.PUT, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP PUT builder with the given url.
|
||||
* @param url the URL
|
||||
@@ -330,28 +220,6 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
return method(HttpMethod.PUT, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP PATCH builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static BodyBuilder patch(String url, Object... uriVariables) {
|
||||
return method(HttpMethod.PATCH, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP PATCH builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static BodyBuilder patch(String url, Map<String, ?> uriVariables) {
|
||||
return method(HttpMethod.PATCH, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP PATCH builder with the given url.
|
||||
* @param url the URL
|
||||
@@ -361,28 +229,6 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
return method(HttpMethod.PATCH, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP DELETE builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static HeadersBuilder<?> delete(String url, Object... uriVariables) {
|
||||
return method(HttpMethod.DELETE, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP DELETE builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static HeadersBuilder<?> delete(String url, Map<String, ?> uriVariables) {
|
||||
return method(HttpMethod.DELETE, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP DELETE builder with the given url.
|
||||
* @param url the URL
|
||||
@@ -392,28 +238,6 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
return method(HttpMethod.DELETE, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP OPTIONS builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static HeadersBuilder<?> options(String url, Object... uriVariables) {
|
||||
return method(HttpMethod.OPTIONS, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an HTTP OPTIONS builder with the given url and uri variables.
|
||||
* <p>URI Template variables are expanded using the given URI variables, if any.
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the created builder
|
||||
*/
|
||||
public static HeadersBuilder<?> options(String url, Map<String, ?> uriVariables) {
|
||||
return method(HttpMethod.OPTIONS, url, uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an HTTP OPTIONS builder with the given url.
|
||||
* @param url the URL
|
||||
|
||||
Reference in New Issue
Block a user