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
05dad451
Commit
05dad451
authored
Jul 06, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add proxy configuration for Jest client
Closes gh-6332
parent
5c44c772
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
0 deletions
+64
-0
JestAutoConfiguration.java
...toconfigure/elasticsearch/jest/JestAutoConfiguration.java
+8
-0
JestProperties.java
...boot/autoconfigure/elasticsearch/jest/JestProperties.java
+39
-0
JestAutoConfigurationTests.java
...figure/elasticsearch/jest/JestAutoConfigurationTests.java
+15
-0
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+2
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfiguration.java
View file @
05dad451
...
@@ -20,6 +20,7 @@ import com.google.gson.Gson;
...
@@ -20,6 +20,7 @@ import com.google.gson.Gson;
import
io.searchbox.client.JestClient
;
import
io.searchbox.client.JestClient
;
import
io.searchbox.client.JestClientFactory
;
import
io.searchbox.client.JestClientFactory
;
import
io.searchbox.client.config.HttpClientConfig
;
import
io.searchbox.client.config.HttpClientConfig
;
import
org.apache.http.HttpHost
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
...
@@ -30,6 +31,7 @@ import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
...
@@ -30,6 +31,7 @@ import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
/**
/**
...
@@ -69,6 +71,12 @@ public class JestAutoConfiguration {
...
@@ -69,6 +71,12 @@ public class JestAutoConfiguration {
builder
.
defaultCredentials
(
this
.
properties
.
getUsername
(),
builder
.
defaultCredentials
(
this
.
properties
.
getUsername
(),
this
.
properties
.
getPassword
());
this
.
properties
.
getPassword
());
}
}
String
proxyHost
=
this
.
properties
.
getProxy
().
getHost
();
if
(
StringUtils
.
hasText
(
proxyHost
))
{
Integer
proxyPort
=
this
.
properties
.
getProxy
().
getPort
();
Assert
.
notNull
(
proxyPort
,
"Proxy port must not be null"
);
builder
.
proxy
(
new
HttpHost
(
proxyHost
,
proxyPort
));
}
Gson
gson
=
this
.
gsonProvider
.
getIfUnique
();
Gson
gson
=
this
.
gsonProvider
.
getIfUnique
();
if
(
gson
!=
null
)
{
if
(
gson
!=
null
)
{
builder
.
gson
(
gson
);
builder
.
gson
(
gson
);
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestProperties.java
View file @
05dad451
...
@@ -55,6 +55,11 @@ public class JestProperties {
...
@@ -55,6 +55,11 @@ public class JestProperties {
*/
*/
private
int
readTimeout
=
3000
;
private
int
readTimeout
=
3000
;
/**
* Proxy settings.
*/
private
final
Proxy
proxy
=
new
Proxy
();
public
List
<
String
>
getUris
()
{
public
List
<
String
>
getUris
()
{
return
this
.
uris
;
return
this
.
uris
;
}
}
...
@@ -95,4 +100,38 @@ public class JestProperties {
...
@@ -95,4 +100,38 @@ public class JestProperties {
this
.
readTimeout
=
readTimeout
;
this
.
readTimeout
=
readTimeout
;
}
}
public
Proxy
getProxy
()
{
return
this
.
proxy
;
}
public
static
class
Proxy
{
/**
* Proxy host the HTTP client should use.
*/
private
String
host
;
/**
* Proxy port the HTTP client should use.
*/
private
Integer
port
;
public
String
getHost
()
{
return
this
.
host
;
}
public
void
setHost
(
String
host
)
{
this
.
host
=
host
;
}
public
Integer
getPort
()
{
return
this
.
port
;
}
public
void
setPort
(
Integer
port
)
{
this
.
port
=
port
;
}
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfigurationTests.java
View file @
05dad451
...
@@ -20,8 +20,11 @@ import com.google.gson.Gson;
...
@@ -20,8 +20,11 @@ import com.google.gson.Gson;
import
io.searchbox.client.JestClient
;
import
io.searchbox.client.JestClient
;
import
io.searchbox.client.http.JestHttpClient
;
import
io.searchbox.client.http.JestHttpClient
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration
;
import
org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
...
@@ -38,6 +41,9 @@ import static org.mockito.Mockito.mock;
...
@@ -38,6 +41,9 @@ import static org.mockito.Mockito.mock;
*/
*/
public
class
JestAutoConfigurationTests
{
public
class
JestAutoConfigurationTests
{
@Rule
public
ExpectedException
thrown
=
ExpectedException
.
none
();
protected
AnnotationConfigApplicationContext
context
;
protected
AnnotationConfigApplicationContext
context
;
@After
@After
...
@@ -66,6 +72,15 @@ public class JestAutoConfigurationTests {
...
@@ -66,6 +72,15 @@ public class JestAutoConfigurationTests {
assertThat
(
client
.
getGson
()).
isSameAs
(
this
.
context
.
getBean
(
"customGson"
));
assertThat
(
client
.
getGson
()).
isSameAs
(
this
.
context
.
getBean
(
"customGson"
));
}
}
@Test
public
void
proxyHostWithoutPort
()
{
this
.
thrown
.
expect
(
BeanCreationException
.
class
);
this
.
thrown
.
expectMessage
(
"Proxy port must not be null"
);
load
(
"spring.elasticsearch.jest.uris=http://localhost:9200"
,
"spring.elasticsearch.jest.proxy.host=proxy.example.com"
);
}
private
void
load
(
String
...
environment
)
{
private
void
load
(
String
...
environment
)
{
load
(
null
,
environment
);
load
(
null
,
environment
);
}
}
...
...
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
05dad451
...
@@ -634,6 +634,8 @@ content into your application; rather pick only the properties that you need.
...
@@ -634,6 +634,8 @@ content into your application; rather pick only the properties that you need.
# JEST (Elasticsearch HTTP client) ({sc-spring-boot-autoconfigure}/jest/JestProperties.{sc-ext}[JestProperties])
# JEST (Elasticsearch HTTP client) ({sc-spring-boot-autoconfigure}/jest/JestProperties.{sc-ext}[JestProperties])
spring.elasticsearch.jest.connection-timeout=3000 # Connection timeout in milliseconds.
spring.elasticsearch.jest.connection-timeout=3000 # Connection timeout in milliseconds.
spring.elasticsearch.jest.password= # Login password.
spring.elasticsearch.jest.password= # Login password.
spring.elasticsearch.jest.proxy.host= # Proxy host the HTTP client should use.
spring.elasticsearch.jest.proxy.port= # Proxy port the HTTP client should use.
spring.elasticsearch.jest.read-timeout=3000 # Read timeout in milliseconds.
spring.elasticsearch.jest.read-timeout=3000 # Read timeout in milliseconds.
spring.elasticsearch.jest.uris=http://localhost:9200 # Comma-separated list of the Elasticsearch instances to use.
spring.elasticsearch.jest.uris=http://localhost:9200 # Comma-separated list of the Elasticsearch instances to use.
spring.elasticsearch.jest.username= # Login user.
spring.elasticsearch.jest.username= # Login user.
...
...
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