类 RestTemplate
- 所有已实现的接口:
RestOperations
HttpURLConnection, Apache HttpComponents, and others. RestTemplate
offers templates for common scenarios by HTTP method, in addition to the
generalized exchange and execute methods that support of
less frequent cases.
RestTemplate is typically used as a shared component. However, its
configuration does not support concurrent modification, and as such its
configuration is typically prepared on startup. If necessary, you can create
multiple, differently configured RestTemplate instances on startup. Such
instances may use the same the underlying ClientHttpRequestFactory
if they need to share HTTP client resources.
NOTE: RestClient offers a more modern
API for synchronous HTTP access. For asynchronous and streaming scenarios,
consider the reactive
WebClient.
- 从以下版本开始:
- 4.0
- 作者:
- Arjen Poutsma, Brian Clozel, Roy Clarkson, Juergen Hoeller, Sam Brannen, Sebastien Deleuze, Harry Yang
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明private classRequest callback implementation that prepares the request's accept headers.private static classResponse extractor that extracts the responseHttpHeaders.private classRequest callback implementation that writes the given object to the request stream.private classResponse extractor forHttpEntity. -
字段概要
字段修饰符和类型字段说明private ResponseErrorHandlerprivate static final booleanprivate final ResponseExtractor<HttpHeaders>private static final booleanprivate static final booleanprivate static final booleanprivate static final booleanprivate static final booleanprivate final List<HttpMessageConverter<?>>private static final booleanprivate UriTemplateHandler从类继承的字段 cn.taketoday.http.client.support.HttpAccessor
logger -
构造器概要
构造器构造器说明Create a new instance of theRestTemplateusing default settings.RestTemplate(ClientHttpRequestFactory requestFactory) Create a new instance of theRestTemplatebased on the givenClientHttpRequestFactory.RestTemplate(List<HttpMessageConverter<?>> messageConverters) Create a new instance of theRestTemplateusing the given list ofHttpMessageConverterto use. -
方法概要
修饰符和类型方法说明<T> RequestCallbackacceptHeaderRequestCallback(Class<T> responseType) Return aRequestCallbackthat sets the requestAcceptheader based on the given response type, cross-checked against the configured message converters.private static voidcopyHttpHeaders(HttpHeaders httpHeaders, HttpHeaders requestHeaders) voidDelete the resources at the specified URI.voidDelete the resources at the specified URI.voidDelete the resources at the specified URL.protected <T> TdoExecute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor) Execute the given method on the provided URI.<T> ResponseEntity<T>exchange(RequestEntity<?> entity, cn.taketoday.core.ParameterizedTypeReference<T> responseType) Execute the request specified in the givenRequestEntityand return the response asResponseEntity.<T> ResponseEntity<T>exchange(RequestEntity<?> entity, Class<T> responseType) Execute the request specified in the givenRequestEntityand return the response asResponseEntity.<T> ResponseEntity<T>exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, cn.taketoday.core.ParameterizedTypeReference<T> responseType, Object... uriVariables) Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ResponseEntity<T>exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, cn.taketoday.core.ParameterizedTypeReference<T> responseType, Map<String, ?> uriVariables) Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ResponseEntity<T>exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ResponseEntity<T>exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables) Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.<T> ResponseEntity<T>exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity, cn.taketoday.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 asResponseEntity.<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 asResponseEntity.<T> Texecute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Object... uriVariables) Execute the HTTP method to the given URI template, preparing the request with theRequestCallback, and reading the response with aResponseExtractor.<T> Texecute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables) Execute the HTTP method to the given URI template, preparing the request with theRequestCallback, and reading the response with aResponseExtractor.<T> Texecute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor) Execute the HTTP method to the given URL, preparing the request with theRequestCallback, and reading the response with aResponseExtractor.Return the error handler.<T> ResponseEntity<T>getForEntity(String url, Class<T> responseType, Object... uriVariables) Retrieve an entity by doing a GET on the specified URL.<T> ResponseEntity<T>getForEntity(String url, Class<T> responseType, Map<String, ?> uriVariables) Retrieve a representation by doing a GET on the URI template.<T> ResponseEntity<T>getForEntity(URI url, Class<T> responseType) Retrieve a representation by doing a GET on the URL .<T> TgetForObject(String url, Class<T> responseType, Object... uriVariables) Retrieve a representation by doing a GET on the specified URL.<T> TgetForObject(String url, Class<T> responseType, Map<String, ?> uriVariables) Retrieve a representation by doing a GET on the URI template.<T> TgetForObject(URI url, Class<T> responseType) Retrieve a representation by doing a GET on the URL .Return the list of message body converters.Return the configured URI template handler.protected voidhandleResponse(URI url, HttpMethod method, ClientHttpResponse response) Handle the given response, performing appropriate logging and invoking theResponseErrorHandlerif necessary.protected ResponseExtractor<HttpHeaders>Return a response extractor forHttpHeaders.headForHeaders(String url, Object... uriVariables) Retrieve all headers of the resource specified by the URI template.headForHeaders(String url, Map<String, ?> uriVariables) Retrieve all headers of the resource specified by the URI template.headForHeaders(URI url) Retrieve all headers of the resource specified by the URL.httpEntityCallback(Object requestBody) Return aRequestCallbackimplementation that writes the given object to the request stream.httpEntityCallback(Object requestBody, Type responseType) Return aRequestCallbackimplementation that: Sets the requestAcceptheader based on the given response type, cross-checked against the configured message converters.private static DefaultUriBuilderFactory(专用程序包) static booleanprivate static <T> TnonNull(T result) optionsForAllow(String url, Object... uriVariables) Return the value of the Allow header for the given URI.optionsForAllow(String url, Map<String, ?> uriVariables) Return the value of the Allow header for the given URI.optionsForAllow(URI url) Return the value of the Allow header for the given URL.<T> TpatchForObject(String url, Object request, Class<T> responseType, Object... uriVariables) Update a resource by PATCHing the given object to the URI template, and return the representation found in the response.<T> TUpdate a resource by PATCHing the given object to the URI template, and return the representation found in the response.<T> TpatchForObject(URI url, Object request, Class<T> responseType) Update a resource by PATCHing the given object to the URL, and return the representation found in the response.<T> ResponseEntity<T>postForEntity(String url, Object request, Class<T> responseType, Object... uriVariables) Create a new resource by POSTing the given object to the URI template, and returns the response asResponseEntity.<T> ResponseEntity<T>Create a new resource by POSTing the given object to the URI template, and returns the response asHttpEntity.<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 asResponseEntity.postForLocation(String url, Object request, Object... uriVariables) Create a new resource by POSTing the given object to the URI template, and returns the value of theLocationheader.postForLocation(String url, Object request, Map<String, ?> uriVariables) Create a new resource by POSTing the given object to the URI template, and returns the value of theLocationheader.postForLocation(URI url, Object request) Create a new resource by POSTing the given object to the URL, and returns the value of theLocationheader.<T> TpostForObject(String url, Object request, Class<T> responseType, Object... uriVariables) Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.<T> TCreate a new resource by POSTing the given object to the URI template, and returns the representation found in the response.<T> TpostForObject(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.voidCreate or update a resource by PUTting the given object to the URI.voidCreates a new resource by PUTting the given object to URI template.voidCreates a new resource by PUTting the given object to URL.private URIresolveUrl(RequestEntity<?> entity) <T> ResponseExtractor<ResponseEntity<T>>responseEntityExtractor(Type responseType) Return aResponseExtractorthat prepares aResponseEntity.voidsetDefaultUriVariables(Map<String, ?> uriVars) 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) Configure a strategy for expanding URI templates.private voidprivate voidvalidateConverters(List<HttpMessageConverter<?>> messageConverters) 从类继承的方法 cn.taketoday.http.client.support.InterceptingHttpAccessor
getInterceptors, getRequestFactory, setInterceptors, setInterceptors, setRequestFactory从类继承的方法 cn.taketoday.http.client.support.HttpAccessor
createRequest, getHttpRequestInitializers, setHttpRequestInitializers
-
字段详细资料
-
gsonPresent
private static final boolean gsonPresent -
jsonbPresent
private static final boolean jsonbPresent -
romePresent
private static final boolean romePresent -
jackson2Present
private static final boolean jackson2Present -
jackson2SmilePresent
private static final boolean jackson2SmilePresent -
jackson2CborPresent
private static final boolean jackson2CborPresent -
jackson2XmlPresent
private static final boolean jackson2XmlPresent -
messageConverters
-
errorHandler
-
uriTemplateHandler
-
headersExtractor
-
-
构造器详细资料
-
RestTemplate
public RestTemplate()Create a new instance of theRestTemplateusing default settings. DefaultHttpMessageConvertersare initialized. -
RestTemplate
Create a new instance of theRestTemplatebased on the givenClientHttpRequestFactory.- 参数:
requestFactory- the HTTP request factory to use- 另请参阅:
-
RestTemplate
Create a new instance of theRestTemplateusing the given list ofHttpMessageConverterto use.- 参数:
messageConverters- the list ofHttpMessageConverterto use
-
-
方法详细资料
-
updateErrorHandlerConverters
private void updateErrorHandlerConverters() -
initUriTemplateHandler
-
setMessageConverters
Set the message body converters to use.These converters are used to convert from and to HTTP requests and responses.
-
validateConverters
-
getMessageConverters
Return the list of message body converters.The returned
Listis active and may get appended to. -
setErrorHandler
Set the error handler.By default, RestTemplate uses a
DefaultResponseErrorHandler. -
getErrorHandler
Return the error handler. -
setDefaultUriVariables
Configure default URI variable values. This is a shortcut for:DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(); handler.setDefaultUriVariables(...); RestTemplate restTemplate = new RestTemplate(); restTemplate.setUriTemplateHandler(handler);
- 参数:
uriVars- the default URI variable values
-
setUriTemplateHandler
Configure a strategy for expanding URI templates.By default,
DefaultUriBuilderFactoryis used. prefer usingTEMPLATE_AND_VALUES.- 参数:
handler- the URI template handler to use- 另请参阅:
-
getUriTemplateHandler
Return the configured URI template handler. -
getForObject
@Nullable public <T> T getForObject(String url, Class<T> responseType, Object... uriVariables) throws RestClientException 从接口复制的说明:RestOperationsRetrieve a representation by doing a GET on the specified URL. The response (if any) is converted and returned.URI Template variables are expanded using the given URI variables, if any.
- 指定者:
getForObject在接口中RestOperations- 参数:
url- the URLresponseType- the type of the return valueuriVariables- the variables to expand the template- 返回:
- the converted object
- 抛出:
RestClientException
-
getForObject
@Nullable public <T> T getForObject(String url, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException从接口复制的说明:RestOperationsRetrieve 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.
- 指定者:
getForObject在接口中RestOperations- 参数:
url- the URLresponseType- the type of the return valueuriVariables- the map containing variables for the URI template- 返回:
- the converted object
- 抛出:
RestClientException
-
getForObject
从接口复制的说明:RestOperationsRetrieve a representation by doing a GET on the URL . The response (if any) is converted and returned.- 指定者:
getForObject在接口中RestOperations- 参数:
url- the URLresponseType- the type of the return value- 返回:
- the converted object
- 抛出:
RestClientException
-
getForEntity
public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... uriVariables) throws RestClientException 从接口复制的说明:RestOperationsRetrieve 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.
- 指定者:
getForEntity在接口中RestOperations- 参数:
url- the URLresponseType- the type of the return valueuriVariables- the variables to expand the template- 返回:
- the entity
- 抛出:
RestClientException
-
getForEntity
public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException从接口复制的说明:RestOperationsRetrieve 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.
- 指定者:
getForEntity在接口中RestOperations- 参数:
url- the URLresponseType- the type of the return valueuriVariables- the map containing variables for the URI template- 返回:
- the converted object
- 抛出:
RestClientException
-
getForEntity
public <T> ResponseEntity<T> getForEntity(URI url, Class<T> responseType) throws RestClientException 从接口复制的说明:RestOperationsRetrieve a representation by doing a GET on the URL . The response is converted and stored in anResponseEntity.- 指定者:
getForEntity在接口中RestOperations- 参数:
url- the URLresponseType- the type of the return value- 返回:
- the converted object
- 抛出:
RestClientException
-
headForHeaders
从接口复制的说明:RestOperationsRetrieve all headers of the resource specified by the URI template.URI Template variables are expanded using the given URI variables, if any.
- 指定者:
headForHeaders在接口中RestOperations- 参数:
url- the URLuriVariables- the variables to expand the template- 返回:
- all HTTP headers of that resource
- 抛出:
RestClientException
-
headForHeaders
public HttpHeaders headForHeaders(String url, Map<String, ?> uriVariables) throws RestClientException从接口复制的说明:RestOperationsRetrieve all headers of the resource specified by the URI template.URI Template variables are expanded using the given map.
- 指定者:
headForHeaders在接口中RestOperations- 参数:
url- the URLuriVariables- the map containing variables for the URI template- 返回:
- all HTTP headers of that resource
- 抛出:
RestClientException
-
headForHeaders
从接口复制的说明:RestOperationsRetrieve all headers of the resource specified by the URL.- 指定者:
headForHeaders在接口中RestOperations- 参数:
url- the URL- 返回:
- all HTTP headers of that resource
- 抛出:
RestClientException
-
postForLocation
@Nullable public URI postForLocation(String url, @Nullable Object request, Object... uriVariables) throws RestClientException 从接口复制的说明:RestOperationsCreate a new resource by POSTing the given object to the URI template, and returns the value of theLocationheader. This header typically indicates where the new resource is stored.URI Template variables are expanded using the given URI variables, if any.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.The body of the entity, or
requestitself, can be aMultiValueMapto create a multipart request. The values in theMultiValueMapcan be any Object representing the body of the part, or anHttpEntityrepresenting a part with body and headers.- 指定者:
postForLocation在接口中RestOperations- 参数:
url- the URLrequest- the Object to be POSTed (may benull)uriVariables- the variables to expand the template- 返回:
- the value for the
Locationheader - 抛出:
RestClientException- 另请参阅:
-
postForLocation
@Nullable public URI postForLocation(String url, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException从接口复制的说明:RestOperationsCreate a new resource by POSTing the given object to the URI template, and returns the value of theLocationheader. This header typically indicates where the new resource is stored.URI Template variables are expanded using the given map.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the requestThe body of the entity, or
requestitself, can be aMultiValueMapto create a multipart request. The values in theMultiValueMapcan be any Object representing the body of the part, or anHttpEntityrepresenting a part with body and headers.- 指定者:
postForLocation在接口中RestOperations- 参数:
url- the URLrequest- the Object to be POSTed (may benull)uriVariables- the variables to expand the template- 返回:
- the value for the
Locationheader - 抛出:
RestClientException- 另请参阅:
-
postForLocation
从接口复制的说明:RestOperationsCreate a new resource by POSTing the given object to the URL, and returns the value of theLocationheader. This header typically indicates where the new resource is stored.The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.The body of the entity, or
requestitself, can be aMultiValueMapto create a multipart request. The values in theMultiValueMapcan be any Object representing the body of the part, or anHttpEntityrepresenting a part with body and headers.- 指定者:
postForLocation在接口中RestOperations- 参数:
url- the URLrequest- the Object to be POSTed (may benull)- 返回:
- the value for the
Locationheader - 抛出:
RestClientException- 另请参阅:
-
postForObject
@Nullable public <T> T postForObject(String url, @Nullable Object request, Class<T> responseType, Object... uriVariables) throws RestClientException 从接口复制的说明:RestOperationsCreate a new resource by POSTing the given object to the URI template, and returns the representation found in the response.URI Template variables are expanded using the given URI variables, if any.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.The body of the entity, or
requestitself, can be aMultiValueMapto create a multipart request. The values in theMultiValueMapcan be any Object representing the body of the part, or anHttpEntityrepresenting a part with body and headers.- 指定者:
postForObject在接口中RestOperations- 参数:
url- the URLrequest- the Object to be POSTed (may benull)responseType- the type of the return valueuriVariables- the variables to expand the template- 返回:
- the converted object
- 抛出:
RestClientException- 另请参阅:
-
postForObject
@Nullable public <T> T postForObject(String url, @Nullable Object request, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException从接口复制的说明:RestOperationsCreate a new resource by POSTing the given object to the URI template, and returns the representation found in the response.URI Template variables are expanded using the given map.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.The body of the entity, or
requestitself, can be aMultiValueMapto create a multipart request. The values in theMultiValueMapcan be any Object representing the body of the part, or anHttpEntityrepresenting a part with body and headers.- 指定者:
postForObject在接口中RestOperations- 参数:
url- the URLrequest- the Object to be POSTed (may benull)responseType- the type of the return valueuriVariables- the variables to expand the template- 返回:
- the converted object
- 抛出:
RestClientException- 另请参阅:
-
postForObject
@Nullable public <T> T postForObject(URI url, @Nullable Object request, Class<T> responseType) throws RestClientException 从接口复制的说明:RestOperationsCreate a new resource by POSTing the given object to the URL, and returns the representation found in the response.The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.The body of the entity, or
requestitself, can be aMultiValueMapto create a multipart request. The values in theMultiValueMapcan be any Object representing the body of the part, or anHttpEntityrepresenting a part with body and headers.- 指定者:
postForObject在接口中RestOperations- 参数:
url- the URLrequest- the Object to be POSTed (may benull)responseType- the type of the return value- 返回:
- the converted object
- 抛出:
RestClientException- 另请参阅:
-
postForEntity
public <T> ResponseEntity<T> postForEntity(String url, @Nullable Object request, Class<T> responseType, Object... uriVariables) throws RestClientException 从接口复制的说明:RestOperationsCreate a new resource by POSTing the given object to the URI template, and returns the response asResponseEntity.URI Template variables are expanded using the given URI variables, if any.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.The body of the entity, or
requestitself, can be aMultiValueMapto create a multipart request. The values in theMultiValueMapcan be any Object representing the body of the part, or anHttpEntityrepresenting a part with body and headers.- 指定者:
postForEntity在接口中RestOperations- 参数:
url- the URLrequest- the Object to be POSTed (may benull)uriVariables- the variables to expand the template- 返回:
- the converted object
- 抛出:
RestClientException- 另请参阅:
-
postForEntity
public <T> ResponseEntity<T> postForEntity(String url, @Nullable Object request, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException从接口复制的说明:RestOperationsCreate a new resource by POSTing the given object to the URI template, and returns the response asHttpEntity.URI Template variables are expanded using the given map.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.The body of the entity, or
requestitself, can be aMultiValueMapto create a multipart request. The values in theMultiValueMapcan be any Object representing the body of the part, or anHttpEntityrepresenting a part with body and headers.- 指定者:
postForEntity在接口中RestOperations- 参数:
url- the URLrequest- the Object to be POSTed (may benull)uriVariables- the variables to expand the template- 返回:
- the converted object
- 抛出:
RestClientException- 另请参阅:
-
postForEntity
public <T> ResponseEntity<T> postForEntity(URI url, @Nullable Object request, Class<T> responseType) throws RestClientException 从接口复制的说明:RestOperationsCreate a new resource by POSTing the given object to the URL, and returns the response asResponseEntity.The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.The body of the entity, or
requestitself, can be aMultiValueMapto create a multipart request. The values in theMultiValueMapcan be any Object representing the body of the part, or anHttpEntityrepresenting a part with body and headers.- 指定者:
postForEntity在接口中RestOperations- 参数:
url- the URLrequest- the Object to be POSTed (may benull)- 返回:
- the converted object
- 抛出:
RestClientException- 另请参阅:
-
put
public void put(String url, @Nullable Object request, Object... uriVariables) throws RestClientException 从接口复制的说明:RestOperationsCreate or update a resource by PUTting the given object to the URI.URI Template variables are expanded using the given URI variables, if any.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- 指定者:
put在接口中RestOperations- 参数:
url- the URLrequest- the Object to be PUT (may benull)uriVariables- the variables to expand the template- 抛出:
RestClientException- 另请参阅:
-
put
public void put(String url, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException从接口复制的说明:RestOperationsCreates a new resource by PUTting the given object to URI template.URI Template variables are expanded using the given map.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- 指定者:
put在接口中RestOperations- 参数:
url- the URLrequest- the Object to be PUT (may benull)uriVariables- the variables to expand the template- 抛出:
RestClientException- 另请参阅:
-
put
从接口复制的说明:RestOperationsCreates a new resource by PUTting the given object to URL.The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.- 指定者:
put在接口中RestOperations- 参数:
url- the URLrequest- the Object to be PUT (may benull)- 抛出:
RestClientException- 另请参阅:
-
patchForObject
@Nullable public <T> T patchForObject(String url, @Nullable Object request, Class<T> responseType, Object... uriVariables) throws RestClientException 从接口复制的说明:RestOperationsUpdate a resource by PATCHing the given object to the URI template, and return the representation found in the response.URI Template variables are expanded using the given URI variables, if any.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.NOTE: The standard JDK HTTP library does not support HTTP PATCH. You need to use the Apache HttpComponents or OkHttp request factory.
- 指定者:
patchForObject在接口中RestOperations- 参数:
url- the URLrequest- the object to be PATCHed (may benull)responseType- the type of the return valueuriVariables- the variables to expand the template- 返回:
- the converted object
- 抛出:
RestClientException- 另请参阅:
-
patchForObject
@Nullable public <T> T patchForObject(String url, @Nullable Object request, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException从接口复制的说明:RestOperationsUpdate a resource by PATCHing the given object to the URI template, and return the representation found in the response.URI Template variables are expanded using the given map.
The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.NOTE: The standard JDK HTTP library does not support HTTP PATCH. You need to use the Apache HttpComponents or OkHttp request factory.
- 指定者:
patchForObject在接口中RestOperations- 参数:
url- the URLrequest- the object to be PATCHed (may benull)responseType- the type of the return valueuriVariables- the variables to expand the template- 返回:
- the converted object
- 抛出:
RestClientException- 另请参阅:
-
patchForObject
@Nullable public <T> T patchForObject(URI url, @Nullable Object request, Class<T> responseType) throws RestClientException 从接口复制的说明:RestOperationsUpdate a resource by PATCHing the given object to the URL, and return the representation found in the response.The
requestparameter can be aHttpEntityin order to add additional HTTP headers to the request.NOTE: The standard JDK HTTP library does not support HTTP PATCH. You need to use the Apache HttpComponents or OkHttp request factory.
- 指定者:
patchForObject在接口中RestOperations- 参数:
url- the URLrequest- the object to be PATCHed (may benull)responseType- the type of the return value- 返回:
- the converted object
- 抛出:
RestClientException- 另请参阅:
-
delete
从接口复制的说明:RestOperationsDelete the resources at the specified URI.URI Template variables are expanded using the given URI variables, if any.
- 指定者:
delete在接口中RestOperations- 参数:
url- the URLuriVariables- the variables to expand in the template- 抛出:
RestClientException
-
delete
从接口复制的说明:RestOperationsDelete the resources at the specified URI.URI Template variables are expanded using the given map.
- 指定者:
delete在接口中RestOperations- 参数:
url- the URLuriVariables- the variables to expand the template- 抛出:
RestClientException
-
delete
从接口复制的说明:RestOperationsDelete the resources at the specified URL.- 指定者:
delete在接口中RestOperations- 参数:
url- the URL- 抛出:
RestClientException
-
optionsForAllow
public Set<HttpMethod> optionsForAllow(String url, Object... uriVariables) throws RestClientException 从接口复制的说明:RestOperationsReturn the value of the Allow header for the given URI.URI Template variables are expanded using the given URI variables, if any.
- 指定者:
optionsForAllow在接口中RestOperations- 参数:
url- the URLuriVariables- the variables to expand in the template- 返回:
- the value of the allow header
- 抛出:
RestClientException
-
optionsForAllow
public Set<HttpMethod> optionsForAllow(String url, Map<String, ?> uriVariables) throws RestClientException从接口复制的说明:RestOperationsReturn the value of the Allow header for the given URI.URI Template variables are expanded using the given map.
- 指定者:
optionsForAllow在接口中RestOperations- 参数:
url- the URLuriVariables- the variables to expand in the template- 返回:
- the value of the allow header
- 抛出:
RestClientException
-
optionsForAllow
从接口复制的说明:RestOperationsReturn the value of the Allow header for the given URL.- 指定者:
optionsForAllow在接口中RestOperations- 参数:
url- the URL- 返回:
- the value of the allow header
- 抛出:
RestClientException
-
exchange
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) throws RestClientException 从接口复制的说明:RestOperationsExecute 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.
- 指定者:
exchange在接口中RestOperations- 参数:
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 to convert the response to, orVoid.classfor no bodyuriVariables- the variables to expand in the template- 返回:
- the response as entity
- 抛出:
RestClientException
-
exchange
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException从接口复制的说明:RestOperationsExecute 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.
- 指定者:
exchange在接口中RestOperations- 参数:
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 to convert the response to, orVoid.classfor no bodyuriVariables- the variables to expand in the template- 返回:
- the response as entity
- 抛出:
RestClientException
-
exchange
public <T> ResponseEntity<T> exchange(URI url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, Class<T> responseType) throws RestClientException 从接口复制的说明:RestOperationsExecute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response asResponseEntity.- 指定者:
exchange在接口中RestOperations- 参数:
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 to convert the response to, orVoid.classfor no body- 返回:
- the response as entity
- 抛出:
RestClientException
-
exchange
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, cn.taketoday.core.ParameterizedTypeReference<T> responseType, Object... uriVariables) throws RestClientException 从接口复制的说明:RestOperationsExecute 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);- 指定者:
exchange在接口中RestOperations- 参数:
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 to convert the response to, orVoid.classfor no bodyuriVariables- the variables to expand in the template- 返回:
- the response as entity
- 抛出:
RestClientException
-
exchange
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, cn.taketoday.core.ParameterizedTypeReference<T> responseType, Map<String, ?> uriVariables) throws RestClientException从接口复制的说明:RestOperationsExecute 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);- 指定者:
exchange在接口中RestOperations- 参数:
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 to convert the response to, orVoid.classfor no bodyuriVariables- the variables to expand in the template- 返回:
- the response as entity
- 抛出:
RestClientException
-
exchange
public <T> ResponseEntity<T> exchange(URI url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, cn.taketoday.core.ParameterizedTypeReference<T> responseType) throws RestClientException 从接口复制的说明:RestOperationsExecute 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);- 指定者:
exchange在接口中RestOperations- 参数:
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 to convert the response to, orVoid.classfor no body- 返回:
- the response as entity
- 抛出:
RestClientException
-
exchange
public <T> ResponseEntity<T> exchange(RequestEntity<?> entity, Class<T> responseType) throws RestClientException 从接口复制的说明:RestOperationsExecute the request specified in the givenRequestEntityand return the response asResponseEntity. Typically used in combination with the static builder methods onRequestEntity, for instance:MyRequest body = ... RequestEntity request = RequestEntity .post(new URI("https://example.com/foo")) .accept(MediaType.APPLICATION_JSON) .body(body); ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);- 指定者:
exchange在接口中RestOperations- 参数:
entity- the entity to write to the requestresponseType- the type to convert the response to, orVoid.classfor no body- 返回:
- the response as entity
- 抛出:
RestClientException
-
exchange
public <T> ResponseEntity<T> exchange(RequestEntity<?> entity, cn.taketoday.core.ParameterizedTypeReference<T> responseType) throws RestClientException 从接口复制的说明:RestOperationsExecute the request specified in the givenRequestEntityand return the response asResponseEntity. The givenParameterizedTypeReferenceis used to pass generic type information:MyRequest body = ... RequestEntity request = RequestEntity .post(new URI("https://example.com/foo")) .accept(MediaType.APPLICATION_JSON) .body(body); ParameterizedTypeReference<List<MyResponse>> myBean = new ParameterizedTypeReference<List<MyResponse>>() {}; ResponseEntity<List<MyResponse>> response = template.exchange(request, myBean);- 指定者:
exchange在接口中RestOperations- 参数:
entity- the entity to write to the requestresponseType- the type to convert the response to, orVoid.classfor no body- 返回:
- the response as entity
- 抛出:
RestClientException
-
resolveUrl
-
execute
@Nullable public <T> T execute(String url, HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor<T> responseExtractor, Object... uriVariables) throws RestClientException Execute the HTTP method to the given URI template, preparing the request with theRequestCallback, and reading the response with aResponseExtractor.URI Template variables are expanded using the given URI variables, if any.
To provide a
RequestCallbackorResponseExtractoronly, but not both, consider using:- 指定者:
execute在接口中RestOperations- 参数:
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- 返回:
- an arbitrary object, as returned by the
ResponseExtractor - 抛出:
RestClientException
-
execute
@Nullable public <T> T execute(String url, HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables) throws RestClientExceptionExecute the HTTP method to the given URI template, preparing the request with theRequestCallback, and reading the response with aResponseExtractor.URI Template variables are expanded using the given URI variables map.
To provide a
RequestCallbackorResponseExtractoronly, but not both, consider using:- 指定者:
execute在接口中RestOperations- 参数:
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- 返回:
- an arbitrary object, as returned by the
ResponseExtractor - 抛出:
RestClientException
-
execute
@Nullable public <T> T execute(URI url, HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor<T> responseExtractor) throws RestClientException Execute the HTTP method to the given URL, preparing the request with theRequestCallback, and reading the response with aResponseExtractor.To provide a
RequestCallbackorResponseExtractoronly, but not both, consider using:- 指定者:
execute在接口中RestOperations- 参数:
url- the URLmethod- the HTTP method (GET, POST, etc)requestCallback- object that prepares the requestresponseExtractor- object that extracts the return value from the response- 返回:
- an arbitrary object, as returned by the
ResponseExtractor - 抛出:
RestClientException
-
doExecute
@Nullable protected <T> T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor<T> responseExtractor) throws RestClientException Execute the given method on the provided URI.The
ClientHttpRequestis processed using theRequestCallback; the response with theResponseExtractor.- 参数:
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)- 返回:
- an arbitrary object, as returned by the
ResponseExtractor - 抛出:
RestClientException
-
handleResponse
protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException Handle the given response, performing appropriate logging and invoking theResponseErrorHandlerif necessary.Can be overridden in subclasses.
- 参数:
url- the fully-expanded URL to connect tomethod- the HTTP method to execute (GET, POST, etc.)response- the resultingClientHttpResponse- 抛出:
IOException- if propagated fromResponseErrorHandler- 另请参阅:
-
acceptHeaderRequestCallback
Return aRequestCallbackthat sets the requestAcceptheader based on the given response type, cross-checked against the configured message converters. -
httpEntityCallback
Return aRequestCallbackimplementation that writes the given object to the request stream. -
httpEntityCallback
Return aRequestCallbackimplementation that:- Sets the request
Acceptheader based on the given response type, cross-checked against the configured message converters. - Writes the given object to the request stream.
- Sets the request
-
responseEntityExtractor
Return aResponseExtractorthat prepares aResponseEntity. -
headersExtractor
Return a response extractor forHttpHeaders. -
nonNull
private static <T> T nonNull(@Nullable T result) -
isPresent
-
copyHttpHeaders
-