Class TestRestTemplate
RestTemplate that is suitable for integration tests.
TestRestTemplate is fault-tolerant. This means that 4xx and 5xx do not result
in an exception being thrown and can instead be detected through the
response entity and its status code.
A TestRestTemplate can optionally carry Basic authentication headers. If Apache
Http Client 4.3.2 or better is available (recommended) it will be used as the client.
Note: To prevent injection problems this class intentionally does not extend
RestTemplate. If you need access to the underlying RestTemplate use
getRestTemplate().
If you are using the @SpringBootTest annotation with an embedded server, a
TestRestTemplate can be auto-configured by adding
@AutoConfigureTestRestTemplate to your test
class. It can then be @Autowired into your test. If you need customizations
(for example to adding additional message converters) use a RestTemplateBuilder
@Bean.
- Since:
- 4.0.0
- Author:
- Dave Syer, Phillip Webb, Andy Wilkinson, Kristine Jetzke, Dmytro Nosan, Yanming Zhou
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDeprecated, for removal: This API element is subject to removal in a future version.Options used to customize the Apache HTTP Client. -
Constructor Summary
ConstructorsConstructorDescriptionTestRestTemplate(@Nullable String username, @Nullable String password, TestRestTemplate.HttpClientOption... httpClientOptions) Deprecated, for removal: This API element is subject to removal in a future version.Create a newTestRestTemplateinstance with the specified credentials.TestRestTemplate(RestTemplateBuilder restTemplateBuilder) Deprecated, for removal: This API element is subject to removal in a future version.Create a newTestRestTemplateinstance.TestRestTemplate(RestTemplateBuilder builder, @Nullable String username, @Nullable String password, TestRestTemplate.HttpClientOption... httpClientOptions) Deprecated, for removal: This API element is subject to removal in a future version.Create a newTestRestTemplateinstance with the specified credentials.TestRestTemplate(TestRestTemplate.HttpClientOption... httpClientOptions) Deprecated, for removal: This API element is subject to removal in a future version.Create a newTestRestTemplateinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated, for removal: This API element is subject to removal in a future version.Delete the resources at the specified URI.voidDeprecated, for removal: This API element is subject to removal in a future version.Delete the resources at the specified URI.voidDeprecated, for removal: This API element is subject to removal in a future version.Delete the resources at the specified URL.<T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, Class<T> responseType, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ResponseEntity<T> exchange(URI url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, Class<T> responseType) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ResponseEntity<T> exchange(URI url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity, Class<T> responseType) Deprecated, for removal: This API element is subject to removal in a future version.Execute the request specified in the givenRequestEntityand return the response asResponseEntity.<T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity, ParameterizedTypeReference<T> responseType) Deprecated, for removal: This API element is subject to removal in a future version.Execute the request specified in the givenRequestEntityand return the response asResponseEntity.<T> @Nullable Texecute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, preparing the request with theRequestCallback, and reading the response with aResponseExtractor.<T> @Nullable Texecute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, preparing the request with theRequestCallback, and reading the response with aResponseExtractor.<T> @Nullable Texecute(URI url, HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor<T> responseExtractor) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URL, preparing the request with theRequestCallback, and reading the response with aResponseExtractor.<T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Retrieve an entity by doing a GET on the specified URL.<T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Retrieve a representation by doing a GET on the URI template.<T> ResponseEntity<T> getForEntity(URI url, Class<T> responseType) Deprecated, for removal: This API element is subject to removal in a future version.Retrieve a representation by doing a GET on the URL .<T> @Nullable TgetForObject(String url, Class<T> responseType, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Retrieve a representation by doing a GET on the specified URL.<T> @Nullable TgetForObject(String url, Class<T> responseType, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Retrieve a representation by doing a GET on the URI template.<T> @Nullable TgetForObject(URI url, Class<T> responseType) Deprecated, for removal: This API element is subject to removal in a future version.Retrieve a representation by doing a GET on the URL .Deprecated, for removal: This API element is subject to removal in a future version.Returns the underlyingRestTemplatethat is actually used to perform the REST operations.@Nullable StringDeprecated, for removal: This API element is subject to removal in a future version.Returns the root URI applied byRestTemplateBuilder.baseUri(String)or""if the root URI has not been applied.headForHeaders(String url, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Retrieve all headers of the resource specified by the URI template.headForHeaders(String url, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Retrieve all headers of the resource specified by the URI template.headForHeaders(URI url) Deprecated, for removal: This API element is subject to removal in a future version.Retrieve all headers of the resource specified by the URL.optionsForAllow(String url, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Return the value of theAllowheader for the given URI.optionsForAllow(String url, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Return the value of theAllowheader for the given URI.optionsForAllow(URI url) Deprecated, for removal: This API element is subject to removal in a future version.Return the value of theAllowheader for the given URL.<T> @Nullable TpatchForObject(String url, @Nullable Object request, Class<T> responseType, Object... uriVariables) Deprecated, for removal: This API element is subject to removal in a future version.Update a resource by PATCHing the given object to the URI template, and returns the representation found in the response.<T> @Nullable TpatchForObject(String url, @Nullable Object request, Class<T> responseType, Map<String, ?> uriVariables) Deprecated, for removal: This API element is subject to removal in a future version.Update a resource by PATCHing the given object to the URI template, and returns the representation found in the response.<T> @Nullable TpatchForObject(URI url, @Nullable Object request, Class<T> responseType) Deprecated, for removal: This API element is subject to removal in a future version.Update a resource by PATCHing the given object to the URL, and returns the representation found in the response.<T> ResponseEntity<T> postForEntity(String url, @Nullable Object request, Class<T> responseType, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URI template, and returns the response asResponseEntity.<T> ResponseEntity<T> postForEntity(String url, @Nullable Object request, Class<T> responseType, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URI template, and returns the response asHttpEntity.<T> ResponseEntity<T> postForEntity(URI url, @Nullable Object request, Class<T> responseType) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URL, and returns the response asResponseEntity.@Nullable URIpostForLocation(String url, @Nullable Object request, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URI template, and returns the value of theLocationheader.@Nullable URIpostForLocation(String url, @Nullable Object request, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URI template, and returns the value of theLocationheader.@Nullable URIpostForLocation(URI url, @Nullable Object request) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URL, and returns the value of theLocationheader.<T> @Nullable TpostForObject(String url, @Nullable Object request, Class<T> responseType, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.<T> @Nullable TpostForObject(String url, @Nullable Object request, Class<T> responseType, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.<T> @Nullable TpostForObject(URI url, @Nullable Object request, Class<T> responseType) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URL, and returns the representation found in the response.voidDeprecated, for removal: This API element is subject to removal in a future version.Create or update a resource by PUTting the given object to the URI.voidDeprecated, for removal: This API element is subject to removal in a future version.Creates a new resource by PUTting the given object to URI template.voidDeprecated, for removal: This API element is subject to removal in a future version.Creates a new resource by PUTting the given object to URL.voidsetUriTemplateHandler(UriTemplateHandler handler) Deprecated, for removal: This API element is subject to removal in a future version.Configure theUriTemplateHandlerto use to expand URI templates.withBasicAuth(@Nullable String username, @Nullable String password) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newTestRestTemplatewith the same configuration as this one, except that it will send basic authorization headers using the givenusernameandpassword.withClientSettings(UnaryOperator<HttpClientSettings> clientSettingsCustomizer) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newTestRestTemplatewith the same configuration as this one, except that it will customize theHttpClientSettings.withClientSettings(HttpClientSettings clientSettings) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newTestRestTemplatewith the same configuration as this one, except that it will apply the givenHttpClientSettings.withCookieHandling(HttpCookieHandling cookieHandling) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newTestRestTemplatewith the same configuration as this one, except that it will apply the givenHttpCookieHandling.withRedirects(HttpRedirects redirects) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newTestRestTemplatewith the same configuration as this one, except that it will apply the givenHttpRedirects.
-
Constructor Details
-
TestRestTemplate
Deprecated, for removal: This API element is subject to removal in a future version.Create a newTestRestTemplateinstance.- Parameters:
restTemplateBuilder- builder used to configure underlyingRestTemplate
-
TestRestTemplate
Deprecated, for removal: This API element is subject to removal in a future version.Create a newTestRestTemplateinstance.- Parameters:
httpClientOptions- client options to use if the Apache HTTP Client is used
-
TestRestTemplate
public TestRestTemplate(@Nullable String username, @Nullable String password, TestRestTemplate.HttpClientOption... httpClientOptions) Deprecated, for removal: This API element is subject to removal in a future version.Create a newTestRestTemplateinstance with the specified credentials.- Parameters:
username- the username to use (ornull)password- the password (ornull)httpClientOptions- client options to use if the Apache HTTP Client is used
-
TestRestTemplate
public TestRestTemplate(RestTemplateBuilder builder, @Nullable String username, @Nullable String password, TestRestTemplate.HttpClientOption... httpClientOptions) Deprecated, for removal: This API element is subject to removal in a future version.Create a newTestRestTemplateinstance with the specified credentials.- Parameters:
builder- builder used to configure underlyingRestTemplateusername- the username to use (ornull)password- the password (ornull)httpClientOptions- client options to use if the Apache HTTP Client is used
-
-
Method Details
-
setUriTemplateHandler
Deprecated, for removal: This API element is subject to removal in a future version.Configure theUriTemplateHandlerto use to expand URI templates. By default theDefaultUriBuilderFactoryis used which relies on Spring's URI template support and exposes several useful properties that customize its behavior for encoding and for prepending a common base URL. An alternative implementation may be used to plug an external URI template library.- Parameters:
handler- the URI template handler to use
-
getRootUri
Deprecated, for removal: This API element is subject to removal in a future version.Returns the root URI applied byRestTemplateBuilder.baseUri(String)or""if the root URI has not been applied.- Returns:
- the root URI
-
getForObject
Deprecated, for removal: This API element is subject to removal in a future version.Retrieve a representation by doing a GET on the specified URL. The response (if any) is converted and returned.URI Template variables are expanded using the given URI variables, if any.
- Type Parameters:
T- the type of the return value- Parameters:
url- the URLresponseType- the type of the return valueurlVariables- the variables to expand the template- Returns:
- the converted object
- See Also:
-
getForObject
Deprecated, for removal: This API element is subject to removal in a future version.Retrieve a representation by doing a GET on the URI template. The response (if any) is converted and returned.URI Template variables are expanded using the given map.
- Type Parameters:
T- the type of the return value- Parameters:
url- the URLresponseType- the type of the return valueurlVariables- the map containing variables for the URI template- Returns:
- the converted object
- See Also:
-
getForObject
Deprecated, for removal: This API element is subject to removal in a future version.Retrieve a representation by doing a GET on the URL . The response (if any) is converted and returned.- Type Parameters:
T- the type of the return value- Parameters:
url- the URLresponseType- the type of the return value- Returns:
- the converted object
- See Also:
-
getForEntity
public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Retrieve an entity by doing a GET on the specified URL. The response is converted and stored in anResponseEntity.URI Template variables are expanded using the given URI variables, if any.
- Type Parameters:
T- the type of the return value- Parameters:
url- the URLresponseType- the type of the return valueurlVariables- the variables to expand the template- Returns:
- the entity
- See Also:
-
getForEntity
public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Retrieve a representation by doing a GET on the URI template. The response is converted and stored in anResponseEntity.URI Template variables are expanded using the given map.
- Type Parameters:
T- the type of the return value- Parameters:
url- the URLresponseType- the type of the return valueurlVariables- the map containing variables for the URI template- Returns:
- the converted object
- See Also:
-
getForEntity
Deprecated, for removal: This API element is subject to removal in a future version.Retrieve a representation by doing a GET on the URL . The response is converted and stored in anResponseEntity.- Type Parameters:
T- the type of the return value- Parameters:
url- the URLresponseType- the type of the return value- Returns:
- the converted object
- See Also:
-
headForHeaders
Deprecated, for removal: This API element is subject to removal in a future version.Retrieve all headers of the resource specified by the URI template.URI Template variables are expanded using the given URI variables, if any.
- Parameters:
url- the URLurlVariables- the variables to expand the template- Returns:
- all HTTP headers of that resource
- See Also:
-
headForHeaders
Deprecated, for removal: This API element is subject to removal in a future version.Retrieve all headers of the resource specified by the URI template.URI Template variables are expanded using the given map.
- Parameters:
url- the URLurlVariables- the map containing variables for the URI template- Returns:
- all HTTP headers of that resource
- See Also:
-
headForHeaders
Deprecated, for removal: This API element is subject to removal in a future version.Retrieve all headers of the resource specified by the URL.- Parameters:
url- the URL- Returns:
- all HTTP headers of that resource
- See Also:
-
postForLocation
Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URI template, and returns the value of theLocationheader. This header typically indicates where the new resource is stored.URI Template variables are expanded using the given URI variables, if any.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- Parameters:
url- the URLrequest- the Object to be POSTed, may benullurlVariables- the variables to expand the template- Returns:
- the value for the
Locationheader - See Also:
-
postForLocation
public @Nullable URI postForLocation(String url, @Nullable Object request, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URI template, and returns the value of theLocationheader. This header typically indicates where the new resource is stored.URI Template variables are expanded using the given map.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- Parameters:
url- the URLrequest- the Object to be POSTed, may benullurlVariables- the variables to expand the template- Returns:
- the value for the
Locationheader - See Also:
-
postForLocation
Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URL, and returns the value of theLocationheader. This header typically indicates where the new resource is stored.The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- Parameters:
url- the URLrequest- the Object to be POSTed, may benull- Returns:
- the value for the
Locationheader - See Also:
-
postForObject
public <T> @Nullable T postForObject(String url, @Nullable Object request, Class<T> responseType, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.URI Template variables are expanded using the given URI variables, if any.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- Type Parameters:
T- the type of the return value- Parameters:
url- the URLrequest- the Object to be POSTed, may benullresponseType- the type of the return valueurlVariables- the variables to expand the template- Returns:
- the converted object
- See Also:
-
postForObject
public <T> @Nullable T postForObject(String url, @Nullable Object request, Class<T> responseType, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.URI Template variables are expanded using the given map.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- Type Parameters:
T- the type of the return value- Parameters:
url- the URLrequest- the Object to be POSTed, may benullresponseType- the type of the return valueurlVariables- the variables to expand the template- Returns:
- the converted object
- See Also:
-
postForObject
Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URL, and returns the representation found in the response.The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- Type Parameters:
T- the type of the return value- Parameters:
url- the URLrequest- the Object to be POSTed, may benullresponseType- the type of the return value- Returns:
- the converted object
- See Also:
-
postForEntity
public <T> ResponseEntity<T> postForEntity(String url, @Nullable Object request, Class<T> responseType, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URI template, and returns the response asResponseEntity.URI Template variables are expanded using the given URI variables, if any.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- Type Parameters:
T- the type of the return value- Parameters:
url- the URLrequest- the Object to be POSTed, may benullresponseType- the response type to returnurlVariables- the variables to expand the template- Returns:
- the converted object
- See Also:
-
postForEntity
public <T> ResponseEntity<T> postForEntity(String url, @Nullable Object request, Class<T> responseType, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URI template, and returns the response asHttpEntity.URI Template variables are expanded using the given map.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- Type Parameters:
T- the type of the return value- Parameters:
url- the URLrequest- the Object to be POSTed, may benullresponseType- the response type to returnurlVariables- the variables to expand the template- Returns:
- the converted object
- See Also:
-
postForEntity
public <T> ResponseEntity<T> postForEntity(URI url, @Nullable Object request, Class<T> responseType) Deprecated, for removal: This API element is subject to removal in a future version.Create a new resource by POSTing the given object to the URL, and returns the response asResponseEntity.The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- Type Parameters:
T- the type of the return value- Parameters:
url- the URLrequest- the Object to be POSTed, may benullresponseType- the response type to return- Returns:
- the converted object
- See Also:
-
put
Deprecated, for removal: This API element is subject to removal in a future version.Create or update a resource by PUTting the given object to the URI.URI Template variables are expanded using the given URI variables, if any.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.If you need to assert the request result consider using the
exchangemethod.- Parameters:
url- the URLrequest- the Object to be PUT, may benullurlVariables- the variables to expand the template- See Also:
-
put
Deprecated, for removal: This API element is subject to removal in a future version.Creates a new resource by PUTting the given object to URI template.URI Template variables are expanded using the given map.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.If you need to assert the request result consider using the
exchangemethod.- Parameters:
url- the URLrequest- the Object to be PUT, may benullurlVariables- the variables to expand the template- See Also:
-
put
Deprecated, for removal: This API element is subject to removal in a future version.Creates a new resource by PUTting the given object to URL.The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.If you need to assert the request result consider using the
exchangemethod.- Parameters:
url- the URLrequest- the Object to be PUT, may benull- See Also:
-
patchForObject
public <T> @Nullable T patchForObject(String url, @Nullable Object request, Class<T> responseType, Object... uriVariables) Deprecated, for removal: This API element is subject to removal in a future version.Update a resource by PATCHing the given object to the URI template, and returns the representation found in the response.URI Template variables are expanded using the given URI variables, if any.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- Type Parameters:
T- the type of the return value- Parameters:
url- the URLrequest- the Object to be PATCHed, may benullresponseType- the type of the return valueuriVariables- the variables to expand the template- Returns:
- the converted object
- See Also:
-
patchForObject
public <T> @Nullable T patchForObject(String url, @Nullable Object request, Class<T> responseType, Map<String, ?> uriVariables) Deprecated, for removal: This API element is subject to removal in a future version.Update a resource by PATCHing the given object to the URI template, and returns the representation found in the response.URI Template variables are expanded using the given map.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- Type Parameters:
T- the type of the return value- Parameters:
url- the URLrequest- the Object to be PATCHed, may benullresponseType- the type of the return valueuriVariables- the variables to expand the template- Returns:
- the converted object
- See Also:
-
patchForObject
Deprecated, for removal: This API element is subject to removal in a future version.Update a resource by PATCHing the given object to the URL, and returns the representation found in the response.The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- Type Parameters:
T- the type of the return value- Parameters:
url- the URLrequest- the Object to be POSTed, may benullresponseType- the type of the return value- Returns:
- the converted object
- See Also:
-
delete
Deprecated, for removal: This API element is subject to removal in a future version.Delete the resources at the specified URI.URI Template variables are expanded using the given URI variables, if any.
If you need to assert the request result consider using the
exchangemethod.- Parameters:
url- the URLurlVariables- the variables to expand in the template- See Also:
-
delete
Deprecated, for removal: This API element is subject to removal in a future version.Delete the resources at the specified URI.URI Template variables are expanded using the given map.
If you need to assert the request result consider using the
exchangemethod.- Parameters:
url- the URLurlVariables- the variables to expand the template- See Also:
-
delete
-
optionsForAllow
Deprecated, for removal: This API element is subject to removal in a future version.Return the value of theAllowheader for the given URI.URI Template variables are expanded using the given URI variables, if any.
- Parameters:
url- the URLurlVariables- the variables to expand in the template- Returns:
- the value of the
Allowheader - See Also:
-
optionsForAllow
Deprecated, for removal: This API element is subject to removal in a future version.Return the value of theAllowheader for the given URI.URI Template variables are expanded using the given map.
- Parameters:
url- the URLurlVariables- the variables to expand in the template- Returns:
- the value of the
Allowheader - See Also:
-
optionsForAllow
Deprecated, for removal: This API element is subject to removal in a future version.Return the value of theAllowheader for the given URL.- Parameters:
url- the URL- Returns:
- the value of the
Allowheader - See Also:
-
exchange
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, Class<T> responseType, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.URI Template variables are expanded using the given URI variables, if any.
- Type Parameters:
T- the type of the return value- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc.)requestEntity- the entity (headers and/or body) to write to the request, may benullresponseType- the type of the return valueurlVariables- the variables to expand in the template- Returns:
- the response as entity
- See Also:
-
exchange
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.URI Template variables are expanded using the given URI variables, if any.
- Type Parameters:
T- the type of the return value- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc.)requestEntity- the entity (headers and/or body) to write to the request, may benullresponseType- the type of the return valueurlVariables- the variables to expand in the template- Returns:
- the response as entity
- See Also:
-
exchange
public <T> ResponseEntity<T> exchange(URI url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, Class<T> responseType) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.- Type Parameters:
T- the type of the return value- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc.)requestEntity- the entity (headers and/or body) to write to the request, may benullresponseType- the type of the return value- Returns:
- the response as entity
- See Also:
-
exchange
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity. The givenParameterizedTypeReferenceis used to pass generic type information:ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {}; ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);- Type Parameters:
T- the type of the return value- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc.)requestEntity- the entity (headers and/or body) to write to the request, may benullresponseType- the type of the return valueurlVariables- the variables to expand in the template- Returns:
- the response as entity
- See Also:
-
exchange
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity. The givenParameterizedTypeReferenceis used to pass generic type information:ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {}; ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);- Type Parameters:
T- the type of the return value- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc.)requestEntity- the entity (headers and/or body) to write to the request, may benullresponseType- the type of the return valueurlVariables- the variables to expand in the template- Returns:
- the response as entity
- See Also:
-
exchange
public <T> ResponseEntity<T> exchange(URI url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity. The givenParameterizedTypeReferenceis used to pass generic type information:ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {}; ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);- Type Parameters:
T- the type of the return value- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc.)requestEntity- the entity (headers and/or body) to write to the request, may benullresponseType- the type of the return value- Returns:
- the response as entity
- See Also:
-
exchange
Deprecated, for removal: This API element is subject to removal in a future version.Execute the request specified in the givenRequestEntityand return the response asResponseEntity. Typically used in combination with the static builder methods onRequestEntity, for instance:MyRequest body = ... RequestEntity request = RequestEntity.post(new URI("https://example.com/foo")).accept(MediaType.APPLICATION_JSON).body(body); ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);- Type Parameters:
T- the type of the return value- Parameters:
requestEntity- the entity to write to the requestresponseType- the type of the return value- Returns:
- the response as entity
- See Also:
-
exchange
public <T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity, ParameterizedTypeReference<T> responseType) Deprecated, for removal: This API element is subject to removal in a future version.Execute the request specified in the givenRequestEntityand return the response asResponseEntity. The givenParameterizedTypeReferenceis used to pass generic type information:MyRequest body = ... RequestEntity request = RequestEntity.post(new URI("https://example.com/foo")).accept(MediaType.APPLICATION_JSON).body(body); ParameterizedTypeReference<List<MyResponse>> myBean = new ParameterizedTypeReference<List<MyResponse>>() {}; ResponseEntity<List<MyResponse>> response = template.exchange(request, myBean);- Type Parameters:
T- the type of the return value- Parameters:
requestEntity- the entity to write to the requestresponseType- the type of the return value- Returns:
- the response as entity
- See Also:
-
execute
public <T> @Nullable T execute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Object... urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, preparing the request with theRequestCallback, and reading the response with aResponseExtractor.URI Template variables are expanded using the given URI variables, if any.
- Type Parameters:
T- the type of the return value- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc.)requestCallback- object that prepares the requestresponseExtractor- object that extracts the return value from the responseurlVariables- the variables to expand in the template- Returns:
- an arbitrary object, as returned by the
ResponseExtractor - See Also:
-
execute
public <T> @Nullable T execute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Map<String, ?> urlVariables) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URI template, preparing the request with theRequestCallback, and reading the response with aResponseExtractor.URI Template variables are expanded using the given URI variables map.
- Type Parameters:
T- the type of the return value- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc.)requestCallback- object that prepares the requestresponseExtractor- object that extracts the return value from the responseurlVariables- the variables to expand in the template- Returns:
- an arbitrary object, as returned by the
ResponseExtractor - See Also:
-
execute
public <T> @Nullable T execute(URI url, HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor<T> responseExtractor) Deprecated, for removal: This API element is subject to removal in a future version.Execute the HTTP method to the given URL, preparing the request with theRequestCallback, and reading the response with aResponseExtractor.- Type Parameters:
T- the type of the return value- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc.)requestCallback- object that prepares the requestresponseExtractor- object that extracts the return value from the response- Returns:
- an arbitrary object, as returned by the
ResponseExtractor - See Also:
-
getRestTemplate
Deprecated, for removal: This API element is subject to removal in a future version.Returns the underlyingRestTemplatethat is actually used to perform the REST operations.- Returns:
- the restTemplate
-
withBasicAuth
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newTestRestTemplatewith the same configuration as this one, except that it will send basic authorization headers using the givenusernameandpassword. The request factory used is a new instance of the underlyingRestTemplate's request factory type (when possible).- Parameters:
username- the usernamepassword- the password- Returns:
- the new template
-
withRedirects
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newTestRestTemplatewith the same configuration as this one, except that it will apply the givenHttpRedirects. The request factory used is a new instance of the underlyingRestTemplate's request factory type (when possible).- Parameters:
redirects- the new redirect settings- Returns:
- the new template
-
withCookieHandling
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newTestRestTemplatewith the same configuration as this one, except that it will apply the givenHttpCookieHandling. The request factory used is a new instance of the underlyingRestTemplate's request factory type (when possible).- Parameters:
cookieHandling- the new cookie handling- Returns:
- the new template
- Since:
- 4.1.0
-
withClientSettings
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newTestRestTemplatewith the same configuration as this one, except that it will apply the givenHttpClientSettings. The request factory used is a new instance of the underlyingRestTemplate's request factory type (when possible).- Parameters:
clientSettings- the new client settings- Returns:
- the new template
-
withClientSettings
public TestRestTemplate withClientSettings(UnaryOperator<HttpClientSettings> clientSettingsCustomizer) Deprecated, for removal: This API element is subject to removal in a future version.Creates a newTestRestTemplatewith the same configuration as this one, except that it will customize theHttpClientSettings. The request factory used is a new instance of the underlyingRestTemplate's request factory type (when possible).- Parameters:
clientSettingsCustomizer- aUnaryOperatorto update the settings- Returns:
- the new template
-
RestTestClient