JavaScript is disabled on your browser.
Method Summary
All Methods Instance Methods Concrete Methods
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> ResponseEntity <T>
exchange (RequestEntity <?> requestEntity,
Class <T> responseType)
<T> ResponseEntity <T>
exchange (RequestEntity <?> requestEntity,
ParameterizedTypeReference <T> responseType)
<T> ResponseEntity <T>
exchange (String url,
HttpMethod method,
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> ResponseEntity <T>
exchange (String url,
HttpMethod method,
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> ResponseEntity <T>
exchange (String url,
HttpMethod method,
HttpEntity <?> requestEntity,
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> ResponseEntity <T>
exchange (String url,
HttpMethod method,
HttpEntity <?> requestEntity,
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> ResponseEntity <T>
exchange (URI url,
HttpMethod method,
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> ResponseEntity <T>
exchange (URI url,
HttpMethod method,
HttpEntity <?> requestEntity,
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,
HttpMethod method,
RequestCallback requestCallback,
ResponseExtractor <T> responseExtractor,
Map <String ,?> urlVariables)
<T> T
execute (String url,
HttpMethod method,
RequestCallback requestCallback,
ResponseExtractor <T> responseExtractor,
Object ... urlVariables)
<T> T
execute (URI url,
HttpMethod method,
RequestCallback requestCallback,
ResponseExtractor <T> responseExtractor)
<T> ResponseEntity <T>
getForEntity (String url,
Class <T> responseType,
Map <String ,?> urlVariables)
Retrieve a representation by doing a GET on the URI template.
<T> ResponseEntity <T>
getForEntity (String url,
Class <T> responseType,
Object ... urlVariables)
Retrieve an entity by doing a GET on the specified URL.
<T> 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 .
RestTemplate
getRestTemplate ()
Returns the underlying
RestTemplate
that is actually used to perform the
REST operations.
String
getRootUri ()
HttpHeaders
headForHeaders (String url,
Map <String ,?> urlVariables)
Retrieve all headers of the resource specified by the URI template.
HttpHeaders
headForHeaders (String url,
Object ... urlVariables)
Retrieve all headers of the resource specified by the URI template.
HttpHeaders
headForHeaders (URI url)
Retrieve all headers of the resource specified by the URL.
Set <HttpMethod >
optionsForAllow (String url,
Map <String ,?> urlVariables)
Return the value of the Allow header for the given URI.
Set <HttpMethod >
optionsForAllow (String url,
Object ... urlVariables)
Return the value of the Allow header for the given URI.
Set <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> 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> 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> 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 (UriTemplateHandler handler)
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
.
Methods inherited from class java.lang.Object
clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait
Constructor Detail
TestRestTemplate
public TestRestTemplate(RestTemplateBuilder restTemplateBuilder,
String username,
String password,
TestRestTemplate.HttpClientOption ... httpClientOptions)
Parameters:
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 used
Since:
2.0.0
Method Detail
getForObject
public <T> T getForObject(String url,
Class <T> responseType,
Map <String ,?> urlVariables)
throws RestClientException
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 URL
responseType
- the type of the return value
urlVariables
- the map containing variables for the URI template
Returns:
the converted object
Throws:
RestClientException
- on client-side HTTP error
See Also:
RestTemplate.getForObject(String, Class, Object...)
postForObject
public <T> T postForObject(String url,
Object request,
Class <T> responseType,
Object ... urlVariables)
throws RestClientException
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 request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
request
- the Object to be POSTed, may be null
responseType
- the type of the return value
urlVariables
- the variables to expand the template
Returns:
the converted object
Throws:
RestClientException
- on client-side HTTP error
See Also:
HttpEntity
,
RestTemplate.postForObject(java.lang.String, java.lang.Object,
java.lang.Class, java.lang.Object[])
postForObject
public <T> T postForObject(String url,
Object request,
Class <T> responseType,
Map <String ,?> urlVariables)
throws RestClientException
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 request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
request
- the Object to be POSTed, may be null
responseType
- the type of the return value
urlVariables
- the variables to expand the template
Returns:
the converted object
Throws:
RestClientException
- on client-side HTTP error
See Also:
HttpEntity
,
RestTemplate.postForObject(java.lang.String, java.lang.Object,
java.lang.Class, java.util.Map)
postForEntity
public <T> ResponseEntity <T> postForEntity(String url,
Object request,
Class <T> responseType,
Object ... urlVariables)
throws RestClientException
Create a new resource by POSTing the given object to the URI template, and returns
the response as
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.
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
request
- the Object to be POSTed, may be null
responseType
- the response type to return
urlVariables
- the variables to expand the template
Returns:
the converted object
Throws:
RestClientException
- on client-side HTTP error
See Also:
HttpEntity
,
RestTemplate.postForEntity(java.lang.String, java.lang.Object,
java.lang.Class, java.lang.Object[])
postForEntity
public <T> ResponseEntity <T> postForEntity(String url,
Object request,
Class <T> responseType,
Map <String ,?> urlVariables)
throws RestClientException
Create a new resource by POSTing the given object to the URI template, and returns
the response as
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.
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
request
- the Object to be POSTed, may be null
responseType
- the response type to return
urlVariables
- the variables to expand the template
Returns:
the converted object
Throws:
RestClientException
- on client-side HTTP error
See Also:
HttpEntity
,
RestTemplate.postForEntity(java.lang.String, java.lang.Object,
java.lang.Class, java.util.Map)
patchForObject
public <T> T patchForObject(String url,
Object request,
Class <T> responseType,
Object ... uriVariables)
throws RestClientException
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 request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
request
- the Object to be PATCHed, may be null
responseType
- the type of the return value
uriVariables
- the variables to expand the template
Returns:
the converted object
Throws:
RestClientException
- on client-side HTTP error
Since:
1.4.4
See Also:
HttpEntity
patchForObject
public <T> T patchForObject(String url,
Object request,
Class <T> responseType,
Map <String ,?> uriVariables)
throws RestClientException
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 request
parameter can be a HttpEntity
in order to add
additional HTTP headers to the request.
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
request
- the Object to be PATCHed, may be null
responseType
- the type of the return value
uriVariables
- the variables to expand the template
Returns:
the converted object
Throws:
RestClientException
- on client-side HTTP error
Since:
1.4.4
See Also:
HttpEntity
exchange
public <T> ResponseEntity <T> exchange(String url,
HttpMethod method,
HttpEntity <?> requestEntity,
Class <T> responseType,
Object ... urlVariables)
throws RestClientException
Execute the HTTP method to the given URI template, writing the given request entity
to the request, and returns the response as
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
method
- 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 value
urlVariables
- the variables to expand in the template
Returns:
the response as entity
Throws:
RestClientException
- on client-side HTTP error
See Also:
RestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod,
org.springframework.http.HttpEntity, java.lang.Class, java.lang.Object[])
exchange
public <T> ResponseEntity <T> exchange(String url,
HttpMethod method,
HttpEntity <?> requestEntity,
Class <T> responseType,
Map <String ,?> urlVariables)
throws RestClientException
Execute the HTTP method to the given URI template, writing the given request entity
to the request, and returns the response as
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
method
- 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 value
urlVariables
- the variables to expand in the template
Returns:
the response as entity
Throws:
RestClientException
- on client-side HTTP error
See Also:
RestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod,
org.springframework.http.HttpEntity, java.lang.Class, java.util.Map)
exchange
public <T> ResponseEntity <T> exchange(URI url,
HttpMethod method,
HttpEntity <?> requestEntity,
Class <T> responseType)
throws RestClientException
Execute the HTTP method to the given URI template, writing the given request entity
to the request, and returns the response as
ResponseEntity
.
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
method
- 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 value
Returns:
the response as entity
Throws:
RestClientException
- on client-side HTTP error
See Also:
RestTemplate.exchange(java.net.URI, org.springframework.http.HttpMethod,
org.springframework.http.HttpEntity, java.lang.Class)
exchange
public <T> ResponseEntity <T> exchange(String url,
HttpMethod method,
HttpEntity <?> requestEntity,
ParameterizedTypeReference <T> responseType,
Object ... urlVariables)
throws RestClientException
Execute the HTTP method to the given URI template, writing the given request entity
to the request, and returns the response as
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("http://example.com",HttpMethod.GET, null, myBean);
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
method
- 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 value
urlVariables
- the variables to expand in the template
Returns:
the response as entity
Throws:
RestClientException
- on client-side HTTP error
See Also:
RestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod,
org.springframework.http.HttpEntity,
org.springframework.core.ParameterizedTypeReference, java.lang.Object[])
exchange
public <T> ResponseEntity <T> exchange(String url,
HttpMethod method,
HttpEntity <?> requestEntity,
ParameterizedTypeReference <T> responseType,
Map <String ,?> urlVariables)
throws RestClientException
Execute the HTTP method to the given URI template, writing the given request entity
to the request, and returns the response as
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("http://example.com",HttpMethod.GET, null, myBean);
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
method
- 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 value
urlVariables
- the variables to expand in the template
Returns:
the response as entity
Throws:
RestClientException
- on client-side HTTP error
See Also:
RestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod,
org.springframework.http.HttpEntity,
org.springframework.core.ParameterizedTypeReference, java.util.Map)
exchange
public <T> ResponseEntity <T> exchange(URI url,
HttpMethod method,
HttpEntity <?> requestEntity,
ParameterizedTypeReference <T> responseType)
throws RestClientException
Execute the HTTP method to the given URI template, writing the given request entity
to the request, and returns the response as
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("http://example.com",HttpMethod.GET, null, myBean);
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
method
- 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 value
Returns:
the response as entity
Throws:
RestClientException
- on client-side HTTP error
See Also:
RestTemplate.exchange(java.net.URI, org.springframework.http.HttpMethod,
org.springframework.http.HttpEntity,
org.springframework.core.ParameterizedTypeReference)
execute
public <T> T execute(String url,
HttpMethod method,
RequestCallback requestCallback,
ResponseExtractor <T> responseExtractor,
Object ... urlVariables)
throws RestClientException
Execute the HTTP method to the given URI template, preparing the request with the
RequestCallback
, and reading the response with a
ResponseExtractor
.
URI Template variables are expanded using the given URI variables, if any.
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
method
- the HTTP method (GET, POST, etc)
requestCallback
- object that prepares the request
responseExtractor
- object that extracts the return value from the response
urlVariables
- the variables to expand in the template
Returns:
an arbitrary object, as returned by the ResponseExtractor
Throws:
RestClientException
- on client-side HTTP error
See Also:
RestTemplate.execute(java.lang.String, org.springframework.http.HttpMethod,
org.springframework.web.client.RequestCallback,
org.springframework.web.client.ResponseExtractor, java.lang.Object[])
execute
public <T> T execute(String url,
HttpMethod method,
RequestCallback requestCallback,
ResponseExtractor <T> responseExtractor,
Map <String ,?> urlVariables)
throws RestClientException
Execute the HTTP method to the given URI template, preparing the request with the
RequestCallback
, and reading the response with a
ResponseExtractor
.
URI Template variables are expanded using the given URI variables map.
Type Parameters:
T
- the type of the return value
Parameters:
url
- the URL
method
- the HTTP method (GET, POST, etc)
requestCallback
- object that prepares the request
responseExtractor
- object that extracts the return value from the response
urlVariables
- the variables to expand in the template
Returns:
an arbitrary object, as returned by the ResponseExtractor
Throws:
RestClientException
- on client-side HTTP error
See Also:
RestTemplate.execute(java.lang.String, org.springframework.http.HttpMethod,
org.springframework.web.client.RequestCallback,
org.springframework.web.client.ResponseExtractor, java.util.Map)
withBasicAuth
public 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
.
Parameters:
username
- the username
password
- the password
Returns:
the new template
Since:
1.4.1