Class AsyncRestTemplate
- java.lang.Object
- org.springframework.http.client.support.AsyncHttpAccessor
- org.springframework.http.client.support.InterceptingAsyncHttpAccessor
- org.springframework.web.client.AsyncRestTemplate
- All Implemented Interfaces:
AsyncRestOperations
public class AsyncRestTemplate extends InterceptingAsyncHttpAccessor implements AsyncRestOperations
Spring's central class for asynchronous client-side HTTP access. Exposes similar methods asRestTemplate, but returnsListenableFuturewrappers as opposed to concrete results.The
AsyncRestTemplateexposes a synchronousRestTemplatevia thegetRestOperations()method and shares its error handler and message converters with thatRestTemplate.Note: by default
AsyncRestTemplaterelies 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 anAsyncClientHttpRequestFactory.For more information, please refer to the
RestTemplateAPI documentation.- Since:
- 4.0
- Author:
- Arjen Poutsma
- See Also:
RestTemplate
Field Summary
Fields inherited from class org.springframework.http.client.support.AsyncHttpAccessor
logger
Constructor Summary
Constructors Constructor Description AsyncRestTemplate()Create a new instance of theAsyncRestTemplateusing default settings.AsyncRestTemplate(AsyncListenableTaskExecutor taskExecutor)Create a new instance of theAsyncRestTemplateusing the givenAsyncTaskExecutor.AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory)Create a new instance of theAsyncRestTemplateusing the givenAsyncClientHttpRequestFactory.AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory, ClientHttpRequestFactory syncRequestFactory)Creates a new instance of theAsyncRestTemplateusing the given asynchronous and synchronous request factories.AsyncRestTemplate(AsyncClientHttpRequestFactory requestFactory, RestTemplate restTemplate)Create a new instance of theAsyncRestTemplateusing the givenAsyncClientHttpRequestFactoryand synchronousRestTemplate.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> AsyncRequestCallbackacceptHeaderRequestCallback(Class<T> responseType)Returns a request callback implementation that prepares the requestAcceptheaders based on the given response type and configured message converters.ListenableFuture<?>delete(String url, Object... uriVariables)Asynchronously delete the resources at the specified URI.ListenableFuture<?>delete(String url, Map<String,?> uriVariables)Asynchronously delete the resources at the specified URI.ListenableFuture<?>delete(URI url)Asynchronously delete the resources at the specified URI.protected <T> ListenableFuture<T>doExecute(URI url, HttpMethod method, AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor)Execute the given method on the provided URI.<T> ListenableFuture<ResponseEntity<T>>exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables)Asynchronously execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ListenableFuture<ResponseEntity<T>>exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Map<String,?> uriVariables)Asynchronously execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ListenableFuture<ResponseEntity<T>>exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, Object... uriVariables)Asynchronously execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ListenableFuture<ResponseEntity<T>>exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, Map<String,?> uriVariables)Asynchronously execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ListenableFuture<ResponseEntity<T>>exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity, 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 asResponseEntity.<T> ListenableFuture<ResponseEntity<T>>exchange(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 asResponseEntity.<T> ListenableFuture<T>execute(String url, HttpMethod method, AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Object... uriVariables)Asynchronously execute the HTTP method to the given URI template, preparing the request with theAsyncRequestCallback, and reading the response with aResponseExtractor.<T> ListenableFuture<T>execute(String url, HttpMethod method, AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Map<String,?> uriVariables)Asynchronously execute the HTTP method to the given URI template, preparing the request with theAsyncRequestCallback, and reading the response with aResponseExtractor.<T> ListenableFuture<T>execute(URI url, HttpMethod method, AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor)Asynchronously execute the HTTP method to the given URL, preparing the request with theAsyncRequestCallback, and reading the response with aResponseExtractor.ResponseErrorHandlergetErrorHandler()Return the error handler.<T> ListenableFuture<ResponseEntity<T>>getForEntity(String url, Class<T> responseType, Object... uriVariables)Asynchronously retrieve an entity by doing a GET on the specified URL.<T> ListenableFuture<ResponseEntity<T>>getForEntity(String url, Class<T> responseType, Map<String,?> uriVariables)Asynchronously retrieve a representation by doing a GET on the URI template.<T> ListenableFuture<ResponseEntity<T>>getForEntity(URI url, Class<T> responseType)Asynchronously retrieve a representation by doing a GET on the URL.List<HttpMessageConverter<?>>getMessageConverters()Return the message body converters.RestOperationsgetRestOperations()Expose the synchronous Spring RestTemplate to allow synchronous invocation.UriTemplateHandlergetUriTemplateHandler()Return the configured URI template handler.protected ResponseExtractor<HttpHeaders>headersExtractor()Returns a response extractor forHttpHeaders.ListenableFuture<HttpHeaders>headForHeaders(String url, Object... uriVariables)Asynchronously retrieve all headers of the resource specified by the URI template.ListenableFuture<HttpHeaders>headForHeaders(String url, Map<String,?> uriVariables)Asynchronously retrieve all headers of the resource specified by the URI template.ListenableFuture<HttpHeaders>headForHeaders(URI url)Asynchronously retrieve all headers of the resource specified by the URL.protected <T> AsyncRequestCallbackhttpEntityCallback(HttpEntity<T> requestBody)Returns a request callback implementation that writes the given object to the request stream.protected <T> AsyncRequestCallbackhttpEntityCallback(HttpEntity<T> request, Type responseType)Returns a request callback implementation that writes the given object to the request stream.ListenableFuture<Set<HttpMethod>>optionsForAllow(String url, Object... uriVars)Asynchronously return the value of the Allow header for the given URI.ListenableFuture<Set<HttpMethod>>optionsForAllow(String url, Map<String,?> uriVars)Asynchronously return the value of the Allow header for the given URI.ListenableFuture<Set<HttpMethod>>optionsForAllow(URI url)Asynchronously return the value of the Allow header for the given URL.<T> ListenableFuture<ResponseEntity<T>>postForEntity(String url, HttpEntity<?> request, Class<T> responseType, Object... uriVariables)Create a new resource by POSTing the given object to the URI template, and asynchronously returns the response asResponseEntity.<T> ListenableFuture<ResponseEntity<T>>postForEntity(String url, HttpEntity<?> request, Class<T> responseType, Map<String,?> uriVariables)Create a new resource by POSTing the given object to the URI template, and asynchronously returns the response asResponseEntity.<T> ListenableFuture<ResponseEntity<T>>postForEntity(URI url, HttpEntity<?> request, Class<T> responseType)Create a new resource by POSTing the given object to the URL, and asynchronously returns the response asResponseEntity.ListenableFuture<URI>postForLocation(String url, HttpEntity<?> request, Object... uriVars)Create a new resource by POSTing the given object to the URI template, and asynchronously returns the value of theLocationheader.ListenableFuture<URI>postForLocation(String url, HttpEntity<?> request, Map<String,?> uriVars)Create a new resource by POSTing the given object to the URI template, and asynchronously returns the value of theLocationheader.ListenableFuture<URI>postForLocation(URI url, HttpEntity<?> request)Create a new resource by POSTing the given object to the URL, and asynchronously returns the value of theLocationheader.ListenableFuture<?>put(String url, HttpEntity<?> request, Object... uriVariables)Create or update a resource by PUTting the given object to the URI.ListenableFuture<?>put(String url, HttpEntity<?> request, Map<String,?> uriVariables)Creates a new resource by PUTting the given object to URI template.ListenableFuture<?>put(URI url, HttpEntity<?> request)Creates a new resource by PUTting the given object to URL.protected <T> ResponseExtractor<ResponseEntity<T>>responseEntityExtractor(Type responseType)Returns a response extractor forResponseEntity.voidsetDefaultUriVariables(Map<String,?> defaultUriVariables)Configure default URI variable values.voidsetErrorHandler(ResponseErrorHandler errorHandler)Set the error handler.voidsetMessageConverters(List<HttpMessageConverter<?>> messageConverters)Set the message body converters to use.voidsetUriTemplateHandler(UriTemplateHandler handler)This property has the same purpose as the corresponding property on theRestTemplate.Methods inherited from class org.springframework.http.client.support.InterceptingAsyncHttpAccessor
getAsyncRequestFactory, getInterceptors, setInterceptors
Methods inherited from class org.springframework.http.client.support.AsyncHttpAccessor
createAsyncRequest, setAsyncRequestFactory
Constructor Detail
AsyncRestTemplate
public AsyncRestTemplate()
Create a new instance of theAsyncRestTemplateusing default settings.This constructor uses a
SimpleClientHttpRequestFactoryin combination with aSimpleAsyncTaskExecutorfor asynchronous execution.
AsyncRestTemplate
public AsyncRestTemplate(AsyncListenableTaskExecutor taskExecutor)
Create a new instance of theAsyncRestTemplateusing the givenAsyncTaskExecutor.This constructor uses a
SimpleClientHttpRequestFactoryin combination with the givenAsyncTaskExecutorfor asynchronous execution.
AsyncRestTemplate
public AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory)
Create a new instance of theAsyncRestTemplateusing the givenAsyncClientHttpRequestFactory.This constructor will cast the given asynchronous
AsyncClientHttpRequestFactoryto aClientHttpRequestFactory. Since all implementations ofClientHttpRequestFactoryprovided in Spring also implementAsyncClientHttpRequestFactory, this should not result in aClassCastException.
AsyncRestTemplate
public AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory, ClientHttpRequestFactory syncRequestFactory)
Creates a new instance of theAsyncRestTemplateusing the given asynchronous and synchronous request factories.- Parameters:
asyncRequestFactory- the asynchronous request factorysyncRequestFactory- the synchronous request factory
AsyncRestTemplate
public AsyncRestTemplate(AsyncClientHttpRequestFactory requestFactory, RestTemplate restTemplate)
Create a new instance of theAsyncRestTemplateusing the givenAsyncClientHttpRequestFactoryand synchronousRestTemplate.- Parameters:
requestFactory- the asynchronous request factory to userestTemplate- the synchronous template to use
Method Detail
setErrorHandler
public void setErrorHandler(ResponseErrorHandler errorHandler)
Set the error handler.By default, AsyncRestTemplate uses a
DefaultResponseErrorHandler.
getErrorHandler
public ResponseErrorHandler getErrorHandler()
Return the error handler.
setDefaultUriVariables
public void setDefaultUriVariables(Map<String,?> defaultUriVariables)
Configure default URI variable values. This is a shortcut for:DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler(); handler.setDefaultUriVariables(...); AsyncRestTemplate restTemplate = new AsyncRestTemplate(); restTemplate.setUriTemplateHandler(handler);
- Parameters:
defaultUriVariables- the default URI variable values- Since:
- 4.3
setUriTemplateHandler
public void setUriTemplateHandler(UriTemplateHandler handler)
This property has the same purpose as the corresponding property on theRestTemplate. For more details seeRestTemplate.setUriTemplateHandler(org.springframework.web.util.UriTemplateHandler).- Parameters:
handler- the URI template handler to use
getUriTemplateHandler
public UriTemplateHandler getUriTemplateHandler()
Return the configured URI template handler.
getRestOperations
public RestOperations getRestOperations()
Description copied from interface:AsyncRestOperationsExpose the synchronous Spring RestTemplate to allow synchronous invocation.- Specified by:
getRestOperationsin interfaceAsyncRestOperations
setMessageConverters
public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters)
Set the message body converters to use.These converters are used to convert from and to HTTP requests and responses.
getMessageConverters
public List<HttpMessageConverter<?>> getMessageConverters()
Return the message body converters.
getForEntity
public <T> ListenableFuture<ResponseEntity<T>> getForEntity(String url, Class<T> responseType, Object... uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously 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.
- Specified by:
getForEntityin interfaceAsyncRestOperations- Parameters:
url- the URLresponseType- the type of the return valueuriVariables- the variables to expand the template- Returns:
- the entity wrapped in a
Future - Throws:
RestClientException
getForEntity
public <T> ListenableFuture<ResponseEntity<T>> getForEntity(String url, Class<T> responseType, Map<String,?> uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously 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.
- Specified by:
getForEntityin interfaceAsyncRestOperations- Parameters:
url- the URLresponseType- the type of the return valueuriVariables- the map containing variables for the URI template- Returns:
- the entity wrapped in a
Future - Throws:
RestClientException
getForEntity
public <T> ListenableFuture<ResponseEntity<T>> getForEntity(URI url, Class<T> responseType) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously retrieve a representation by doing a GET on the URL. The response is converted and stored in anResponseEntity.- Specified by:
getForEntityin interfaceAsyncRestOperations- Parameters:
url- the URLresponseType- the type of the return value- Returns:
- the entity wrapped in a
Future - Throws:
RestClientException
headForHeaders
public ListenableFuture<HttpHeaders> headForHeaders(String url, Object... uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously retrieve all headers of the resource specified by the URI template.URI Template variables are expanded using the given URI variables, if any.
- Specified by:
headForHeadersin interfaceAsyncRestOperations- Parameters:
url- the URLuriVariables- the variables to expand the template- Returns:
- all HTTP headers of that resource wrapped in a
Future - Throws:
RestClientException
headForHeaders
public ListenableFuture<HttpHeaders> headForHeaders(String url, Map<String,?> uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously retrieve all headers of the resource specified by the URI template.URI Template variables are expanded using the given map.
- Specified by:
headForHeadersin interfaceAsyncRestOperations- Parameters:
url- the URLuriVariables- the map containing variables for the URI template- Returns:
- all HTTP headers of that resource wrapped in a
Future - Throws:
RestClientException
headForHeaders
public ListenableFuture<HttpHeaders> headForHeaders(URI url) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously retrieve all headers of the resource specified by the URL.- Specified by:
headForHeadersin interfaceAsyncRestOperations- Parameters:
url- the URL- Returns:
- all HTTP headers of that resource wrapped in a
Future - Throws:
RestClientException
postForLocation
public ListenableFuture<URI> postForLocation(String url, HttpEntity<?> request, Object... uriVars) throws RestClientException
Description copied from interface:AsyncRestOperationsCreate a new resource by POSTing the given object to the URI template, and asynchronously 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.
- Specified by:
postForLocationin interfaceAsyncRestOperations- Parameters:
url- the URLrequest- the Object to be POSTed (may benull)uriVars- the variables to expand the template- Returns:
- the value for the
Locationheader wrapped in aFuture - Throws:
RestClientException- See Also:
HttpEntity
postForLocation
public ListenableFuture<URI> postForLocation(String url, HttpEntity<?> request, Map<String,?> uriVars) throws RestClientException
Description copied from interface:AsyncRestOperationsCreate a new resource by POSTing the given object to the URI template, and asynchronously returns the value of theLocationheader. This header typically indicates where the new resource is stored.URI Template variables are expanded using the given map.
- Specified by:
postForLocationin interfaceAsyncRestOperations- Parameters:
url- the URLrequest- the Object to be POSTed (may benull)uriVars- the variables to expand the template- Returns:
- the value for the
Locationheader wrapped in aFuture - Throws:
RestClientException- See Also:
HttpEntity
postForLocation
public ListenableFuture<URI> postForLocation(URI url, HttpEntity<?> request) throws RestClientException
Description copied from interface:AsyncRestOperationsCreate a new resource by POSTing the given object to the URL, and asynchronously returns the value of theLocationheader. This header typically indicates where the new resource is stored.- Specified by:
postForLocationin interfaceAsyncRestOperations- Parameters:
url- the URLrequest- the Object to be POSTed (may benull)- Returns:
- the value for the
Locationheader wrapped in aFuture - Throws:
RestClientException- See Also:
HttpEntity
postForEntity
public <T> ListenableFuture<ResponseEntity<T>> postForEntity(String url, HttpEntity<?> request, Class<T> responseType, Object... uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsCreate a new resource by POSTing the given object to the URI template, and asynchronously returns the response asResponseEntity.URI Template variables are expanded using the given URI variables, if any.
- Specified by:
postForEntityin interfaceAsyncRestOperations- Parameters:
url- the URLrequest- the Object to be POSTed (may benull)uriVariables- the variables to expand the template- Returns:
- the entity wrapped in a
Future - Throws:
RestClientException- See Also:
HttpEntity
postForEntity
public <T> ListenableFuture<ResponseEntity<T>> postForEntity(String url, HttpEntity<?> request, Class<T> responseType, Map<String,?> uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsCreate a new resource by POSTing the given object to the URI template, and asynchronously returns the response asResponseEntity.URI Template variables are expanded using the given map.
- Specified by:
postForEntityin interfaceAsyncRestOperations- Parameters:
url- the URLrequest- the Object to be POSTed (may benull)uriVariables- the variables to expand the template- Returns:
- the entity wrapped in a
Future - Throws:
RestClientException- See Also:
HttpEntity
postForEntity
public <T> ListenableFuture<ResponseEntity<T>> postForEntity(URI url, HttpEntity<?> request, Class<T> responseType) throws RestClientException
Description copied from interface:AsyncRestOperationsCreate a new resource by POSTing the given object to the URL, and asynchronously returns the response asResponseEntity.- Specified by:
postForEntityin interfaceAsyncRestOperations- Parameters:
url- the URLrequest- the Object to be POSTed (may benull)- Returns:
- the entity wrapped in a
Future - Throws:
RestClientException- See Also:
HttpEntity
put
public ListenableFuture<?> put(String url, HttpEntity<?> request, Object... uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsCreate 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 Future will return a
nullresult upon completion.- Specified by:
putin interfaceAsyncRestOperations- Parameters:
url- the URLrequest- the Object to be PUT (may benull)uriVariables- the variables to expand the template- Throws:
RestClientException- See Also:
HttpEntity
put
public ListenableFuture<?> put(String url, HttpEntity<?> request, Map<String,?> uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsCreates a new resource by PUTting the given object to URI template.URI Template variables are expanded using the given map.
The Future will return a
nullresult upon completion.- Specified by:
putin interfaceAsyncRestOperations- Parameters:
url- the URLrequest- the Object to be PUT (may benull)uriVariables- the variables to expand the template- Throws:
RestClientException- See Also:
HttpEntity
put
public ListenableFuture<?> put(URI url, HttpEntity<?> request) throws RestClientException
Description copied from interface:AsyncRestOperationsCreates a new resource by PUTting the given object to URL.The Future will return a
nullresult upon completion.- Specified by:
putin interfaceAsyncRestOperations- Parameters:
url- the URLrequest- the Object to be PUT (may benull)- Throws:
RestClientException- See Also:
HttpEntity
delete
public ListenableFuture<?> delete(String url, Object... uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously delete the resources at the specified URI.URI Template variables are expanded using the given URI variables, if any.
The Future will return a
nullresult upon completion.- Specified by:
deletein interfaceAsyncRestOperations- Parameters:
url- the URLuriVariables- the variables to expand in the template- Throws:
RestClientException
delete
public ListenableFuture<?> delete(String url, Map<String,?> uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously delete the resources at the specified URI.URI Template variables are expanded using the given URI variables, if any.
The Future will return a
nullresult upon completion.- Specified by:
deletein interfaceAsyncRestOperations- Parameters:
url- the URLuriVariables- the variables to expand in the template- Throws:
RestClientException
delete
public ListenableFuture<?> delete(URI url) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously delete the resources at the specified URI.URI Template variables are expanded using the given URI variables, if any.
The Future will return a
nullresult upon completion.- Specified by:
deletein interfaceAsyncRestOperations- Parameters:
url- the URL- Throws:
RestClientException
optionsForAllow
public ListenableFuture<Set<HttpMethod>> optionsForAllow(String url, Object... uriVars) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously return the value of the Allow header for the given URI.URI Template variables are expanded using the given URI variables, if any.
- Specified by:
optionsForAllowin interfaceAsyncRestOperations- Parameters:
url- the URLuriVars- the variables to expand in the template- Returns:
- the value of the allow header wrapped in a
Future - Throws:
RestClientException
optionsForAllow
public ListenableFuture<Set<HttpMethod>> optionsForAllow(String url, Map<String,?> uriVars) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously return the value of the Allow header for the given URI.URI Template variables are expanded using the given map.
- Specified by:
optionsForAllowin interfaceAsyncRestOperations- Parameters:
url- the URLuriVars- the variables to expand in the template- Returns:
- the value of the allow header wrapped in a
Future - Throws:
RestClientException
optionsForAllow
public ListenableFuture<Set<HttpMethod>> optionsForAllow(URI url) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously return the value of the Allow header for the given URL.- Specified by:
optionsForAllowin interfaceAsyncRestOperations- Parameters:
url- the URL- Returns:
- the value of the allow header wrapped in a
Future - Throws:
RestClientException
exchange
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously 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.
- Specified by:
exchangein interfaceAsyncRestOperations- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc)requestEntity- the entity (headers and/or body) to write to the request (may benull)responseType- the type of the return valueuriVariables- the variables to expand in the template- Returns:
- the response as entity wrapped in a
Future - Throws:
RestClientException
exchange
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Map<String,?> uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously 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.
- Specified by:
exchangein interfaceAsyncRestOperations- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc)requestEntity- the entity (headers and/or body) to write to the request (may benull)responseType- the type of the return valueuriVariables- the variables to expand in the template- Returns:
- the response as entity wrapped in a
Future - Throws:
RestClientException
exchange
public <T> ListenableFuture<ResponseEntity<T>> exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.- Specified by:
exchangein interfaceAsyncRestOperations- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc)requestEntity- the entity (headers and/or body) to write to the request (may benull)responseType- the type of the return value- Returns:
- the response as entity wrapped in a
Future - Throws:
RestClientException
exchange
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, Object... uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously 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);- Specified by:
exchangein interfaceAsyncRestOperations- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc)requestEntity- the entity (headers and/or body) to write to the request (may benull)responseType- the type of the return valueuriVariables- the variables to expand in the template- Returns:
- the response as entity wrapped in a
Future - Throws:
RestClientException
exchange
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, Map<String,?> uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously 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);- Specified by:
exchangein interfaceAsyncRestOperations- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc)requestEntity- the entity (headers and/or body) to write to the request (may benull)responseType- the type of the return valueuriVariables- the variables to expand in the template- Returns:
- the response as entity wrapped in a
Future - Throws:
RestClientException
exchange
public <T> ListenableFuture<ResponseEntity<T>> exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously 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);- Specified by:
exchangein interfaceAsyncRestOperations- Parameters:
url- the URLmethod- the HTTP method (GET, POST, etc)requestEntity- the entity (headers and/or body) to write to the request (may benull)responseType- the type of the return value- Returns:
- the response as entity wrapped in a
Future - Throws:
RestClientException
execute
public <T> ListenableFuture<T> execute(String url, HttpMethod method, AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Object... uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously execute the HTTP method to the given URI template, preparing the request with theAsyncRequestCallback, and reading the response with aResponseExtractor.URI Template variables are expanded using the given URI variables, if any.
- Specified by:
executein interfaceAsyncRestOperations- Parameters:
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 template- Returns:
- an arbitrary object, as returned by the
ResponseExtractor - Throws:
RestClientException
execute
public <T> ListenableFuture<T> execute(String url, HttpMethod method, AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Map<String,?> uriVariables) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously execute the HTTP method to the given URI template, preparing the request with theAsyncRequestCallback, and reading the response with aResponseExtractor.URI Template variables are expanded using the given URI variables map.
- Specified by:
executein interfaceAsyncRestOperations- Parameters:
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 template- Returns:
- an arbitrary object, as returned by the
ResponseExtractor - Throws:
RestClientException
execute
public <T> ListenableFuture<T> execute(URI url, HttpMethod method, AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws RestClientException
Description copied from interface:AsyncRestOperationsAsynchronously execute the HTTP method to the given URL, preparing the request with theAsyncRequestCallback, and reading the response with aResponseExtractor.- Specified by:
executein interfaceAsyncRestOperations- 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 - Throws:
RestClientException
doExecute
protected <T> ListenableFuture<T> doExecute(URI url, HttpMethod method, AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws RestClientException
Execute the given method on the provided URI. TheClientHttpRequestis processed using theRequestCallback; the response with theResponseExtractor.- Parameters:
url- the fully-expanded URL to connect tomethod- the HTTP method to execute (GET, POST, etc.)requestCallback- object that prepares the request (can benull)responseExtractor- object that extracts the return value from the response (can benull)- Returns:
- an arbitrary object, as returned by the
ResponseExtractor - Throws:
RestClientException
acceptHeaderRequestCallback
protected <T> AsyncRequestCallback acceptHeaderRequestCallback(Class<T> responseType)
Returns a request callback implementation that prepares the requestAcceptheaders based on the given response type and configured message converters.
httpEntityCallback
protected <T> AsyncRequestCallback httpEntityCallback(HttpEntity<T> requestBody)
Returns a request callback implementation that writes the given object to the request stream.
httpEntityCallback
protected <T> AsyncRequestCallback httpEntityCallback(HttpEntity<T> request, Type responseType)
Returns a request callback implementation that writes the given object to the request stream.
responseEntityExtractor
protected <T> ResponseExtractor<ResponseEntity<T>> responseEntityExtractor(Type responseType)
Returns a response extractor forResponseEntity.
headersExtractor
protected ResponseExtractor<HttpHeaders> headersExtractor()
Returns a response extractor forHttpHeaders.