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
19cddd65
Commit
19cddd65
authored
Aug 08, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3.x'
parents
a729d48b
cec6015f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
178 additions
and
9 deletions
+178
-9
EndpointWebMvcHypermediaManagementContextConfiguration.java
...dpointWebMvcHypermediaManagementContextConfiguration.java
+23
-9
EndpointWebMvcHypermediaManagementContextConfigurationTests.java
...tWebMvcHypermediaManagementContextConfigurationTests.java
+155
-0
actuator-docs-index.html
...boot-actuator/src/test/resources/actuator-docs-index.html
+0
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.java
View file @
19cddd65
...
@@ -54,6 +54,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
...
@@ -54,6 +54,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
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.context.annotation.Conditional
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.core.io.ResourceLoader
;
...
@@ -117,14 +118,6 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
...
@@ -117,14 +118,6 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
return
new
HalJsonMvcEndpoint
(
managementServletContext
);
return
new
HalJsonMvcEndpoint
(
managementServletContext
);
}
}
@Bean
@ConditionalOnEnabledEndpoint
(
"docs"
)
@ConditionalOnResource
(
resources
=
"classpath:/META-INF/resources/spring-boot-actuator/docs/index.html"
)
public
DocsMvcEndpoint
docsMvcEndpoint
(
ManagementServletContext
managementServletContext
)
{
return
new
DocsMvcEndpoint
(
managementServletContext
);
}
@Bean
@Bean
@ConditionalOnBean
(
DocsMvcEndpoint
.
class
)
@ConditionalOnBean
(
DocsMvcEndpoint
.
class
)
@ConditionalOnMissingBean
(
CurieProvider
.
class
)
@ConditionalOnMissingBean
(
CurieProvider
.
class
)
...
@@ -133,12 +126,33 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
...
@@ -133,12 +126,33 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
ManagementServerProperties
management
,
DocsMvcEndpoint
endpoint
)
{
ManagementServerProperties
management
,
DocsMvcEndpoint
endpoint
)
{
String
path
=
management
.
getContextPath
()
+
endpoint
.
getPath
()
String
path
=
management
.
getContextPath
()
+
endpoint
.
getPath
()
+
"/#spring_boot_actuator__{rel}"
;
+
"/#spring_boot_actuator__{rel}"
;
if
(
server
.
getPort
().
equals
(
management
.
getPort
())
&&
management
.
getPort
()
!=
0
)
{
if
(
server
AndManagementPortsAreTheSame
(
server
,
management
)
)
{
path
=
server
.
getPath
(
path
);
path
=
server
.
getPath
(
path
);
}
}
return
new
DefaultCurieProvider
(
"boot"
,
new
UriTemplate
(
path
));
return
new
DefaultCurieProvider
(
"boot"
,
new
UriTemplate
(
path
));
}
}
private
boolean
serverAndManagementPortsAreTheSame
(
ServerProperties
server
,
ManagementServerProperties
management
)
{
if
(
server
.
getPort
()
==
null
)
{
return
management
.
getPort
()
==
null
;
}
return
server
.
getPort
().
equals
(
management
.
getPort
())
&&
management
.
getPort
()
!=
0
;
}
@Configuration
static
class
DocsMvcEndpointConfiguration
{
@Bean
@ConditionalOnEnabledEndpoint
(
"docs"
)
@ConditionalOnResource
(
resources
=
"classpath:/META-INF/resources/spring-boot-actuator/docs/index.html"
)
public
DocsMvcEndpoint
docsMvcEndpoint
(
ManagementServletContext
managementServletContext
)
{
return
new
DocsMvcEndpoint
(
managementServletContext
);
}
}
/**
/**
* Controller advice that adds links to the actuator endpoint's path.
* Controller advice that adds links to the actuator endpoint's path.
*/
*/
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfigurationTests.java
0 → 100644
View file @
19cddd65
/*
* Copyright 2012-2016 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
*
* http://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
org
.
springframework
.
boot
.
actuate
.
autoconfigure
;
import
java.net.URL
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.endpoint.mvc.DocsMvcEndpoint
;
import
org.springframework.boot.actuate.endpoint.mvc.HalJsonMvcEndpoint
;
import
org.springframework.boot.actuate.endpoint.mvc.ManagementServletContext
;
import
org.springframework.boot.actuate.endpoint.mvc.MvcEndpoints
;
import
org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.ServerProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.hateoas.Link
;
import
org.springframework.hateoas.hal.DefaultCurieProvider
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link EndpointWebMvcHypermediaManagementContextConfigurationTests}.
*
* @author Andy Wilkinson
*/
public
class
EndpointWebMvcHypermediaManagementContextConfigurationTests
{
private
AnnotationConfigWebApplicationContext
context
;
@Before
public
void
setRequestAttributes
()
{
RequestContextHolder
.
setRequestAttributes
(
new
ServletRequestAttributes
(
new
MockHttpServletRequest
()));
}
@After
public
void
resetRequestAttributes
()
{
RequestContextHolder
.
resetRequestAttributes
();
}
@After
public
void
closeContext
()
{
this
.
context
.
close
();
}
@Test
public
void
basicConfiguration
()
{
load
();
assertThat
(
this
.
context
.
getBeansOfType
(
ManagementServletContext
.
class
))
.
hasSize
(
1
);
assertThat
(
this
.
context
.
getBeansOfType
(
HalJsonMvcEndpoint
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBeansOfType
(
DocsMvcEndpoint
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBeansOfType
(
DefaultCurieProvider
.
class
)).
isEmpty
();
}
@Test
public
void
curiesEnabledWithDefaultPorts
()
{
load
(
"endpoints.docs.curies.enabled:true"
);
assertThat
(
getCurieHref
())
.
isEqualTo
(
"http://localhost/docs/#spring_boot_actuator__{rel}"
);
}
@Test
public
void
curiesEnabledWithRandomPorts
()
{
load
(
"endpoints.docs.curies.enabled:true"
,
"server.port:0"
,
"management.port:0"
);
assertThat
(
getCurieHref
())
.
isEqualTo
(
"http://localhost/docs/#spring_boot_actuator__{rel}"
);
}
@Test
public
void
curiesEnabledWithSpecificServerPort
()
{
load
(
"endpoints.docs.curies.enabled:true"
,
"server.port:8080"
);
assertThat
(
getCurieHref
())
.
isEqualTo
(
"http://localhost/docs/#spring_boot_actuator__{rel}"
);
}
@Test
public
void
curiesEnabledWithSpecificManagementPort
()
{
load
(
"endpoints.docs.curies.enabled:true"
,
"management.port:8081"
);
assertThat
(
getCurieHref
())
.
isEqualTo
(
"http://localhost/docs/#spring_boot_actuator__{rel}"
);
}
@Test
public
void
curiesEnabledWithSpecificManagementAndServerPorts
()
{
load
(
"endpoints.docs.curies.enabled:true"
,
"server.port:8080"
,
"management.port:8081"
);
assertThat
(
getCurieHref
())
.
isEqualTo
(
"http://localhost/docs/#spring_boot_actuator__{rel}"
);
}
private
void
load
(
String
...
properties
)
{
this
.
context
=
new
AnnotationConfigWebApplicationContext
();
this
.
context
.
setClassLoader
(
new
ClassLoader
(
getClass
().
getClassLoader
())
{
@Override
public
URL
getResource
(
String
name
)
{
if
(
"META-INF/resources/spring-boot-actuator/docs/index.html"
.
equals
(
name
))
{
return
super
.
getResource
(
"actuator-docs-index.html"
);
}
return
super
.
getResource
(
name
);
}
});
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
properties
);
this
.
context
.
register
(
TestConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
EndpointWebMvcHypermediaManagementContextConfiguration
.
class
);
this
.
context
.
refresh
();
}
private
String
getCurieHref
()
{
DefaultCurieProvider
curieProvider
=
this
.
context
.
getBean
(
DefaultCurieProvider
.
class
);
Link
link
=
(
Link
)
curieProvider
.
getCurieInformation
(
null
).
iterator
().
next
();
return
link
.
getHref
();
}
@Configuration
@EnableConfigurationProperties
({
ManagementServerProperties
.
class
,
ServerProperties
.
class
})
static
class
TestConfiguration
{
@Bean
public
MvcEndpoints
mvcEndpoints
()
{
return
new
MvcEndpoints
();
}
}
}
spring-boot-actuator/src/test/resources/actuator-docs-index.html
0 → 100644
View file @
19cddd65
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