use of org.springframework.data.elasticsearch.client.ClientConfiguration in project spring-boot by spring-projects.
the class ReactiveElasticsearchRestClientAutoConfigurationTests method whenMultipleUrisHaveHttpsSchemeThenClientConfigurationUsesSsl.
@Test
void whenMultipleUrisHaveHttpsSchemeThenClientConfigurationUsesSsl() {
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=https://localhost:9876,https://localhost:8765").run((context) -> {
ClientConfiguration clientConfiguration = context.getBean(ClientConfiguration.class);
List<InetSocketAddress> endpoints = clientConfiguration.getEndpoints();
assertThat(endpoints).hasSize(2);
assertThat(endpoints.get(0).getHostString()).isEqualTo("localhost");
assertThat(endpoints.get(0).getPort()).isEqualTo(9876);
assertThat(endpoints.get(1).getHostString()).isEqualTo("localhost");
assertThat(endpoints.get(1).getPort()).isEqualTo(8765);
assertThat(clientConfiguration.useSsl()).isTrue();
});
}
use of org.springframework.data.elasticsearch.client.ClientConfiguration in project spring-boot by spring-projects.
the class ReactiveElasticsearchRestClientAutoConfigurationTests method whenUriHasUsernameAndPasswordThenDefaultAuthorizationHeaderHasUsernameAndPassword.
@Test
void whenUriHasUsernameAndPasswordThenDefaultAuthorizationHeaderHasUsernameAndPassword() {
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=http://user:secret@localhost:9200").run((context) -> {
ClientConfiguration clientConfiguration = context.getBean(ClientConfiguration.class);
assertThat(clientConfiguration.getDefaultHeaders().get(HttpHeaders.AUTHORIZATION)).containsExactly("Basic " + Base64.getEncoder().encodeToString("user:secret".getBytes(StandardCharsets.UTF_8)));
});
}
use of org.springframework.data.elasticsearch.client.ClientConfiguration in project spring-boot by spring-projects.
the class ReactiveElasticsearchRestClientAutoConfiguration method clientConfiguration.
@Bean
@ConditionalOnMissingBean
public ClientConfiguration clientConfiguration() {
ClientConfiguration.MaybeSecureClientConfigurationBuilder builder = ClientConfiguration.builder().connectedTo(this.properties.getEndpoints().toArray(new String[0]));
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(this.properties.isUseSsl()).whenTrue().toCall(builder::usingSsl);
map.from(this.properties.getCredentials()).to((credentials) -> builder.withBasicAuth(credentials.getUsername(), credentials.getPassword()));
map.from(this.properties.getConnectionTimeout()).to(builder::withConnectTimeout);
map.from(this.properties.getSocketTimeout()).to(builder::withSocketTimeout);
map.from(this.properties.getPathPrefix()).to(builder::withPathPrefix);
configureExchangeStrategies(map, builder);
return builder.build();
}
use of org.springframework.data.elasticsearch.client.ClientConfiguration in project spring-boot by spring-projects.
the class ReactiveElasticsearchRestClientAutoConfigurationTests method whenUriUserInfoMatchesUsernameAndPasswordPropertiesThenDefaultAuthorizationHeaderIsConfigured.
@Test
void whenUriUserInfoMatchesUsernameAndPasswordPropertiesThenDefaultAuthorizationHeaderIsConfigured() {
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=http://user:secret@localhost:9876", "spring.elasticsearch.username=user", "spring.elasticsearch.password=secret").run((context) -> {
ClientConfiguration clientConfiguration = context.getBean(ClientConfiguration.class);
assertThat(clientConfiguration.getDefaultHeaders().get(HttpHeaders.AUTHORIZATION)).containsExactly("Basic " + Base64.getEncoder().encodeToString("user:secret".getBytes(StandardCharsets.UTF_8)));
});
}
use of org.springframework.data.elasticsearch.client.ClientConfiguration in project spring-boot by spring-projects.
the class ReactiveElasticsearchRestClientAutoConfigurationTests method whenUriHasHttpsSchemeThenClientConfigurationUsesSsl.
@Test
void whenUriHasHttpsSchemeThenClientConfigurationUsesSsl() {
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=https://localhost:9876").run((context) -> {
ClientConfiguration clientConfiguration = context.getBean(ClientConfiguration.class);
List<InetSocketAddress> endpoints = clientConfiguration.getEndpoints();
assertThat(endpoints).hasSize(1);
assertThat(endpoints.get(0).getHostString()).isEqualTo("localhost");
assertThat(endpoints.get(0).getPort()).isEqualTo(9876);
assertThat(clientConfiguration.useSsl()).isTrue();
});
}
Aggregations