Skip to content

Commit 8364840

Browse files
committed
Merge branch '2.4.x' into 2.5.x
Closes gh-28047
2 parents 9058ffd + eacb927 commit 8364840

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticsearchRestClientAutoConfiguration.java

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@
2828
import org.springframework.data.elasticsearch.client.ClientConfiguration;
2929
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
3030
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients;
31-
import org.springframework.http.HttpHeaders;
3231
import org.springframework.util.unit.DataSize;
3332
import org.springframework.web.reactive.function.client.ExchangeStrategies;
3433
import org.springframework.web.reactive.function.client.WebClient;
@@ -50,36 +49,25 @@ public class ReactiveElasticsearchRestClientAutoConfiguration {
5049
public ClientConfiguration clientConfiguration(ReactiveElasticsearchRestClientProperties properties) {
5150
ClientConfiguration.MaybeSecureClientConfigurationBuilder builder = ClientConfiguration.builder()
5251
.connectedTo(properties.getEndpoints().toArray(new String[0]));
53-
if (properties.isUseSsl()) {
54-
builder.usingSsl();
55-
}
56-
configureTimeouts(builder, properties);
57-
configureExchangeStrategies(builder, properties);
52+
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
53+
map.from(properties.isUseSsl()).whenTrue().toCall(builder::usingSsl);
54+
map.from(properties.getUsername()).whenHasText()
55+
.to((username) -> builder.withBasicAuth(username, properties.getPassword()));
56+
map.from(properties.getConnectionTimeout()).to(builder::withConnectTimeout);
57+
map.from(properties.getSocketTimeout()).to(builder::withSocketTimeout);
58+
configureExchangeStrategies(map, builder, properties);
5859
return builder.build();
5960
}
6061

61-
private void configureTimeouts(ClientConfiguration.TerminalClientConfigurationBuilder builder,
62+
private void configureExchangeStrategies(PropertyMapper map,
63+
ClientConfiguration.TerminalClientConfigurationBuilder builder,
6264
ReactiveElasticsearchRestClientProperties properties) {
63-
PropertyMapper map = PropertyMapper.get();
64-
map.from(properties.getConnectionTimeout()).whenNonNull().to(builder::withConnectTimeout);
65-
map.from(properties.getSocketTimeout()).whenNonNull().to(builder::withSocketTimeout);
66-
map.from(properties.getUsername()).whenHasText().to((username) -> {
67-
HttpHeaders headers = new HttpHeaders();
68-
headers.setBasicAuth(username, properties.getPassword());
69-
builder.withDefaultHeaders(headers);
70-
});
71-
}
72-
73-
private void configureExchangeStrategies(ClientConfiguration.TerminalClientConfigurationBuilder builder,
74-
ReactiveElasticsearchRestClientProperties properties) {
75-
PropertyMapper map = PropertyMapper.get();
76-
builder.withWebClientConfigurer((webClient) -> {
77-
ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder()
78-
.codecs((configurer) -> map.from(properties.getMaxInMemorySize()).whenNonNull()
79-
.asInt(DataSize::toBytes)
80-
.to((maxInMemorySize) -> configurer.defaultCodecs().maxInMemorySize(maxInMemorySize)))
81-
.build();
82-
return webClient.mutate().exchangeStrategies(exchangeStrategies).build();
65+
map.from(properties.getMaxInMemorySize()).asInt(DataSize::toBytes).to((maxInMemorySize) -> {
66+
builder.withWebClientConfigurer((webClient) -> {
67+
ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder()
68+
.codecs((configurer) -> configurer.defaultCodecs().maxInMemorySize(maxInMemorySize)).build();
69+
return webClient.mutate().exchangeStrategies(exchangeStrategies).build();
70+
});
8371
});
8472
}
8573

0 commit comments

Comments
 (0)