|
|
|
@ -60,55 +60,20 @@ import org.springframework.web.util.DefaultUriBuilderFactory; |
|
|
|
import org.springframework.web.util.UriTemplateHandler; |
|
|
|
import org.springframework.web.util.UriTemplateHandler; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* <strong>Spring's central class for synchronous client-side HTTP access.</strong> |
|
|
|
* Synchronous client to perform HTTP requests, exposing a simple, template |
|
|
|
* It simplifies communication with HTTP servers, and enforces RESTful principles. |
|
|
|
* method API over underlying HTTP client libraries such as the JDK |
|
|
|
* It handles HTTP connections, leaving application code to provide URLs |
|
|
|
* {@code HttpURLConnection}, Apache HttpComponents, and others. |
|
|
|
* (with possible template variables) and extract results. |
|
|
|
|
|
|
|
* |
|
|
|
* |
|
|
|
* <p><strong>Note:</strong> by default the RestTemplate relies on standard JDK |
|
|
|
* <p>The RestTemplate offers templates for common scenarios by HTTP method, in |
|
|
|
* facilities to establish HTTP connections. You can switch to use a different |
|
|
|
* addition to the generalized {@code exchange} and {@code execute} methods that |
|
|
|
* HTTP library such as Apache HttpComponents, Netty, and OkHttp through the |
|
|
|
* support of less frequent cases. |
|
|
|
* {@link #setRequestFactory} property. |
|
|
|
|
|
|
|
* |
|
|
|
* |
|
|
|
* <p>The main entry points of this template are the methods named after the six main HTTP methods: |
|
|
|
* <p><strong>NOTE:</strong> As of 5.0, the non-blocking, reactive |
|
|
|
* <table> |
|
|
|
* {@link org.springframework.web.reactive.client.WebClient WebClient} offers a |
|
|
|
* <tr><th>HTTP method</th><th>RestTemplate methods</th></tr> |
|
|
|
* modern alternative to the {@code RestTemplate} with efficient support for |
|
|
|
* <tr><td>DELETE</td><td>{@link #delete}</td></tr> |
|
|
|
* both sync and async, as well as streaming scenarios. The {@code RestTemplate} |
|
|
|
* <tr><td>GET</td><td>{@link #getForObject}</td></tr> |
|
|
|
* will be deprecated in a future version and will not have major new features |
|
|
|
* <tr><td></td><td>{@link #getForEntity}</td></tr> |
|
|
|
* gong forward. |
|
|
|
* <tr><td>HEAD</td><td>{@link #headForHeaders}</td></tr> |
|
|
|
|
|
|
|
* <tr><td>OPTIONS</td><td>{@link #optionsForAllow}</td></tr> |
|
|
|
|
|
|
|
* <tr><td>POST</td><td>{@link #postForLocation}</td></tr> |
|
|
|
|
|
|
|
* <tr><td></td><td>{@link #postForObject}</td></tr> |
|
|
|
|
|
|
|
* <tr><td>PUT</td><td>{@link #put}</td></tr> |
|
|
|
|
|
|
|
* <tr><td>any</td><td>{@link #exchange}</td></tr> |
|
|
|
|
|
|
|
* <tr><td></td><td>{@link #execute}</td></tr> </table> |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p>In addition the {@code exchange} and {@code execute} methods are generalized versions of |
|
|
|
|
|
|
|
* the above methods and can be used to support additional, less frequent combinations (e.g. |
|
|
|
|
|
|
|
* HTTP PATCH, HTTP PUT with response body, etc.). Note however that the underlying HTTP |
|
|
|
|
|
|
|
* library used must also support the desired combination. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> For URI templates it is assumed encoding is necessary, e.g. |
|
|
|
|
|
|
|
* {@code restTemplate.getForObject("http://example.com/hotel list")} becomes |
|
|
|
|
|
|
|
* {@code "http://example.com/hotel%20list"}. This also means if the URI template |
|
|
|
|
|
|
|
* or URI variables are already encoded, double encoding will occur, e.g. |
|
|
|
|
|
|
|
* {@code http://example.com/hotel%20list} becomes
|
|
|
|
|
|
|
|
* {@code http://example.com/hotel%2520list}). To avoid that use a {@code URI} method
|
|
|
|
|
|
|
|
* variant to provide (or re-use) a previously encoded URI. To prepare such an URI |
|
|
|
|
|
|
|
* with full control over encoding, consider using |
|
|
|
|
|
|
|
* {@link org.springframework.web.util.UriComponentsBuilder}. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p>Internally the template uses {@link HttpMessageConverter} instances to |
|
|
|
|
|
|
|
* convert HTTP messages to and from POJOs. Converters for the main mime types |
|
|
|
|
|
|
|
* are registered by default but you can also register additional converters |
|
|
|
|
|
|
|
* via {@link #setMessageConverters}. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p>This template uses a |
|
|
|
|
|
|
|
* {@link org.springframework.http.client.SimpleClientHttpRequestFactory} and a |
|
|
|
|
|
|
|
* {@link DefaultResponseErrorHandler} as default strategies for creating HTTP |
|
|
|
|
|
|
|
* connections or handling HTTP errors, respectively. These defaults can be overridden |
|
|
|
|
|
|
|
* through {@link #setRequestFactory} and {@link #setErrorHandler} respectively. |
|
|
|
|
|
|
|
* |
|
|
|
* |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Brian Clozel |
|
|
|
* @author Brian Clozel |
|
|
|
@ -119,7 +84,6 @@ import org.springframework.web.util.UriTemplateHandler; |
|
|
|
* @see RequestCallback |
|
|
|
* @see RequestCallback |
|
|
|
* @see ResponseExtractor |
|
|
|
* @see ResponseExtractor |
|
|
|
* @see ResponseErrorHandler |
|
|
|
* @see ResponseErrorHandler |
|
|
|
* @see AsyncRestTemplate |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class RestTemplate extends InterceptingHttpAccessor implements RestOperations { |
|
|
|
public class RestTemplate extends InterceptingHttpAccessor implements RestOperations { |
|
|
|
|
|
|
|
|
|
|
|
|