public class AsyncRestTemplate extends InterceptingAsyncHttpAccessor implements AsyncRestOperations
RestTemplate
, but returns ListenableFuture
wrappers as opposed to concrete results.
The AsyncRestTemplate
exposes a synchronous RestTemplate
via the
getRestOperations()
method and shares its error handler
and message converters with that RestTemplate
.
Note: by default AsyncRestTemplate
relies on
standard JDK facilities to establish HTTP connections. You can switch to use
a different HTTP library such as Apache HttpComponents, Netty, and OkHttp by
using a constructor accepting an AsyncClientHttpRequestFactory
.
For more information, please refer to the RestTemplate
API documentation.
RestTemplate
logger
Constructor and Description |
---|
AsyncRestTemplate()
Create a new instance of the
AsyncRestTemplate using default settings. |
AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory)
Create a new instance of the
AsyncRestTemplate using the given
AsyncClientHttpRequestFactory . |
AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory,
ClientHttpRequestFactory syncRequestFactory)
Creates a new instance of the
AsyncRestTemplate using the given
asynchronous and synchronous request factories. |
AsyncRestTemplate(AsyncClientHttpRequestFactory requestFactory,
RestTemplate restTemplate)
Create a new instance of the
AsyncRestTemplate using the given
AsyncClientHttpRequestFactory and synchronous RestTemplate . |
AsyncRestTemplate(AsyncListenableTaskExecutor taskExecutor)
Create a new instance of the
AsyncRestTemplate using the given
AsyncTaskExecutor . |
Modifier and Type | Method and Description |
---|---|
protected <T> AsyncRequestCallback |
acceptHeaderRequestCallback(java.lang.Class<T> responseType)
Returns a request callback implementation that prepares the request
Accept
headers based on the given response type and configured message converters. |
ListenableFuture<?> |
delete(java.lang.String url,
java.util.Map<java.lang.String,?> uriVariables)
Asynchronously delete the resources at the specified URI.
|
ListenableFuture<?> |
delete(java.lang.String url,
java.lang.Object... uriVariables)
Asynchronously delete the resources at the specified URI.
|
ListenableFuture<?> |
delete(java.net.URI url)
Asynchronously delete the resources at the specified URI.
|
protected <T> ListenableFuture<T> |
doExecute(java.net.URI url,
HttpMethod method,
AsyncRequestCallback requestCallback,
ResponseExtractor<T> responseExtractor)
Execute the given method on the provided URI.
|
<T> ListenableFuture<ResponseEntity<T>> |
exchange(java.lang.String url,
HttpMethod method,
HttpEntity<?> requestEntity,
java.lang.Class<T> responseType,
java.util.Map<java.lang.String,?> uriVariables)
Asynchronously execute the HTTP method to the given URI template, writing the
given request entity to the request, and returns the response as
ResponseEntity . |
<T> ListenableFuture<ResponseEntity<T>> |
exchange(java.lang.String url,
HttpMethod method,
HttpEntity<?> requestEntity,
java.lang.Class<T> responseType,
java.lang.Object... uriVariables)
Asynchronously execute the HTTP method to the given URI template, writing the
given request entity to the request, and returns the response as
ResponseEntity . |
<T> ListenableFuture<ResponseEntity<T>> |
exchange(java.lang.String url,
HttpMethod method,
HttpEntity<?> requestEntity,
ParameterizedTypeReference<T> responseType,
java.util.Map<java.lang.String,?> uriVariables)
Asynchronously execute the HTTP method to the given URI template, writing the given
request entity to the request, and returns the response as
ResponseEntity . |
<T> ListenableFuture<ResponseEntity<T>> |
exchange(java.lang.String url,
HttpMethod method,
HttpEntity<?> requestEntity,
ParameterizedTypeReference<T> responseType,
java.lang.Object... uriVariables)
Asynchronously execute the HTTP method to the given URI template, writing the given
request entity to the request, and returns the response as
ResponseEntity . |
<T> ListenableFuture<ResponseEntity<T>> |
exchange(java.net.URI url,
HttpMethod method,
HttpEntity<?> requestEntity,
java.lang.Class<T> responseType)
Asynchronously execute the HTTP method to the given URI template, writing the
given request entity to the request, and returns the response as
ResponseEntity . |
<T> ListenableFuture<ResponseEntity<T>> |
exchange(java.net.URI url,
HttpMethod method,
HttpEntity<?> requestEntity,
ParameterizedTypeReference<T> responseType)
Asynchronously execute the HTTP method to the given URI template, writing the given
request entity to the request, and returns the response as
ResponseEntity . |
<T> ListenableFuture<T> |
execute(java.lang.String url,
HttpMethod method,
AsyncRequestCallback requestCallback,
ResponseExtractor<T> responseExtractor,
java.util.Map<java.lang.String,?> uriVariables)
Asynchronously execute the HTTP method to the given URI template, preparing the
request with the
AsyncRequestCallback , and reading the response with a
ResponseExtractor . |
<T> ListenableFuture<T> |
execute(java.lang.String url,
HttpMethod method,
AsyncRequestCallback requestCallback,
ResponseExtractor<T> responseExtractor,
java.lang.Object... uriVariables)
Asynchronously execute the HTTP method to the given URI template, preparing the
request with the
AsyncRequestCallback , and reading the response with a
ResponseExtractor . |
<T> ListenableFuture<T> |
execute(java.net.URI url,
HttpMethod method,
AsyncRequestCallback requestCallback,
ResponseExtractor<T> responseExtractor)
Asynchronously execute the HTTP method to the given URL, preparing the request
with the
AsyncRequestCallback , and reading the response with a
ResponseExtractor . |
ResponseErrorHandler |
getErrorHandler()
Return the error handler.
|
<T> ListenableFuture<ResponseEntity<T>> |
getForEntity(java.lang.String url,
java.lang.Class<T> responseType,
java.util.Map<java.lang.String,?> uriVariables)
Asynchronously retrieve a representation by doing a GET on the URI template.
|
<T> ListenableFuture<ResponseEntity<T>> |
getForEntity(java.lang.String url,
java.lang.Class<T> responseType,
java.lang.Object... uriVariables)
Asynchronously retrieve an entity by doing a GET on the specified URL.
|
<T> ListenableFuture<ResponseEntity<T>> |
getForEntity(java.net.URI url,
java.lang.Class<T> responseType)
Asynchronously retrieve a representation by doing a GET on the URL.
|
java.util.List<HttpMessageConverter<?>> |
getMessageConverters()
Return the message body converters.
|
RestOperations |
getRestOperations()
Expose the synchronous Spring RestTemplate to allow synchronous invocation.
|
UriTemplateHandler |
getUriTemplateHandler()
Return the configured URI template handler.
|
protected ResponseExtractor<HttpHeaders> |
headersExtractor()
Returns a response extractor for
HttpHeaders . |
ListenableFuture<HttpHeaders> |
headForHeaders(java.lang.String url,
java.util.Map<java.lang.String,?> uriVariables)
Asynchronously retrieve all headers of the resource specified by the URI template.
|
ListenableFuture<HttpHeaders> |
headForHeaders(java.lang.String url,
java.lang.Object... uriVariables)
Asynchronously retrieve all headers of the resource specified by the URI template.
|
ListenableFuture<HttpHeaders> |
headForHeaders(java.net.URI url)
Asynchronously retrieve all headers of the resource specified by the URL.
|
protected <T> AsyncRequestCallback |
httpEntityCallback(HttpEntity<T> requestBody)
Returns a request callback implementation that writes the given object to the
request stream.
|
protected <T> AsyncRequestCallback |
httpEntityCallback(HttpEntity<T> request,
java.lang.reflect.Type responseType)
Returns a request callback implementation that writes the given object to the
request stream.
|
ListenableFuture<java.util.Set<HttpMethod>> |
optionsForAllow(java.lang.String url,
java.util.Map<java.lang.String,?> uriVars)
Asynchronously return the value of the Allow header for the given URI.
|
ListenableFuture<java.util.Set<HttpMethod>> |
optionsForAllow(java.lang.String url,
java.lang.Object... uriVars)
Asynchronously return the value of the Allow header for the given URI.
|
ListenableFuture<java.util.Set<HttpMethod>> |
optionsForAllow(java.net.URI url)
Asynchronously return the value of the Allow header for the given URL.
|
<T> ListenableFuture<ResponseEntity<T>> |
postForEntity(java.lang.String url,
HttpEntity<?> request,
java.lang.Class<T> responseType,
java.util.Map<java.lang.String,?> uriVariables)
Create a new resource by POSTing the given object to the URI template,
and asynchronously returns the response as
ResponseEntity . |
<T> ListenableFuture<ResponseEntity<T>> |
postForEntity(java.lang.String url,
HttpEntity<?> request,
java.lang.Class<T> responseType,
java.lang.Object... uriVariables)
Create a new resource by POSTing the given object to the URI template,
and asynchronously returns the response as
ResponseEntity . |
<T> ListenableFuture<ResponseEntity<T>> |
postForEntity(java.net.URI url,
HttpEntity<?> request,
java.lang.Class<T> responseType)
Create a new resource by POSTing the given object to the URL,
and asynchronously returns the response as
ResponseEntity . |
ListenableFuture<java.net.URI> |
postForLocation(java.lang.String url,
HttpEntity<?> request,
java.util.Map<java.lang.String,?> uriVars)
Create a new resource by POSTing the given object to the URI template, and
asynchronously returns the value of the
Location header. |
ListenableFuture<java.net.URI> |
postForLocation(java.lang.String url,
HttpEntity<?> request,
java.lang.Object... uriVars)
Create a new resource by POSTing the given object to the URI template, and
asynchronously returns the value of the
Location header. |
ListenableFuture<java.net.URI> |
postForLocation(java.net.URI url,
HttpEntity<?> request)
Create a new resource by POSTing the given object to the URL, and asynchronously
returns the value of the
Location header. |
ListenableFuture<?> |
put(java.lang.String url,
HttpEntity<?> request,
java.util.Map<java.lang.String,?> uriVariables)
Creates a new resource by PUTting the given object to URI template.
|
ListenableFuture<?> |
put(java.lang.String url,
HttpEntity<?> request,
java.lang.Object... uriVariables)
Create or update a resource by PUTting the given object to the URI.
|
ListenableFuture<?> |
put(java.net.URI url,
HttpEntity<?> request)
Creates a new resource by PUTting the given object to URL.
|
protected <T> ResponseExtractor<ResponseEntity<T>> |
responseEntityExtractor(java.lang.reflect.Type responseType)
Returns a response extractor for
ResponseEntity . |
void |
setDefaultUriVariables(java.util.Map<java.lang.String,?> defaultUriVariables)
Configure default URI variable values.
|
void |
setErrorHandler(ResponseErrorHandler errorHandler)
Set the error handler.
|
void |
setMessageConverters(java.util.List<HttpMessageConverter<?>> messageConverters)
Set the message body converters to use.
|
void |
setUriTemplateHandler(UriTemplateHandler handler)
This property has the same purpose as the corresponding property on the
RestTemplate . |
getAsyncRequestFactory, getInterceptors, setInterceptors
createAsyncRequest, setAsyncRequestFactory
public AsyncRestTemplate()
AsyncRestTemplate
using default settings.
This constructor uses a SimpleClientHttpRequestFactory
in combination
with a SimpleAsyncTaskExecutor
for asynchronous execution.
public AsyncRestTemplate(AsyncListenableTaskExecutor taskExecutor)
AsyncRestTemplate
using the given
AsyncTaskExecutor
.
This constructor uses a SimpleClientHttpRequestFactory
in combination
with the given AsyncTaskExecutor
for asynchronous execution.
public AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory)
AsyncRestTemplate
using the given
AsyncClientHttpRequestFactory
.
This constructor will cast the given asynchronous
AsyncClientHttpRequestFactory
to a ClientHttpRequestFactory
. Since
all implementations of ClientHttpRequestFactory
provided in Spring also
implement AsyncClientHttpRequestFactory
, this should not result in a
ClassCastException
.
public AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory, ClientHttpRequestFactory syncRequestFactory)
AsyncRestTemplate
using the given
asynchronous and synchronous request factories.asyncRequestFactory
- the asynchronous request factorysyncRequestFactory
- the synchronous request factorypublic AsyncRestTemplate(AsyncClientHttpRequestFactory requestFactory, RestTemplate restTemplate)
AsyncRestTemplate
using the given
AsyncClientHttpRequestFactory
and synchronous RestTemplate
.requestFactory
- the asynchronous request factory to userestTemplate
- the synchronous template to usepublic void setErrorHandler(ResponseErrorHandler errorHandler)
By default, AsyncRestTemplate uses a
DefaultResponseErrorHandler
.
public ResponseErrorHandler getErrorHandler()
public void setDefaultUriVariables(java.util.Map<java.lang.String,?> defaultUriVariables)
DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler(); handler.setDefaultUriVariables(...); AsyncRestTemplate restTemplate = new AsyncRestTemplate(); restTemplate.setUriTemplateHandler(handler);
defaultUriVariables
- the default URI variable valuespublic void setUriTemplateHandler(UriTemplateHandler handler)
RestTemplate
. For more details see
RestTemplate.setUriTemplateHandler(org.springframework.web.util.UriTemplateHandler)
.handler
- the URI template handler to usepublic UriTemplateHandler getUriTemplateHandler()
public RestOperations getRestOperations()
AsyncRestOperations
getRestOperations
in interface AsyncRestOperations
public void setMessageConverters(java.util.List<HttpMessageConverter<?>> messageConverters)
These converters are used to convert from and to HTTP requests and responses.
public java.util.List<HttpMessageConverter<?>> getMessageConverters()
public <T> ListenableFuture<ResponseEntity<T>> getForEntity(java.lang.String url, java.lang.Class<T> responseType, java.lang.Object... uriVariables) throws RestClientException
AsyncRestOperations
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
getForEntity
in interface AsyncRestOperations
url
- the URLresponseType
- the type of the return valueuriVariables
- the variables to expand the templateFuture
RestClientException
public <T> ListenableFuture<ResponseEntity<T>> getForEntity(java.lang.String url, java.lang.Class<T> responseType, java.util.Map<java.lang.String,?> uriVariables) throws RestClientException
AsyncRestOperations
ResponseEntity
.
URI Template variables are expanded using the given map.
getForEntity
in interface AsyncRestOperations
url
- the URLresponseType
- the type of the return valueuriVariables
- the map containing variables for the URI templateFuture
RestClientException
public <T> ListenableFuture<ResponseEntity<T>> getForEntity(java.net.URI url, java.lang.Class<T> responseType) throws RestClientException
AsyncRestOperations
ResponseEntity
.getForEntity
in interface AsyncRestOperations
url
- the URLresponseType
- the type of the return valueFuture
RestClientException
public ListenableFuture<HttpHeaders> headForHeaders(java.lang.String url, java.lang.Object... uriVariables) throws RestClientException
AsyncRestOperations
URI Template variables are expanded using the given URI variables, if any.
headForHeaders
in interface AsyncRestOperations
url
- the URLuriVariables
- the variables to expand the templateFuture
RestClientException
public ListenableFuture<HttpHeaders> headForHeaders(java.lang.String url, java.util.Map<java.lang.String,?> uriVariables) throws RestClientException
AsyncRestOperations
URI Template variables are expanded using the given map.
headForHeaders
in interface AsyncRestOperations
url
- the URLuriVariables
- the map containing variables for the URI templateFuture
RestClientException
public ListenableFuture<HttpHeaders> headForHeaders(java.net.URI url) throws RestClientException
AsyncRestOperations
headForHeaders
in interface AsyncRestOperations
url
- the URLFuture
RestClientException
public ListenableFuture<java.net.URI> postForLocation(java.lang.String url, HttpEntity<?> request, java.lang.Object... uriVars) throws RestClientException
AsyncRestOperations
Location
header. This header
typically indicates where the new resource is stored.
URI Template variables are expanded using the given URI variables, if any.
postForLocation
in interface AsyncRestOperations
url
- the URLrequest
- the Object to be POSTed (may be null
)uriVars
- the variables to expand the templateLocation
header wrapped in a Future
RestClientException
HttpEntity
public ListenableFuture<java.net.URI> postForLocation(java.lang.String url, HttpEntity<?> request, java.util.Map<java.lang.String,?> uriVars) throws RestClientException
AsyncRestOperations
Location
header. This header
typically indicates where the new resource is stored.
URI Template variables are expanded using the given map.
postForLocation
in interface AsyncRestOperations
url
- the URLrequest
- the Object to be POSTed (may be null
)uriVars
- the variables to expand the templateLocation
header wrapped in a Future
RestClientException
HttpEntity
public ListenableFuture<java.net.URI> postForLocation(java.net.URI url, HttpEntity<?> request) throws RestClientException
AsyncRestOperations
Location
header. This header typically indicates
where the new resource is stored.postForLocation
in interface AsyncRestOperations
url
- the URLrequest
- the Object to be POSTed (may be null
)Location
header wrapped in a Future
RestClientException
HttpEntity
public <T> ListenableFuture<ResponseEntity<T>> postForEntity(java.lang.String url, HttpEntity<?> request, java.lang.Class<T> responseType, java.lang.Object... uriVariables) throws RestClientException
AsyncRestOperations
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
postForEntity
in interface AsyncRestOperations
url
- the URLrequest
- the Object to be POSTed (may be null
)uriVariables
- the variables to expand the templateFuture
RestClientException
HttpEntity
public <T> ListenableFuture<ResponseEntity<T>> postForEntity(java.lang.String url, HttpEntity<?> request, java.lang.Class<T> responseType, java.util.Map<java.lang.String,?> uriVariables) throws RestClientException
AsyncRestOperations
ResponseEntity
.
URI Template variables are expanded using the given map.
postForEntity
in interface AsyncRestOperations
url
- the URLrequest
- the Object to be POSTed (may be null
)uriVariables
- the variables to expand the templateFuture
RestClientException
HttpEntity
public <T> ListenableFuture<ResponseEntity<T>> postForEntity(java.net.URI url, HttpEntity<?> request, java.lang.Class<T> responseType) throws RestClientException
AsyncRestOperations
ResponseEntity
.postForEntity
in interface AsyncRestOperations
url
- the URLrequest
- the Object to be POSTed (may be null
)Future
RestClientException
HttpEntity
public ListenableFuture<?> put(java.lang.String url, HttpEntity<?> request, java.lang.Object... uriVariables) throws RestClientException
AsyncRestOperations
URI Template variables are expanded using the given URI variables, if any.
The Future will return a null
result upon completion.
put
in interface AsyncRestOperations
url
- the URLrequest
- the Object to be PUT (may be null
)uriVariables
- the variables to expand the templateRestClientException
HttpEntity
public ListenableFuture<?> put(java.lang.String url, HttpEntity<?> request, java.util.Map<java.lang.String,?> uriVariables) throws RestClientException
AsyncRestOperations
URI Template variables are expanded using the given map.
The Future will return a null
result upon completion.
put
in interface AsyncRestOperations
url
- the URLrequest
- the Object to be PUT (may be null
)uriVariables
- the variables to expand the templateRestClientException
HttpEntity
public ListenableFuture<?> put(java.net.URI url, HttpEntity<?> request) throws RestClientException
AsyncRestOperations
The Future will return a null
result upon completion.
put
in interface AsyncRestOperations
url
- the URLrequest
- the Object to be PUT (may be null
)RestClientException
HttpEntity
public ListenableFuture<?> delete(java.lang.String url, java.lang.Object... uriVariables) throws RestClientException
AsyncRestOperations
URI Template variables are expanded using the given URI variables, if any.
The Future will return a null
result upon completion.
delete
in interface AsyncRestOperations
url
- the URLuriVariables
- the variables to expand in the templateRestClientException
public ListenableFuture<?> delete(java.lang.String url, java.util.Map<java.lang.String,?> uriVariables) throws RestClientException
AsyncRestOperations
URI Template variables are expanded using the given URI variables, if any.
The Future will return a null
result upon completion.
delete
in interface AsyncRestOperations
url
- the URLuriVariables
- the variables to expand in the templateRestClientException
public ListenableFuture<?> delete(java.net.URI url) throws RestClientException
AsyncRestOperations
URI Template variables are expanded using the given URI variables, if any.
The Future will return a null
result upon completion.
delete
in interface AsyncRestOperations
url
- the URLRestClientException
public ListenableFuture<java.util.Set<HttpMethod>> optionsForAllow(java.lang.String url, java.lang.Object... uriVars) throws RestClientException
AsyncRestOperations
URI Template variables are expanded using the given URI variables, if any.
optionsForAllow
in interface AsyncRestOperations
url
- the URLuriVars
- the variables to expand in the templateFuture
RestClientException
public ListenableFuture<java.util.Set<HttpMethod>> optionsForAllow(java.lang.String url, java.util.Map<java.lang.String,?> uriVars) throws RestClientException
AsyncRestOperations
URI Template variables are expanded using the given map.
optionsForAllow
in interface AsyncRestOperations
url
- the URLuriVars
- the variables to expand in the templateFuture
RestClientException
public ListenableFuture<java.util.Set<HttpMethod>> optionsForAllow(java.net.URI url) throws RestClientException
AsyncRestOperations
optionsForAllow
in interface AsyncRestOperations
url
- the URLFuture
RestClientException
public <T> ListenableFuture<ResponseEntity<T>> exchange(java.lang.String url, HttpMethod method, HttpEntity<?> requestEntity, java.lang.Class<T> responseType, java.lang.Object... uriVariables) throws RestClientException
AsyncRestOperations
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
exchange
in interface AsyncRestOperations
url
- 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 valueuriVariables
- the variables to expand in the templateFuture
RestClientException
public <T> ListenableFuture<ResponseEntity<T>> exchange(java.lang.String url, HttpMethod method, HttpEntity<?> requestEntity, java.lang.Class<T> responseType, java.util.Map<java.lang.String,?> uriVariables) throws RestClientException
AsyncRestOperations
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
exchange
in interface AsyncRestOperations
url
- 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 valueuriVariables
- the variables to expand in the templateFuture
RestClientException
public <T> ListenableFuture<ResponseEntity<T>> exchange(java.net.URI url, HttpMethod method, HttpEntity<?> requestEntity, java.lang.Class<T> responseType) throws RestClientException
AsyncRestOperations
ResponseEntity
.exchange
in interface AsyncRestOperations
url
- 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 valueFuture
RestClientException
public <T> ListenableFuture<ResponseEntity<T>> exchange(java.lang.String url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, java.lang.Object... uriVariables) throws RestClientException
AsyncRestOperations
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);
exchange
in interface AsyncRestOperations
url
- 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 valueuriVariables
- the variables to expand in the templateFuture
RestClientException
public <T> ListenableFuture<ResponseEntity<T>> exchange(java.lang.String url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, java.util.Map<java.lang.String,?> uriVariables) throws RestClientException
AsyncRestOperations
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);
exchange
in interface AsyncRestOperations
url
- 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 valueuriVariables
- the variables to expand in the templateFuture
RestClientException
public <T> ListenableFuture<ResponseEntity<T>> exchange(java.net.URI url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType) throws RestClientException
AsyncRestOperations
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);
exchange
in interface AsyncRestOperations
url
- 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 valueFuture
RestClientException
public <T> ListenableFuture<T> execute(java.lang.String url, HttpMethod method, AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor, java.lang.Object... uriVariables) throws RestClientException
AsyncRestOperations
AsyncRequestCallback
, and reading the response with a
ResponseExtractor
.
URI Template variables are expanded using the given URI variables, if any.
execute
in interface AsyncRestOperations
url
- the URLmethod
- the HTTP method (GET, POST, etc)requestCallback
- object that prepares the requestresponseExtractor
- object that extracts the return value from the responseuriVariables
- the variables to expand in the templateResponseExtractor
RestClientException
public <T> ListenableFuture<T> execute(java.lang.String url, HttpMethod method, AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor, java.util.Map<java.lang.String,?> uriVariables) throws RestClientException
AsyncRestOperations
AsyncRequestCallback
, and reading the response with a
ResponseExtractor
.
URI Template variables are expanded using the given URI variables map.
execute
in interface AsyncRestOperations
url
- the URLmethod
- the HTTP method (GET, POST, etc)requestCallback
- object that prepares the requestresponseExtractor
- object that extracts the return value from the responseuriVariables
- the variables to expand in the templateResponseExtractor
RestClientException
public <T> ListenableFuture<T> execute(java.net.URI url, HttpMethod method, AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws RestClientException
AsyncRestOperations
AsyncRequestCallback
, and reading the response with a
ResponseExtractor
.execute
in interface AsyncRestOperations
url
- the URLmethod
- the HTTP method (GET, POST, etc)requestCallback
- object that prepares the requestresponseExtractor
- object that extracts the return value from the responseResponseExtractor
RestClientException
protected <T> ListenableFuture<T> doExecute(java.net.URI url, HttpMethod method, AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws RestClientException
ClientHttpRequest
is processed using the RequestCallback
; the response with
the ResponseExtractor
.url
- the fully-expanded URL to connect tomethod
- the HTTP method to execute (GET, POST, etc.)requestCallback
- object that prepares the request (can be null
)responseExtractor
- object that extracts the return value from the response (can
be null
)ResponseExtractor
RestClientException
protected <T> AsyncRequestCallback acceptHeaderRequestCallback(java.lang.Class<T> responseType)
Accept
headers based on the given response type and configured message converters.protected <T> AsyncRequestCallback httpEntityCallback(HttpEntity<T> requestBody)
protected <T> AsyncRequestCallback httpEntityCallback(HttpEntity<T> request, java.lang.reflect.Type responseType)
protected <T> ResponseExtractor<ResponseEntity<T>> responseEntityExtractor(java.lang.reflect.Type responseType)
ResponseEntity
.protected ResponseExtractor<HttpHeaders> headersExtractor()
HttpHeaders
.