类 TestRestTemplate

java.lang.Object
cn.taketoday.framework.test.web.client.TestRestTemplate

public class TestRestTemplate extends Object
Convenient alternative of RestTemplate that is suitable for integration tests. TestRestTemplate is fault tolerant. This means that 4xx and 5xx do not result in an exception being thrown and can instead be detected via the response entity and its status code.

A TestRestTemplate can optionally carry Basic authentication headers. If Apache Http Client 4.3.2 or better is available (recommended) it will be used as the client, and by default configured to ignore cookies and redirects.

Note: To prevent injection problems this class intentionally does not extend RestTemplate. If you need access to the underlying RestTemplate use getRestTemplate().

If you are using the @InfraTest annotation with an embedded server, a TestRestTemplate is automatically available and can be @Autowired into your test. If you need customizations (for example to adding additional message converters) use a RestTemplateBuilder @Bean.

从以下版本开始:
4.0
作者:
Dave Syer, Phillip Webb, Andy Wilkinson, Kristine Jetzke, Dmytro Nosan
  • 嵌套类概要

    嵌套类
    修饰符和类型
    说明
    protected static class 
    HttpComponentsClientHttpRequestFactory to apply customizations.
    static enum 
    Options used to customize the Apache HTTP Client.
    private static class 
     
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    private final cn.taketoday.web.client.config.RestTemplateBuilder
     
     
    private final cn.taketoday.web.client.RestTemplate
     
  • 构造器概要

    构造器
    构造器
    说明
    Create a new TestRestTemplate instance.
    TestRestTemplate(cn.taketoday.web.client.config.RestTemplateBuilder restTemplateBuilder)
    Create a new TestRestTemplate instance.
    TestRestTemplate(cn.taketoday.web.client.config.RestTemplateBuilder builder, String username, String password, TestRestTemplate.HttpClientOption... httpClientOptions)
    Create a new TestRestTemplate instance with the specified credentials.
    TestRestTemplate(String username, String password, TestRestTemplate.HttpClientOption... httpClientOptions)
    Create a new TestRestTemplate instance with the specified credentials.
  • 方法概要

    修饰符和类型
    方法
    说明
    private URI
     
    private cn.taketoday.http.RequestEntity<?>
    createRequestEntityWithRootAppliedUri(cn.taketoday.http.RequestEntity<?> requestEntity)
     
    void
    delete(String url, Object... urlVariables)
    Delete the resources at the specified URI.
    void
    delete(String url, Map<String,?> urlVariables)
    Delete the resources at the specified URI.
    void
    delete(URI url)
    Delete the resources at the specified URL.
    <T> cn.taketoday.http.ResponseEntity<T>
    exchange(cn.taketoday.http.RequestEntity<?> requestEntity, cn.taketoday.core.ParameterizedTypeReference<T> responseType)
    Execute the request specified in the given RequestEntity and return the response as ResponseEntity.
    <T> cn.taketoday.http.ResponseEntity<T>
    exchange(cn.taketoday.http.RequestEntity<?> requestEntity, Class<T> responseType)
    Execute the request specified in the given RequestEntity and return the response as ResponseEntity.
    <T> cn.taketoday.http.ResponseEntity<T>
    exchange(String url, cn.taketoday.http.HttpMethod method, cn.taketoday.http.HttpEntity<?> requestEntity, cn.taketoday.core.ParameterizedTypeReference<T> responseType, Object... urlVariables)
    Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
    <T> cn.taketoday.http.ResponseEntity<T>
    exchange(String url, cn.taketoday.http.HttpMethod method, cn.taketoday.http.HttpEntity<?> requestEntity, cn.taketoday.core.ParameterizedTypeReference<T> responseType, Map<String,?> urlVariables)
    Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
    <T> cn.taketoday.http.ResponseEntity<T>
    exchange(String url, cn.taketoday.http.HttpMethod method, cn.taketoday.http.HttpEntity<?> requestEntity, Class<T> responseType, Object... urlVariables)
    Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
    <T> cn.taketoday.http.ResponseEntity<T>
    exchange(String url, cn.taketoday.http.HttpMethod method, cn.taketoday.http.HttpEntity<?> requestEntity, Class<T> responseType, Map<String,?> urlVariables)
    Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
    <T> cn.taketoday.http.ResponseEntity<T>
    exchange(URI url, cn.taketoday.http.HttpMethod method, cn.taketoday.http.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 as ResponseEntity.
    <T> cn.taketoday.http.ResponseEntity<T>
    exchange(URI url, cn.taketoday.http.HttpMethod method, cn.taketoday.http.HttpEntity<?> requestEntity, Class<T> responseType)
    Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
    <T> T
    execute(String url, cn.taketoday.http.HttpMethod method, cn.taketoday.web.client.RequestCallback requestCallback, cn.taketoday.web.client.ResponseExtractor<T> responseExtractor, Object... urlVariables)
    Execute the HTTP method to the given URI template, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.
    <T> T
    execute(String url, cn.taketoday.http.HttpMethod method, cn.taketoday.web.client.RequestCallback requestCallback, cn.taketoday.web.client.ResponseExtractor<T> responseExtractor, Map<String,?> urlVariables)
    Execute the HTTP method to the given URI template, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.
    <T> T
    execute(URI url, cn.taketoday.http.HttpMethod method, cn.taketoday.web.client.RequestCallback requestCallback, cn.taketoday.web.client.ResponseExtractor<T> responseExtractor)
    Execute the HTTP method to the given URL, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.
    <T> cn.taketoday.http.ResponseEntity<T>
    getForEntity(String url, Class<T> responseType, Object... urlVariables)
    Retrieve an entity by doing a GET on the specified URL.
    <T> cn.taketoday.http.ResponseEntity<T>
    getForEntity(String url, Class<T> responseType, Map<String,?> urlVariables)
    Retrieve a representation by doing a GET on the URI template.
    <T> cn.taketoday.http.ResponseEntity<T>
    getForEntity(URI url, Class<T> responseType)
    Retrieve a representation by doing a GET on the URL .
    <T> T
    getForObject(String url, Class<T> responseType, Object... urlVariables)
    Retrieve a representation by doing a GET on the specified URL.
    <T> T
    getForObject(String url, Class<T> responseType, Map<String,?> urlVariables)
    Retrieve a representation by doing a GET on the URI template.
    <T> T
    getForObject(URI url, Class<T> responseType)
    Retrieve a representation by doing a GET on the URL .
    cn.taketoday.web.client.RestTemplate
    Returns the underlying RestTemplate that is actually used to perform the REST operations.
    Returns the root URI applied by a RootUriTemplateHandler or "" if the root URI is not available.
    cn.taketoday.http.HttpHeaders
    headForHeaders(String url, Object... urlVariables)
    Retrieve all headers of the resource specified by the URI template.
    cn.taketoday.http.HttpHeaders
    headForHeaders(String url, Map<String,?> urlVariables)
    Retrieve all headers of the resource specified by the URI template.
    cn.taketoday.http.HttpHeaders
    Retrieve all headers of the resource specified by the URL.
    Set<cn.taketoday.http.HttpMethod>
    optionsForAllow(String url, Object... urlVariables)
    Return the value of the Allow header for the given URI.
    Set<cn.taketoday.http.HttpMethod>
    optionsForAllow(String url, Map<String,?> urlVariables)
    Return the value of the Allow header for the given URI.
    Set<cn.taketoday.http.HttpMethod>
    Return the value of the Allow header for the given URL.
    <T> T
    patchForObject(String url, Object request, Class<T> responseType, Object... uriVariables)
    Update a resource by PATCHing the given object to the URI template, and returns the representation found in the response.
    <T> T
    patchForObject(String url, Object request, Class<T> responseType, Map<String,?> uriVariables)
    Update a resource by PATCHing the given object to the URI template, and returns the representation found in the response.
    <T> T
    patchForObject(URI url, Object request, Class<T> responseType)
    Update a resource by PATCHing the given object to the URL, and returns the representation found in the response.
    <T> cn.taketoday.http.ResponseEntity<T>
    postForEntity(String url, Object request, Class<T> responseType, Object... urlVariables)
    Create a new resource by POSTing the given object to the URI template, and returns the response as ResponseEntity.
    <T> cn.taketoday.http.ResponseEntity<T>
    postForEntity(String url, Object request, Class<T> responseType, Map<String,?> urlVariables)
    Create a new resource by POSTing the given object to the URI template, and returns the response as HttpEntity.
    <T> cn.taketoday.http.ResponseEntity<T>
    postForEntity(URI url, Object request, Class<T> responseType)
    Create a new resource by POSTing the given object to the URL, and returns the response as ResponseEntity.
    postForLocation(String url, Object request, Object... urlVariables)
    Create a new resource by POSTing the given object to the URI template, and returns the value of the Location header.
    postForLocation(String url, Object request, Map<String,?> urlVariables)
    Create a new resource by POSTing the given object to the URI template, and returns the value of the Location header.
    postForLocation(URI url, Object request)
    Create a new resource by POSTing the given object to the URL, and returns the value of the Location header.
    <T> T
    postForObject(String url, Object request, Class<T> responseType, Object... urlVariables)
    Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.
    <T> T
    postForObject(String url, Object request, Class<T> responseType, Map<String,?> urlVariables)
    Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.
    <T> T
    postForObject(URI url, Object request, Class<T> responseType)
    Create a new resource by POSTing the given object to the URL, and returns the representation found in the response.
    void
    put(String url, Object request, Object... urlVariables)
    Create or update a resource by PUTting the given object to the URI.
    void
    put(String url, Object request, Map<String,?> urlVariables)
    Creates a new resource by PUTting the given object to URI template.
    void
    put(URI url, Object request)
    Creates a new resource by PUTting the given object to URL.
    private URI
    resolveUri(cn.taketoday.http.RequestEntity<?> entity)
     
    void
    setUriTemplateHandler(cn.taketoday.web.util.UriTemplateHandler handler)
    Configure the UriTemplateHandler to use to expand URI templates.
    withBasicAuth(String username, String password)
    Creates a new TestRestTemplate with the same configuration as this one, except that it will send basic authorization headers using the given username and password.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • builder

      private final cn.taketoday.web.client.config.RestTemplateBuilder builder
    • httpClientOptions

      private final TestRestTemplate.HttpClientOption[] httpClientOptions
    • restTemplate

      private final cn.taketoday.web.client.RestTemplate restTemplate
  • 构造器详细资料

    • TestRestTemplate

      public TestRestTemplate(cn.taketoday.web.client.config.RestTemplateBuilder restTemplateBuilder)
      Create a new TestRestTemplate instance.
      参数:
      restTemplateBuilder - builder used to configure underlying RestTemplate
    • TestRestTemplate

      public TestRestTemplate(TestRestTemplate.HttpClientOption... httpClientOptions)
      Create a new TestRestTemplate instance.
      参数:
      httpClientOptions - client options to use if the Apache HTTP Client is used
    • TestRestTemplate

      public TestRestTemplate(String username, String password, TestRestTemplate.HttpClientOption... httpClientOptions)
      Create a new TestRestTemplate instance with the specified credentials.
      参数:
      username - the username to use (or null)
      password - the password (or null)
      httpClientOptions - client options to use if the Apache HTTP Client is used
    • TestRestTemplate

      public TestRestTemplate(cn.taketoday.web.client.config.RestTemplateBuilder builder, String username, String password, TestRestTemplate.HttpClientOption... httpClientOptions)
      Create a new TestRestTemplate instance with the specified credentials.
      参数:
      builder - builder used to configure underlying RestTemplate
      username - the username to use (or null)
      password - the password (or null)
      httpClientOptions - client options to use if the Apache HTTP Client is used
  • 方法详细资料

    • setUriTemplateHandler

      public void setUriTemplateHandler(cn.taketoday.web.util.UriTemplateHandler handler)
      Configure the UriTemplateHandler to use to expand URI templates. By default the DefaultUriBuilderFactory is used which relies on Infra URI template support and exposes several useful properties that customize its behavior for encoding and for prepending a common base URL. An alternative implementation may be used to plug an external URI template library.
      参数:
      handler - the URI template handler to use
    • getRootUri

      public String getRootUri()
      Returns the root URI applied by a RootUriTemplateHandler or "" if the root URI is not available.
      返回:
      the root URI
    • getForObject

      public <T> T getForObject(String url, Class<T> responseType, Object... urlVariables)
      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.

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      responseType - the type of the return value
      urlVariables - the variables to expand the template
      返回:
      the converted object
      另请参阅:
      • RestTemplate.getForObject(String, Class, Object...)
    • getForObject

      public <T> T getForObject(String url, Class<T> responseType, Map<String,?> urlVariables)
      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.

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      responseType - the type of the return value
      urlVariables - the map containing variables for the URI template
      返回:
      the converted object
      另请参阅:
      • RestTemplate.getForObject(String, Class, Object...)
    • getForObject

      public <T> T getForObject(URI url, Class<T> responseType)
      Retrieve a representation by doing a GET on the URL . The response (if any) is converted and returned.
      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      responseType - the type of the return value
      返回:
      the converted object
      另请参阅:
      • RestTemplate.getForObject(URI, Class)
    • getForEntity

      public <T> cn.taketoday.http.ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... urlVariables)
      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.

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      responseType - the type of the return value
      urlVariables - the variables to expand the template
      返回:
      the entity
      另请参阅:
      • RestTemplate.getForEntity(String, Class, Object[])
    • getForEntity

      public <T> cn.taketoday.http.ResponseEntity<T> getForEntity(String url, Class<T> responseType, Map<String,?> urlVariables)
      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.

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      responseType - the type of the return value
      urlVariables - the map containing variables for the URI template
      返回:
      the converted object
      另请参阅:
      • RestTemplate.getForEntity(String, Class, Map)
    • getForEntity

      public <T> cn.taketoday.http.ResponseEntity<T> getForEntity(URI url, Class<T> responseType)
      Retrieve a representation by doing a GET on the URL . The response is converted and stored in an ResponseEntity.
      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      responseType - the type of the return value
      返回:
      the converted object
      另请参阅:
      • RestTemplate.getForEntity(URI, Class)
    • headForHeaders

      public cn.taketoday.http.HttpHeaders headForHeaders(String url, Object... urlVariables)
      Retrieve all headers of the resource specified by the URI template.

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

      参数:
      url - the URL
      urlVariables - the variables to expand the template
      返回:
      all HTTP headers of that resource
      另请参阅:
      • RestTemplate.headForHeaders(String, Object[])
    • headForHeaders

      public cn.taketoday.http.HttpHeaders headForHeaders(String url, Map<String,?> urlVariables)
      Retrieve all headers of the resource specified by the URI template.

      URI Template variables are expanded using the given map.

      参数:
      url - the URL
      urlVariables - the map containing variables for the URI template
      返回:
      all HTTP headers of that resource
      另请参阅:
      • RestTemplate.headForHeaders(String, Map)
    • headForHeaders

      public cn.taketoday.http.HttpHeaders headForHeaders(URI url)
      Retrieve all headers of the resource specified by the URL.
      参数:
      url - the URL
      返回:
      all HTTP headers of that resource
      另请参阅:
      • RestTemplate.headForHeaders(URI)
    • postForLocation

      public URI postForLocation(String url, Object request, Object... urlVariables)
      Create a new resource by POSTing the given object to the URI template, and returns the value of the Location header. 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.

      参数:
      url - the URL
      request - the Object to be POSTed, may be null
      urlVariables - the variables to expand the template
      返回:
      the value for the Location header
      另请参阅:
      • HttpEntity
      • RestTemplate.postForLocation(String, Object, Object[])
    • postForLocation

      public URI postForLocation(String url, Object request, Map<String,?> urlVariables)
      Create a new resource by POSTing the given object to the URI template, and returns the value of the Location header. 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.

      参数:
      url - the URL
      request - the Object to be POSTed, may be null
      urlVariables - the variables to expand the template
      返回:
      the value for the Location header
      另请参阅:
      • HttpEntity
      • RestTemplate.postForLocation(String, Object, Map)
    • postForLocation

      public URI postForLocation(URI url, Object request)
      Create a new resource by POSTing the given object to the URL, and returns the value of the Location header. 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.

      参数:
      url - the URL
      request - the Object to be POSTed, may be null
      返回:
      the value for the Location header
      另请参阅:
      • HttpEntity
      • RestTemplate.postForLocation(URI, Object)
    • postForObject

      public <T> T postForObject(String url, Object request, Class<T> responseType, Object... urlVariables)
      Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.

      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.

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      request - the Object to be POSTed, may be null
      responseType - the type of the return value
      urlVariables - the variables to expand the template
      返回:
      the converted object
      另请参阅:
      • HttpEntity
      • RestTemplate.postForObject(String, Object, Class, Object[])
    • postForObject

      public <T> T postForObject(String url, Object request, Class<T> responseType, Map<String,?> urlVariables)
      Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.

      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.

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      request - the Object to be POSTed, may be null
      responseType - the type of the return value
      urlVariables - the variables to expand the template
      返回:
      the converted object
      另请参阅:
      • HttpEntity
      • RestTemplate.postForObject(String, Object, Class, Map)
    • postForObject

      public <T> T postForObject(URI url, Object request, Class<T> responseType)
      Create a new resource by POSTing the given object to the URL, and returns the representation found in the response.

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

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      request - the Object to be POSTed, may be null
      responseType - the type of the return value
      返回:
      the converted object
      另请参阅:
      • HttpEntity
      • RestTemplate.postForObject(URI, Object, Class)
    • postForEntity

      public <T> cn.taketoday.http.ResponseEntity<T> postForEntity(String url, Object request, Class<T> responseType, Object... urlVariables)
      Create a new resource by POSTing the given object to the URI template, and returns the response as ResponseEntity.

      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.

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      request - the Object to be POSTed, may be null
      responseType - the response type to return
      urlVariables - the variables to expand the template
      返回:
      the converted object
      另请参阅:
      • HttpEntity
      • RestTemplate.postForEntity(String, Object, Class, Object[])
    • postForEntity

      public <T> cn.taketoday.http.ResponseEntity<T> postForEntity(String url, Object request, Class<T> responseType, Map<String,?> urlVariables)
      Create a new resource by POSTing the given object to the URI template, and returns the response as HttpEntity.

      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.

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      request - the Object to be POSTed, may be null
      responseType - the response type to return
      urlVariables - the variables to expand the template
      返回:
      the converted object
      另请参阅:
      • HttpEntity
      • RestTemplate.postForEntity(String, Object, Class, Map)
    • postForEntity

      public <T> cn.taketoday.http.ResponseEntity<T> postForEntity(URI url, Object request, Class<T> responseType)
      Create a new resource by POSTing the given object to the URL, and returns the response as ResponseEntity.

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

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      request - the Object to be POSTed, may be null
      responseType - the response type to return
      返回:
      the converted object
      另请参阅:
      • HttpEntity
      • RestTemplate.postForEntity(URI, Object, Class)
    • put

      public void put(String url, Object request, Object... urlVariables)
      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.

      If you need to assert the request result consider using the exchange method.

      参数:
      url - the URL
      request - the Object to be PUT, may be null
      urlVariables - the variables to expand the template
      另请参阅:
      • HttpEntity
      • RestTemplate.put(String, Object, Object[])
    • put

      public void put(String url, Object request, Map<String,?> urlVariables)
      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.

      If you need to assert the request result consider using the exchange method.

      参数:
      url - the URL
      request - the Object to be PUT, may be null
      urlVariables - the variables to expand the template
      另请参阅:
      • HttpEntity
      • RestTemplate.put(String, Object, Map)
    • put

      public void put(URI url, Object request)
      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.

      If you need to assert the request result consider using the exchange method.

      参数:
      url - the URL
      request - the Object to be PUT, may be null
      另请参阅:
      • HttpEntity
      • RestTemplate.put(URI, Object)
    • patchForObject

      public <T> T patchForObject(String url, Object request, Class<T> responseType, Object... uriVariables)
      Update a resource by PATCHing the given object to the URI template, and returns the representation found in the response.

      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.

      类型参数:
      T - the type of the return value
      参数:
      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
      另请参阅:
      • HttpEntity
    • patchForObject

      public <T> T patchForObject(String url, Object request, Class<T> responseType, Map<String,?> uriVariables)
      Update a resource by PATCHing the given object to the URI template, and returns the representation found in the response.

      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.

      类型参数:
      T - the type of the return value
      参数:
      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
      另请参阅:
      • HttpEntity
    • patchForObject

      public <T> T patchForObject(URI url, Object request, Class<T> responseType)
      Update a resource by PATCHing the given object to the URL, and returns the representation found in the response.

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

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      request - the Object to be POSTed, may be null
      responseType - the type of the return value
      返回:
      the converted object
      另请参阅:
      • HttpEntity
    • delete

      public void delete(String url, Object... urlVariables)
      Delete the resources at the specified URI.

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

      If you need to assert the request result consider using the exchange method.

      参数:
      url - the URL
      urlVariables - the variables to expand in the template
      另请参阅:
      • RestTemplate.delete(String, Object[])
    • delete

      public void delete(String url, Map<String,?> urlVariables)
      Delete the resources at the specified URI.

      URI Template variables are expanded using the given map.

      If you need to assert the request result consider using the exchange method.

      参数:
      url - the URL
      urlVariables - the variables to expand the template
      另请参阅:
      • RestTemplate.delete(String, Map)
    • delete

      public void delete(URI url)
      Delete the resources at the specified URL.

      If you need to assert the request result consider using the exchange method.

      参数:
      url - the URL
      另请参阅:
      • RestTemplate.delete(URI)
    • optionsForAllow

      public Set<cn.taketoday.http.HttpMethod> optionsForAllow(String url, Object... urlVariables)
      Return the value of the Allow header for the given URI.

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

      参数:
      url - the URL
      urlVariables - the variables to expand in the template
      返回:
      the value of the allow header
      另请参阅:
      • RestTemplate.optionsForAllow(String, Object[])
    • optionsForAllow

      public Set<cn.taketoday.http.HttpMethod> optionsForAllow(String url, Map<String,?> urlVariables)
      Return the value of the Allow header for the given URI.

      URI Template variables are expanded using the given map.

      参数:
      url - the URL
      urlVariables - the variables to expand in the template
      返回:
      the value of the allow header
      另请参阅:
      • RestTemplate.optionsForAllow(String, Map)
    • optionsForAllow

      public Set<cn.taketoday.http.HttpMethod> optionsForAllow(URI url)
      Return the value of the Allow header for the given URL.
      参数:
      url - the URL
      返回:
      the value of the allow header
      另请参阅:
      • RestTemplate.optionsForAllow(URI)
    • exchange

      public <T> cn.taketoday.http.ResponseEntity<T> exchange(String url, cn.taketoday.http.HttpMethod method, cn.taketoday.http.HttpEntity<?> requestEntity, Class<T> responseType, Object... urlVariables)
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.

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

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc.)
      requestEntity - the entity (headers and/or body) to write to the request, may be null
      responseType - the type of the return value
      urlVariables - the variables to expand in the template
      返回:
      the response as entity
      另请参阅:
      • RestTemplate.exchange(String, cn.taketoday.http.HttpMethod, cn.taketoday.http.HttpEntity, Class, Object[])
    • exchange

      public <T> cn.taketoday.http.ResponseEntity<T> exchange(String url, cn.taketoday.http.HttpMethod method, cn.taketoday.http.HttpEntity<?> requestEntity, Class<T> responseType, Map<String,?> urlVariables)
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.

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

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc.)
      requestEntity - the entity (headers and/or body) to write to the request, may be null
      responseType - the type of the return value
      urlVariables - the variables to expand in the template
      返回:
      the response as entity
      另请参阅:
      • RestTemplate.exchange(String, cn.taketoday.http.HttpMethod, cn.taketoday.http.HttpEntity, Class, Map)
    • exchange

      public <T> cn.taketoday.http.ResponseEntity<T> exchange(URI url, cn.taketoday.http.HttpMethod method, cn.taketoday.http.HttpEntity<?> requestEntity, Class<T> responseType)
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc.)
      requestEntity - the entity (headers and/or body) to write to the request, may be null
      responseType - the type of the return value
      返回:
      the response as entity
      另请参阅:
      • RestTemplate.exchange(URI, cn.taketoday.http.HttpMethod, cn.taketoday.http.HttpEntity, Class)
    • exchange

      public <T> cn.taketoday.http.ResponseEntity<T> exchange(String url, cn.taketoday.http.HttpMethod method, cn.taketoday.http.HttpEntity<?> requestEntity, cn.taketoday.core.ParameterizedTypeReference<T> responseType, Object... urlVariables)
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity. The given ParameterizedTypeReference is used to pass generic type information:
       TypeReference<List<MyBean>> myBean = new TypeReference<List<MyBean>>() {};
       ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);
       
      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc.)
      requestEntity - the entity (headers and/or body) to write to the request, may be null
      responseType - the type of the return value
      urlVariables - the variables to expand in the template
      返回:
      the response as entity
      另请参阅:
      • RestTemplate.exchange(String, cn.taketoday.http.HttpMethod, cn.taketoday.http.HttpEntity, ParameterizedTypeReference, Object[])
    • exchange

      public <T> cn.taketoday.http.ResponseEntity<T> exchange(String url, cn.taketoday.http.HttpMethod method, cn.taketoday.http.HttpEntity<?> requestEntity, cn.taketoday.core.ParameterizedTypeReference<T> responseType, Map<String,?> urlVariables)
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity. The given ParameterizedTypeReference is used to pass generic type information:
       TypeReference<List<MyBean>> myBean = new TypeReference<List<MyBean>>() {};
       ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);
       
      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc.)
      requestEntity - the entity (headers and/or body) to write to the request, may be null
      responseType - the type of the return value
      urlVariables - the variables to expand in the template
      返回:
      the response as entity
      另请参阅:
      • RestTemplate.exchange(String, cn.taketoday.http.HttpMethod, cn.taketoday.http.HttpEntity, ParameterizedTypeReference, Map)
    • exchange

      public <T> cn.taketoday.http.ResponseEntity<T> exchange(URI url, cn.taketoday.http.HttpMethod method, cn.taketoday.http.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 as ResponseEntity. The given ParameterizedTypeReference is used to pass generic type information:
       TypeReference<List<MyBean>> myBean = new TypeReference<List<MyBean>>() {};
       ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);
       
      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc.)
      requestEntity - the entity (headers and/or body) to write to the request, may be null
      responseType - the type of the return value
      返回:
      the response as entity
      另请参阅:
      • RestTemplate.exchange(URI, cn.taketoday.http.HttpMethod, cn.taketoday.http.HttpEntity, ParameterizedTypeReference)
    • exchange

      public <T> cn.taketoday.http.ResponseEntity<T> exchange(cn.taketoday.http.RequestEntity<?> requestEntity, Class<T> responseType)
      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);
       
      类型参数:
      T - the type of the return value
      参数:
      requestEntity - the entity to write to the request
      responseType - the type of the return value
      返回:
      the response as entity
      另请参阅:
      • RestTemplate.exchange(cn.taketoday.http.RequestEntity, Class)
    • exchange

      public <T> cn.taketoday.http.ResponseEntity<T> exchange(cn.taketoday.http.RequestEntity<?> requestEntity, cn.taketoday.core.ParameterizedTypeReference<T> responseType)
      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);
       TypeReference<List<MyResponse>> myBean = new TypeReference<List<MyResponse>>() {};
       ResponseEntity<List<MyResponse>> response = template.exchange(request, myBean);
       
      类型参数:
      T - the type of the return value
      参数:
      requestEntity - the entity to write to the request
      responseType - the type of the return value
      返回:
      the response as entity
      另请参阅:
      • RestTemplate.exchange(cn.taketoday.http.RequestEntity, ParameterizedTypeReference)
    • execute

      public <T> T execute(String url, cn.taketoday.http.HttpMethod method, cn.taketoday.web.client.RequestCallback requestCallback, cn.taketoday.web.client.ResponseExtractor<T> responseExtractor, Object... urlVariables)
      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.

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc.)
      requestCallback - object that prepares the request
      responseExtractor - object that extracts the return value from the response
      urlVariables - the variables to expand in the template
      返回:
      an arbitrary object, as returned by the ResponseExtractor
      另请参阅:
      • RestTemplate.execute(String, cn.taketoday.http.HttpMethod, cn.taketoday.web.client.RequestCallback, cn.taketoday.web.client.ResponseExtractor, Object[])
    • execute

      public <T> T execute(String url, cn.taketoday.http.HttpMethod method, cn.taketoday.web.client.RequestCallback requestCallback, cn.taketoday.web.client.ResponseExtractor<T> responseExtractor, Map<String,?> urlVariables)
      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.

      类型参数:
      T - the type of the return value
      参数:
      url - the URL
      method - the HTTP method (GET, POST, etc.)
      requestCallback - object that prepares the request
      responseExtractor - object that extracts the return value from the response
      urlVariables - the variables to expand in the template
      返回:
      an arbitrary object, as returned by the ResponseExtractor
      另请参阅:
      • RestTemplate.execute(String, cn.taketoday.http.HttpMethod, cn.taketoday.web.client.RequestCallback, cn.taketoday.web.client.ResponseExtractor, Map)
    • execute

      public <T> T execute(URI url, cn.taketoday.http.HttpMethod method, cn.taketoday.web.client.RequestCallback requestCallback, cn.taketoday.web.client.ResponseExtractor<T> responseExtractor)
      Execute the HTTP method to the given URL, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.
      类型参数:
      T - the type of the return value
      参数:
      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
      另请参阅:
      • RestTemplate.execute(URI, cn.taketoday.http.HttpMethod, cn.taketoday.web.client.RequestCallback, cn.taketoday.web.client.ResponseExtractor)
    • getRestTemplate

      public cn.taketoday.web.client.RestTemplate getRestTemplate()
      Returns the underlying RestTemplate that is actually used to perform the REST operations.
      返回:
      the restTemplate
    • withBasicAuth

      public TestRestTemplate withBasicAuth(String username, String password)
      Creates a new TestRestTemplate with the same configuration as this one, except that it will send basic authorization headers using the given username and password. The request factory used is a new instance of the underlying RestTemplate's request factory type (when possible).
      参数:
      username - the username
      password - the password
      返回:
      the new template
    • createRequestEntityWithRootAppliedUri

      private cn.taketoday.http.RequestEntity<?> createRequestEntityWithRootAppliedUri(cn.taketoday.http.RequestEntity<?> requestEntity)
    • applyRootUriIfNecessary

      private URI applyRootUriIfNecessary(URI uri)
    • resolveUri

      private URI resolveUri(cn.taketoday.http.RequestEntity<?> entity)