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
c1086293
Commit
c1086293
authored
Jul 03, 2019
by
HaiTao Zhang
Committed by
Madhura Bhave
Jul 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide links for actuators at / when using a separate management port
See gh-17418
parent
edea2238
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
147 additions
and
10 deletions
+147
-10
JerseyWebEndpointManagementContextConfiguration.java
...rsey/JerseyWebEndpointManagementContextConfiguration.java
+6
-2
WebFluxEndpointManagementContextConfiguration.java
...active/WebFluxEndpointManagementContextConfiguration.java
+7
-2
WebMvcEndpointManagementContextConfiguration.java
...servlet/WebMvcEndpointManagementContextConfiguration.java
+6
-2
EndpointMapping.java
...gframework/boot/actuate/endpoint/web/EndpointMapping.java
+13
-1
JerseyEndpointResourceFactory.java
...te/endpoint/web/jersey/JerseyEndpointResourceFactory.java
+1
-1
AbstractWebFluxEndpointHandlerMapping.java
...t/web/reactive/AbstractWebFluxEndpointHandlerMapping.java
+1
-1
AbstractWebMvcEndpointHandlerMapping.java
...int/web/servlet/AbstractWebMvcEndpointHandlerMapping.java
+1
-1
EndpointMappingTests.java
...ework/boot/actuate/endpoint/web/EndpointMappingTests.java
+5
-0
ManagementDifferentPortSampleActuatorApplicationTests.java
...anagementDifferentPortSampleActuatorApplicationTests.java
+37
-0
JerseyDifferentPortSampleActuatorApplicationTests.java
...ey/JerseyDifferentPortSampleActuatorApplicationTests.java
+35
-0
WebFluxDifferentPortSampleActuatorApplicationTests.java
...x/WebFluxDifferentPortSampleActuatorApplicationTests.java
+35
-0
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointManagementContextConfiguration.java
View file @
c1086293
...
@@ -26,6 +26,7 @@ import org.glassfish.jersey.server.ResourceConfig;
...
@@ -26,6 +26,7 @@ import org.glassfish.jersey.server.ResourceConfig;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType
;
import
org.springframework.boot.actuate.endpoint.ExposableEndpoint
;
import
org.springframework.boot.actuate.endpoint.ExposableEndpoint
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
import
org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver
;
import
org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver
;
...
@@ -42,6 +43,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
...
@@ -42,6 +43,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer
;
import
org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.core.env.Environment
;
/**
/**
* {@link ManagementContextConfiguration @ManagementContextConfiguration} for Jersey
* {@link ManagementContextConfiguration @ManagementContextConfiguration} for Jersey
...
@@ -62,14 +64,16 @@ class JerseyWebEndpointManagementContextConfiguration {
...
@@ -62,14 +64,16 @@ class JerseyWebEndpointManagementContextConfiguration {
@Bean
@Bean
ResourceConfigCustomizer
webEndpointRegistrar
(
WebEndpointsSupplier
webEndpointsSupplier
,
ResourceConfigCustomizer
webEndpointRegistrar
(
WebEndpointsSupplier
webEndpointsSupplier
,
ServletEndpointsSupplier
servletEndpointsSupplier
,
EndpointMediaTypes
endpointMediaTypes
,
ServletEndpointsSupplier
servletEndpointsSupplier
,
EndpointMediaTypes
endpointMediaTypes
,
WebEndpointProperties
webEndpointProperties
)
{
WebEndpointProperties
webEndpointProperties
,
Environment
environment
)
{
List
<
ExposableEndpoint
<?>>
allEndpoints
=
new
ArrayList
<>();
List
<
ExposableEndpoint
<?>>
allEndpoints
=
new
ArrayList
<>();
allEndpoints
.
addAll
(
webEndpointsSupplier
.
getEndpoints
());
allEndpoints
.
addAll
(
webEndpointsSupplier
.
getEndpoints
());
allEndpoints
.
addAll
(
servletEndpointsSupplier
.
getEndpoints
());
allEndpoints
.
addAll
(
servletEndpointsSupplier
.
getEndpoints
());
return
(
resourceConfig
)
->
{
return
(
resourceConfig
)
->
{
JerseyEndpointResourceFactory
resourceFactory
=
new
JerseyEndpointResourceFactory
();
JerseyEndpointResourceFactory
resourceFactory
=
new
JerseyEndpointResourceFactory
();
String
basePath
=
webEndpointProperties
.
getBasePath
();
String
basePath
=
webEndpointProperties
.
getBasePath
();
EndpointMapping
endpointMapping
=
new
EndpointMapping
(
basePath
);
ManagementPortType
type
=
ManagementPortType
.
get
(
environment
);
Boolean
samePort
=
type
==
ManagementPortType
.
SAME
;
EndpointMapping
endpointMapping
=
new
EndpointMapping
(
basePath
,
samePort
);
Collection
<
ExposableWebEndpoint
>
webEndpoints
=
Collections
Collection
<
ExposableWebEndpoint
>
webEndpoints
=
Collections
.
unmodifiableCollection
(
webEndpointsSupplier
.
getEndpoints
());
.
unmodifiableCollection
(
webEndpointsSupplier
.
getEndpoints
());
resourceConfig
.
registerResources
(
new
HashSet
<>(
resourceFactory
.
createEndpointResources
(
endpointMapping
,
resourceConfig
.
registerResources
(
new
HashSet
<>(
resourceFactory
.
createEndpointResources
(
endpointMapping
,
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/reactive/WebFluxEndpointManagementContextConfiguration.java
View file @
c1086293
...
@@ -23,6 +23,7 @@ import java.util.List;
...
@@ -23,6 +23,7 @@ import java.util.List;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType
;
import
org.springframework.boot.actuate.endpoint.ExposableEndpoint
;
import
org.springframework.boot.actuate.endpoint.ExposableEndpoint
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
import
org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver
;
import
org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver
;
...
@@ -40,6 +41,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
...
@@ -40,6 +41,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.core.env.Environment
;
import
org.springframework.http.server.reactive.HttpHandler
;
import
org.springframework.http.server.reactive.HttpHandler
;
import
org.springframework.web.reactive.DispatcherHandler
;
import
org.springframework.web.reactive.DispatcherHandler
;
...
@@ -62,8 +64,11 @@ public class WebFluxEndpointManagementContextConfiguration {
...
@@ -62,8 +64,11 @@ public class WebFluxEndpointManagementContextConfiguration {
@ConditionalOnMissingBean
@ConditionalOnMissingBean
public
WebFluxEndpointHandlerMapping
webEndpointReactiveHandlerMapping
(
WebEndpointsSupplier
webEndpointsSupplier
,
public
WebFluxEndpointHandlerMapping
webEndpointReactiveHandlerMapping
(
WebEndpointsSupplier
webEndpointsSupplier
,
ControllerEndpointsSupplier
controllerEndpointsSupplier
,
EndpointMediaTypes
endpointMediaTypes
,
ControllerEndpointsSupplier
controllerEndpointsSupplier
,
EndpointMediaTypes
endpointMediaTypes
,
CorsEndpointProperties
corsProperties
,
WebEndpointProperties
webEndpointProperties
)
{
CorsEndpointProperties
corsProperties
,
WebEndpointProperties
webEndpointProperties
,
EndpointMapping
endpointMapping
=
new
EndpointMapping
(
webEndpointProperties
.
getBasePath
());
Environment
environment
)
{
ManagementPortType
type
=
ManagementPortType
.
get
(
environment
);
Boolean
samePort
=
type
==
ManagementPortType
.
SAME
;
EndpointMapping
endpointMapping
=
new
EndpointMapping
(
webEndpointProperties
.
getBasePath
(),
samePort
);
Collection
<
ExposableWebEndpoint
>
endpoints
=
webEndpointsSupplier
.
getEndpoints
();
Collection
<
ExposableWebEndpoint
>
endpoints
=
webEndpointsSupplier
.
getEndpoints
();
List
<
ExposableEndpoint
<?>>
allEndpoints
=
new
ArrayList
<>();
List
<
ExposableEndpoint
<?>>
allEndpoints
=
new
ArrayList
<>();
allEndpoints
.
addAll
(
endpoints
);
allEndpoints
.
addAll
(
endpoints
);
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/servlet/WebMvcEndpointManagementContextConfiguration.java
View file @
c1086293
...
@@ -23,6 +23,7 @@ import java.util.List;
...
@@ -23,6 +23,7 @@ import java.util.List;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType
;
import
org.springframework.boot.actuate.endpoint.ExposableEndpoint
;
import
org.springframework.boot.actuate.endpoint.ExposableEndpoint
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
import
org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver
;
import
org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver
;
...
@@ -41,6 +42,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
...
@@ -41,6 +42,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.core.env.Environment
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
org.springframework.web.servlet.DispatcherServlet
;
/**
/**
...
@@ -63,13 +65,15 @@ public class WebMvcEndpointManagementContextConfiguration {
...
@@ -63,13 +65,15 @@ public class WebMvcEndpointManagementContextConfiguration {
public
WebMvcEndpointHandlerMapping
webEndpointServletHandlerMapping
(
WebEndpointsSupplier
webEndpointsSupplier
,
public
WebMvcEndpointHandlerMapping
webEndpointServletHandlerMapping
(
WebEndpointsSupplier
webEndpointsSupplier
,
ServletEndpointsSupplier
servletEndpointsSupplier
,
ControllerEndpointsSupplier
controllerEndpointsSupplier
,
ServletEndpointsSupplier
servletEndpointsSupplier
,
ControllerEndpointsSupplier
controllerEndpointsSupplier
,
EndpointMediaTypes
endpointMediaTypes
,
CorsEndpointProperties
corsProperties
,
EndpointMediaTypes
endpointMediaTypes
,
CorsEndpointProperties
corsProperties
,
WebEndpointProperties
webEndpointProperties
)
{
WebEndpointProperties
webEndpointProperties
,
Environment
environment
)
{
List
<
ExposableEndpoint
<?>>
allEndpoints
=
new
ArrayList
<>();
List
<
ExposableEndpoint
<?>>
allEndpoints
=
new
ArrayList
<>();
Collection
<
ExposableWebEndpoint
>
webEndpoints
=
webEndpointsSupplier
.
getEndpoints
();
Collection
<
ExposableWebEndpoint
>
webEndpoints
=
webEndpointsSupplier
.
getEndpoints
();
allEndpoints
.
addAll
(
webEndpoints
);
allEndpoints
.
addAll
(
webEndpoints
);
allEndpoints
.
addAll
(
servletEndpointsSupplier
.
getEndpoints
());
allEndpoints
.
addAll
(
servletEndpointsSupplier
.
getEndpoints
());
allEndpoints
.
addAll
(
controllerEndpointsSupplier
.
getEndpoints
());
allEndpoints
.
addAll
(
controllerEndpointsSupplier
.
getEndpoints
());
EndpointMapping
endpointMapping
=
new
EndpointMapping
(
webEndpointProperties
.
getBasePath
());
ManagementPortType
type
=
ManagementPortType
.
get
(
environment
);
Boolean
samePort
=
type
==
ManagementPortType
.
SAME
;
EndpointMapping
endpointMapping
=
new
EndpointMapping
(
webEndpointProperties
.
getBasePath
(),
samePort
);
return
new
WebMvcEndpointHandlerMapping
(
endpointMapping
,
webEndpoints
,
endpointMediaTypes
,
return
new
WebMvcEndpointHandlerMapping
(
endpointMapping
,
webEndpoints
,
endpointMediaTypes
,
corsProperties
.
toCorsConfiguration
(),
corsProperties
.
toCorsConfiguration
(),
new
EndpointLinksResolver
(
allEndpoints
,
webEndpointProperties
.
getBasePath
()));
new
EndpointLinksResolver
(
allEndpoints
,
webEndpointProperties
.
getBasePath
()));
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/EndpointMapping.java
View file @
c1086293
...
@@ -28,12 +28,20 @@ public class EndpointMapping {
...
@@ -28,12 +28,20 @@ public class EndpointMapping {
private
final
String
path
;
private
final
String
path
;
private
final
Boolean
samePort
;
/**
/**
* Creates a new {@code EndpointMapping} using the given {@code path}.
* Creates a new {@code EndpointMapping} using the given {@code path}.
* @param path the path
* @param path the path
* @param samePort states true or false for same port as server
*/
*/
public
EndpointMapping
(
String
path
)
{
public
EndpointMapping
(
String
path
,
Boolean
samePort
)
{
this
.
path
=
normalizePath
(
path
);
this
.
path
=
normalizePath
(
path
);
this
.
samePort
=
samePort
;
}
public
EndpointMapping
(
String
path
)
{
this
(
path
,
true
);
}
}
/**
/**
...
@@ -44,6 +52,10 @@ public class EndpointMapping {
...
@@ -44,6 +52,10 @@ public class EndpointMapping {
return
this
.
path
;
return
this
.
path
;
}
}
public
boolean
isSamePort
()
{
return
this
.
samePort
;
}
public
String
createSubPath
(
String
path
)
{
public
String
createSubPath
(
String
path
)
{
return
this
.
path
+
normalizePath
(
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 @
c1086293
...
@@ -79,7 +79,7 @@ public class JerseyEndpointResourceFactory {
...
@@ -79,7 +79,7 @@ public class JerseyEndpointResourceFactory {
List
<
Resource
>
resources
=
new
ArrayList
<>();
List
<
Resource
>
resources
=
new
ArrayList
<>();
endpoints
.
stream
().
flatMap
((
endpoint
)
->
endpoint
.
getOperations
().
stream
())
endpoints
.
stream
().
flatMap
((
endpoint
)
->
endpoint
.
getOperations
().
stream
())
.
map
((
operation
)
->
createResource
(
endpointMapping
,
operation
)).
forEach
(
resources:
:
add
);
.
map
((
operation
)
->
createResource
(
endpointMapping
,
operation
)).
forEach
(
resources:
:
add
);
if
(
StringUtils
.
hasText
(
endpointMapping
.
getPath
()))
{
if
(
StringUtils
.
hasText
(
endpointMapping
.
getPath
())
||
!
endpointMapping
.
isSamePort
()
)
{
Resource
resource
=
createEndpointLinksResource
(
endpointMapping
.
getPath
(),
endpointMediaTypes
,
Resource
resource
=
createEndpointLinksResource
(
endpointMapping
.
getPath
(),
endpointMediaTypes
,
linksResolver
);
linksResolver
);
resources
.
add
(
resource
);
resources
.
add
(
resource
);
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java
View file @
c1086293
...
@@ -120,7 +120,7 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi
...
@@ -120,7 +120,7 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi
registerMappingForOperation
(
endpoint
,
operation
);
registerMappingForOperation
(
endpoint
,
operation
);
}
}
}
}
if
(
StringUtils
.
hasText
(
this
.
endpointMapping
.
getPath
()))
{
if
(
StringUtils
.
hasText
(
this
.
endpointMapping
.
getPath
())
||
!
this
.
endpointMapping
.
isSamePort
()
)
{
registerLinksMapping
();
registerLinksMapping
();
}
}
}
}
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java
View file @
c1086293
...
@@ -123,7 +123,7 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin
...
@@ -123,7 +123,7 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin
registerMappingForOperation
(
endpoint
,
operation
);
registerMappingForOperation
(
endpoint
,
operation
);
}
}
}
}
if
(
StringUtils
.
hasText
(
this
.
endpointMapping
.
getPath
()))
{
if
(
StringUtils
.
hasText
(
this
.
endpointMapping
.
getPath
())
||
!
this
.
endpointMapping
.
isSamePort
()
)
{
registerLinksMapping
();
registerLinksMapping
();
}
}
}
}
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/EndpointMappingTests.java
View file @
c1086293
...
@@ -77,4 +77,9 @@ class EndpointMappingTests {
...
@@ -77,4 +77,9 @@ class EndpointMappingTests {
assertThat
(
new
EndpointMapping
(
"/test"
).
createSubPath
(
"one/"
)).
isEqualTo
(
"/test/one"
);
assertThat
(
new
EndpointMapping
(
"/test"
).
createSubPath
(
"one/"
)).
isEqualTo
(
"/test/one"
);
}
}
@Test
void
setDifferentPort
()
{
assertThat
(
new
EndpointMapping
(
"/test"
,
false
).
isSamePort
()).
isFalse
();
}
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementDifferentPortSampleActuatorApplicationTests.java
0 → 100644
View file @
c1086293
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
;
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
properties
=
{
"management.endpoints.web.base-path=/"
,
"management.server.port=0"
})
public
class
ManagementDifferentPortSampleActuatorApplicationTests
{
@LocalServerPort
private
int
port
;
@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\""
);
}
}
private
String
getPassword
(){
return
"password"
;
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/JerseyDifferentPortSampleActuatorApplicationTests.java
0 → 100644
View file @
c1086293
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
{
@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\""
);
}
}
private
String
getPassword
(){
return
"password"
;
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/test/java/smoketest/webflux/WebFluxDifferentPortSampleActuatorApplicationTests.java
0 → 100644
View file @
c1086293
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
{
@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\""
);
}
}
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