Example usage for org.springframework.boot.context.properties PropertyMapper from

List of usage examples for org.springframework.boot.context.properties PropertyMapper from

Introduction

In this page you can find the example usage for org.springframework.boot.context.properties PropertyMapper from.

Prototype

public <T> Source<T> from(T value) 

Source Link

Document

Return a new Source from the specified value that can be used to perform the mapping.

Usage

From source file:org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoConfiguration.java

@Bean
@ConditionalOnMissingBean//  w w  w . j  a  v  a  2  s .  c  om
public RestClientBuilder restClientBuilder() {
    HttpHost[] hosts = this.properties.getUris().stream().map(HttpHost::create).toArray(HttpHost[]::new);
    RestClientBuilder builder = RestClient.builder(hosts);
    PropertyMapper map = PropertyMapper.get();
    map.from(this.properties::getUsername).whenHasText().to((username) -> {
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        Credentials credentials = new UsernamePasswordCredentials(this.properties.getUsername(),
                this.properties.getPassword());
        credentialsProvider.setCredentials(AuthScope.ANY, credentials);
        builder.setHttpClientConfigCallback(
                (httpClientBuilder) -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
    });
    this.builderCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
    return builder;
}