类 RestTemplate

所有已实现的接口:
RestOperations

public class RestTemplate extends InterceptingHttpAccessor implements RestOperations
Synchronous client to perform HTTP requests, exposing a simple, template method API over underlying HTTP client libraries such as the JDK 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
另请参阅:
  • 字段详细资料

    • 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

      private final List<HttpMessageConverter<?>> messageConverters
    • errorHandler

      private ResponseErrorHandler errorHandler
    • uriTemplateHandler

      private UriTemplateHandler uriTemplateHandler
    • headersExtractor

      private final ResponseExtractor<HttpHeaders> headersExtractor
  • 构造器详细资料

  • 方法详细资料

    • updateErrorHandlerConverters

      private void updateErrorHandlerConverters()
    • initUriTemplateHandler

      private static DefaultUriBuilderFactory initUriTemplateHandler()
    • 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.

    • validateConverters

      private void validateConverters(List<HttpMessageConverter<?>> messageConverters)
    • getMessageConverters

      public List<HttpMessageConverter<?>> getMessageConverters()
      Return the list of message body converters.

      The returned List is active and may get appended to.

    • setErrorHandler

      public void setErrorHandler(ResponseErrorHandler errorHandler)
      Set the error handler.

      By default, RestTemplate uses a DefaultResponseErrorHandler.

    • getErrorHandler

      public ResponseErrorHandler getErrorHandler()
      Return the error handler.
    • setDefaultUriVariables

      public void setDefaultUriVariables(Map<String,?> uriVars)
      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

      public void setUriTemplateHandler(UriTemplateHandler handler)
      Configure a strategy for expanding URI templates.

      By default, DefaultUriBuilderFactory is used. prefer using TEMPLATE_AND_VALUES.

      参数:
      handler - the URI template handler to use
      另请参阅:
    • getUriTemplateHandler

      public UriTemplateHandler getUriTemplateHandler()
      Return the configured URI template handler.
    • getForObject

      @Nullable public <T> T getForObject(String url, Class<T> responseType, Object... uriVariables) throws RestClientException
      从接口复制的说明: RestOperations
      Retrieve 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 URL
      responseType - the type of the return value
      uriVariables - 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
      从接口复制的说明: RestOperations
      Retrieve a representation by doing a GET on the URI template. The response (if any) is converted and returned.

      URI Template variables are expanded using the given map.

      指定者:
      getForObject 在接口中 RestOperations
      参数:
      url - the URL
      responseType - the type of the return value
      uriVariables - the map containing variables for the URI template
      返回:
      the converted object
      抛出:
      RestClientException
    • getForObject

      @Nullable public <T> T getForObject(URI url, Class<T> responseType) throws RestClientException
      从接口复制的说明: RestOperations
      Retrieve a representation by doing a GET on the URL . The response (if any) is converted and returned.
      指定者:
      getForObject 在接口中 RestOperations
      参数:
      url - the URL
      responseType - 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
      从接口复制的说明: RestOperations
      Retrieve an entity by doing a GET on the specified URL. The response is converted and stored in an ResponseEntity.

      URI Template variables are expanded using the given URI variables, if any.

      指定者:
      getForEntity 在接口中 RestOperations
      参数:
      url - the URL
      responseType - the type of the return value
      uriVariables - 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
      从接口复制的说明: RestOperations
      Retrieve a representation by doing a GET on the URI template. The response is converted and stored in an ResponseEntity.

      URI Template variables are expanded using the given map.

      指定者:
      getForEntity 在接口中 RestOperations
      参数:
      url - the URL
      responseType - the type of the return value
      uriVariables - 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
      从接口复制的说明: RestOperations
      Retrieve a representation by doing a GET on the URL . The response is converted and stored in an ResponseEntity.
      指定者:
      getForEntity 在接口中 RestOperations
      参数:
      url - the URL
      responseType - the type of the return value
      返回:
      the converted object
      抛出:
      RestClientException
    • headForHeaders

      public HttpHeaders headForHeaders(String url, Object... uriVariables) throws RestClientException
      从接口复制的说明: RestOperations
      Retrieve 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 URL
      uriVariables - the variables to expand the template
      返回:
      all HTTP headers of that resource
      抛出:
      RestClientException
    • headForHeaders

      public HttpHeaders headForHeaders(String url, Map<String,?> uriVariables) throws RestClientException
      从接口复制的说明: RestOperations
      Retrieve all headers of the resource specified by the URI template.

      URI Template variables are expanded using the given map.

      指定者:
      headForHeaders 在接口中 RestOperations
      参数:
      url - the URL
      uriVariables - the map containing variables for the URI template
      返回:
      all HTTP headers of that resource
      抛出:
      RestClientException
    • headForHeaders

      public HttpHeaders headForHeaders(URI url) throws RestClientException
      从接口复制的说明: RestOperations
      Retrieve 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
      从接口复制的说明: RestOperations
      Create a new resource by POSTing the given object to the URI template, and returns the value of the Location header. This header typically indicates where the new resource is stored.

      URI Template variables are expanded using the given URI variables, if any.

      The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

      The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers.

      指定者:
      postForLocation 在接口中 RestOperations
      参数:
      url - the URL
      request - the Object to be POSTed (may be null)
      uriVariables - the variables to expand the template
      返回:
      the value for the Location header
      抛出:
      RestClientException
      另请参阅:
    • postForLocation

      @Nullable public URI postForLocation(String url, @Nullable Object request, Map<String,?> uriVariables) throws RestClientException
      从接口复制的说明: RestOperations
      Create a new resource by POSTing the given object to the URI template, and returns the value of the Location header. This header typically indicates where the new resource is stored.

      URI Template variables are expanded using the given map.

      The request parameter can be a HttpEntity in order to add additional HTTP headers to the request

      The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers.

      指定者:
      postForLocation 在接口中 RestOperations
      参数:
      url - the URL
      request - the Object to be POSTed (may be null)
      uriVariables - the variables to expand the template
      返回:
      the value for the Location header
      抛出:
      RestClientException
      另请参阅:
    • postForLocation

      @Nullable public URI postForLocation(URI url, @Nullable Object request) throws RestClientException
      从接口复制的说明: RestOperations
      Create a new resource by POSTing the given object to the URL, and returns the value of the Location header. This header typically indicates where the new resource is stored.

      The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

      The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers.

      指定者:
      postForLocation 在接口中 RestOperations
      参数:
      url - the URL
      request - the Object to be POSTed (may be null)
      返回:
      the value for the Location header
      抛出:
      RestClientException
      另请参阅:
    • postForObject

      @Nullable public <T> T postForObject(String url, @Nullable Object request, Class<T> responseType, Object... uriVariables) throws RestClientException
      从接口复制的说明: RestOperations
      Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.

      URI Template variables are expanded using the given URI variables, if any.

      The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

      The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers.

      指定者:
      postForObject 在接口中 RestOperations
      参数:
      url - the URL
      request - the Object to be POSTed (may be null)
      responseType - the type of the return value
      uriVariables - 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
      从接口复制的说明: RestOperations
      Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.

      URI Template variables are expanded using the given map.

      The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

      The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers.

      指定者:
      postForObject 在接口中 RestOperations
      参数:
      url - the URL
      request - the Object to be POSTed (may be null)
      responseType - the type of the return value
      uriVariables - 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
      从接口复制的说明: RestOperations
      Create a new resource by POSTing the given object to the URL, and returns the representation found in the response.

      The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

      The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers.

      指定者:
      postForObject 在接口中 RestOperations
      参数:
      url - the URL
      request - the Object to be POSTed (may be null)
      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
      从接口复制的说明: RestOperations
      Create a new resource by POSTing the given object to the URI template, and returns the response as ResponseEntity.

      URI Template variables are expanded using the given URI variables, if any.

      The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

      The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers.

      指定者:
      postForEntity 在接口中 RestOperations
      参数:
      url - the URL
      request - the Object to be POSTed (may be null)
      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
      从接口复制的说明: RestOperations
      Create a new resource by POSTing the given object to the URI template, and returns the response as HttpEntity.

      URI Template variables are expanded using the given map.

      The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

      The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers.

      指定者:
      postForEntity 在接口中 RestOperations
      参数:
      url - the URL
      request - the Object to be POSTed (may be null)
      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
      从接口复制的说明: RestOperations
      Create a new resource by POSTing the given object to the URL, and returns the response as ResponseEntity.

      The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

      The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers.

      指定者:
      postForEntity 在接口中 RestOperations
      参数:
      url - the URL
      request - the Object to be POSTed (may be null)
      返回:
      the converted object
      抛出:
      RestClientException
      另请参阅:
    • put

      public void put(String url, @Nullable Object request, Object... uriVariables) throws RestClientException
      从接口复制的说明: RestOperations
      Create 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 request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

      指定者:
      put 在接口中 RestOperations
      参数:
      url - the URL
      request - the Object to be PUT (may be null)
      uriVariables - the variables to expand the template
      抛出:
      RestClientException
      另请参阅:
    • put

      public void put(String url, @Nullable Object request, Map<String,?> uriVariables) throws RestClientException
      从接口复制的说明: RestOperations
      Creates a new resource by PUTting the given object to URI template.

      URI Template variables are expanded using the given map.

      The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

      指定者:
      put 在接口中 RestOperations
      参数:
      url - the URL
      request - the Object to be PUT (may be null)
      uriVariables - the variables to expand the template
      抛出:
      RestClientException
      另请参阅:
    • put

      public void put(URI url, @Nullable Object request) throws RestClientException
      从接口复制的说明: RestOperations
      Creates a new resource by PUTting the given object to URL.

      The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

      指定者:
      put 在接口中 RestOperations
      参数:
      url - the URL
      request - the Object to be PUT (may be null)
      抛出:
      RestClientException
      另请参阅:
    • patchForObject

      @Nullable public <T> T patchForObject(String url, @Nullable Object request, Class<T> responseType, Object... uriVariables) throws RestClientException
      从接口复制的说明: RestOperations
      Update 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 request parameter can be a HttpEntity in 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 URL
      request - the object to be PATCHed (may be null)
      responseType - the type of the return value
      uriVariables - 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
      从接口复制的说明: RestOperations
      Update 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 request parameter can be a HttpEntity in 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 URL
      request - the object to be PATCHed (may be null)
      responseType - the type of the return value
      uriVariables - 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
      从接口复制的说明: RestOperations
      Update a resource by PATCHing the given object to the URL, and return the representation found in the response.

      The request parameter can be a HttpEntity in 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 URL
      request - the object to be PATCHed (may be null)
      responseType - the type of the return value
      返回:
      the converted object
      抛出:
      RestClientException
      另请参阅:
    • delete

      public void delete(String url, Object... uriVariables) throws RestClientException
      从接口复制的说明: RestOperations
      Delete the resources at the specified URI.

      URI Template variables are expanded using the given URI variables, if any.

      指定者:
      delete 在接口中 RestOperations
      参数:
      url - the URL
      uriVariables - the variables to expand in the template
      抛出:
      RestClientException
    • delete

      public void delete(String url, Map<String,?> uriVariables) throws RestClientException
      从接口复制的说明: RestOperations
      Delete the resources at the specified URI.

      URI Template variables are expanded using the given map.

      指定者:
      delete 在接口中 RestOperations
      参数:
      url - the URL
      uriVariables - the variables to expand the template
      抛出:
      RestClientException
    • delete

      public void delete(URI url) throws RestClientException
      从接口复制的说明: RestOperations
      Delete the resources at the specified URL.
      指定者:
      delete 在接口中 RestOperations
      参数:
      url - the URL
      抛出:
      RestClientException
    • optionsForAllow

      public Set<HttpMethod> optionsForAllow(String url, Object... uriVariables) throws RestClientException
      从接口复制的说明: RestOperations
      Return 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 URL
      uriVariables - 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
      从接口复制的说明: RestOperations
      Return the value of the Allow header for the given URI.

      URI Template variables are expanded using the given map.

      指定者:
      optionsForAllow 在接口中 RestOperations
      参数:
      url - the URL
      uriVariables - the variables to expand in the template
      返回:
      the value of the allow header
      抛出:
      RestClientException
    • optionsForAllow

      public Set<HttpMethod> optionsForAllow(URI url) throws RestClientException
      从接口复制的说明: RestOperations
      Return 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
      从接口复制的说明: RestOperations
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.

      URI Template variables are expanded using the given URI variables, if any.

      指定者:
      exchange 在接口中 RestOperations
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc)
      requestEntity - the entity (headers and/or body) to write to the request may be null)
      responseType - the type to convert the response to, or Void.class for no body
      uriVariables - 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
      从接口复制的说明: RestOperations
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.

      URI Template variables are expanded using the given URI variables, if any.

      指定者:
      exchange 在接口中 RestOperations
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc)
      requestEntity - the entity (headers and/or body) to write to the request (may be null)
      responseType - the type to convert the response to, or Void.class for no body
      uriVariables - 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
      从接口复制的说明: RestOperations
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
      指定者:
      exchange 在接口中 RestOperations
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc)
      requestEntity - the entity (headers and/or body) to write to the request (may be null)
      responseType - the type to convert the response to, or Void.class for 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
      从接口复制的说明: RestOperations
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity. The given ParameterizedTypeReference is used to pass generic type information:
      
       ParameterizedTypeReference<List<MyBean>> myBean =
           new ParameterizedTypeReference<List<MyBean>>() {};
      
       ResponseEntity<List<MyBean>> response =
           template.exchange("https://example.com", HttpMethod.GET, null, myBean);
       
      指定者:
      exchange 在接口中 RestOperations
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc)
      requestEntity - the entity (headers and/or body) to write to the request (may be null)
      responseType - the type to convert the response to, or Void.class for no body
      uriVariables - 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
      从接口复制的说明: RestOperations
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity. The given ParameterizedTypeReference is used to pass generic type information:
      
       ParameterizedTypeReference<List<MyBean>> myBean =
           new ParameterizedTypeReference<List<MyBean>>() {};
      
       ResponseEntity<List<MyBean>> response =
           template.exchange("https://example.com",HttpMethod.GET, null, myBean);
       
      指定者:
      exchange 在接口中 RestOperations
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc)
      requestEntity - the entity (headers and/or body) to write to the request (may be null)
      responseType - the type to convert the response to, or Void.class for no body
      uriVariables - 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
      从接口复制的说明: RestOperations
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity. The given ParameterizedTypeReference is used to pass generic type information:
      
       ParameterizedTypeReference<List<MyBean>> myBean =
           new ParameterizedTypeReference<List<MyBean>>() {};
      
       ResponseEntity<List<MyBean>> response =
           template.exchange("https://example.com",HttpMethod.GET, null, myBean);
        
      指定者:
      exchange 在接口中 RestOperations
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc)
      requestEntity - the entity (headers and/or body) to write to the request (may be null)
      responseType - the type to convert the response to, or Void.class for no body
      返回:
      the response as entity
      抛出:
      RestClientException
    • exchange

      public <T> ResponseEntity<T> exchange(RequestEntity<?> entity, Class<T> responseType) throws RestClientException
      从接口复制的说明: RestOperations
      Execute the request specified in the given RequestEntity and return the response as ResponseEntity. Typically used in combination with the static builder methods on RequestEntity, for instance:
      
       MyRequest body = ...
       RequestEntity request = RequestEntity
           .post(new URI("https://example.com/foo"))
           .accept(MediaType.APPLICATION_JSON)
           .body(body);
       ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
       
      指定者:
      exchange 在接口中 RestOperations
      参数:
      entity - the entity to write to the request
      responseType - the type to convert the response to, or Void.class for no body
      返回:
      the response as entity
      抛出:
      RestClientException
    • exchange

      public <T> ResponseEntity<T> exchange(RequestEntity<?> entity, cn.taketoday.core.ParameterizedTypeReference<T> responseType) throws RestClientException
      从接口复制的说明: RestOperations
      Execute the request specified in the given RequestEntity and return the response as ResponseEntity. The given ParameterizedTypeReference is used to pass generic type information:
      
       MyRequest body = ...
       RequestEntity request = RequestEntity
           .post(new URI("https://example.com/foo"))
           .accept(MediaType.APPLICATION_JSON)
           .body(body);
       ParameterizedTypeReference<List<MyResponse>> myBean =
           new ParameterizedTypeReference<List<MyResponse>>() {};
       ResponseEntity<List<MyResponse>> response = template.exchange(request, myBean);
       
      指定者:
      exchange 在接口中 RestOperations
      参数:
      entity - the entity to write to the request
      responseType - the type to convert the response to, or Void.class for no body
      返回:
      the response as entity
      抛出:
      RestClientException
    • resolveUrl

      private URI resolveUrl(RequestEntity<?> entity)
    • 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 the RequestCallback, and reading the response with a ResponseExtractor.

      URI Template variables are expanded using the given URI variables, if any.

      To provide a RequestCallback or ResponseExtractor only, but not both, consider using:

      指定者:
      execute 在接口中 RestOperations
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc)
      requestCallback - object that prepares the request
      responseExtractor - object that extracts the return value from the response
      uriVariables - 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 RestClientException
      Execute the HTTP method to the given URI template, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.

      URI Template variables are expanded using the given URI variables map.

      To provide a RequestCallback or ResponseExtractor only, but not both, consider using:

      指定者:
      execute 在接口中 RestOperations
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc)
      requestCallback - object that prepares the request
      responseExtractor - object that extracts the return value from the response
      uriVariables - 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 the RequestCallback, and reading the response with a ResponseExtractor.

      To provide a RequestCallback or ResponseExtractor only, but not both, consider using:

      指定者:
      execute 在接口中 RestOperations
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc)
      requestCallback - object that prepares the request
      responseExtractor - object that extracts the return value from the response
      返回:
      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 ClientHttpRequest is processed using the RequestCallback; the response with the ResponseExtractor.

      参数:
      url - the fully-expanded URL to connect to
      method - 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)
      返回:
      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 the ResponseErrorHandler if necessary.

      Can be overridden in subclasses.

      参数:
      url - the fully-expanded URL to connect to
      method - the HTTP method to execute (GET, POST, etc.)
      response - the resulting ClientHttpResponse
      抛出:
      IOException - if propagated from ResponseErrorHandler
      另请参阅:
    • acceptHeaderRequestCallback

      public <T> RequestCallback acceptHeaderRequestCallback(Class<T> responseType)
      Return a RequestCallback that sets the request Accept header based on the given response type, cross-checked against the configured message converters.
    • httpEntityCallback

      public RequestCallback httpEntityCallback(@Nullable Object requestBody)
      Return a RequestCallback implementation that writes the given object to the request stream.
    • httpEntityCallback

      public RequestCallback httpEntityCallback(@Nullable Object requestBody, Type responseType)
      Return a RequestCallback implementation that:
      1. Sets the request Accept header based on the given response type, cross-checked against the configured message converters.
      2. Writes the given object to the request stream.
    • responseEntityExtractor

      public <T> ResponseExtractor<ResponseEntity<T>> responseEntityExtractor(Type responseType)
      Return a ResponseExtractor that prepares a ResponseEntity.
    • headersExtractor

      protected ResponseExtractor<HttpHeaders> headersExtractor()
      Return a response extractor for HttpHeaders.
    • nonNull

      private static <T> T nonNull(@Nullable T result)
    • isPresent

      static boolean isPresent(String name)
    • copyHttpHeaders

      private static void copyHttpHeaders(HttpHeaders httpHeaders, HttpHeaders requestHeaders)