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
39b15af5
Commit
39b15af5
authored
Jul 03, 2019
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Provide links / when using a separate management port"
See gh-17418
parent
c1086293
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
171 additions
and
99 deletions
+171
-99
CloudFoundryWebFluxEndpointHandlerMapping.java
...y/reactive/CloudFoundryWebFluxEndpointHandlerMapping.java
+1
-1
CloudFoundryWebEndpointServletHandlerMapping.java
...servlet/CloudFoundryWebEndpointServletHandlerMapping.java
+1
-1
JerseyWebEndpointManagementContextConfiguration.java
...rsey/JerseyWebEndpointManagementContextConfiguration.java
+9
-4
WebFluxEndpointManagementContextConfiguration.java
...active/WebFluxEndpointManagementContextConfiguration.java
+10
-5
WebMvcEndpointManagementContextConfiguration.java
...servlet/WebMvcEndpointManagementContextConfiguration.java
+7
-5
JerseyEndpointRequestIntegrationTests.java
...curity/servlet/JerseyEndpointRequestIntegrationTests.java
+1
-1
MvcEndpointRequestIntegrationTests.java
.../security/servlet/MvcEndpointRequestIntegrationTests.java
+2
-1
EndpointMapping.java
...gframework/boot/actuate/endpoint/web/EndpointMapping.java
+1
-13
JerseyEndpointResourceFactory.java
...te/endpoint/web/jersey/JerseyEndpointResourceFactory.java
+3
-2
AbstractWebFluxEndpointHandlerMapping.java
...t/web/reactive/AbstractWebFluxEndpointHandlerMapping.java
+6
-2
WebFluxEndpointHandlerMapping.java
.../endpoint/web/reactive/WebFluxEndpointHandlerMapping.java
+3
-2
AbstractWebMvcEndpointHandlerMapping.java
...int/web/servlet/AbstractWebMvcEndpointHandlerMapping.java
+10
-4
WebMvcEndpointHandlerMapping.java
...te/endpoint/web/servlet/WebMvcEndpointHandlerMapping.java
+3
-2
EndpointMappingTests.java
...ework/boot/actuate/endpoint/web/EndpointMappingTests.java
+0
-5
JerseyWebEndpointIntegrationTests.java
...ndpoint/web/jersey/JerseyWebEndpointIntegrationTests.java
+4
-2
WebFluxEndpointIntegrationTests.java
...ndpoint/web/reactive/WebFluxEndpointIntegrationTests.java
+4
-2
MvcWebEndpointIntegrationTests.java
.../endpoint/web/servlet/MvcWebEndpointIntegrationTests.java
+4
-2
WebEndpointTestInvocationContextProvider.java
...nt/web/test/WebEndpointTestInvocationContextProvider.java
+5
-3
ManagementDifferentPortSampleActuatorApplicationTests.java
...anagementDifferentPortSampleActuatorApplicationTests.java
+31
-14
JerseyDifferentPortSampleActuatorApplicationTests.java
...ey/JerseyDifferentPortSampleActuatorApplicationTests.java
+33
-14
WebFluxDifferentPortSampleActuatorApplicationTests.java
...x/WebFluxDifferentPortSampleActuatorApplicationTests.java
+33
-14
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundryWebFluxEndpointHandlerMapping.java
View file @
39b15af5
...
...
@@ -60,7 +60,7 @@ class CloudFoundryWebFluxEndpointHandlerMapping extends AbstractWebFluxEndpointH
Collection
<
ExposableWebEndpoint
>
endpoints
,
EndpointMediaTypes
endpointMediaTypes
,
CorsConfiguration
corsConfiguration
,
CloudFoundrySecurityInterceptor
securityInterceptor
,
EndpointLinksResolver
linksResolver
)
{
super
(
endpointMapping
,
endpoints
,
endpointMediaTypes
,
corsConfiguration
);
super
(
endpointMapping
,
endpoints
,
endpointMediaTypes
,
corsConfiguration
,
true
);
this
.
linksResolver
=
linksResolver
;
this
.
securityInterceptor
=
securityInterceptor
;
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryWebEndpointServletHandlerMapping.java
View file @
39b15af5
...
...
@@ -59,7 +59,7 @@ class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebMvcEndpoin
Collection
<
ExposableWebEndpoint
>
endpoints
,
EndpointMediaTypes
endpointMediaTypes
,
CorsConfiguration
corsConfiguration
,
CloudFoundrySecurityInterceptor
securityInterceptor
,
EndpointLinksResolver
linksResolver
)
{
super
(
endpointMapping
,
endpoints
,
endpointMediaTypes
,
corsConfiguration
);
super
(
endpointMapping
,
endpoints
,
endpointMediaTypes
,
corsConfiguration
,
true
);
this
.
securityInterceptor
=
securityInterceptor
;
this
.
linksResolver
=
linksResolver
;
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointManagementContextConfiguration.java
View file @
39b15af5
...
...
@@ -44,6 +44,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
import
org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.core.env.Environment
;
import
org.springframework.util.StringUtils
;
/**
* {@link ManagementContextConfiguration @ManagementContextConfiguration} for Jersey
...
...
@@ -71,14 +72,18 @@ class JerseyWebEndpointManagementContextConfiguration {
return
(
resourceConfig
)
->
{
JerseyEndpointResourceFactory
resourceFactory
=
new
JerseyEndpointResourceFactory
();
String
basePath
=
webEndpointProperties
.
getBasePath
();
ManagementPortType
type
=
ManagementPortType
.
get
(
environment
);
Boolean
samePort
=
type
==
ManagementPortType
.
SAME
;
EndpointMapping
endpointMapping
=
new
EndpointMapping
(
basePath
,
samePort
);
EndpointMapping
endpointMapping
=
new
EndpointMapping
(
basePath
);
Collection
<
ExposableWebEndpoint
>
webEndpoints
=
Collections
.
unmodifiableCollection
(
webEndpointsSupplier
.
getEndpoints
());
resourceConfig
.
registerResources
(
new
HashSet
<>(
resourceFactory
.
createEndpointResources
(
endpointMapping
,
webEndpoints
,
endpointMediaTypes
,
new
EndpointLinksResolver
(
allEndpoints
,
basePath
))));
webEndpoints
,
endpointMediaTypes
,
new
EndpointLinksResolver
(
allEndpoints
,
basePath
),
shouldRegisterLinksMapping
(
environment
,
basePath
))));
};
}
private
boolean
shouldRegisterLinksMapping
(
Environment
environment
,
String
basePath
)
{
return
StringUtils
.
hasText
(
basePath
)
||
ManagementPortType
.
get
(
environment
).
equals
(
ManagementPortType
.
DIFFERENT
);
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/reactive/WebFluxEndpointManagementContextConfiguration.java
View file @
39b15af5
...
...
@@ -43,6 +43,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import
org.springframework.context.annotation.Bean
;
import
org.springframework.core.env.Environment
;
import
org.springframework.http.server.reactive.HttpHandler
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.reactive.DispatcherHandler
;
/**
...
...
@@ -66,16 +67,20 @@ public class WebFluxEndpointManagementContextConfiguration {
ControllerEndpointsSupplier
controllerEndpointsSupplier
,
EndpointMediaTypes
endpointMediaTypes
,
CorsEndpointProperties
corsProperties
,
WebEndpointProperties
webEndpointProperties
,
Environment
environment
)
{
ManagementPortType
type
=
ManagementPortType
.
get
(
environment
);
Boolean
samePort
=
type
==
ManagementPortType
.
SAME
;
EndpointMapping
endpointMapping
=
new
EndpointMapping
(
webEndpointProperties
.
getBasePath
(),
samePort
);
String
basePath
=
webEndpointProperties
.
getBasePath
();
EndpointMapping
endpointMapping
=
new
EndpointMapping
(
basePath
);
Collection
<
ExposableWebEndpoint
>
endpoints
=
webEndpointsSupplier
.
getEndpoints
();
List
<
ExposableEndpoint
<?>>
allEndpoints
=
new
ArrayList
<>();
allEndpoints
.
addAll
(
endpoints
);
allEndpoints
.
addAll
(
controllerEndpointsSupplier
.
getEndpoints
());
return
new
WebFluxEndpointHandlerMapping
(
endpointMapping
,
endpoints
,
endpointMediaTypes
,
corsProperties
.
toCorsConfiguration
(),
new
EndpointLinksResolver
(
allEndpoints
,
webEndpointProperties
.
getBasePath
()));
corsProperties
.
toCorsConfiguration
(),
new
EndpointLinksResolver
(
allEndpoints
,
basePath
),
shouldRegisterLinksMapping
(
environment
,
basePath
));
}
private
boolean
shouldRegisterLinksMapping
(
Environment
environment
,
String
basePath
)
{
return
StringUtils
.
hasText
(
basePath
)
||
ManagementPortType
.
get
(
environment
).
equals
(
ManagementPortType
.
DIFFERENT
);
}
@Bean
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/servlet/WebMvcEndpointManagementContextConfiguration.java
View file @
39b15af5
...
...
@@ -43,6 +43,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.core.env.Environment
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.servlet.DispatcherServlet
;
/**
...
...
@@ -71,12 +72,13 @@ public class WebMvcEndpointManagementContextConfiguration {
allEndpoints
.
addAll
(
webEndpoints
);
allEndpoints
.
addAll
(
servletEndpointsSupplier
.
getEndpoints
());
allEndpoints
.
addAll
(
controllerEndpointsSupplier
.
getEndpoints
());
ManagementPortType
type
=
ManagementPortType
.
get
(
environment
);
Boolean
samePort
=
type
==
ManagementPortType
.
SAME
;
EndpointMapping
endpointMapping
=
new
EndpointMapping
(
webEndpointProperties
.
getBasePath
(),
samePort
);
String
basePath
=
webEndpointProperties
.
getBasePath
();
EndpointMapping
endpointMapping
=
new
EndpointMapping
(
basePath
);
boolean
shouldRegisterLinksMapping
=
StringUtils
.
hasText
(
basePath
)
||
ManagementPortType
.
get
(
environment
).
equals
(
ManagementPortType
.
DIFFERENT
);
return
new
WebMvcEndpointHandlerMapping
(
endpointMapping
,
webEndpoints
,
endpointMediaTypes
,
corsProperties
.
toCorsConfiguration
(),
new
EndpointLinksResolver
(
allEndpoints
,
webEndpointProperties
.
getBasePath
())
);
corsProperties
.
toCorsConfiguration
(),
new
EndpointLinksResolver
(
allEndpoints
,
basePath
),
shouldRegisterLinksMapping
);
}
@Bean
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/JerseyEndpointRequestIntegrationTests.java
View file @
39b15af5
...
...
@@ -133,7 +133,7 @@ class JerseyEndpointRequestIntegrationTests extends AbstractEndpointRequestInteg
Arrays
.
asList
(
EndpointId:
:
toString
),
Collections
.
emptyList
(),
Collections
.
emptyList
());
Collection
<
Resource
>
resources
=
new
JerseyEndpointResourceFactory
().
createEndpointResources
(
new
EndpointMapping
(
"/actuator"
),
discoverer
.
getEndpoints
(),
endpointMediaTypes
,
new
EndpointLinksResolver
(
discoverer
.
getEndpoints
()));
new
EndpointLinksResolver
(
discoverer
.
getEndpoints
())
,
true
);
config
.
registerResources
(
new
HashSet
<>(
resources
));
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/MvcEndpointRequestIntegrationTests.java
View file @
39b15af5
...
...
@@ -119,7 +119,8 @@ class MvcEndpointRequestIntegrationTests extends AbstractEndpointRequestIntegrat
new
ConversionServiceParameterValueMapper
(),
endpointMediaTypes
,
Arrays
.
asList
(
EndpointId:
:
toString
),
Collections
.
emptyList
(),
Collections
.
emptyList
());
return
new
WebMvcEndpointHandlerMapping
(
new
EndpointMapping
(
"/actuator"
),
discoverer
.
getEndpoints
(),
endpointMediaTypes
,
new
CorsConfiguration
(),
new
EndpointLinksResolver
(
discoverer
.
getEndpoints
()));
endpointMediaTypes
,
new
CorsConfiguration
(),
new
EndpointLinksResolver
(
discoverer
.
getEndpoints
()),
true
);
}
}
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/EndpointMapping.java
View file @
39b15af5
...
...
@@ -28,20 +28,12 @@ public class EndpointMapping {
private
final
String
path
;
private
final
Boolean
samePort
;
/**
* Creates a new {@code EndpointMapping} using the given {@code path}.
* @param path the path
* @param samePort states true or false for same port as server
*/
public
EndpointMapping
(
String
path
,
Boolean
samePort
)
{
this
.
path
=
normalizePath
(
path
);
this
.
samePort
=
samePort
;
}
public
EndpointMapping
(
String
path
)
{
this
(
path
,
true
);
this
.
path
=
normalizePath
(
path
);
}
/**
...
...
@@ -52,10 +44,6 @@ public class EndpointMapping {
return
this
.
path
;
}
public
boolean
isSamePort
()
{
return
this
.
samePort
;
}
public
String
createSubPath
(
String
path
)
{
return
this
.
path
+
normalizePath
(
path
);
}
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/jersey/JerseyEndpointResourceFactory.java
View file @
39b15af5
...
...
@@ -71,15 +71,16 @@ public class JerseyEndpointResourceFactory {
* @param endpoints the web endpoints
* @param endpointMediaTypes media types consumed and produced by the endpoints
* @param linksResolver resolver for determining links to available endpoints
* @param shouldRegisterLinks should register links
* @return the resources for the operations
*/
public
Collection
<
Resource
>
createEndpointResources
(
EndpointMapping
endpointMapping
,
Collection
<
ExposableWebEndpoint
>
endpoints
,
EndpointMediaTypes
endpointMediaTypes
,
EndpointLinksResolver
linksResolver
)
{
EndpointLinksResolver
linksResolver
,
boolean
shouldRegisterLinks
)
{
List
<
Resource
>
resources
=
new
ArrayList
<>();
endpoints
.
stream
().
flatMap
((
endpoint
)
->
endpoint
.
getOperations
().
stream
())
.
map
((
operation
)
->
createResource
(
endpointMapping
,
operation
)).
forEach
(
resources:
:
add
);
if
(
StringUtils
.
hasText
(
endpointMapping
.
getPath
())
||
!
endpointMapping
.
isSamePort
()
)
{
if
(
shouldRegisterLinks
)
{
Resource
resource
=
createEndpointLinksResource
(
endpointMapping
.
getPath
(),
endpointMediaTypes
,
linksResolver
);
resources
.
add
(
resource
);
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java
View file @
39b15af5
...
...
@@ -95,6 +95,8 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi
private
final
Method
handleReadMethod
=
ReflectionUtils
.
findMethod
(
ReadOperationHandler
.
class
,
"handle"
,
ServerWebExchange
.
class
);
private
final
boolean
shouldRegisterLinksMapping
;
/**
* Creates a new {@code AbstractWebFluxEndpointHandlerMapping} that provides mappings
* for the operations of the given {@code webEndpoints}.
...
...
@@ -102,14 +104,16 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi
* @param endpoints the web endpoints
* @param endpointMediaTypes media types consumed and produced by the endpoints
* @param corsConfiguration the CORS configuration for the endpoints
* @param shouldRegisterLinksMapping whether the links endpoint should be registered
*/
public
AbstractWebFluxEndpointHandlerMapping
(
EndpointMapping
endpointMapping
,
Collection
<
ExposableWebEndpoint
>
endpoints
,
EndpointMediaTypes
endpointMediaTypes
,
CorsConfiguration
corsConfiguration
)
{
CorsConfiguration
corsConfiguration
,
boolean
shouldRegisterLinksMapping
)
{
this
.
endpointMapping
=
endpointMapping
;
this
.
endpoints
=
endpoints
;
this
.
endpointMediaTypes
=
endpointMediaTypes
;
this
.
corsConfiguration
=
corsConfiguration
;
this
.
shouldRegisterLinksMapping
=
shouldRegisterLinksMapping
;
setOrder
(-
100
);
}
...
...
@@ -120,7 +124,7 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi
registerMappingForOperation
(
endpoint
,
operation
);
}
}
if
(
StringUtils
.
hasText
(
this
.
endpointMapping
.
getPath
())
||
!
this
.
endpointMapping
.
isSamePort
()
)
{
if
(
this
.
shouldRegisterLinksMapping
)
{
registerLinksMapping
();
}
}
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/WebFluxEndpointHandlerMapping.java
View file @
39b15af5
...
...
@@ -53,11 +53,12 @@ public class WebFluxEndpointHandlerMapping extends AbstractWebFluxEndpointHandle
* @param endpointMediaTypes media types consumed and produced by the endpoints
* @param corsConfiguration the CORS configuration for the endpoints or {@code null}
* @param linksResolver resolver for determining links to available endpoints
* @param shouldRegisterLinksMapping whether the links endpoint should be registered
*/
public
WebFluxEndpointHandlerMapping
(
EndpointMapping
endpointMapping
,
Collection
<
ExposableWebEndpoint
>
endpoints
,
EndpointMediaTypes
endpointMediaTypes
,
CorsConfiguration
corsConfiguration
,
EndpointLinksResolver
linksResolver
)
{
super
(
endpointMapping
,
endpoints
,
endpointMediaTypes
,
corsConfiguration
);
EndpointLinksResolver
linksResolver
,
boolean
shouldRegisterLinksMapping
)
{
super
(
endpointMapping
,
endpoints
,
endpointMediaTypes
,
corsConfiguration
,
shouldRegisterLinksMapping
);
this
.
linksResolver
=
linksResolver
;
setOrder
(-
100
);
}
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java
View file @
39b15af5
...
...
@@ -81,6 +81,8 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin
private
final
CorsConfiguration
corsConfiguration
;
private
final
boolean
shouldRegisterLinksMapping
;
private
final
Method
handleMethod
=
ReflectionUtils
.
findMethod
(
OperationHandler
.
class
,
"handle"
,
HttpServletRequest
.
class
,
Map
.
class
);
...
...
@@ -92,10 +94,12 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin
* @param endpointMapping the base mapping for all endpoints
* @param endpoints the web endpoints
* @param endpointMediaTypes media types consumed and produced by the endpoints
* @param shouldRegisterLinksMapping whether the links endpoint should be registered
*/
public
AbstractWebMvcEndpointHandlerMapping
(
EndpointMapping
endpointMapping
,
Collection
<
ExposableWebEndpoint
>
endpoints
,
EndpointMediaTypes
endpointMediaTypes
)
{
this
(
endpointMapping
,
endpoints
,
endpointMediaTypes
,
null
);
Collection
<
ExposableWebEndpoint
>
endpoints
,
EndpointMediaTypes
endpointMediaTypes
,
boolean
shouldRegisterLinksMapping
)
{
this
(
endpointMapping
,
endpoints
,
endpointMediaTypes
,
null
,
shouldRegisterLinksMapping
);
}
/**
...
...
@@ -105,14 +109,16 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin
* @param endpoints the web endpoints
* @param endpointMediaTypes media types consumed and produced by the endpoints
* @param corsConfiguration the CORS configuration for the endpoints or {@code null}
* @param shouldRegisterLinksMapping whether the links endpoint should be registered
*/
public
AbstractWebMvcEndpointHandlerMapping
(
EndpointMapping
endpointMapping
,
Collection
<
ExposableWebEndpoint
>
endpoints
,
EndpointMediaTypes
endpointMediaTypes
,
CorsConfiguration
corsConfiguration
)
{
CorsConfiguration
corsConfiguration
,
boolean
shouldRegisterLinksMapping
)
{
this
.
endpointMapping
=
endpointMapping
;
this
.
endpoints
=
endpoints
;
this
.
endpointMediaTypes
=
endpointMediaTypes
;
this
.
corsConfiguration
=
corsConfiguration
;
this
.
shouldRegisterLinksMapping
=
shouldRegisterLinksMapping
;
setOrder
(-
100
);
}
...
...
@@ -123,7 +129,7 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin
registerMappingForOperation
(
endpoint
,
operation
);
}
}
if
(
StringUtils
.
hasText
(
this
.
endpointMapping
.
getPath
())
||
!
this
.
endpointMapping
.
isSamePort
()
)
{
if
(
this
.
shouldRegisterLinksMapping
)
{
registerLinksMapping
();
}
}
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcEndpointHandlerMapping.java
View file @
39b15af5
...
...
@@ -52,11 +52,12 @@ public class WebMvcEndpointHandlerMapping extends AbstractWebMvcEndpointHandlerM
* @param endpointMediaTypes media types consumed and produced by the endpoints
* @param corsConfiguration the CORS configuration for the endpoints or {@code null}
* @param linksResolver resolver for determining links to available endpoints
* @param shouldRegisterLinksMapping whether the links endpoint should be registered
*/
public
WebMvcEndpointHandlerMapping
(
EndpointMapping
endpointMapping
,
Collection
<
ExposableWebEndpoint
>
endpoints
,
EndpointMediaTypes
endpointMediaTypes
,
CorsConfiguration
corsConfiguration
,
EndpointLinksResolver
linksResolver
)
{
super
(
endpointMapping
,
endpoints
,
endpointMediaTypes
,
corsConfiguration
);
EndpointLinksResolver
linksResolver
,
boolean
shouldRegisterLinksMapping
)
{
super
(
endpointMapping
,
endpoints
,
endpointMediaTypes
,
corsConfiguration
,
shouldRegisterLinksMapping
);
this
.
linksResolver
=
linksResolver
;
setOrder
(-
100
);
}
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/EndpointMappingTests.java
View file @
39b15af5
...
...
@@ -77,9 +77,4 @@ class EndpointMappingTests {
assertThat
(
new
EndpointMapping
(
"/test"
).
createSubPath
(
"one/"
)).
isEqualTo
(
"/test/one"
);
}
@Test
void
setDifferentPort
()
{
assertThat
(
new
EndpointMapping
(
"/test"
,
false
).
isSamePort
()).
isFalse
();
}
}
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/jersey/JerseyWebEndpointIntegrationTests.java
View file @
39b15af5
...
...
@@ -52,6 +52,7 @@ import org.springframework.security.core.context.SecurityContext;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper
;
import
org.springframework.test.web.reactive.server.WebTestClient
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.filter.OncePerRequestFilter
;
/**
...
...
@@ -106,9 +107,10 @@ public class JerseyWebEndpointIntegrationTests
ResourceConfig
resourceConfig
(
Environment
environment
,
WebEndpointDiscoverer
endpointDiscoverer
,
EndpointMediaTypes
endpointMediaTypes
)
{
ResourceConfig
resourceConfig
=
new
ResourceConfig
();
String
endpointPath
=
environment
.
getProperty
(
"endpointPath"
);
Collection
<
Resource
>
resources
=
new
JerseyEndpointResourceFactory
().
createEndpointResources
(
new
EndpointMapping
(
en
vironment
.
getProperty
(
"endpointPath"
)),
endpointDiscoverer
.
getEndpoints
()
,
endpointMediaTypes
,
new
EndpointLinksResolver
(
endpointDiscoverer
.
getEndpoints
()
));
new
EndpointMapping
(
en
dpointPath
),
endpointDiscoverer
.
getEndpoints
(),
endpointMediaTypes
,
new
EndpointLinksResolver
(
endpointDiscoverer
.
getEndpoints
()),
StringUtils
.
hasText
(
endpointPath
));
resourceConfig
.
registerResources
(
new
HashSet
<>(
resources
));
resourceConfig
.
register
(
JacksonFeature
.
class
);
resourceConfig
.
register
(
new
ObjectMapperContextResolver
(
new
ObjectMapper
()),
ContextResolver
.
class
);
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/WebFluxEndpointIntegrationTests.java
View file @
39b15af5
...
...
@@ -41,6 +41,7 @@ import org.springframework.http.server.reactive.HttpHandler;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
org.springframework.security.core.context.ReactiveSecurityContextHolder
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.reactive.config.EnableWebFlux
;
import
org.springframework.web.server.WebFilter
;
...
...
@@ -122,9 +123,10 @@ class WebFluxEndpointIntegrationTests
CorsConfiguration
corsConfiguration
=
new
CorsConfiguration
();
corsConfiguration
.
setAllowedOrigins
(
Arrays
.
asList
(
"https://example.com"
));
corsConfiguration
.
setAllowedMethods
(
Arrays
.
asList
(
"GET"
,
"POST"
));
return
new
WebFluxEndpointHandlerMapping
(
new
EndpointMapping
(
environment
.
getProperty
(
"endpointPath"
)),
String
endpointPath
=
environment
.
getProperty
(
"endpointPath"
);
return
new
WebFluxEndpointHandlerMapping
(
new
EndpointMapping
(
endpointPath
),
endpointDiscoverer
.
getEndpoints
(),
endpointMediaTypes
,
corsConfiguration
,
new
EndpointLinksResolver
(
endpointDiscoverer
.
getEndpoints
()));
new
EndpointLinksResolver
(
endpointDiscoverer
.
getEndpoints
())
,
StringUtils
.
hasText
(
endpointPath
)
);
}
@Bean
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/MvcWebEndpointIntegrationTests.java
View file @
39b15af5
...
...
@@ -52,6 +52,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
import
org.springframework.security.core.context.SecurityContext
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.filter.OncePerRequestFilter
;
import
org.springframework.web.servlet.handler.RequestMatchResult
;
...
...
@@ -145,9 +146,10 @@ class MvcWebEndpointIntegrationTests
CorsConfiguration
corsConfiguration
=
new
CorsConfiguration
();
corsConfiguration
.
setAllowedOrigins
(
Arrays
.
asList
(
"https://example.com"
));
corsConfiguration
.
setAllowedMethods
(
Arrays
.
asList
(
"GET"
,
"POST"
));
return
new
WebMvcEndpointHandlerMapping
(
new
EndpointMapping
(
environment
.
getProperty
(
"endpointPath"
)),
String
endpointPath
=
environment
.
getProperty
(
"endpointPath"
);
return
new
WebMvcEndpointHandlerMapping
(
new
EndpointMapping
(
endpointPath
),
endpointDiscoverer
.
getEndpoints
(),
endpointMediaTypes
,
corsConfiguration
,
new
EndpointLinksResolver
(
endpointDiscoverer
.
getEndpoints
()));
new
EndpointLinksResolver
(
endpointDiscoverer
.
getEndpoints
())
,
StringUtils
.
hasText
(
endpointPath
)
);
}
}
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebEndpointTestInvocationContextProvider.java
View file @
39b15af5
...
...
@@ -242,7 +242,7 @@ class WebEndpointTestInvocationContextProvider implements TestTemplateInvocation
Collections
.
emptyList
());
Collection
<
Resource
>
resources
=
new
JerseyEndpointResourceFactory
().
createEndpointResources
(
new
EndpointMapping
(
"/actuator"
),
discoverer
.
getEndpoints
(),
endpointMediaTypes
,
new
EndpointLinksResolver
(
discoverer
.
getEndpoints
()));
new
EndpointLinksResolver
(
discoverer
.
getEndpoints
())
,
true
);
config
.
registerResources
(
new
HashSet
<>(
resources
));
}
...
...
@@ -288,7 +288,8 @@ class WebEndpointTestInvocationContextProvider implements TestTemplateInvocation
new
ConversionServiceParameterValueMapper
(),
endpointMediaTypes
,
null
,
Collections
.
emptyList
(),
Collections
.
emptyList
());
return
new
WebFluxEndpointHandlerMapping
(
new
EndpointMapping
(
"/actuator"
),
discoverer
.
getEndpoints
(),
endpointMediaTypes
,
new
CorsConfiguration
(),
new
EndpointLinksResolver
(
discoverer
.
getEndpoints
()));
endpointMediaTypes
,
new
CorsConfiguration
(),
new
EndpointLinksResolver
(
discoverer
.
getEndpoints
()),
true
);
}
}
...
...
@@ -317,7 +318,8 @@ class WebEndpointTestInvocationContextProvider implements TestTemplateInvocation
new
ConversionServiceParameterValueMapper
(),
endpointMediaTypes
,
null
,
Collections
.
emptyList
(),
Collections
.
emptyList
());
return
new
WebMvcEndpointHandlerMapping
(
new
EndpointMapping
(
"/actuator"
),
discoverer
.
getEndpoints
(),
endpointMediaTypes
,
new
CorsConfiguration
(),
new
EndpointLinksResolver
(
discoverer
.
getEndpoints
()));
endpointMediaTypes
,
new
CorsConfiguration
(),
new
EndpointLinksResolver
(
discoverer
.
getEndpoints
()),
true
);
}
}
...
...
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementDifferentPortSampleActuatorApplicationTests.java
View file @
39b15af5
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
smoketest
.
actuator
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.boot.web.server.LocalServerPort
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for separate management and main service ports with empty endpoint
* base path.
*
* @author HaiTao Zhang
*/
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
properties
=
{
"management.endpoints.web.base-path=/"
,
"management.server.port=0"
})
public
class
ManagementDifferentPortSampleActuatorApplicationTests
{
@LocalServerPort
private
int
port
;
properties
=
{
"management.endpoints.web.base-path=/"
,
"management.server.port=0"
})
class
ManagementDifferentPortSampleActuatorApplicationTests
{
@LocalManagementPort
private
int
managementPort
;
@Test
void
testDifferentServerPort
(){
if
(
this
.
managementPort
!=
this
.
port
)
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"_links\""
);
}
void
linksEndpointShouldBeAvailable
()
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"_links\""
);
}
private
String
getPassword
(){
private
String
getPassword
()
{
return
"password"
;
}
...
...
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/JerseyDifferentPortSampleActuatorApplicationTests.java
View file @
39b15af5
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
smoketest
.
jersey
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.boot.web.server.LocalServerPort
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
properties
=
{
"management.server.port=0"
,
"management.endpoints.web.base-path=/"
})
public
class
JerseyDifferentPortSampleActuatorApplicationTests
{
/**
* Integration tests for separate management and main service ports with empty base path
* for endpoints.
*
* @author HaiTao Zhang
*/
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
properties
=
{
"management.server.port=0"
,
"management.endpoints.web.base-path=/"
})
class
JerseyDifferentPortSampleActuatorApplicationTests
{
@LocalManagementPort
private
int
managementPort
;
@LocalServerPort
private
int
port
;
@Test
void
testDifferentServerPort
(){
if
(
this
.
managementPort
!=
this
.
port
)
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"_links\""
);
}
void
linksEndpointShouldBeAvailable
()
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"_links\""
);
}
private
String
getPassword
(){
private
String
getPassword
()
{
return
"password"
;
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/test/java/smoketest/webflux/WebFluxDifferentPortSampleActuatorApplicationTests.java
View file @
39b15af5
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
smoketest
.
webflux
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.boot.web.server.LocalServerPort
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
properties
=
{
"management.server.port=0"
,
"management.endpoints.web.base-path=/"
})
public
class
WebFluxDifferentPortSampleActuatorApplicationTests
{
/**
* Integration tests for separate management and main service ports with empty endpoint
* base path.
*
* @author HaiTao Zhang
*/
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
properties
=
{
"management.server.port=0"
,
"management.endpoints.web.base-path=/"
})
class
WebFluxDifferentPortSampleActuatorApplicationTests
{
@LocalManagementPort
private
int
managementPort
;
@LocalServerPort
private
int
port
;
@Test
void
testDifferentServerPort
(){
if
(
this
.
managementPort
!=
this
.
port
)
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"_links\""
);
}
void
linksEndpointShouldBeAvailable
()
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"_links\""
);
}
private
String
getPassword
(){
private
String
getPassword
()
{
return
"password"
;
}
}
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