|
|
|
|
@ -24,42 +24,44 @@ import org.springframework.http.HttpHeaders;
@@ -24,42 +24,44 @@ import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Interface specifying a basic set of RESTful operations. Implemented by {@link RestTemplate}. Not often used directly, |
|
|
|
|
* but a useful option to enhance testability, as it can easily be mocked or stubbed. |
|
|
|
|
* Interface specifying a basic set of RESTful operations. Implemented by {@link RestTemplate}. |
|
|
|
|
* Not often used directly, but a useful option to enhance testability, as it can easily |
|
|
|
|
* be mocked or stubbed. |
|
|
|
|
* |
|
|
|
|
* @author Arjen Poutsma |
|
|
|
|
* @see RestTemplate |
|
|
|
|
* @author Juergen Hoeller |
|
|
|
|
* @since 3.0 |
|
|
|
|
* @see RestTemplate |
|
|
|
|
*/ |
|
|
|
|
public interface RestOperations { |
|
|
|
|
|
|
|
|
|
// GET
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieve a representation by doing a GET on the specified URL. The response (if any) is converted and returned. |
|
|
|
|
* Retrieve a representation by doing a GET on the specified URL. |
|
|
|
|
* The response (if any) is converted and returned. |
|
|
|
|
* <p>URI Template variables are expanded using the given URI variables, if any. |
|
|
|
|
* |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param responseType the type of the return value |
|
|
|
|
* @param uriVariables the variables to expand the template |
|
|
|
|
* @return the converted object |
|
|
|
|
*/ |
|
|
|
|
<T> T getForObject(String url, Class<T> responseType, String... uriVariables) throws RestClientException; |
|
|
|
|
<T> T getForObject(String url, Class<T> responseType, Object... uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieve a representation by doing a GET on the URI template. The response (if any) is converted and returned. |
|
|
|
|
* Retrieve a representation by doing a GET on the URI template. |
|
|
|
|
* The response (if any) is converted and returned. |
|
|
|
|
* <p>URI Template variables are expanded using the given map. |
|
|
|
|
* |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param responseType the type of the return value |
|
|
|
|
* @param uriVariables the map containing variables for the URI template |
|
|
|
|
* @return the converted object |
|
|
|
|
*/ |
|
|
|
|
<T> T getForObject(String url, Class<T> responseType, Map<String, String> uriVariables) throws RestClientException; |
|
|
|
|
<T> T getForObject(String url, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieve a representation by doing a GET on the URL . The response (if any) is converted and returned. |
|
|
|
|
* |
|
|
|
|
* Retrieve a representation by doing a GET on the URL . |
|
|
|
|
* The response (if any) is converted and returned. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param responseType the type of the return value |
|
|
|
|
* @return the converted object |
|
|
|
|
@ -69,28 +71,25 @@ public interface RestOperations {
@@ -69,28 +71,25 @@ public interface RestOperations {
|
|
|
|
|
// HEAD
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieve all headers of the resource specified by the URI template. <p>URI Template variables are expanded using the |
|
|
|
|
* given URI variables, if any. |
|
|
|
|
* |
|
|
|
|
* Retrieve all headers of the resource specified by the URI template. |
|
|
|
|
* <p>URI Template variables are expanded using the given URI variables, if any. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param uriVariables the variables to expand the template |
|
|
|
|
* @return all HTTP headers of that resource |
|
|
|
|
*/ |
|
|
|
|
HttpHeaders headForHeaders(String url, String... uriVariables) throws RestClientException; |
|
|
|
|
HttpHeaders headForHeaders(String url, Object... uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieve all headers of the resource specified by the URI template. <p>URI Template variables are expanded using the |
|
|
|
|
* given map. |
|
|
|
|
* |
|
|
|
|
* Retrieve all headers of the resource specified by the URI template. |
|
|
|
|
* <p>URI Template variables are expanded using the given map. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param uriVariables the map containing variables for the URI template |
|
|
|
|
* @return all HTTP headers of that resource |
|
|
|
|
*/ |
|
|
|
|
HttpHeaders headForHeaders(String url, Map<String, String> uriVariables) throws RestClientException; |
|
|
|
|
HttpHeaders headForHeaders(String url, Map<String, ?> uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieve all headers of the resource specified by the URL. |
|
|
|
|
* |
|
|
|
|
* @param url the URL |
|
|
|
|
* @return all HTTP headers of that resource |
|
|
|
|
*/ |
|
|
|
|
@ -100,32 +99,29 @@ public interface RestOperations {
@@ -100,32 +99,29 @@ public interface RestOperations {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new resource by POSTing the given object to the URI template, and returns the value of the |
|
|
|
|
* <code>Location</code> header. This header typically indicates where the new resource is stored. <p>URI Template |
|
|
|
|
* variables are expanded using the given URI variables, if any. |
|
|
|
|
* |
|
|
|
|
* <code>Location</code> header. This header typically indicates where the new resource is stored. |
|
|
|
|
* <p>URI Template variables are expanded using the given URI variables, if any. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param request the Object to be POSTed, may be <code>null</code> |
|
|
|
|
* @param uriVariables the variables to expand the template |
|
|
|
|
* @return the value for the <code>Location</code> header |
|
|
|
|
*/ |
|
|
|
|
URI postForLocation(String url, Object request, String... uriVariables) throws RestClientException; |
|
|
|
|
URI postForLocation(String url, Object request, Object... uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new resource by POSTing the given object to the URI template, and returns the value of the |
|
|
|
|
* <code>Location</code> header. This header typically indicates where the new resource is stored. <p>URI Template |
|
|
|
|
* variables are expanded using the given map. |
|
|
|
|
* |
|
|
|
|
* <code>Location</code> header. This header typically indicates where the new resource is stored. |
|
|
|
|
* <p>URI Template variables are expanded using the given map. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param request the Object to be POSTed, may be <code>null</code> |
|
|
|
|
* @param uriVariables the variables to expand the template |
|
|
|
|
* @return the value for the <code>Location</code> header |
|
|
|
|
*/ |
|
|
|
|
URI postForLocation(String url, Object request, Map<String, String> uriVariables) throws RestClientException; |
|
|
|
|
URI postForLocation(String url, Object request, Map<String, ?> uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new resource by POSTing the given object to the URL, and returns the value of the |
|
|
|
|
* <code>Location</code> header. This header typically indicates where the new resource is stored. |
|
|
|
|
* |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param request the Object to be POSTed, may be <code>null</code> |
|
|
|
|
* @return the value for the <code>Location</code> header |
|
|
|
|
@ -133,33 +129,32 @@ public interface RestOperations {
@@ -133,33 +129,32 @@ public interface RestOperations {
|
|
|
|
|
URI postForLocation(URI url, Object request) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new resource by POSTing the given object to the URI template, and returns the representation |
|
|
|
|
* found in the response. <p>URI Template variables are expanded using the given URI variables, if any. |
|
|
|
|
* |
|
|
|
|
* Create a new resource by POSTing the given object to the URI template, |
|
|
|
|
* and returns the representation found in the response. |
|
|
|
|
* <p>URI Template variables are expanded using the given URI variables, if any. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param request the Object to be POSTed, may be <code>null</code> |
|
|
|
|
* @param uriVariables the variables to expand the template |
|
|
|
|
* @return the converted object |
|
|
|
|
*/ |
|
|
|
|
<T> T postForObject(String url, Object request, Class<T> responseType, String... uriVariables) |
|
|
|
|
<T> T postForObject(String url, Object request, Class<T> responseType, Object... uriVariables) |
|
|
|
|
throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new resource by POSTing the given object to the URI template, and returns the representation |
|
|
|
|
* found in the response. <p>URI Template variables are expanded using the given map. |
|
|
|
|
* |
|
|
|
|
* Create a new resource by POSTing the given object to the URI template, |
|
|
|
|
* and returns the representation found in the response. |
|
|
|
|
* <p>URI Template variables are expanded using the given map. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param request the Object to be POSTed, may be <code>null</code> |
|
|
|
|
* @param uriVariables the variables to expand the template |
|
|
|
|
* @return the converted object |
|
|
|
|
*/ |
|
|
|
|
<T> T postForObject(String url, Object request, Class<T> responseType, Map<String, String> uriVariables) |
|
|
|
|
<T> T postForObject(String url, Object request, Class<T> responseType, Map<String, ?> uriVariables) |
|
|
|
|
throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new resource by POSTing the given object to the URL, and returns the representation |
|
|
|
|
* found in the response. |
|
|
|
|
* |
|
|
|
|
* Create a new resource by POSTing the given object to the URL, |
|
|
|
|
* and returns the representation found in the response. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param request the Object to be POSTed, may be <code>null</code> |
|
|
|
|
* @return the converted object |
|
|
|
|
@ -169,28 +164,25 @@ public interface RestOperations {
@@ -169,28 +164,25 @@ public interface RestOperations {
|
|
|
|
|
// PUT
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create or update a resource by PUTting the given object to the URI. <p>URI Template variables are expanded using the |
|
|
|
|
* given URI variables, if any. |
|
|
|
|
* |
|
|
|
|
* Create or update a resource by PUTting the given object to the URI. |
|
|
|
|
* <p>URI Template variables are expanded using the given URI variables, if any. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param request the Object to be PUT, may be <code>null</code> |
|
|
|
|
* @param uriVariables the variables to expand the template |
|
|
|
|
*/ |
|
|
|
|
void put(String url, Object request, String... uriVariables) throws RestClientException; |
|
|
|
|
void put(String url, Object request, Object... uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creates a new resource by PUTting the given object to URI template. <p>URI Template variables are expanded using the |
|
|
|
|
* given map. |
|
|
|
|
* |
|
|
|
|
* Creates a new resource by PUTting the given object to URI template. |
|
|
|
|
* <p>URI Template variables are expanded using the given map. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param request the Object to be PUT, may be <code>null</code> |
|
|
|
|
* @param uriVariables the variables to expand the template |
|
|
|
|
*/ |
|
|
|
|
void put(String url, Object request, Map<String, String> uriVariables) throws RestClientException; |
|
|
|
|
void put(String url, Object request, Map<String, ?> uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creates a new resource by PUTting the given object to URL. |
|
|
|
|
* |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param request the Object to be PUT, may be <code>null</code> |
|
|
|
|
*/ |
|
|
|
|
@ -199,25 +191,24 @@ public interface RestOperations {
@@ -199,25 +191,24 @@ public interface RestOperations {
|
|
|
|
|
// DELETE
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Delete the resources at the specified URI. <p>URI Template variables are expanded using the given URI variables, if |
|
|
|
|
* any. |
|
|
|
|
* |
|
|
|
|
* Delete the resources at the specified URI. |
|
|
|
|
* <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 |
|
|
|
|
*/ |
|
|
|
|
void delete(String url, String... uriVariables) throws RestClientException; |
|
|
|
|
void delete(String url, Object... uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Delete the resources at the specified URI. <p>URI Template variables are expanded using the given map. |
|
|
|
|
* Delete the resources at the specified URI. |
|
|
|
|
* <p>URI Template variables are expanded using the given map. |
|
|
|
|
* |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param uriVariables the variables to expand the template |
|
|
|
|
*/ |
|
|
|
|
void delete(String url, Map<String, String> uriVariables) throws RestClientException; |
|
|
|
|
void delete(String url, Map<String, ?> uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Delete the resources at the specified URL. |
|
|
|
|
* |
|
|
|
|
* @param url the URL |
|
|
|
|
*/ |
|
|
|
|
void delete(URI url) throws RestClientException; |
|
|
|
|
@ -225,27 +216,25 @@ public interface RestOperations {
@@ -225,27 +216,25 @@ public interface RestOperations {
|
|
|
|
|
// OPTIONS
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return the value of the Allow header for the given URI. <p>URI Template variables are expanded using the given URI |
|
|
|
|
* variables, if any. |
|
|
|
|
* |
|
|
|
|
* Return the value of the Allow header for the given URI. |
|
|
|
|
* <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 value of the allow header |
|
|
|
|
*/ |
|
|
|
|
Set<HttpMethod> optionsForAllow(String url, String... uriVariables) throws RestClientException; |
|
|
|
|
Set<HttpMethod> optionsForAllow(String url, Object... uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return the value of the Allow header for the given URI. <p>URI Template variables are expanded using the given map. |
|
|
|
|
* |
|
|
|
|
* Return the value of the Allow header for the given URI. |
|
|
|
|
* <p>URI Template variables are expanded using the given map. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param uriVariables the variables to expand in the template |
|
|
|
|
* @return the value of the allow header |
|
|
|
|
*/ |
|
|
|
|
Set<HttpMethod> optionsForAllow(String url, Map<String, String> uriVariables) throws RestClientException; |
|
|
|
|
Set<HttpMethod> optionsForAllow(String url, Map<String, ?> uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return the value of the Allow header for the given URL. |
|
|
|
|
* |
|
|
|
|
* @param url the URL |
|
|
|
|
* @return the value of the allow header |
|
|
|
|
*/ |
|
|
|
|
@ -254,10 +243,9 @@ public interface RestOperations {
@@ -254,10 +243,9 @@ public interface RestOperations {
|
|
|
|
|
// general execution
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Execute the HTTP methods to the given URI template, preparing the request with the {@link RequestCallback}, and reading the |
|
|
|
|
* response with a {@link ResponseExtractor}. <p>URI Template variables are expanded using the given URI variables, if |
|
|
|
|
* any. |
|
|
|
|
* |
|
|
|
|
* Execute the HTTP methods to the given URI template, preparing the request with the |
|
|
|
|
* {@link RequestCallback}, and reading the response with a{@link ResponseExtractor}. |
|
|
|
|
* <p>URI Template variables are expanded using the given URI variables, if any. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param method the HTTP method (GET, POST, etc) |
|
|
|
|
* @param requestCallback object that prepares the request |
|
|
|
|
@ -265,17 +253,13 @@ public interface RestOperations {
@@ -265,17 +253,13 @@ public interface RestOperations {
|
|
|
|
|
* @param uriVariables the variables to expand in the template |
|
|
|
|
* @return an arbitrary object, as returned by the {@link ResponseExtractor} |
|
|
|
|
*/ |
|
|
|
|
<T> T execute(String url, |
|
|
|
|
HttpMethod method, |
|
|
|
|
RequestCallback requestCallback, |
|
|
|
|
ResponseExtractor<T> responseExtractor, |
|
|
|
|
String... uriVariables) throws RestClientException; |
|
|
|
|
<T> T execute(String url, HttpMethod method, RequestCallback requestCallback, |
|
|
|
|
ResponseExtractor<T> responseExtractor, Object... uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Execute the HTTP methods to the given URI template, preparing the request with the {@link RequestCallback}, and reading the |
|
|
|
|
* response with a {@link ResponseExtractor}. <p>URI Template variables are expanded using the given URI variables |
|
|
|
|
* map. |
|
|
|
|
* |
|
|
|
|
* Execute the HTTP methods to the given URI template, preparing the request with the |
|
|
|
|
* {@link RequestCallback}, and reading the response with a {@link ResponseExtractor}. |
|
|
|
|
* <p>URI Template variables are expanded using the given URI variables map. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param method the HTTP method (GET, POST, etc) |
|
|
|
|
* @param requestCallback object that prepares the request |
|
|
|
|
@ -283,25 +267,19 @@ public interface RestOperations {
@@ -283,25 +267,19 @@ public interface RestOperations {
|
|
|
|
|
* @param uriVariables the variables to expand in the template |
|
|
|
|
* @return an arbitrary object, as returned by the {@link ResponseExtractor} |
|
|
|
|
*/ |
|
|
|
|
<T> T execute(String url, |
|
|
|
|
HttpMethod method, |
|
|
|
|
RequestCallback requestCallback, |
|
|
|
|
ResponseExtractor<T> responseExtractor, |
|
|
|
|
Map<String, String> uriVariables) throws RestClientException; |
|
|
|
|
<T> T execute(String url, HttpMethod method, RequestCallback requestCallback, |
|
|
|
|
ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables) throws RestClientException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Execute the HTTP methods to the given URL, preparing the request with the {@link RequestCallback}, and reading the |
|
|
|
|
* response with a {@link ResponseExtractor}. |
|
|
|
|
* |
|
|
|
|
* Execute the HTTP methods to the given URL, preparing the request with the |
|
|
|
|
* {@link RequestCallback}, and reading the response with a {@link ResponseExtractor}. |
|
|
|
|
* @param url the URL |
|
|
|
|
* @param method the HTTP method (GET, POST, etc) |
|
|
|
|
* @param requestCallback object that prepares the request |
|
|
|
|
* @param responseExtractor object that extracts the return value from the response |
|
|
|
|
* @return an arbitrary object, as returned by the {@link ResponseExtractor} |
|
|
|
|
*/ |
|
|
|
|
<T> T execute(URI url, |
|
|
|
|
HttpMethod method, |
|
|
|
|
RequestCallback requestCallback, |
|
|
|
|
<T> T execute(URI url, HttpMethod method, RequestCallback requestCallback, |
|
|
|
|
ResponseExtractor<T> responseExtractor) throws RestClientException; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|