Update RestTemplate Javadoc

Issue: SPR-10497
This commit is contained in:
Rossen Stoyanchev 2014-07-31 17:02:30 -04:00
parent e4182da4eb
commit c4d7976c37
1 changed files with 24 additions and 39 deletions

View File

@ -72,48 +72,33 @@ import org.springframework.web.util.UriTemplate;
* <tr><td>any</td><td>{@link #exchange}</td></tr> * <tr><td>any</td><td>{@link #exchange}</td></tr>
* <tr><td></td><td>{@link #execute}</td></tr> </table> * <tr><td></td><td>{@link #execute}</td></tr> </table>
* *
* <p>The {@code exchange} and {@code execute} methods are generalized versions of the more specific methods listed * <p>In addition the {@code exchange} and {@code execute} methods are generalized versions of
* above them. They support additional, less frequently used combinations including support for requests using the * the above methods and can be used to support additional, less frequent combinations (e.g.
* HTTP PATCH method. However, note that the underlying HTTP library must also support the desired combination. * HTTP PATCH, HTTP PUT with response body, etc.). Note however that the underlying HTTP
* library used must also support the desired combination.
* *
* <p>For each of these HTTP methods, there are three corresponding Java methods in the {@code RestTemplate}. * <p>For each HTTP method there are 3 variants -- two accept a URI template string
* Two variants take a {@code String} URI as first argument (eg. {@link #getForObject(String, Class, Object[])}, * and URI variables (array or map) while a third accepts a {@link URI}.
* {@link #getForObject(String, Class, Map)}), and are capable of substituting any {@linkplain UriTemplate URI templates} * Note that for URI templates it is assumed encoding is necessary, e.g.
* in that URL using either a {@code String} variable arguments array, or a {@code Map<String, String>}. * {@code restTemplate.getForObject("http://example.com/hotel list")} becomes
* The string varargs variant expands the given template variables in order, so that * {@code "http://example.com/hotel%20list"}. This also means if the URI template
* <pre class="code"> * or URI variables are already encoded, double encoding will occur, e.g.
* String result = restTemplate.getForObject("http://example.com/hotels/{hotel}/bookings/{booking}", String.class, "42", * {@code http://example.com/hotel%20list} becomes
* "21"); * {@code http://example.com/hotel%2520list}). To avoid that use a {@code URI} method
* </pre> * variant to provide (or re-use) a previously encoded URI. To prepare such an URI
* will perform a GET on {@code http://example.com/hotels/42/bookings/21}. The map variant expands the template based * with full control over encoding, consider using
* on variable name, and is therefore more useful when using many variables, or when a single variable is used multiple * {@link org.springframework.web.util.UriComponentsBuilder}.
* times. For example:
* <pre class="code">
* Map&lt;String, String&gt; vars = Collections.singletonMap("hotel", "42");
* String result = restTemplate.getForObject("http://example.com/hotels/{hotel}/rooms/{hotel}", String.class, vars);
* </pre>
* will perform a GET on {@code http://example.com/hotels/42/rooms/42}. Alternatively, there are {@link URI} variant
* methods ({@link #getForObject(URI, Class)}), which do not allow for URI templates, but allow you to reuse a single,
* expanded URI multiple times.
* *
* <p>Furthermore, the {@code String}-argument methods assume that the URL String is unencoded. This means that * <p>Internally the template uses {@link HttpMessageConverter} instances to
* <pre class="code"> * convert HTTP messages to and from POJOs. Converters for the main mime types
* restTemplate.getForObject("http://example.com/hotel list"); * are registered by default but you can also register additional converters
* </pre> * via {@link #setMessageConverters}.
* will perform a GET on {@code http://example.com/hotel%20list}. As a result, any URL passed that is already encoded
* will be encoded twice (i.e. {@code http://example.com/hotel%20list} will become {@code
* http://example.com/hotel%2520list}). If this behavior is undesirable, use the {@code URI}-argument methods, which
* will not perform any URL encoding.
* *
* <p>Objects passed to and returned from these methods are converted to and from HTTP messages by * <p>This template uses a
* {@link HttpMessageConverter} instances. Converters for the main mime types are registered by default, * {@link org.springframework.http.client.SimpleClientHttpRequestFactory} and a
* but you can also write your own converter and register it via the {@link #setMessageConverters messageConverters} * {@link DefaultResponseErrorHandler} as default strategies for creating HTTP
* bean property. * connections or handling HTTP errors, respectively. These defaults can be overridden
* * through {@link #setRequestFactory} and {@link #setErrorHandler} respectively.
* <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 the {@link #setRequestFactory(ClientHttpRequestFactory)
* requestFactory} and {@link #setErrorHandler(ResponseErrorHandler) errorHandler} bean properties.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @author Brian Clozel * @author Brian Clozel