Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
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-boot-admin
Commits
880f10f0
Commit
880f10f0
authored
Oct 11, 2016
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3.x'
parents
c1ff8c4b
91e79dea
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
165 additions
and
94 deletions
+165
-94
AdminClientProperties.java
.../codecentric/boot/admin/config/AdminClientProperties.java
+52
-60
AdminClientPropertiesTest.java
...ecentric/boot/admin/config/AdminClientPropertiesTest.java
+109
-34
SpringBootAdminClientAutoConfigurationTest.java
...in/config/SpringBootAdminClientAutoConfigurationTest.java
+4
-0
No files found.
spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/config/AdminClientProperties.java
View file @
880f10f0
...
...
@@ -15,18 +15,21 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
config
;
import
static
org
.
springframework
.
util
.
StringUtils
.
trimLeadingCharacter
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.actuate.autoconfigure.ManagementServerProperties
;
import
org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint
;
import
org.springframework.boot.autoconfigure.web.ServerProperties
;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.util.UriComponentsBuilder
;
@ConfigurationProperties
(
prefix
=
"spring.boot.admin.client"
)
public
class
AdminClientProperties
{
...
...
@@ -54,15 +57,15 @@ public class AdminClientProperties {
@Value
(
"${spring.application.name:spring-boot-application}"
)
private
String
name
;
@Value
(
"${endpoints.health.id:health}"
)
private
String
healthEndpointId
;
/**
* Should the registered urls be built with server.address or with hostname.
*/
private
boolean
preferIp
=
false
;
@Autowired
private
HealthMvcEndpoint
healthEndpoint
;
@Autowired
private
ManagementServerProperties
management
;
@Autowired
...
...
@@ -82,71 +85,50 @@ public class AdminClientProperties {
}
}
public
String
getManagementUrl
()
{
if
(
managementUrl
!=
null
)
{
return
managementUrl
;
}
if
((
managementPort
==
null
||
managementPort
.
equals
(
serverPort
))
&&
getServiceUrl
()
!=
null
)
{
return
append
(
append
(
getServiceUrl
(),
server
.
getServletPrefix
()),
management
.
getContextPath
());
public
String
getServiceUrl
()
{
if
(
serviceUrl
!=
null
)
{
return
serviceUrl
;
}
if
(
management
Port
==
null
)
{
if
(
server
Port
==
null
)
{
throw
new
IllegalStateException
(
"serviceUrl must be set when deployed to servlet-container"
);
}
if
(
preferIp
)
{
InetAddress
address
=
management
.
getAddress
();
if
(
address
==
null
)
{
address
=
getHostAddress
();
}
return
append
(
append
(
createLocalUri
(
address
.
getHostAddress
(),
managementPort
),
server
.
getContextPath
()),
management
.
getContextPath
());
return
UriComponentsBuilder
.
newInstance
().
scheme
(
getScheme
()).
host
(
getServiceHost
())
.
port
(
serverPort
).
path
(
server
.
getContextPath
()).
toUriString
();
}
public
String
getManagementUrl
()
{
if
(
managementUrl
!=
null
)
{
return
managementUrl
;
}
return
append
(
createLocalUri
(
getHostAddress
().
getCanonicalHostName
(),
managementPort
),
management
.
getContextPath
());
}
public
void
setManagementUrl
(
String
managementUrl
)
{
this
.
managementUrl
=
managementUrl
;
if
(
managementPort
==
null
||
managementPort
.
equals
(
serverPort
))
{
return
UriComponentsBuilder
.
fromHttpUrl
(
getServiceUrl
())
.
pathSegment
(
server
.
getServletPrefix
())
.
pathSegment
(
trimLeadingCharacter
(
management
.
getContextPath
(),
'/'
))
.
toUriString
();
}
return
UriComponentsBuilder
.
newInstance
().
scheme
(
getScheme
()).
host
(
getManagementHost
())
.
port
(
managementPort
).
path
(
management
.
getContextPath
()).
toUriString
();
}
public
String
getHealthUrl
()
{
if
(
healthUrl
!=
null
)
{
return
healthUrl
;
}
return
append
(
getManagementUrl
(),
healthEndpointId
);
return
UriComponentsBuilder
.
fromHttpUrl
(
getManagementUrl
())
.
pathSegment
(
trimLeadingCharacter
(
healthEndpoint
.
getPath
(),
'/'
)).
toUriString
();
}
public
void
set
HealthUrl
(
String
health
Url
)
{
this
.
healthUrl
=
health
Url
;
public
void
set
ManagementUrl
(
String
management
Url
)
{
this
.
managementUrl
=
management
Url
;
}
public
String
getServiceUrl
()
{
if
(
serviceUrl
!=
null
)
{
return
serviceUrl
;
}
if
(
serverPort
==
null
)
{
throw
new
IllegalStateException
(
"serviceUrl must be set when deployed to servlet-container"
);
}
if
(
preferIp
)
{
InetAddress
address
=
server
.
getAddress
();
if
(
address
==
null
)
{
address
=
getHostAddress
();
}
return
append
(
createLocalUri
(
address
.
getHostAddress
(),
serverPort
),
server
.
getContextPath
());
}
return
append
(
createLocalUri
(
getHostAddress
().
getCanonicalHostName
(),
serverPort
),
server
.
getContextPath
());
public
void
setHealthUrl
(
String
healthUrl
)
{
this
.
healthUrl
=
healthUrl
;
}
public
void
setServiceUrl
(
String
serviceUrl
)
{
...
...
@@ -169,26 +151,36 @@ public class AdminClientProperties {
return
preferIp
;
}
private
String
createLocalUri
(
String
host
,
int
port
)
{
String
scheme
=
server
.
getSsl
()
!=
null
&&
server
.
getSsl
().
isEnabled
()
?
"https"
:
"http"
;
return
scheme
+
"://"
+
host
+
":"
+
port
;
private
String
getScheme
()
{
return
server
.
getSsl
()
!=
null
&&
server
.
getSsl
().
isEnabled
()
?
"https"
:
"http"
;
}
private
String
append
(
String
uri
,
String
path
)
{
String
baseUri
=
uri
.
replaceFirst
(
"/+$"
,
""
);
if
(
StringUtils
.
isEmpty
(
path
))
{
return
baseUri
;
private
String
getHost
(
InetAddress
address
)
{
return
preferIp
?
address
.
getHostAddress
()
:
address
.
getCanonicalHostName
();
}
private
String
getServiceHost
()
{
InetAddress
address
=
server
.
getAddress
();
if
(
address
==
null
)
{
address
=
getLocalHost
();
}
return
getHost
(
address
);
}
String
normPath
=
path
.
replaceFirst
(
"^/+"
,
""
).
replaceFirst
(
"/+$"
,
""
);
return
baseUri
+
"/"
+
normPath
;
private
String
getManagementHost
()
{
InetAddress
address
=
management
.
getAddress
();
if
(
address
!=
null
)
{
return
getHost
(
address
);
}
return
getServiceHost
();
}
private
InetAddress
get
HostAddress
()
{
private
InetAddress
get
LocalHost
()
{
try
{
return
InetAddress
.
getLocalHost
();
}
catch
(
UnknownHostException
ex
)
{
throw
new
IllegalArgumentException
(
ex
.
getMessage
(),
ex
);
}
}
}
spring-boot-admin-starter-client/src/test/java/de/codecentric/boot/admin/config/AdminClientPropertiesTest.java
View file @
880f10f0
This diff is collapsed.
Click to expand it.
spring-boot-admin-starter-client/src/test/java/de/codecentric/boot/admin/config/SpringBootAdminClientAutoConfigurationTest.java
View file @
880f10f0
...
...
@@ -4,6 +4,8 @@ import static org.junit.Assert.assertTrue;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.EndpointWebMvcManagementContextConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.RestTemplateConfiguration
;
...
...
@@ -47,6 +49,8 @@ public class SpringBootAdminClientAutoConfigurationTest {
applicationContext
.
register
(
ServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
RestTemplateConfiguration
.
class
);
applicationContext
.
register
(
ManagementServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
EndpointAutoConfiguration
.
class
);
applicationContext
.
register
(
EndpointWebMvcManagementContextConfiguration
.
class
);
applicationContext
.
register
(
SpringBootAdminClientAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
applicationContext
,
environment
);
applicationContext
.
refresh
();
...
...
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