public class TestRestTemplate extends Object
RestTemplate
that is suitable for integration tests.
They are fault tolerant, and optionally can carry Basic authentication headers. If
Apache Http Client 4.3.2 or better is available (recommended) it will be used as the
client, and by default configured to ignore cookies and redirects.
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, a TestRestTemplate
is automatically available and can be
@Autowired
into your test. If you need customizations (for example to adding
additional message converters) use a RestTemplateBuilder
@Bean
.
Modifier and Type | Class and Description |
---|---|
protected static class |
TestRestTemplate.CustomHttpComponentsClientHttpRequestFactory
HttpComponentsClientHttpRequestFactory to apply customizations. |
static class |
TestRestTemplate.HttpClientOption
Options used to customize the Apache Http Client if it is used.
|
Constructor and Description |
---|
TestRestTemplate(RestTemplateBuilder restTemplateBuilder)
Create a new
TestRestTemplate instance. |
TestRestTemplate(RestTemplateBuilder restTemplateBuilder,
String username,
String password,
TestRestTemplate.HttpClientOption... httpClientOptions)
Create a new
TestRestTemplate instance with the specified credentials. |
TestRestTemplate(String username,
String password,
TestRestTemplate.HttpClientOption... httpClientOptions)
Create a new
TestRestTemplate instance with the specified credentials. |
TestRestTemplate(TestRestTemplate.HttpClientOption... httpClientOptions)
Create a new
TestRestTemplate instance. |
Modifier and Type | Method and Description |
---|---|
void |
delete(String url,
Map<String,?> urlVariables)
Delete the resources at the specified URI.
|
void |
delete(String url,
Object... urlVariables)
Delete the resources at the specified URI.
|
void |
delete(URI url)
Delete the resources at the specified URL.
|
<T> org.springframework.http.ResponseEntity<T> |
exchange(org.springframework.http.RequestEntity<?> requestEntity,
Class<T> responseType)
Execute the request specified in the given
RequestEntity and return the
response as ResponseEntity . |
<T> org.springframework.http.ResponseEntity<T> |
exchange(org.springframework.http.RequestEntity<?> requestEntity,
org.springframework.core.ParameterizedTypeReference<T> responseType)
Execute the request specified in the given
RequestEntity and return the
response as ResponseEntity . |
<T> org.springframework.http.ResponseEntity<T> |
exchange(String url,
org.springframework.http.HttpMethod method,
org.springframework.http.HttpEntity<?> requestEntity,
Class<T> responseType,
Map<String,?> urlVariables)
Execute the HTTP method to the given URI template, writing the given request entity
to the request, and returns the response as
ResponseEntity . |
<T> org.springframework.http.ResponseEntity<T> |
exchange(String url,
org.springframework.http.HttpMethod method,
org.springframework.http.HttpEntity<?> requestEntity,
Class<T> responseType,
Object... urlVariables)
Execute the HTTP method to the given URI template, writing the given request entity
to the request, and returns the response as
ResponseEntity . |
<T> org.springframework.http.ResponseEntity<T> |
exchange(String url,
org.springframework.http.HttpMethod method,
org.springframework.http.HttpEntity<?> requestEntity,
org.springframework.core.ParameterizedTypeReference<T> responseType,
Map<String,?> urlVariables)
Execute the HTTP method to the given URI template, writing the given request entity
to the request, and returns the response as
ResponseEntity . |
<T> org.springframework.http.ResponseEntity<T> |
exchange(String url,
org.springframework.http.HttpMethod method,
org.springframework.http.HttpEntity<?> requestEntity,
org.springframework.core.ParameterizedTypeReference<T> responseType,
Object... urlVariables)
Execute the HTTP method to the given URI template, writing the given request entity
to the request, and returns the response as
ResponseEntity . |
<T> org.springframework.http.ResponseEntity<T> |
exchange(URI url,
org.springframework.http.HttpMethod method,
org.springframework.http.HttpEntity<?> requestEntity,
Class<T> responseType)
Execute the HTTP method to the given URI template, writing the given request entity
to the request, and returns the response as
ResponseEntity . |
<T> org.springframework.http.ResponseEntity<T> |
exchange(URI url,
org.springframework.http.HttpMethod method,
org.springframework.http.HttpEntity<?> requestEntity,
org.springframework.core.ParameterizedTypeReference<T> responseType)
Execute the HTTP method to the given URI template, writing the given request entity
to the request, and returns the response as
ResponseEntity . |
<T> T |
execute(String url,
org.springframework.http.HttpMethod method,
org.springframework.web.client.RequestCallback requestCallback,
org.springframework.web.client.ResponseExtractor<T> responseExtractor,
Map<String,?> urlVariables)
Execute the HTTP method to the given URI template, preparing the request with the
RequestCallback , and reading the response with a ResponseExtractor . |
<T> T |
execute(String url,
org.springframework.http.HttpMethod method,
org.springframework.web.client.RequestCallback requestCallback,
org.springframework.web.client.ResponseExtractor<T> responseExtractor,
Object... urlVariables)
Execute the HTTP method to the given URI template, preparing the request with the
RequestCallback , and reading the response with a ResponseExtractor . |
<T> T |
execute(URI url,
org.springframework.http.HttpMethod method,
org.springframework.web.client.RequestCallback requestCallback,
org.springframework.web.client.ResponseExtractor<T> responseExtractor)
Execute the HTTP method to the given URL, preparing the request with the
RequestCallback , and reading the response with a ResponseExtractor . |
<T> org.springframework.http.ResponseEntity<T> |
getForEntity(String url,
Class<T> responseType,
Map<String,?> urlVariables)
Retrieve a representation by doing a GET on the URI template.
|
<T> org.springframework.http.ResponseEntity<T> |
getForEntity(String url,
Class<T> responseType,
Object... urlVariables)
Retrieve an entity by doing a GET on the specified URL.
|
<T> org.springframework.http.ResponseEntity<T> |
getForEntity(URI url,
Class<T> responseType)
Retrieve a representation by doing a GET on the URL .
|
<T> T |
getForObject(String url,
Class<T> responseType,
Map<String,?> urlVariables)
Retrieve a representation by doing a GET on the URI template.
|
<T> T |
getForObject(String url,
Class<T> responseType,
Object... urlVariables)
Retrieve a representation by doing a GET on the specified URL.
|
<T> T |
getForObject(URI url,
Class<T> responseType)
Retrieve a representation by doing a GET on the URL .
|
org.springframework.web.client.RestTemplate |
getRestTemplate()
Returns the underlying
RestTemplate that is actually used to perform the
REST operations. |
String |
getRootUri()
Returns the root URI applied by a
RootUriTemplateHandler or "" if
the root URI is not available. |
org.springframework.http.HttpHeaders |
headForHeaders(String url,
Map<String,?> urlVariables)
Retrieve all headers of the resource specified by the URI template.
|
org.springframework.http.HttpHeaders |
headForHeaders(String url,
Object... urlVariables)
Retrieve all headers of the resource specified by the URI template.
|
org.springframework.http.HttpHeaders |
headForHeaders(URI url)
Retrieve all headers of the resource specified by the URL.
|
Set<org.springframework.http.HttpMethod> |
optionsForAllow(String url,
Map<String,?> urlVariables)
Return the value of the Allow header for the given URI.
|
Set<org.springframework.http.HttpMethod> |
optionsForAllow(String url,
Object... urlVariables)
Return the value of the Allow header for the given URI.
|
Set<org.springframework.http.HttpMethod> |
optionsForAllow(URI url)
Return the value of the Allow header for the given URL.
|
<T> T |
patchForObject(String url,
Object request,
Class<T> responseType,
Map<String,?> uriVariables)
Update a resource by PATCHing the given object to the URI template, and returns the
representation found in the response.
|
<T> T |
patchForObject(String url,
Object request,
Class<T> responseType,
Object... uriVariables)
Update a resource by PATCHing the given object to the URI template, and returns the
representation found in the response.
|
<T> T |
patchForObject(URI url,
Object request,
Class<T> responseType)
Update a resource by PATCHing the given object to the URL, and returns the
representation found in the response.
|
<T> org.springframework.http.ResponseEntity<T> |
postForEntity(String url,
Object request,
Class<T> responseType,
Map<String,?> urlVariables)
Create a new resource by POSTing the given object to the URI template, and returns
the response as
HttpEntity . |
<T> org.springframework.http.ResponseEntity<T> |
postForEntity(String url,
Object request,
Class<T> responseType,
Object... urlVariables)
Create a new resource by POSTing the given object to the URI template, and returns
the response as
ResponseEntity . |
<T> org.springframework.http.ResponseEntity<T> |
postForEntity(URI url,
Object request,
Class<T> responseType)
Create a new resource by POSTing the given object to the URL, and returns the
response as
ResponseEntity . |
URI |
postForLocation(String url,
Object request,
Map<String,?> urlVariables)
Create a new resource by POSTing the given object to the URI template, and returns
the value of the
Location header. |
URI |
postForLocation(String url,
Object request,
Object... urlVariables)
Create a new resource by POSTing the given object to the URI template, and returns
the value of the
Location header. |
URI |
postForLocation(URI url,
Object request)
Create a new resource by POSTing the given object to the URL, and returns the value
of the
Location header. |
<T> T |
postForObject(String url,
Object request,
Class<T> responseType,
Map<String,?> urlVariables)
Create a new resource by POSTing the given object to the URI template, and returns
the representation found in the response.
|
<T> T |
postForObject(String url,
Object request,
Class<T> responseType,
Object... urlVariables)
Create a new resource by POSTing the given object to the URI template, and returns
the representation found in the response.
|
<T> T |
postForObject(URI url,
Object request,
Class<T> responseType)
Create a new resource by POSTing the given object to the URL, and returns the
representation found in the response.
|
void |
put(String url,
Object request,
Map<String,?> urlVariables)
Creates a new resource by PUTting the given object to URI template.
|
void |
put(String url,
Object request,
Object... urlVariables)
Create or update a resource by PUTting the given object to the URI.
|
void |
put(URI url,
Object request)
Creates a new resource by PUTting the given object to URL.
|
void |
setUriTemplateHandler(org.springframework.web.util.UriTemplateHandler handler)
Configure the
UriTemplateHandler to use to expand URI templates. |
TestRestTemplate |
withBasicAuth(String username,
String password)
Creates a new
TestRestTemplate with the same configuration as this one,
except that it will send basic authorization headers using the given
username and password . |
public TestRestTemplate(RestTemplateBuilder restTemplateBuilder)
TestRestTemplate
instance.restTemplateBuilder
- builder used to configure underlying
RestTemplate
public TestRestTemplate(TestRestTemplate.HttpClientOption... httpClientOptions)
TestRestTemplate
instance.httpClientOptions
- client options to use if the Apache HTTP Client is usedpublic TestRestTemplate(String username, String password, TestRestTemplate.HttpClientOption... httpClientOptions)
TestRestTemplate
instance with the specified credentials.username
- the username to use (or null
)password
- the password (or null
)httpClientOptions
- client options to use if the Apache HTTP Client is usedpublic TestRestTemplate(RestTemplateBuilder restTemplateBuilder, String username, String password, TestRestTemplate.HttpClientOption... httpClientOptions)
TestRestTemplate
instance with the specified credentials.restTemplateBuilder
- builder used to configure underlying
RestTemplate
username
- the username to use (or null
)password
- the password (or null
)httpClientOptions
- client options to use if the Apache HTTP Client is usedpublic void setUriTemplateHandler(org.springframework.web.util.UriTemplateHandler handler)
UriTemplateHandler
to use to expand URI templates. By default
the DefaultUriBuilderFactory
is 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.handler
- the URI template handler to usepublic String getRootUri()
RootUriTemplateHandler
or ""
if
the root URI is not available.public <T> T getForObject(String url, Class<T> responseType, Object... urlVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given URI variables, if any.
T
- the type of the return valueurl
- the URLresponseType
- the type of the return valueurlVariables
- the variables to expand the templateorg.springframework.web.client.RestClientException
- on client-side HTTP error on client-side HTTP errorRestTemplate.getForObject(String, Class, Object...)
public <T> T getForObject(String url, Class<T> responseType, Map<String,?> urlVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given map.
T
- the type of the return valueurl
- the URLresponseType
- the type of the return valueurlVariables
- the map containing variables for the URI templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.getForObject(String, Class, Object...)
public <T> T getForObject(URI url, Class<T> responseType) throws org.springframework.web.client.RestClientException
T
- the type of the return valueurl
- the URLresponseType
- the type of the return valueorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.getForObject(java.net.URI, java.lang.Class)
public <T> org.springframework.http.ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... urlVariables) throws org.springframework.web.client.RestClientException
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
T
- the type of the return valueurl
- the URLresponseType
- the type of the return valueurlVariables
- the variables to expand the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.getForEntity(java.lang.String, java.lang.Class,
java.lang.Object[])
public <T> org.springframework.http.ResponseEntity<T> getForEntity(String url, Class<T> responseType, Map<String,?> urlVariables) throws org.springframework.web.client.RestClientException
ResponseEntity
.
URI Template variables are expanded using the given map.
T
- the type of the return valueurl
- the URLresponseType
- the type of the return valueurlVariables
- the map containing variables for the URI templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.getForEntity(java.lang.String, java.lang.Class, java.util.Map)
public <T> org.springframework.http.ResponseEntity<T> getForEntity(URI url, Class<T> responseType) throws org.springframework.web.client.RestClientException
ResponseEntity
.T
- the type of the return valueurl
- the URLresponseType
- the type of the return valueorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.getForEntity(java.net.URI, java.lang.Class)
public org.springframework.http.HttpHeaders headForHeaders(String url, Object... urlVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given URI variables, if any.
url
- the URLurlVariables
- the variables to expand the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.headForHeaders(java.lang.String, java.lang.Object[])
public org.springframework.http.HttpHeaders headForHeaders(String url, Map<String,?> urlVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given map.
url
- the URLurlVariables
- the map containing variables for the URI templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.headForHeaders(java.lang.String, java.util.Map)
public org.springframework.http.HttpHeaders headForHeaders(URI url) throws org.springframework.web.client.RestClientException
url
- the URLorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.headForHeaders(java.net.URI)
public URI postForLocation(String url, Object request, Object... urlVariables) throws org.springframework.web.client.RestClientException
Location
header. This header typically indicates where the
new resource is stored.
URI Template variables are expanded using the given URI variables, if any.
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
url
- the URLrequest
- the Object to be POSTed, may be null
urlVariables
- the variables to expand the templateLocation
headerorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
,
RestTemplate.postForLocation(java.lang.String, java.lang.Object,
java.lang.Object[])
public URI postForLocation(String url, Object request, Map<String,?> urlVariables) throws org.springframework.web.client.RestClientException
Location
header. This header typically indicates where the
new resource is stored.
URI Template variables are expanded using the given map.
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
url
- the URLrequest
- the Object to be POSTed, may be null
urlVariables
- the variables to expand the templateLocation
headerorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
,
RestTemplate.postForLocation(java.lang.String, java.lang.Object,
java.util.Map)
public URI postForLocation(URI url, Object request) throws org.springframework.web.client.RestClientException
Location
header. This header typically indicates where the new
resource is stored.
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
url
- the URLrequest
- the Object to be POSTed, may be null
Location
headerorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
,
RestTemplate.postForLocation(java.net.URI, java.lang.Object)
public <T> T postForObject(String url, Object request, Class<T> responseType, Object... urlVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given URI variables, if any.
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return valueurl
- the URLrequest
- the Object to be POSTed, may be null
responseType
- the type of the return valueurlVariables
- the variables to expand the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
,
RestTemplate.postForObject(java.lang.String, java.lang.Object,
java.lang.Class, java.lang.Object[])
public <T> T postForObject(String url, Object request, Class<T> responseType, Map<String,?> urlVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given map.
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return valueurl
- the URLrequest
- the Object to be POSTed, may be null
responseType
- the type of the return valueurlVariables
- the variables to expand the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
,
RestTemplate.postForObject(java.lang.String, java.lang.Object,
java.lang.Class, java.util.Map)
public <T> T postForObject(URI url, Object request, Class<T> responseType) throws org.springframework.web.client.RestClientException
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return valueurl
- the URLrequest
- the Object to be POSTed, may be null
responseType
- the type of the return valueorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
,
RestTemplate.postForObject(java.net.URI, java.lang.Object, java.lang.Class)
public <T> org.springframework.http.ResponseEntity<T> postForEntity(String url, Object request, Class<T> responseType, Object... urlVariables) throws org.springframework.web.client.RestClientException
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return valueurl
- the URLrequest
- the Object to be POSTed, may be null
responseType
- the response type to returnurlVariables
- the variables to expand the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
,
RestTemplate.postForEntity(java.lang.String, java.lang.Object,
java.lang.Class, java.lang.Object[])
public <T> org.springframework.http.ResponseEntity<T> postForEntity(String url, Object request, Class<T> responseType, Map<String,?> urlVariables) throws org.springframework.web.client.RestClientException
HttpEntity
.
URI Template variables are expanded using the given map.
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return valueurl
- the URLrequest
- the Object to be POSTed, may be null
responseType
- the response type to returnurlVariables
- the variables to expand the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
,
RestTemplate.postForEntity(java.lang.String, java.lang.Object,
java.lang.Class, java.util.Map)
public <T> org.springframework.http.ResponseEntity<T> postForEntity(URI url, Object request, Class<T> responseType) throws org.springframework.web.client.RestClientException
ResponseEntity
.
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return valueurl
- the URLrequest
- the Object to be POSTed, may be null
responseType
- the response type to returnorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
,
RestTemplate.postForEntity(java.net.URI, java.lang.Object, java.lang.Class)
public void put(String url, Object request, Object... urlVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given URI variables, if any.
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
url
- the URLrequest
- the Object to be PUT, may be null
urlVariables
- the variables to expand the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
,
RestTemplate.put(java.lang.String, java.lang.Object, java.lang.Object[])
public void put(String url, Object request, Map<String,?> urlVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given map.
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
url
- the URLrequest
- the Object to be PUT, may be null
urlVariables
- the variables to expand the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
,
RestTemplate.put(java.lang.String, java.lang.Object, java.util.Map)
public void put(URI url, Object request) throws org.springframework.web.client.RestClientException
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
url
- the URLrequest
- the Object to be PUT, may be null
org.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
,
RestTemplate.put(java.net.URI, java.lang.Object)
public <T> T patchForObject(String url, Object request, Class<T> responseType, Object... uriVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given URI variables, if any.
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return valueurl
- the URLrequest
- the Object to be PATCHed, may be null
responseType
- the type of the return valueuriVariables
- the variables to expand the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
public <T> T patchForObject(String url, Object request, Class<T> responseType, Map<String,?> uriVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given map.
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return valueurl
- the URLrequest
- the Object to be PATCHed, may be null
responseType
- the type of the return valueuriVariables
- the variables to expand the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
public <T> T patchForObject(URI url, Object request, Class<T> responseType) throws org.springframework.web.client.RestClientException
The request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return valueurl
- the URLrequest
- the Object to be POSTed, may be null
responseType
- the type of the return valueorg.springframework.web.client.RestClientException
- on client-side HTTP errorHttpEntity
public void delete(String url, Object... urlVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given URI variables, if any.
url
- the URLurlVariables
- the variables to expand in the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.delete(java.lang.String, java.lang.Object[])
public void delete(String url, Map<String,?> urlVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given map.
url
- the URLurlVariables
- the variables to expand the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.delete(java.lang.String, java.util.Map)
public void delete(URI url) throws org.springframework.web.client.RestClientException
url
- the URLorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.delete(java.net.URI)
public Set<org.springframework.http.HttpMethod> optionsForAllow(String url, Object... urlVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given URI variables, if any.
url
- the URLurlVariables
- the variables to expand in the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.optionsForAllow(java.lang.String, java.lang.Object[])
public Set<org.springframework.http.HttpMethod> optionsForAllow(String url, Map<String,?> urlVariables) throws org.springframework.web.client.RestClientException
URI Template variables are expanded using the given map.
url
- the URLurlVariables
- the variables to expand in the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.optionsForAllow(java.lang.String, java.util.Map)
public Set<org.springframework.http.HttpMethod> optionsForAllow(URI url) throws org.springframework.web.client.RestClientException
url
- the URLorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.optionsForAllow(java.net.URI)
public <T> org.springframework.http.ResponseEntity<T> exchange(String url, org.springframework.http.HttpMethod method, org.springframework.http.HttpEntity<?> requestEntity, Class<T> responseType, Object... urlVariables) throws org.springframework.web.client.RestClientException
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
T
- the type of the return valueurl
- the URLmethod
- the HTTP method (GET, POST, etc)requestEntity
- the entity (headers and/or body) to write to the request, may
be null
responseType
- the type of the return valueurlVariables
- the variables to expand in the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod,
org.springframework.http.HttpEntity, java.lang.Class, java.lang.Object[])
public <T> org.springframework.http.ResponseEntity<T> exchange(String url, org.springframework.http.HttpMethod method, org.springframework.http.HttpEntity<?> requestEntity, Class<T> responseType, Map<String,?> urlVariables) throws org.springframework.web.client.RestClientException
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
T
- the type of the return valueurl
- the URLmethod
- the HTTP method (GET, POST, etc)requestEntity
- the entity (headers and/or body) to write to the request, may
be null
responseType
- the type of the return valueurlVariables
- the variables to expand in the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod,
org.springframework.http.HttpEntity, java.lang.Class, java.util.Map)
public <T> org.springframework.http.ResponseEntity<T> exchange(URI url, org.springframework.http.HttpMethod method, org.springframework.http.HttpEntity<?> requestEntity, Class<T> responseType) throws org.springframework.web.client.RestClientException
ResponseEntity
.T
- the type of the return valueurl
- the URLmethod
- the HTTP method (GET, POST, etc)requestEntity
- the entity (headers and/or body) to write to the request, may
be null
responseType
- the type of the return valueorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.exchange(java.net.URI, org.springframework.http.HttpMethod,
org.springframework.http.HttpEntity, java.lang.Class)
public <T> org.springframework.http.ResponseEntity<T> exchange(String url, org.springframework.http.HttpMethod method, org.springframework.http.HttpEntity<?> requestEntity, org.springframework.core.ParameterizedTypeReference<T> responseType, Object... urlVariables) throws org.springframework.web.client.RestClientException
ResponseEntity
. The given
ParameterizedTypeReference
is 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);
T
- the type of the return valueurl
- the URLmethod
- the HTTP method (GET, POST, etc)requestEntity
- the entity (headers and/or body) to write to the request, may
be null
responseType
- the type of the return valueurlVariables
- the variables to expand in the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod,
org.springframework.http.HttpEntity,
org.springframework.core.ParameterizedTypeReference, java.lang.Object[])
public <T> org.springframework.http.ResponseEntity<T> exchange(String url, org.springframework.http.HttpMethod method, org.springframework.http.HttpEntity<?> requestEntity, org.springframework.core.ParameterizedTypeReference<T> responseType, Map<String,?> urlVariables) throws org.springframework.web.client.RestClientException
ResponseEntity
. The given
ParameterizedTypeReference
is 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);
T
- the type of the return valueurl
- the URLmethod
- the HTTP method (GET, POST, etc)requestEntity
- the entity (headers and/or body) to write to the request, may
be null
responseType
- the type of the return valueurlVariables
- the variables to expand in the templateorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod,
org.springframework.http.HttpEntity,
org.springframework.core.ParameterizedTypeReference, java.util.Map)
public <T> org.springframework.http.ResponseEntity<T> exchange(URI url, org.springframework.http.HttpMethod method, org.springframework.http.HttpEntity<?> requestEntity, org.springframework.core.ParameterizedTypeReference<T> responseType) throws org.springframework.web.client.RestClientException
ResponseEntity
. The given
ParameterizedTypeReference
is 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);
T
- the type of the return valueurl
- the URLmethod
- the HTTP method (GET, POST, etc)requestEntity
- the entity (headers and/or body) to write to the request, may
be null
responseType
- the type of the return valueorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.exchange(java.net.URI, org.springframework.http.HttpMethod,
org.springframework.http.HttpEntity,
org.springframework.core.ParameterizedTypeReference)
public <T> org.springframework.http.ResponseEntity<T> exchange(org.springframework.http.RequestEntity<?> requestEntity, Class<T> responseType) throws org.springframework.web.client.RestClientException
RequestEntity
and return the
response as ResponseEntity
. Typically used in combination with the static
builder methods on RequestEntity
, 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);
T
- the type of the return valuerequestEntity
- the entity to write to the requestresponseType
- the type of the return valueorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.exchange(org.springframework.http.RequestEntity, java.lang.Class)
public <T> org.springframework.http.ResponseEntity<T> exchange(org.springframework.http.RequestEntity<?> requestEntity, org.springframework.core.ParameterizedTypeReference<T> responseType) throws org.springframework.web.client.RestClientException
RequestEntity
and return the
response as ResponseEntity
. The given ParameterizedTypeReference
is
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);
T
- the type of the return valuerequestEntity
- the entity to write to the requestresponseType
- the type of the return valueorg.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.exchange(org.springframework.http.RequestEntity,
org.springframework.core.ParameterizedTypeReference)
public <T> T execute(String url, org.springframework.http.HttpMethod method, org.springframework.web.client.RequestCallback requestCallback, org.springframework.web.client.ResponseExtractor<T> responseExtractor, Object... urlVariables) throws org.springframework.web.client.RestClientException
RequestCallback
, and reading the response with a ResponseExtractor
.
URI Template variables are expanded using the given URI variables, if any.
T
- the type of the return valueurl
- 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 templateResponseExtractor
org.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.execute(java.lang.String, org.springframework.http.HttpMethod,
org.springframework.web.client.RequestCallback,
org.springframework.web.client.ResponseExtractor, java.lang.Object[])
public <T> T execute(String url, org.springframework.http.HttpMethod method, org.springframework.web.client.RequestCallback requestCallback, org.springframework.web.client.ResponseExtractor<T> responseExtractor, Map<String,?> urlVariables) throws org.springframework.web.client.RestClientException
RequestCallback
, and reading the response with a ResponseExtractor
.
URI Template variables are expanded using the given URI variables map.
T
- the type of the return valueurl
- 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 templateResponseExtractor
org.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.execute(java.lang.String, org.springframework.http.HttpMethod,
org.springframework.web.client.RequestCallback,
org.springframework.web.client.ResponseExtractor, java.util.Map)
public <T> T execute(URI url, org.springframework.http.HttpMethod method, org.springframework.web.client.RequestCallback requestCallback, org.springframework.web.client.ResponseExtractor<T> responseExtractor) throws org.springframework.web.client.RestClientException
RequestCallback
, and reading the response with a ResponseExtractor
.T
- the type of the return valueurl
- the URLmethod
- the HTTP method (GET, POST, etc)requestCallback
- object that prepares the requestresponseExtractor
- object that extracts the return value from the responseResponseExtractor
org.springframework.web.client.RestClientException
- on client-side HTTP errorRestTemplate.execute(java.net.URI, org.springframework.http.HttpMethod,
org.springframework.web.client.RequestCallback,
org.springframework.web.client.ResponseExtractor)
public org.springframework.web.client.RestTemplate getRestTemplate()
RestTemplate
that is actually used to perform the
REST operations.public TestRestTemplate withBasicAuth(String username, String password)
TestRestTemplate
with the same configuration as this one,
except that it will send basic authorization headers using the given
username
and password
. The request factory used is a new instance
of the underlying RestTemplate
's request factory type (when possible).username
- the usernamepassword
- the passwordCopyright © 2019 Pivotal Software, Inc.. All rights reserved.