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
c937bb68
Commit
c937bb68
authored
May 10, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ServletEndpoints should take servletPath into account
Fixes gh-13106
parent
fbf97447
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
10 deletions
+78
-10
ServletEndpointManagementContextConfiguration.java
...nt/web/ServletEndpointManagementContextConfiguration.java
+45
-8
ServletEndpointManagementContextConfigurationTests.java
...b/ServletEndpointManagementContextConfigurationTests.java
+33
-2
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.java
View file @
c937bb68
...
...
@@ -16,35 +16,35 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
endpoint
.
web
;
import
org.glassfish.jersey.server.ResourceConfig
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.ExposeExcludePropertyEndpointFilter
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration
;
import
org.springframework.boot.actuate.endpoint.web.ExposableServletEndpoint
;
import
org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar
;
import
org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPathProvider
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.DispatcherServlet
;
/**
* {@link ManagementContextConfiguration} for servlet endpoints.
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author Madhura Bhave
* @since 2.0.0
*/
@Configuration
@ConditionalOnWebApplication
(
type
=
Type
.
SERVLET
)
public
class
ServletEndpointManagementContextConfiguration
{
@Bean
public
ServletEndpointRegistrar
servletEndpointRegistrar
(
WebEndpointProperties
properties
,
ServletEndpointsSupplier
servletEndpointsSupplier
)
{
return
new
ServletEndpointRegistrar
(
properties
.
getBasePath
(),
servletEndpointsSupplier
.
getEndpoints
());
}
@Bean
public
ExposeExcludePropertyEndpointFilter
<
ExposableServletEndpoint
>
servletExposeExcludePropertyEndpointFilter
(
WebEndpointProperties
properties
)
{
...
...
@@ -53,4 +53,41 @@ public class ServletEndpointManagementContextConfiguration {
exposure
.
getInclude
(),
exposure
.
getExclude
());
}
@Configuration
@ConditionalOnClass
(
DispatcherServlet
.
class
)
public
class
WebMvcServletEndpointManagementContextConfiguration
{
private
final
ApplicationContext
context
;
public
WebMvcServletEndpointManagementContextConfiguration
(
ApplicationContext
context
)
{
this
.
context
=
context
;
}
@Bean
public
ServletEndpointRegistrar
servletEndpointRegistrar
(
WebEndpointProperties
properties
,
ServletEndpointsSupplier
servletEndpointsSupplier
)
{
DispatcherServletPathProvider
servletPathProvider
=
this
.
context
.
getBean
(
DispatcherServletPathProvider
.
class
);
String
servletPath
=
(
servletPathProvider
.
getServletPath
().
equals
(
"/"
)
?
""
:
servletPathProvider
.
getServletPath
());
return
new
ServletEndpointRegistrar
(
servletPath
+
properties
.
getBasePath
(),
servletEndpointsSupplier
.
getEndpoints
());
}
}
@Configuration
@ConditionalOnClass
(
ResourceConfig
.
class
)
@ConditionalOnMissingClass
(
"org.springframework.web.servlet.DispatcherServlet"
)
public
class
JerseyServletEndpointManagementContextConfiguration
{
@Bean
public
ServletEndpointRegistrar
servletEndpointRegistrar
(
WebEndpointProperties
properties
,
ServletEndpointsSupplier
servletEndpointsSupplier
)
{
return
new
ServletEndpointRegistrar
(
properties
.
getBasePath
(),
servletEndpointsSupplier
.
getEndpoints
());
}
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfigurationTests.java
View file @
c937bb68
...
...
@@ -18,16 +18,21 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.web;
import
java.util.Collections
;
import
org.glassfish.jersey.server.ResourceConfig
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar
;
import
org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier
;
import
org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPathProvider
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.test.context.FilteredClassLoader
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -35,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link ServletEndpointManagementContextConfiguration}.
*
* @author Phillip Webb
* @author Madhura Bhave
*/
public
class
ServletEndpointManagementContextConfigurationTests
{
...
...
@@ -43,8 +49,28 @@ public class ServletEndpointManagementContextConfigurationTests {
@Test
public
void
contextShouldContainServletEndpointRegistrar
()
{
this
.
contextRunner
.
run
((
context
)
->
assertThat
(
context
)
.
hasSingleBean
(
ServletEndpointRegistrar
.
class
));
FilteredClassLoader
classLoader
=
new
FilteredClassLoader
(
ResourceConfig
.
class
);
this
.
contextRunner
.
withClassLoader
(
classLoader
).
run
((
context
)
->
{
assertThat
(
context
)
.
hasSingleBean
(
ServletEndpointRegistrar
.
class
);
ServletEndpointRegistrar
bean
=
context
.
getBean
(
ServletEndpointRegistrar
.
class
);
String
basePath
=
(
String
)
ReflectionTestUtils
.
getField
(
bean
,
"basePath"
);
assertThat
(
basePath
).
isEqualTo
(
"/test/actuator"
);
});
}
@Test
public
void
servletPathShouldNotAffectJerseyConfiguration
()
{
FilteredClassLoader
classLoader
=
new
FilteredClassLoader
(
DispatcherServlet
.
class
);
this
.
contextRunner
.
withClassLoader
(
classLoader
).
run
((
context
)
->
{
assertThat
(
context
)
.
hasSingleBean
(
ServletEndpointRegistrar
.
class
);
ServletEndpointRegistrar
bean
=
context
.
getBean
(
ServletEndpointRegistrar
.
class
);
String
basePath
=
(
String
)
ReflectionTestUtils
.
getField
(
bean
,
"basePath"
);
assertThat
(
basePath
).
isEqualTo
(
"/actuator"
);
});
}
@Test
...
...
@@ -64,6 +90,11 @@ public class ServletEndpointManagementContextConfigurationTests {
return
()
->
Collections
.
emptyList
();
}
@Bean
public
DispatcherServletPathProvider
servletPathProvider
()
{
return
()
->
"/test"
;
}
}
}
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