• TestRestTemplate(RestTemplateBuilder)
  • TestRestTemplate(TestRestTemplate.HttpClientOption...)
  • TestRestTemplate(String, String, TestRestTemplate.HttpClientOption...)
  • TestRestTemplate(RestTemplateBuilder, String, String, TestRestTemplate.HttpClientOption...)
  • Method Details
  • setUriTemplateHandler(UriTemplateHandler)
  • getRootUri()
  • getForObject(String, Class, Object...)
  • getForObject(String, Class, Map)
  • getForObject(URI, Class)
  • getForEntity(String, Class, Object...)
  • getForEntity(String, Class, Map)
  • getForEntity(URI, Class)
  • headForHeaders(String, Object...)
  • headForHeaders(String, Map)
  • headForHeaders(URI)
  • postForLocation(String, Object, Object...)
  • postForLocation(String, Object, Map)
  • postForLocation(URI, Object)
  • postForObject(String, Object, Class, Object...)
  • postForObject(String, Object, Class, Map)
  • postForObject(URI, Object, Class)
  • postForEntity(String, Object, Class, Object...)
  • postForEntity(String, Object, Class, Map)
  • postForEntity(URI, Object, Class)
  • put(String, Object, Object...)
  • put(String, Object, Map)
  • put(URI, Object)
  • patchForObject(String, Object, Class, Object...)
  • patchForObject(String, Object, Class, Map)
  • patchForObject(URI, Object, Class)
  • delete(String, Object...)
  • delete(String, Map)
  • delete(URI)
  • optionsForAllow(String, Object...)
  • optionsForAllow(String, Map)
  • optionsForAllow(URI)
  • exchange(String, HttpMethod, HttpEntity, Class, Object...)
  • exchange(String, HttpMethod, HttpEntity, Class, Map)
  • exchange(URI, HttpMethod, HttpEntity, Class)
  • exchange(String, HttpMethod, HttpEntity, ParameterizedTypeReference, Object...)
  • exchange(String, HttpMethod, HttpEntity, ParameterizedTypeReference, Map)
  • exchange(URI, HttpMethod, HttpEntity, ParameterizedTypeReference)
  • exchange(RequestEntity, Class)
  • exchange(RequestEntity, ParameterizedTypeReference)
  • execute(String, HttpMethod, RequestCallback, ResponseExtractor, Object...)
  • execute(String, HttpMethod, RequestCallback, ResponseExtractor, Map)
  • execute(URI, HttpMethod, RequestCallback, ResponseExtractor)
  • getRestTemplate()
  • withBasicAuth(String, String)
  • withRedirects(HttpRedirects)
  • withClientSettings(HttpClientSettings)
  • withClientSettings(UnaryOperator)
  • Class TestRestTemplate

    java.lang.Object
    org.springframework.boot.resttestclient.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 through 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. 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 @SpringBootTest annotation with an embedded server, a TestRestTemplate can be auto-configured by adding @AutoConfigureTestRestTemplate to your test class. It can then be @Autowired into your test. If you need customizations (for example to adding additional message converters) use a RestTemplateBuilder @Bean .

    Since:
    4.0.0
    Author:
    Dave Syer, Phillip Webb, Andy Wilkinson, Kristine Jetzke, Dmytro Nosan, Yanming Zhou
    TestRestTemplate (@Nullable String username, @Nullable String password, TestRestTemplate.HttpClientOption ... httpClientOptions)
    Create a new TestRestTemplate instance with the specified credentials.
    Create a new TestRestTemplate instance.
    TestRestTemplate ( RestTemplateBuilder builder, @Nullable String username, @Nullable String password, TestRestTemplate.HttpClientOption ... httpClientOptions)
    Create a new TestRestTemplate instance with the specified credentials.
    Create a new TestRestTemplate instance.
    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 .
    exchange ( String url, HttpMethod method, @Nullable 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 .
    exchange ( String url, HttpMethod method, @Nullable HttpEntity <?> requestEntity, 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 .
    exchange ( String url, HttpMethod method, @Nullable HttpEntity <?> requestEntity, 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 .
    exchange ( URI url, HttpMethod method, @Nullable 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 .
    exchange ( URI url, HttpMethod method, @Nullable HttpEntity <?> requestEntity, 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 .
    exchange ( RequestEntity <?> requestEntity, Class <T> responseType)
    Execute the request specified in the given RequestEntity and return the response as ResponseEntity .
    exchange ( RequestEntity <?> requestEntity, ParameterizedTypeReference <T> responseType)
    Execute the request specified in the given RequestEntity and return the response as ResponseEntity .
    <T> @Nullable T
    execute ( String url, HttpMethod method, RequestCallback requestCallback, 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> @Nullable T
    execute ( String url, HttpMethod method, RequestCallback requestCallback, 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> @Nullable T
    execute ( URI url, HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor <T> responseExtractor)
    Execute the HTTP method to the given URL, preparing the request with the RequestCallback , and reading the response with a ResponseExtractor .
    getForEntity ( String url, Class <T> responseType, Object ... urlVariables)
    Retrieve an entity by doing a GET on the specified URL.
    getForEntity ( String url, Class <T> responseType, Map < String , ?> urlVariables)
    Retrieve a representation by doing a GET on the URI template.
    getForEntity ( URI url, Class <T> responseType)
    Retrieve a representation by doing a GET on the URL .
    <T> @Nullable T
    getForObject ( String url, Class <T> responseType, Object ... urlVariables)
    Retrieve a representation by doing a GET on the specified URL.
    <T> @Nullable T
    getForObject ( String url, Class <T> responseType, Map < String , ?> urlVariables)
    Retrieve a representation by doing a GET on the URI template.
    <T> @Nullable T
    getForObject ( URI url, Class <T> responseType)
    Retrieve a representation by doing a GET on the URL .
    Returns the underlying RestTemplate that is actually used to perform the REST operations.
    @Nullable String
    Returns the root URI applied by RestTemplateBuilder.rootUri(String) or "" if the root URI has not been applied.
    headForHeaders ( String url, Object ... urlVariables)
    Retrieve all headers of the resource specified by the URI template.
    headForHeaders ( String url, Map < String , ?> urlVariables)
    Retrieve all headers of the resource specified by the URI template.
    Retrieve all headers of the resource specified by the URL.
    optionsForAllow ( String url, Object ... urlVariables)
    Return the value of the Allow header for the given URI.
    optionsForAllow ( String url, Map < String , ?> urlVariables)
    Return the value of the Allow header for the given URI.
    Return the value of the Allow header for the given URL.
    <T> @Nullable T
    patchForObject ( String url, @Nullable 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> @Nullable T
    patchForObject ( String url, @Nullable 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> @Nullable T
    patchForObject ( URI url, @Nullable Object request, Class <T> responseType)
    Update a resource by PATCHing the given object to the URL, and returns the representation found in the response.
    postForEntity ( String url, @Nullable 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 .
    postForEntity ( String url, @Nullable 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 .
    postForEntity ( URI url, @Nullable Object request, Class <T> responseType)
    Create a new resource by POSTing the given object to the URL, and returns the response as ResponseEntity .
    @Nullable URI
    postForLocation ( String url, @Nullable 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.
    @Nullable URI
    postForLocation ( String url, @Nullable 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.
    @Nullable URI
    postForLocation ( URI url, @Nullable Object request)
    Create a new resource by POSTing the given object to the URL, and returns the value of the Location header.
    <T> @Nullable T
    postForObject ( String url, @Nullable 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> @Nullable T
    postForObject ( String url, @Nullable 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> @Nullable T
    postForObject ( URI url, @Nullable 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.
    put ( String url, @Nullable Object request, Object ... urlVariables)
    Create or update a resource by PUTting the given object to the URI.
    put ( String url, @Nullable Object request, Map < String , ?> urlVariables)
    Creates a new resource by PUTting the given object to URI template.
    put ( URI url, @Nullable Object request)
    Creates a new resource by PUTting the given object to URL.
    Configure the UriTemplateHandler to use to expand URI templates.
    withBasicAuth (@Nullable String username, @Nullable 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 .
    Creates a new TestRestTemplate with the same configuration as this one, except that it will customize the HttpClientSettings .
    Creates a new TestRestTemplate with the same configuration as this one, except that it will apply the given HttpClientSettings .
    Creates a new TestRestTemplate with the same configuration as this one, except that it will apply the given HttpRedirects .
    public TestRestTemplate ( RestTemplateBuilder restTemplateBuilder)
    Create a new TestRestTemplate instance.
    Parameters:
    restTemplateBuilder - builder used to configure underlying RestTemplate

    TestRestTemplate

    public TestRestTemplate ( TestRestTemplate.HttpClientOption ... httpClientOptions)
    Create a new TestRestTemplate instance.
    Parameters:
    httpClientOptions - client options to use if the Apache HTTP Client is used
    public TestRestTemplate (@Nullable String username, @Nullable String password, TestRestTemplate.HttpClientOption ... httpClientOptions)
    Create a new TestRestTemplate instance with the specified credentials.
    Parameters:
    username - the username to use (or null )
    password - the password (or null )
    httpClientOptions - client options to use if the Apache HTTP Client is used
    public TestRestTemplate ( RestTemplateBuilder builder, @Nullable String username, @Nullable String password, TestRestTemplate.HttpClientOption ... httpClientOptions)
    Create a new TestRestTemplate instance with the specified credentials.
    Parameters:
    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 ( UriTemplateHandler handler)
    Configure the UriTemplateHandler to use to expand URI templates. By default the DefaultUriBuilderFactory is used which relies on Spring's 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.
    Parameters:
    handler - the URI template handler to use
    public @Nullable String getRootUri ()
    Returns the root URI applied by RestTemplateBuilder.rootUri(String) or "" if the root URI has not been applied.
    Returns:
    the root URI
    public <T> @Nullable 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    url - the URL
    responseType - the type of the return value
    urlVariables - the variables to expand the template
    Returns:
    the converted object
    See Also:
  • RestTemplate.getForObject(String, Class, Object...)
  • public <T> @Nullable 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    url - the URL
    responseType - the type of the return value
    urlVariables - the map containing variables for the URI template
    Returns:
    the converted object
    See Also:
  • RestTemplate.getForObject(String, Class, Object...)
  • public <T> @Nullable 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.
    Type Parameters:
    T - the type of the return value
    Parameters:
    url - the URL
    responseType - the type of the return value
    Returns:
    the converted object
    See Also:
  • RestTemplate.getForObject(java.net.URI, java.lang.Class)
  • public <T> 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    url - the URL
    responseType - the type of the return value
    urlVariables - the variables to expand the template
    Returns:
    the entity
    See Also:
  • RestTemplate.getForEntity(java.lang.String, java.lang.Class, java.lang.Object[])
  • public <T> 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    url - the URL
    responseType - the type of the return value
    urlVariables - the map containing variables for the URI template
    Returns:
    the converted object
    See Also:
  • RestTemplate.getForEntity(java.lang.String, java.lang.Class, java.util.Map)
  • public <T> 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 .
    Type Parameters:
    T - the type of the return value
    Parameters:
    url - the URL
    responseType - the type of the return value
    Returns:
    the converted object
    See Also:
  • RestTemplate.getForEntity(java.net.URI, java.lang.Class)
  • public 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.

    Parameters:
    url - the URL
    urlVariables - the variables to expand the template
    Returns:
    all HTTP headers of that resource
    See Also:
  • RestTemplate.headForHeaders(java.lang.String, java.lang.Object[])
  • public 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.

    Parameters:
    url - the URL
    urlVariables - the map containing variables for the URI template
    Returns:
    all HTTP headers of that resource
    See Also:
  • RestTemplate.headForHeaders(java.lang.String, java.util.Map)
  • public HttpHeaders headForHeaders ( URI url)
    Retrieve all headers of the resource specified by the URL.
    Parameters:
    url - the URL
    Returns:
    all HTTP headers of that resource
    See Also:
  • RestTemplate.headForHeaders(java.net.URI)
  • public @Nullable URI postForLocation ( String url, @Nullable 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.

    Parameters:
    url - the URL
    request - the Object to be POSTed, may be null
    urlVariables - the variables to expand the template
    Returns:
    the value for the Location header
    See Also:
  • HttpEntity
  • RestTemplate.postForLocation(java.lang.String, java.lang.Object, java.lang.Object[])
  • public @Nullable URI postForLocation ( String url, @Nullable 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.

    Parameters:
    url - the URL
    request - the Object to be POSTed, may be null
    urlVariables - the variables to expand the template
    Returns:
    the value for the Location header
    See Also:
  • HttpEntity
  • RestTemplate.postForLocation(java.lang.String, java.lang.Object, java.util.Map)
  • public @Nullable URI postForLocation ( URI url, @Nullable 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.

    Parameters:
    url - the URL
    request - the Object to be POSTed, may be null
    Returns:
    the value for the Location header
    See Also:
  • HttpEntity
  • RestTemplate.postForLocation(java.net.URI, java.lang.Object)
  • public <T> @Nullable T postForObject ( String url, @Nullable 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    the converted object
    See Also:
  • HttpEntity
  • RestTemplate.postForObject(java.lang.String, java.lang.Object, java.lang.Class, java.lang.Object[])
  • public <T> @Nullable T postForObject ( String url, @Nullable 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    the converted object
    See Also:
  • HttpEntity
  • RestTemplate.postForObject(java.lang.String, java.lang.Object, java.lang.Class, java.util.Map)
  • public <T> @Nullable T postForObject ( URI url, @Nullable 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    url - the URL
    request - the Object to be POSTed, may be null
    responseType - the type of the return value
    Returns:
    the converted object
    See Also:
  • HttpEntity
  • RestTemplate.postForObject(java.net.URI, java.lang.Object, java.lang.Class)
  • public <T> ResponseEntity <T> postForEntity ( String url, @Nullable 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    the converted object
    See Also:
  • HttpEntity
  • RestTemplate.postForEntity(java.lang.String, java.lang.Object, java.lang.Class, java.lang.Object[])
  • public <T> ResponseEntity <T> postForEntity ( String url, @Nullable 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    the converted object
    See Also:
  • HttpEntity
  • RestTemplate.postForEntity(java.lang.String, java.lang.Object, java.lang.Class, java.util.Map)
  • public <T> ResponseEntity <T> postForEntity ( URI url, @Nullable 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    url - the URL
    request - the Object to be POSTed, may be null
    responseType - the response type to return
    Returns:
    the converted object
    See Also:
  • HttpEntity
  • RestTemplate.postForEntity(java.net.URI, java.lang.Object, java.lang.Class)
  • @Nullable 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.

    Parameters:
    url - the URL
    request - the Object to be PUT, may be null
    urlVariables - the variables to expand the template
    See Also:
  • HttpEntity
  • RestTemplate.put(java.lang.String, java.lang.Object, java.lang.Object[])
  • public void put ( String url, @Nullable 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.

    Parameters:
    url - the URL
    request - the Object to be PUT, may be null
    urlVariables - the variables to expand the template
    See Also:
  • HttpEntity
  • RestTemplate.put(java.lang.String, java.lang.Object, java.util.Map)
  • public void put ( URI url, @Nullable 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.

    Parameters:
    url - the URL
    request - the Object to be PUT, may be null
    See Also:
  • HttpEntity
  • RestTemplate.put(java.net.URI, java.lang.Object)
  • public <T> @Nullable T patchForObject ( String url, @Nullable 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    the converted object
    See Also:
  • HttpEntity
  • public <T> @Nullable T patchForObject ( String url, @Nullable 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    the converted object
    See Also:
  • HttpEntity
  • public <T> @Nullable T patchForObject ( URI url, @Nullable 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    url - the URL
    request - the Object to be POSTed, may be null
    responseType - the type of the return value
    Returns:
    the converted object
    See Also:
  • HttpEntity
  • 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.

    Parameters:
    url - the URL
    urlVariables - the variables to expand in the template
    See Also:
  • RestTemplate.delete(java.lang.String, java.lang.Object[])
  • 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.

    Parameters:
    url - the URL
    urlVariables - the variables to expand the template
    See Also:
  • RestTemplate.delete(java.lang.String, java.util.Map)
  • Delete the resources at the specified URL. If you need to assert the request result consider using the exchange method.

    Parameters:
    url - the URL
    See Also:
  • RestTemplate.delete(java.net.URI)
  • public Set < 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.

    Parameters:
    url - the URL
    urlVariables - the variables to expand in the template
    Returns:
    the value of the Allow header
    See Also:
  • RestTemplate.optionsForAllow(java.lang.String, java.lang.Object[])
  • public Set < 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.

    Parameters:
    url - the URL
    urlVariables - the variables to expand in the template
    Returns:
    the value of the Allow header
    See Also:
  • RestTemplate.optionsForAllow(java.lang.String, java.util.Map)
  • public Set < HttpMethod > optionsForAllow ( URI url)
    Return the value of the Allow header for the given URL.
    Parameters:
    url - the URL
    Returns:
    the value of the Allow header
    See Also:
  • RestTemplate.optionsForAllow(java.net.URI)
  • public <T> ResponseEntity <T> exchange ( String url, HttpMethod method, @Nullable 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    the response as entity
    See Also:
  • RestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod, org.springframework.http.HttpEntity, java.lang.Class, java.lang.Object[])
  • public <T> ResponseEntity <T> exchange ( String url, HttpMethod method, @Nullable 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    the response as entity
    See Also:
  • RestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod, org.springframework.http.HttpEntity, java.lang.Class, java.util.Map)
  • public <T> ResponseEntity <T> exchange ( URI url, HttpMethod method, @Nullable 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 .
    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    the response as entity
    See Also:
  • RestTemplate.exchange(java.net.URI, org.springframework.http.HttpMethod, org.springframework.http.HttpEntity, java.lang.Class)
  • public <T> ResponseEntity <T> exchange ( String url, HttpMethod method, @Nullable HttpEntity <?> requestEntity, 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: ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {}; ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);
    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    the response as entity
    See Also:
  • RestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod, org.springframework.http.HttpEntity, org.springframework.core.ParameterizedTypeReference, java.lang.Object[])
  • public <T> ResponseEntity <T> exchange ( String url, HttpMethod method, @Nullable HttpEntity <?> requestEntity, 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: ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {}; ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);
    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    the response as entity
    See Also:
  • RestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod, org.springframework.http.HttpEntity, org.springframework.core.ParameterizedTypeReference, java.util.Map)
  • public <T> ResponseEntity <T> exchange ( URI url, HttpMethod method, @Nullable HttpEntity <?> requestEntity, 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: ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {}; ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);
    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    the response as entity
    See Also:
  • RestTemplate.exchange(java.net.URI, org.springframework.http.HttpMethod, org.springframework.http.HttpEntity, org.springframework.core.ParameterizedTypeReference)
  • public <T> ResponseEntity <T> exchange ( 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);
    
    Type Parameters:
    T - the type of the return value
    Parameters:
    requestEntity - the entity to write to the request
    responseType - the type of the return value
    Returns:
    the response as entity
    See Also:
  • RestTemplate.exchange(org.springframework.http.RequestEntity, java.lang.Class)
  • public <T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity, 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);
    ParameterizedTypeReference<List<MyResponse>> myBean = new ParameterizedTypeReference<List<MyResponse>>() {};
    ResponseEntity<List<MyResponse>> response = template.exchange(request, myBean);
    
    Type Parameters:
    T - the type of the return value
    Parameters:
    requestEntity - the entity to write to the request
    responseType - the type of the return value
    Returns:
    the response as entity
    See Also:
  • RestTemplate.exchange(org.springframework.http.RequestEntity, org.springframework.core.ParameterizedTypeReference)
  • public <T> @Nullable T execute(String url, HttpMethod method, RequestCallback requestCallback, 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    an arbitrary object, as returned by the ResponseExtractor
    See Also:
  • RestTemplate.execute(java.lang.String, org.springframework.http.HttpMethod, org.springframework.web.client.RequestCallback, org.springframework.web.client.ResponseExtractor, java.lang.Object[])
  • public <T> @Nullable T execute(String url, HttpMethod method, RequestCallback requestCallback, 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.

    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    an arbitrary object, as returned by the ResponseExtractor
    See Also:
  • RestTemplate.execute(java.lang.String, org.springframework.http.HttpMethod, org.springframework.web.client.RequestCallback, org.springframework.web.client.ResponseExtractor, java.util.Map)
  • public <T> @Nullable T execute(URI url, HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor<T> responseExtractor)
    Execute the HTTP method to the given URL, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.
    Type Parameters:
    T - the type of the return value
    Parameters:
    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
    Returns:
    an arbitrary object, as returned by the ResponseExtractor
    See Also:
  • RestTemplate.execute(java.net.URI, org.springframework.http.HttpMethod, org.springframework.web.client.RequestCallback, org.springframework.web.client.ResponseExtractor)
  • public RestTemplate getRestTemplate()
    Returns the underlying RestTemplate that is actually used to perform the REST operations.
    Returns:
    the restTemplate
    public TestRestTemplate withBasicAuth(@Nullable String username, @Nullable 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).
    Parameters:
    username - the username
    password - the password
    Returns:
    the new template
    public TestRestTemplate withRedirects(HttpRedirects redirects)
    Creates a new TestRestTemplate with the same configuration as this one, except that it will apply the given HttpRedirects. The request factory used is a new instance of the underlying RestTemplate's request factory type (when possible).
    Parameters:
    redirects - the new redirect settings
    Returns:
    the new template

    withClientSettings

    public TestRestTemplate withClientSettings(HttpClientSettings clientSettings)
    Creates a new TestRestTemplate with the same configuration as this one, except that it will apply the given HttpClientSettings. The request factory used is a new instance of the underlying RestTemplate's request factory type (when possible).
    Parameters:
    clientSettings - the new client settings
    Returns:
    the new template

    withClientSettings

    public TestRestTemplate withClientSettings(UnaryOperator<HttpClientSettings> clientSettingsCustomizer)
    Creates a new TestRestTemplate with the same configuration as this one, except that it will customize the HttpClientSettings. The request factory used is a new instance of the underlying RestTemplate's request factory type (when possible).
    Parameters:
    clientSettingsCustomizer - a UnaryOperator to update the settings
    Returns:
    the new template