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
4a61e456
Commit
4a61e456
authored
Jul 30, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Require separate management port to use management context path of /
Closes gh-9898
parent
fb3d79c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
9 deletions
+48
-9
EndpointWebMvcAutoConfiguration.java
...ctuate/autoconfigure/EndpointWebMvcAutoConfiguration.java
+6
-0
EndpointWebMvcAutoConfigurationTests.java
...e/autoconfigure/EndpointWebMvcAutoConfigurationTests.java
+42
-9
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java
View file @
4a61e456
...
...
@@ -143,6 +143,12 @@ public class EndpointWebMvcAutoConfiguration
}
}
if
(
managementPort
==
ManagementServerPort
.
SAME
)
{
String
contextPath
=
environment
.
getProperty
(
"management.context-path"
);
if
(
""
.
equals
(
contextPath
)
||
"/"
.
equals
(
contextPath
))
{
throw
new
IllegalStateException
(
"A management context path of '"
+
contextPath
+
"' requires the management server to be "
+
"listening on a separate port"
);
}
if
(
environment
.
getProperty
(
"management.ssl.enabled"
,
Boolean
.
class
,
false
))
{
throw
new
IllegalStateException
(
"Management-specific SSL cannot be configured as the management "
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java
View file @
4a61e456
...
...
@@ -121,8 +121,7 @@ public class EndpointWebMvcAutoConfigurationTests {
Ports
values
=
new
Ports
();
ports
.
set
(
values
);
TestPropertyValues
.
of
(
"management.context-path="
,
"management.security.enabled=false"
,
"server.servlet.context-path="
,
.
of
(
"management.security.enabled=false"
,
"server.servlet.context-path="
,
"server.port="
+
ports
.
get
().
server
)
.
applyTo
(
this
.
applicationContext
);
}
...
...
@@ -140,9 +139,9 @@ public class EndpointWebMvcAutoConfigurationTests {
BaseConfiguration
.
class
,
EndpointWebMvcAutoConfiguration
.
class
);
this
.
applicationContext
.
refresh
();
assertContent
(
"/controller"
,
ports
.
get
().
server
,
"controlleroutput"
);
assertContent
(
"/endpoint"
,
ports
.
get
().
server
,
"endpointoutput"
);
assertThat
(
hasHeader
(
"/
endpoint"
,
ports
.
get
().
server
,
"X-Application-Context"
))
.
isFalse
();
assertContent
(
"/
application/
endpoint"
,
ports
.
get
().
server
,
"endpointoutput"
);
assertThat
(
hasHeader
(
"/
application/endpoint"
,
ports
.
get
().
server
,
"X-Application-Context"
))
.
isFalse
();
assertThat
(
this
.
applicationContext
.
containsBean
(
"applicationContextIdFilter"
))
.
isFalse
();
}
...
...
@@ -171,6 +170,26 @@ public class EndpointWebMvcAutoConfigurationTests {
assertContent
(
"/controller"
,
ports
.
get
().
server
,
"controlleroutput"
);
assertContent
(
"/endpoint"
,
ports
.
get
().
server
,
null
);
assertContent
(
"/controller"
,
ports
.
get
().
management
,
null
);
assertContent
(
"/application/endpoint"
,
ports
.
get
().
management
,
"endpointoutput"
);
assertContent
(
"/error"
,
ports
.
get
().
management
,
startsWith
(
"{"
));
ApplicationContext
managementContext
=
this
.
applicationContext
.
getBean
(
ManagementContextResolver
.
class
).
getApplicationContext
();
List
<?>
interceptors
=
(
List
<?>)
ReflectionTestUtils
.
getField
(
managementContext
.
getBean
(
EndpointHandlerMapping
.
class
),
"interceptors"
);
assertThat
(
interceptors
).
hasSize
(
2
);
}
@Test
public
void
onDifferentPortAndRootContext
()
throws
Exception
{
TestPropertyValues
.
of
(
"management.port="
+
ports
.
get
().
management
,
"management.context-path=/"
).
applyTo
(
this
.
applicationContext
);
this
.
applicationContext
.
register
(
RootConfig
.
class
,
EndpointConfig
.
class
,
DifferentPortConfig
.
class
,
BaseConfiguration
.
class
,
EndpointWebMvcAutoConfiguration
.
class
,
ErrorMvcAutoConfiguration
.
class
);
this
.
applicationContext
.
refresh
();
assertContent
(
"/controller"
,
ports
.
get
().
server
,
"controlleroutput"
);
assertContent
(
"/endpoint"
,
ports
.
get
().
server
,
null
);
assertContent
(
"/controller"
,
ports
.
get
().
management
,
null
);
assertContent
(
"/endpoint"
,
ports
.
get
().
management
,
"endpointoutput"
);
assertContent
(
"/error"
,
ports
.
get
().
management
,
startsWith
(
"{"
));
ApplicationContext
managementContext
=
this
.
applicationContext
...
...
@@ -191,7 +210,7 @@ public class EndpointWebMvcAutoConfigurationTests {
assertContent
(
"/controller"
,
ports
.
get
().
server
,
"controlleroutput"
);
assertContent
(
"/endpoint"
,
ports
.
get
().
server
,
null
);
assertContent
(
"/controller"
,
ports
.
get
().
management
,
null
);
assertContent
(
"/endpoint"
,
ports
.
get
().
management
,
"endpointoutput"
);
assertContent
(
"/
application/
endpoint"
,
ports
.
get
().
management
,
"endpointoutput"
);
assertContent
(
"/error"
,
ports
.
get
().
management
,
startsWith
(
"{"
));
ApplicationContext
managementContext
=
this
.
applicationContext
.
getBean
(
ManagementContextResolver
.
class
).
getApplicationContext
();
...
...
@@ -310,7 +329,7 @@ public class EndpointWebMvcAutoConfigurationTests {
assertContent
(
"/controller"
,
ports
.
get
().
server
,
"controlleroutput"
);
assertContent
(
"/endpoint"
,
ports
.
get
().
server
,
null
);
assertContent
(
"/controller"
,
ports
.
get
().
management
,
null
);
assertContent
(
"/endpoint"
,
ports
.
get
().
management
,
"endpointoutput"
);
assertContent
(
"/
application/
endpoint"
,
ports
.
get
().
management
,
"endpointoutput"
);
}
@Test
...
...
@@ -508,7 +527,8 @@ public class EndpointWebMvcAutoConfigurationTests {
assertContent
(
"/controller"
,
ports
.
get
().
server
,
"controlleroutput"
);
assertContent
(
"/endpoint"
,
ports
.
get
().
server
,
null
);
assertHttpsContent
(
"/controller"
,
ports
.
get
().
management
,
null
);
assertHttpsContent
(
"/endpoint"
,
ports
.
get
().
management
,
"endpointoutput"
);
assertHttpsContent
(
"/application/endpoint"
,
ports
.
get
().
management
,
"endpointoutput"
);
assertHttpsContent
(
"/error"
,
ports
.
get
().
management
,
startsWith
(
"{"
));
ApplicationContext
managementContext
=
this
.
applicationContext
.
getBean
(
ManagementContextResolver
.
class
).
getApplicationContext
();
...
...
@@ -537,6 +557,19 @@ public class EndpointWebMvcAutoConfigurationTests {
this
.
applicationContext
.
refresh
();
}
@Test
public
void
rootManagementContextPathUsingSamePortFails
()
throws
Exception
{
TestPropertyValues
.
of
(
"management.context-path=/"
)
.
applyTo
(
this
.
applicationContext
);
this
.
applicationContext
.
register
(
RootConfig
.
class
,
EndpointConfig
.
class
,
BaseConfiguration
.
class
,
EndpointWebMvcAutoConfiguration
.
class
,
ErrorMvcAutoConfiguration
.
class
);
this
.
thrown
.
expect
(
IllegalStateException
.
class
);
this
.
thrown
.
expectMessage
(
"A management context path of '/' requires the"
+
" management server to be listening on a separate port"
);
this
.
applicationContext
.
refresh
();
}
@Test
public
void
samePortCanBeUsedWhenManagementSslIsExplicitlyDisabled
()
throws
Exception
{
...
...
@@ -562,7 +595,7 @@ public class EndpointWebMvcAutoConfigurationTests {
assertHttpsContent
(
"/controller"
,
ports
.
get
().
server
,
"controlleroutput"
);
assertHttpsContent
(
"/endpoint"
,
ports
.
get
().
server
,
null
);
assertContent
(
"/controller"
,
ports
.
get
().
management
,
null
);
assertContent
(
"/endpoint"
,
ports
.
get
().
management
,
"endpointoutput"
);
assertContent
(
"/
application/
endpoint"
,
ports
.
get
().
management
,
"endpointoutput"
);
assertContent
(
"/error"
,
ports
.
get
().
management
,
startsWith
(
"{"
));
ApplicationContext
managementContext
=
this
.
applicationContext
.
getBean
(
ManagementContextResolver
.
class
).
getApplicationContext
();
...
...
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