Package org.springframework.vault.client
Class RestTemplateBuilder
java.lang.Object
org.springframework.vault.client.RestTemplateBuilder
Builder that can be used to configure and create a
RestTemplate
. Provides
convenience methods to configure ClientHttpRequestFactory
, error handlers
and default headers
.
By default the built RestTemplate
will attempt to use the most suitable
ClientHttpRequestFactory
using ClientHttpRequestFactoryFactory.create(org.springframework.vault.support.ClientOptions, org.springframework.vault.support.SslConfiguration)
.- Since:
- 2.2
- Author:
- Mark Paluch
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build a newRestTemplate
.static RestTemplateBuilder
builder()
Create a newRestTemplateBuilder
.protected RestTemplate
Create theRestTemplate
to use.customizers
(RestTemplateCustomizer... customizer) Add theRestTemplateCustomizers
that should be applied to theRestTemplate
.defaultHeader
(String name, String value) Add a default header that will be set if not already present on the outgoingHttpRequest
.endpoint
(VaultEndpoint endpoint) Set theVaultEndpoint
that should be used with theRestTemplate
.endpointProvider
(VaultEndpointProvider provider) Set theVaultEndpointProvider
that should be used with theRestTemplate
.errorHandler
(ResponseErrorHandler errorHandler) Set theResponseErrorHandler
that should be used with theRestTemplate
.requestCustomizers
(RestTemplateRequestCustomizer<?>... requestCustomizers) Add theRestTemplateRequestCustomizers
that should be applied to theClientHttpRequest
.requestFactory
(Supplier<ClientHttpRequestFactory> requestFactory) Set theSupplier
ofClientHttpRequestFactory
that should be called each time webuild()
a newRestTemplate
instance.requestFactory
(ClientHttpRequestFactory requestFactory) Set theClientHttpRequestFactory
that should be used with theRestTemplate
.
-
Method Details
-
builder
Create a newRestTemplateBuilder
.- Returns:
- a new
RestTemplateBuilder
.
-
endpoint
Set theVaultEndpoint
that should be used with theRestTemplate
.- Parameters:
endpoint
- theVaultEndpoint
provider.- Returns:
this
RestTemplateBuilder
.
-
endpointProvider
Set theVaultEndpointProvider
that should be used with theRestTemplate
.- Parameters:
provider
- theVaultEndpoint
provider.- Returns:
this
RestTemplateBuilder
.
-
requestFactory
Set theClientHttpRequestFactory
that should be used with theRestTemplate
.- Parameters:
requestFactory
- the request factory.- Returns:
this
RestTemplateBuilder
.
-
requestFactory
Set theSupplier
ofClientHttpRequestFactory
that should be called each time webuild()
a newRestTemplate
instance.- Parameters:
requestFactory
- the supplier for the request factory.- Returns:
this
RestTemplateBuilder
.
-
errorHandler
Set theResponseErrorHandler
that should be used with theRestTemplate
.- Parameters:
errorHandler
- the error handler to use.- Returns:
this
RestTemplateBuilder
.
-
defaultHeader
Add a default header that will be set if not already present on the outgoingHttpRequest
.- Parameters:
name
- the name of the header.value
- the header value.- Returns:
this
RestTemplateBuilder
.
-
customizers
Add theRestTemplateCustomizers
that should be applied to theRestTemplate
. Customizers are applied in the order that they were added.- Parameters:
customizer
- the template customizers to add.- Returns:
this
RestTemplateBuilder
.
-
requestCustomizers
public RestTemplateBuilder requestCustomizers(RestTemplateRequestCustomizer<?>... requestCustomizers) Add theRestTemplateRequestCustomizers
that should be applied to theClientHttpRequest
. Customizers are applied in the order that they were added.- Parameters:
requestCustomizers
- the request customizers to add.- Returns:
this
RestTemplateBuilder
.
-
build
Build a newRestTemplate
.VaultEndpoint
must be set. Applies alsoResponseErrorHandler
andRestTemplateCustomizer
if configured.- Returns:
- a new
RestTemplate
.
-
createTemplate
Create theRestTemplate
to use.- Returns:
- the
RestTemplate
to use.
-