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
ba87fef3
Unverified
Commit
ba87fef3
authored
Feb 05, 2018
by
Ryan Baxter
Committed by
GitHub
Feb 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set secure health check url. Fixes #2673 (#2710)
parent
a9aca1b8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
7 deletions
+51
-7
EurekaClientAutoConfiguration.java
...k/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
+4
-0
DefaultManagementMetadataProvider.java
...ix/eureka/metadata/DefaultManagementMetadataProvider.java
+12
-7
ManagementMetadata.java
...ork/cloud/netflix/eureka/metadata/ManagementMetadata.java
+10
-0
DefaultManagementMetadataProviderTest.java
...ureka/metadata/DefaultManagementMetadataProviderTest.java
+25
-0
No files found.
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
View file @
ba87fef3
...
...
@@ -142,6 +142,7 @@ public class EurekaClientAutoConfiguration {
instance
.
setNonSecurePort
(
serverPort
);
instance
.
setInstanceId
(
getDefaultInstanceId
(
environmentPropertyResolver
));
instance
.
setPreferIpAddress
(
preferIpAddress
);
instance
.
setSecurePortEnabled
(
isSecurePortEnabled
);
if
(
StringUtils
.
hasText
(
ipAddress
))
{
instance
.
setIpAddress
(
ipAddress
);
}
...
...
@@ -169,6 +170,9 @@ public class EurekaClientAutoConfiguration {
if
(
metadata
!=
null
)
{
instance
.
setStatusPageUrl
(
metadata
.
getStatusPageUrl
());
instance
.
setHealthCheckUrl
(
metadata
.
getHealthCheckUrl
());
if
(
instance
.
isSecurePortEnabled
())
{
instance
.
setSecureHealthCheckUrl
(
metadata
.
getSecureHealthCheckUrl
());
}
Map
<
String
,
String
>
metadataMap
=
instance
.
getMetadataMap
();
if
(
metadataMap
.
get
(
"management.port"
)
==
null
)
{
metadataMap
.
put
(
"management.port"
,
String
.
valueOf
(
metadata
.
getManagementPort
()));
...
...
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/metadata/DefaultManagementMetadataProvider.java
View file @
ba87fef3
...
...
@@ -24,11 +24,16 @@ public class DefaultManagementMetadataProvider implements ManagementMetadataProv
return
null
;
}
String
healthCheckUrl
=
getHealthCheckUrl
(
instance
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
);
managementContextPath
,
managementPort
,
false
);
String
statusPageUrl
=
getStatusPageUrl
(
instance
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
);
return
new
ManagementMetadata
(
healthCheckUrl
,
statusPageUrl
,
managementPort
==
null
?
serverPort
:
managementPort
);
ManagementMetadata
metadata
=
new
ManagementMetadata
(
healthCheckUrl
,
statusPageUrl
,
managementPort
==
null
?
serverPort
:
managementPort
);
if
(
instance
.
isSecurePortEnabled
())
{
metadata
.
setSecureHealthCheckUrl
(
getHealthCheckUrl
(
instance
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
,
true
));
}
return
metadata
;
}
private
boolean
isRandom
(
Integer
port
)
{
...
...
@@ -36,10 +41,10 @@ public class DefaultManagementMetadataProvider implements ManagementMetadataProv
}
private
String
getHealthCheckUrl
(
EurekaInstanceConfigBean
instance
,
int
serverPort
,
String
serverContextPath
,
String
managementContextPath
,
Integer
managementPort
)
{
String
managementContextPath
,
Integer
managementPort
,
boolean
isSecure
)
{
String
healthCheckUrlPath
=
instance
.
getHealthCheckUrlPath
();
String
healthCheckUrl
=
getUrl
(
instance
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
,
healthCheckUrlPath
);
managementPort
,
healthCheckUrlPath
,
isSecure
);
log
.
debug
(
"Constructed eureka meta-data healthcheckUrl: "
+
healthCheckUrl
);
return
healthCheckUrl
;
}
...
...
@@ -48,19 +53,19 @@ public class DefaultManagementMetadataProvider implements ManagementMetadataProv
String
managementContextPath
,
Integer
managementPort
)
{
String
statusPageUrlPath
=
instance
.
getStatusPageUrlPath
();
String
statusPageUrl
=
getUrl
(
instance
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
,
statusPageUrlPath
);
managementPort
,
statusPageUrlPath
,
false
);
log
.
debug
(
"Constructed eureka meta-data statusPageUrl: "
+
statusPageUrl
);
return
statusPageUrl
;
}
private
String
getUrl
(
EurekaInstanceConfigBean
instance
,
int
serverPort
,
String
serverContextPath
,
String
managementContextPath
,
Integer
managementPort
,
String
urlPath
)
{
Integer
managementPort
,
String
urlPath
,
boolean
isSecure
)
{
managementContextPath
=
refineManagementContextPath
(
serverContextPath
,
managementContextPath
,
managementPort
);
if
(
managementPort
==
null
)
{
managementPort
=
serverPort
;
}
String
scheme
=
i
nstance
.
getSecurePortEnabled
()
?
"https"
:
"http"
;
String
scheme
=
i
sSecure
?
"https"
:
"http"
;
return
constructValidUrl
(
scheme
,
instance
.
getHostname
(),
managementPort
,
managementContextPath
,
urlPath
);
}
...
...
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/metadata/ManagementMetadata.java
View file @
ba87fef3
...
...
@@ -7,11 +7,13 @@ public class ManagementMetadata {
private
final
String
healthCheckUrl
;
private
final
String
statusPageUrl
;
private
final
Integer
managementPort
;
private
String
secureHealthCheckUrl
;
public
ManagementMetadata
(
String
healthCheckUrl
,
String
statusPageUrl
,
Integer
managementPort
)
{
this
.
healthCheckUrl
=
healthCheckUrl
;
this
.
statusPageUrl
=
statusPageUrl
;
this
.
managementPort
=
managementPort
;
this
.
secureHealthCheckUrl
=
null
;
}
public
String
getHealthCheckUrl
()
{
...
...
@@ -26,6 +28,14 @@ public class ManagementMetadata {
return
managementPort
;
}
public
String
getSecureHealthCheckUrl
()
{
return
secureHealthCheckUrl
;
}
public
void
setSecureHealthCheckUrl
(
String
secureHealthCheckUrl
)
{
this
.
secureHealthCheckUrl
=
secureHealthCheckUrl
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
...
...
spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/metadata/DefaultManagementMetadataProviderTest.java
View file @
ba87fef3
...
...
@@ -5,6 +5,7 @@ import org.junit.Test;
import
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
...
...
@@ -18,6 +19,7 @@ public class DefaultManagementMetadataProviderTest {
when
(
INSTANCE
.
getHostname
()).
thenReturn
(
"host"
);
when
(
INSTANCE
.
getHealthCheckUrlPath
()).
thenReturn
(
"health"
);
when
(
INSTANCE
.
getStatusPageUrlPath
()).
thenReturn
(
"info"
);
when
(
INSTANCE
.
isSecurePortEnabled
()).
thenReturn
(
false
);
}
@Test
...
...
@@ -51,6 +53,7 @@ public class DefaultManagementMetadataProviderTest {
ManagementMetadata
actual
=
provider
.
get
(
INSTANCE
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
);
assertThat
(
actual
.
getHealthCheckUrl
()).
isEqualTo
(
"http://host:7777/health"
);
assertThat
(
actual
.
getSecureHealthCheckUrl
()).
isNullOrEmpty
();
assertThat
(
actual
.
getStatusPageUrl
()).
isEqualTo
(
"http://host:7777/info"
);
assertThat
(
actual
.
getManagementPort
()).
isEqualTo
(
7777
);
}
...
...
@@ -64,6 +67,7 @@ public class DefaultManagementMetadataProviderTest {
ManagementMetadata
actual
=
provider
.
get
(
INSTANCE
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
);
assertThat
(
actual
.
getHealthCheckUrl
()).
isEqualTo
(
"http://host:8888/health"
);
assertThat
(
actual
.
getSecureHealthCheckUrl
()).
isNullOrEmpty
();
assertThat
(
actual
.
getStatusPageUrl
()).
isEqualTo
(
"http://host:8888/info"
);
assertThat
(
actual
.
getManagementPort
()).
isEqualTo
(
8888
);
}
...
...
@@ -77,6 +81,7 @@ public class DefaultManagementMetadataProviderTest {
ManagementMetadata
actual
=
provider
.
get
(
INSTANCE
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
);
assertThat
(
actual
.
getHealthCheckUrl
()).
isEqualTo
(
"http://host:8888/health"
);
assertThat
(
actual
.
getSecureHealthCheckUrl
()).
isNullOrEmpty
();
assertThat
(
actual
.
getStatusPageUrl
()).
isEqualTo
(
"http://host:8888/info"
);
assertThat
(
actual
.
getManagementPort
()).
isEqualTo
(
8888
);
}
...
...
@@ -90,6 +95,7 @@ public class DefaultManagementMetadataProviderTest {
ManagementMetadata
actual
=
provider
.
get
(
INSTANCE
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
);
assertThat
(
actual
.
getHealthCheckUrl
()).
isEqualTo
(
"http://host:8888/Management/health"
);
assertThat
(
actual
.
getSecureHealthCheckUrl
()).
isNullOrEmpty
();
assertThat
(
actual
.
getStatusPageUrl
()).
isEqualTo
(
"http://host:8888/Management/info"
);
assertThat
(
actual
.
getManagementPort
()).
isEqualTo
(
8888
);
}
...
...
@@ -103,6 +109,7 @@ public class DefaultManagementMetadataProviderTest {
ManagementMetadata
actual
=
provider
.
get
(
INSTANCE
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
);
assertThat
(
actual
.
getHealthCheckUrl
()).
isEqualTo
(
"http://host:7777/Management/health"
);
assertThat
(
actual
.
getSecureHealthCheckUrl
()).
isNullOrEmpty
();
assertThat
(
actual
.
getStatusPageUrl
()).
isEqualTo
(
"http://host:7777/Management/info"
);
assertThat
(
actual
.
getManagementPort
()).
isEqualTo
(
7777
);
}
...
...
@@ -116,6 +123,7 @@ public class DefaultManagementMetadataProviderTest {
ManagementMetadata
actual
=
provider
.
get
(
INSTANCE
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
);
assertThat
(
actual
.
getHealthCheckUrl
()).
isEqualTo
(
"http://host:7777/Server/health"
);
assertThat
(
actual
.
getSecureHealthCheckUrl
()).
isNullOrEmpty
();
assertThat
(
actual
.
getStatusPageUrl
()).
isEqualTo
(
"http://host:7777/Server/info"
);
assertThat
(
actual
.
getManagementPort
()).
isEqualTo
(
7777
);
}
...
...
@@ -129,6 +137,23 @@ public class DefaultManagementMetadataProviderTest {
ManagementMetadata
actual
=
provider
.
get
(
INSTANCE
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
);
assertThat
(
actual
.
getHealthCheckUrl
()).
isEqualTo
(
"http://host:8888/Management/health"
);
assertThat
(
actual
.
getSecureHealthCheckUrl
()).
isNullOrEmpty
();
assertThat
(
actual
.
getStatusPageUrl
()).
isEqualTo
(
"http://host:8888/Management/info"
);
assertThat
(
actual
.
getManagementPort
()).
isEqualTo
(
8888
);
}
@Test
public
void
setSecureHealthCheckUrl
()
throws
Exception
{
int
serverPort
=
7777
;
String
serverContextPath
=
"/"
;
String
managementContextPath
=
"/Management"
;
Integer
managementPort
=
8888
;
doReturn
(
true
).
when
(
INSTANCE
).
isSecurePortEnabled
();
ManagementMetadata
actual
=
provider
.
get
(
INSTANCE
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
);
assertThat
(
actual
.
getHealthCheckUrl
()).
isEqualTo
(
"http://host:8888/Management/health"
);
assertThat
(
actual
.
getSecureHealthCheckUrl
()).
isEqualTo
(
"https://host:8888/Management/health"
);
assertThat
(
actual
.
getStatusPageUrl
()).
isEqualTo
(
"http://host:8888/Management/info"
);
assertThat
(
actual
.
getManagementPort
()).
isEqualTo
(
8888
);
...
...
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