Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
d77c4c83
Commit
d77c4c83
authored
May 09, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
a41c9eb7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
23 deletions
+17
-23
RestClientAutoConfiguration.java
...igure/elasticsearch/rest/RestClientAutoConfiguration.java
+7
-8
RestClientAutoConfigurationTests.java
.../elasticsearch/rest/RestClientAutoConfigurationTests.java
+10
-15
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfiguration.java
View file @
d77c4c83
...
...
@@ -39,8 +39,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
/**
* {@link EnableAutoConfiguration Auto-Configuration}
* for Elasticseach REST clients.
* {@link EnableAutoConfiguration Auto-Configuration} for Elasticseach REST clients.
*
* @author Brian Clozel
* @since 2.1.0
...
...
@@ -50,7 +49,6 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties
(
RestClientProperties
.
class
)
public
class
RestClientAutoConfiguration
{
private
final
RestClientProperties
properties
;
private
final
List
<
RestClientBuilderCustomizer
>
builderCustomizers
;
...
...
@@ -58,7 +56,8 @@ public class RestClientAutoConfiguration {
public
RestClientAutoConfiguration
(
RestClientProperties
properties
,
ObjectProvider
<
List
<
RestClientBuilderCustomizer
>>
builderCustomizers
)
{
this
.
properties
=
properties
;
this
.
builderCustomizers
=
builderCustomizers
.
getIfAvailable
(
Collections:
:
emptyList
);
this
.
builderCustomizers
=
builderCustomizers
.
getIfAvailable
(
Collections:
:
emptyList
);
}
@Bean
(
destroyMethod
=
"close"
)
...
...
@@ -69,8 +68,8 @@ public class RestClientAutoConfiguration {
}
protected
RestClientBuilder
configureBuilder
()
{
HttpHost
[]
hosts
=
this
.
properties
.
getUris
().
stream
()
.
map
(
HttpHost:
:
create
).
toArray
(
HttpHost
[]::
new
);
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
)
->
{
...
...
@@ -78,8 +77,8 @@ public class RestClientAutoConfiguration {
Credentials
credentials
=
new
UsernamePasswordCredentials
(
this
.
properties
.
getUsername
(),
this
.
properties
.
getPassword
());
credentialsProvider
.
setCredentials
(
AuthScope
.
ANY
,
credentials
);
builder
.
setHttpClientConfigCallback
(
httpClientBuilder
->
httpClientBuilder
.
setDefaultCredentialsProvider
(
credentialsProvider
));
builder
.
setHttpClientConfigCallback
(
(
httpClientBuilder
)
->
httpClientBuilder
.
setDefaultCredentialsProvider
(
credentialsProvider
));
});
this
.
builderCustomizers
.
forEach
((
customizer
)
->
customizer
.
customize
(
builder
));
return
builder
;
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java
View file @
d77c4c83
...
...
@@ -16,7 +16,6 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
elasticsearch
.
rest
;
import
java.lang.reflect.Field
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -49,26 +48,21 @@ public class RestClientAutoConfigurationTests {
@Test
public
void
configureShouldCreateBothRestClientVariants
()
{
this
.
contextRunner
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
RestClient
.
class
)
.
hasSingleBean
(
RestHighLevelClient
.
class
);
});
this
.
contextRunner
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
RestClient
.
class
)
.
hasSingleBean
(
RestHighLevelClient
.
class
));
}
@Test
public
void
configureWhenCustomClientShouldBackOff
()
{
this
.
contextRunner
.
withUserConfiguration
(
CustomRestClientConfiguration
.
class
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
RestClient
.
class
)
.
hasBean
(
"customRestClient"
);
});
this
.
contextRunner
.
withUserConfiguration
(
CustomRestClientConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
RestClient
.
class
)
.
hasBean
(
"customRestClient"
));
}
@Test
public
void
configureWhenBuilderCustomizerShouldApply
()
{
this
.
contextRunner
.
withUserConfiguration
(
BuilderCustomizerConfiguration
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
BuilderCustomizerConfiguration
.
class
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
RestClient
.
class
);
RestClient
restClient
=
context
.
getBean
(
RestClient
.
class
);
...
...
@@ -86,7 +80,8 @@ public class RestClientAutoConfigurationTests {
.
withPropertyValues
(
"spring.elasticsearch.rest.uris=http://localhost:"
+
node
.
getHttpPort
())
.
run
((
context
)
->
{
RestHighLevelClient
client
=
context
.
getBean
(
RestHighLevelClient
.
class
);
RestHighLevelClient
client
=
context
.
getBean
(
RestHighLevelClient
.
class
);
Map
<
String
,
String
>
source
=
new
HashMap
<>();
source
.
put
(
"a"
,
"alpha"
);
source
.
put
(
"b"
,
"bravo"
);
...
...
@@ -112,7 +107,7 @@ public class RestClientAutoConfigurationTests {
@Bean
public
RestClientBuilderCustomizer
myCustomizer
()
{
return
builder
->
builder
.
setMaxRetryTimeoutMillis
(
42
);
return
(
builder
)
->
builder
.
setMaxRetryTimeoutMillis
(
42
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment