Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
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
openSource
spring-cloud-netflix
Commits
9bd3a66b
Commit
9bd3a66b
authored
Apr 19, 2016
by
Andrei Sfat
Committed by
Dave Syer
Apr 26, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#920 add slash when eureka.client.service-url.defaultZone does not contain one
parent
314d229c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
13 deletions
+50
-13
EurekaClientConfigBean.java
...ramework/cloud/netflix/eureka/EurekaClientConfigBean.java
+15
-2
EurekaClientConfigBeanTests.java
...ork/cloud/netflix/eureka/EurekaClientConfigBeanTests.java
+35
-11
No files found.
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientConfigBean.java
View file @
9bd3a66b
...
...
@@ -25,6 +25,7 @@ import java.util.Map;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.core.env.PropertyResolver
;
import
org.springframework.util.StringUtils
;
import
com.netflix.appinfo.EurekaAccept
;
import
com.netflix.discovery.EurekaClientConfig
;
...
...
@@ -430,13 +431,25 @@ public class EurekaClientConfigBean implements EurekaClientConfig, EurekaConstan
if
(
serviceUrls
==
null
||
serviceUrls
.
isEmpty
())
{
serviceUrls
=
this
.
serviceUrl
.
get
(
DEFAULT_ZONE
);
}
if
(
serviceUrls
!=
null
)
{
return
Arrays
.
asList
(
serviceUrls
.
split
(
","
));
if
(!
StringUtils
.
isEmpty
(
serviceUrls
))
{
final
String
[]
serviceUrlsSplit
=
serviceUrls
.
split
(
","
);
List
<
String
>
eurekaServiceUrls
=
new
ArrayList
<>(
serviceUrlsSplit
.
length
);
for
(
String
eurekaServiceUrl
:
serviceUrlsSplit
)
{
if
(!
endsWithSlash
(
eurekaServiceUrl
))
{
eurekaServiceUrl
+=
"/"
;
}
eurekaServiceUrls
.
add
(
eurekaServiceUrl
);
}
return
eurekaServiceUrls
;
}
return
new
ArrayList
<>();
}
private
boolean
endsWithSlash
(
String
url
)
{
return
url
.
endsWith
(
"/"
);
}
@Override
public
boolean
shouldFilterOnlyUpInstances
()
{
return
this
.
filterOnlyUpInstances
;
...
...
spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientConfigBeanTests.java
View file @
9bd3a66b
...
...
@@ -65,9 +65,7 @@ public class EurekaClientConfigBeanTests {
assertEquals
(
"{defaultZone=http://example.com}"
,
this
.
context
.
getBean
(
EurekaClientConfigBean
.
class
).
getServiceUrl
()
.
toString
());
assertEquals
(
"[http://example.com]"
,
this
.
context
.
getBean
(
EurekaClientConfigBean
.
class
)
.
getEurekaServerServiceUrls
(
"defaultZone"
).
toString
());
assertEquals
(
"[http://example.com/]"
,
getEurekaServiceUrlsForDefaultZone
());
}
@Test
...
...
@@ -76,16 +74,15 @@ public class EurekaClientConfigBeanTests {
this
.
context
.
getEnvironment
().
getPropertySources
().
addFirst
(
source
);
source
.
addPropertySource
(
new
MapPropertySource
(
"config"
,
Collections
.<
String
,
Object
>
singletonMap
(
"eureka.client.serviceUrl.defaultZone"
,
"http://example.com"
)));
"http://example.com
,http://example2.com
"
)));
this
.
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
TestConfiguration
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"{defaultZone=http://example.com}"
,
assertEquals
(
"{defaultZone=http://example.com
,http://example2.com
}"
,
this
.
context
.
getBean
(
EurekaClientConfigBean
.
class
).
getServiceUrl
()
.
toString
());
assertEquals
(
"[http://example.com]"
,
this
.
context
.
getBean
(
EurekaClientConfigBean
.
class
)
.
getEurekaServerServiceUrls
(
"defaultZone"
).
toString
());
assertEquals
(
"[http://example.com/, http://example2.com/]"
,
getEurekaServiceUrlsForDefaultZone
());
}
@Test
...
...
@@ -95,9 +92,36 @@ public class EurekaClientConfigBeanTests {
this
.
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
TestConfiguration
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"[http://example.com]"
,
this
.
context
.
getBean
(
EurekaClientConfigBean
.
class
)
.
getEurekaServerServiceUrls
(
"defaultZone"
).
toString
());
assertEquals
(
"[http://example.com/]"
,
getEurekaServiceUrlsForDefaultZone
());
}
@Test
public
void
serviceUrlWithCustomZone
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"eureka.client.serviceUrl.customZone:http://custom-example.com"
);
this
.
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
TestConfiguration
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"[http://custom-example.com/]"
,
getEurekaServiceUrls
(
"customZone"
));
}
@Test
public
void
serviceUrlWithEmptyServiceUrls
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"eureka.client.serviceUrl.defaultZone:"
);
this
.
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
TestConfiguration
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"[]"
,
getEurekaServiceUrlsForDefaultZone
());
}
private
String
getEurekaServiceUrlsForDefaultZone
()
{
return
getEurekaServiceUrls
(
"defaultZone"
);
}
private
String
getEurekaServiceUrls
(
String
myZone
)
{
return
this
.
context
.
getBean
(
EurekaClientConfigBean
.
class
)
.
getEurekaServerServiceUrls
(
myZone
).
toString
();
}
@Configuration
...
...
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