Example usage for org.springframework.boot.web.client RestTemplateCustomizer customize

List of usage examples for org.springframework.boot.web.client RestTemplateCustomizer customize

Introduction

In this page you can find the example usage for org.springframework.boot.web.client RestTemplateCustomizer customize.

Prototype

void customize(RestTemplate restTemplate);

Source Link

Document

Callback to customize a RestTemplate instance.

Usage

From source file:org.springframework.boot.web.client.RestTemplateBuilder.java

/**
 * Configure the provided {@link RestTemplate} instance using this builder.
 * @param <T> the type of rest template
 * @param restTemplate the {@link RestTemplate} to configure
 * @return the rest template instance//from  w w w. ja  v  a2s  .  c om
 * @see RestTemplateBuilder#build()
 * @see RestTemplateBuilder#build(Class)
 */
public <T extends RestTemplate> T configure(T restTemplate) {
    configureRequestFactory(restTemplate);
    if (!CollectionUtils.isEmpty(this.messageConverters)) {
        restTemplate.setMessageConverters(new ArrayList<>(this.messageConverters));
    }
    if (this.uriTemplateHandler != null) {
        restTemplate.setUriTemplateHandler(this.uriTemplateHandler);
    }
    if (this.errorHandler != null) {
        restTemplate.setErrorHandler(this.errorHandler);
    }
    if (this.rootUri != null) {
        RootUriTemplateHandler.addTo(restTemplate, this.rootUri);
    }
    if (this.basicAuthorization != null) {
        restTemplate.getInterceptors().add(this.basicAuthorization);
    }
    if (!CollectionUtils.isEmpty(this.restTemplateCustomizers)) {
        for (RestTemplateCustomizer customizer : this.restTemplateCustomizers) {
            customizer.customize(restTemplate);
        }
    }
    restTemplate.getInterceptors().addAll(this.interceptors);
    return restTemplate;
}