le.com/hotels/{hotel}/bookings/{booking}", String.class,"42", "21"); will perform a GET on {@code http://example.com/hotels/42/bookings/21}. The map variant expands the template based on variable name, and is therefore more useful when using many variables, or when a single variable is used multiple times. For example:
Map<String, String> vars = Collections.singletonMap("hotel", "42"); String result = restTemplate.getForObject("http://example.com/hotels/{hotel}/rooms/{hotel}", String.class, vars);
will perform a GET on {@code http://example.com/hotels/42/rooms/42}. Alternatively, there are {@link URI} variantmethods ( {@link #getForObject(URI,Class)}), which do not allow for URI templates, but allow you to reuse a single, expanded URI multiple times.
Furthermore, the {@code String}-argument methods assume that the URL String is unencoded. This means that
restTemplate.getForObject("http://example.com/hotel list");
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.
Objects passed to and returned from these methods are converted to and from HTTP messages by {@link HttpMessageConverter} instances. Converters for the main mime types are registered by default, but you can also writeyour own converter and register it via the {@link #setMessageConverters messageConverters} bean property.
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
@see HttpMessageConverter
@see RequestCallback
@see ResponseExtractor
@see ResponseErrorHandler
@since 3.0