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
ad69a1ae
Commit
ad69a1ae
authored
Jan 01, 2015
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2265 from metcox/master
* pull2265: Fix global `endpoints.enabled` property support
parents
491a61d5
bf839e57
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
15 deletions
+37
-15
AbstractEndpoint.java
...ringframework/boot/actuate/endpoint/AbstractEndpoint.java
+6
-1
EnvironmentEndpoint.java
...gframework/boot/actuate/endpoint/EnvironmentEndpoint.java
+5
-14
AbstractEndpointTests.java
...ramework/boot/actuate/endpoint/AbstractEndpointTests.java
+26
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/AbstractEndpoint.java
View file @
ad69a1ae
...
...
@@ -84,6 +84,10 @@ public abstract class AbstractEndpoint<T> implements Endpoint<T>, EnvironmentAwa
this
.
enabled
=
enabled
;
}
protected
final
Environment
getEnvironment
()
{
return
this
.
environment
;
}
@Override
public
void
setEnvironment
(
Environment
environment
)
{
this
.
environment
=
environment
;
...
...
@@ -104,7 +108,8 @@ public abstract class AbstractEndpoint<T> implements Endpoint<T>, EnvironmentAwa
return
this
.
enabled
;
}
if
(
this
.
environment
!=
null
)
{
this
.
environment
.
getProperty
(
ENDPOINTS_ENABLED_PROPERTY
,
Boolean
.
class
,
true
);
return
this
.
environment
.
getProperty
(
ENDPOINTS_ENABLED_PROPERTY
,
Boolean
.
class
,
true
);
}
return
true
;
}
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpoint.java
View file @
ad69a1ae
...
...
@@ -21,7 +21,6 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.core.env.CompositePropertySource
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.EnumerablePropertySource
;
...
...
@@ -38,10 +37,7 @@ import org.springframework.core.env.StandardEnvironment;
* @author Christian Dupuis
*/
@ConfigurationProperties
(
prefix
=
"endpoints.env"
,
ignoreUnknownFields
=
false
)
public
class
EnvironmentEndpoint
extends
AbstractEndpoint
<
Map
<
String
,
Object
>>
implements
EnvironmentAware
{
private
Environment
environment
;
public
class
EnvironmentEndpoint
extends
AbstractEndpoint
<
Map
<
String
,
Object
>>
{
private
final
Sanitizer
sanitizer
=
new
Sanitizer
();
...
...
@@ -59,7 +55,7 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> i
@Override
public
Map
<
String
,
Object
>
invoke
()
{
Map
<
String
,
Object
>
result
=
new
LinkedHashMap
<
String
,
Object
>();
result
.
put
(
"profiles"
,
this
.
environment
.
getActiveProfiles
());
result
.
put
(
"profiles"
,
getEnvironment
()
.
getActiveProfiles
());
for
(
Entry
<
String
,
PropertySource
<?>>
entry
:
getPropertySources
().
entrySet
())
{
PropertySource
<?>
source
=
entry
.
getValue
();
String
sourceName
=
entry
.
getKey
();
...
...
@@ -78,9 +74,9 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> i
private
Map
<
String
,
PropertySource
<?>>
getPropertySources
()
{
Map
<
String
,
PropertySource
<?>>
map
=
new
LinkedHashMap
<
String
,
PropertySource
<?>>();
MutablePropertySources
sources
=
null
;
if
(
this
.
environment
!=
null
&&
this
.
environment
instanceof
ConfigurableEnvironment
)
{
sources
=
((
ConfigurableEnvironment
)
this
.
environment
).
getPropertySources
();
Environment
environment
=
getEnvironment
();
if
(
environment
!=
null
&&
environment
instanceof
ConfigurableEnvironment
)
{
sources
=
((
ConfigurableEnvironment
)
environment
).
getPropertySources
();
}
else
{
sources
=
new
StandardEnvironment
().
getPropertySources
();
...
...
@@ -108,9 +104,4 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> i
return
this
.
sanitizer
.
sanitize
(
name
,
object
);
}
@Override
public
void
setEnvironment
(
Environment
environment
)
{
this
.
environment
=
environment
;
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AbstractEndpointTests.java
View file @
ad69a1ae
...
...
@@ -17,6 +17,8 @@
package
org
.
springframework
.
boot
.
actuate
.
endpoint
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.junit.After
;
import
org.junit.Before
;
...
...
@@ -133,6 +135,30 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
assertThat
(
getEndpointBean
().
isEnabled
(),
equalTo
(
true
));
}
@Test
public
void
isAllEndpointsDisabled
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
PropertySource
<?>
propertySource
=
new
MapPropertySource
(
"test"
,
Collections
.<
String
,
Object
>
singletonMap
(
"endpoints.enabled"
,
false
));
this
.
context
.
getEnvironment
().
getPropertySources
().
addFirst
(
propertySource
);
this
.
context
.
register
(
this
.
configClass
);
this
.
context
.
refresh
();
assertThat
(
getEndpointBean
().
isEnabled
(),
equalTo
(
false
));
}
@Test
public
void
isOptIn
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
Map
<
String
,
Object
>
source
=
new
HashMap
<
String
,
Object
>();
source
.
put
(
"endpoints.enabled"
,
false
);
source
.
put
(
this
.
property
+
".enabled"
,
true
);
PropertySource
<?>
propertySource
=
new
MapPropertySource
(
"test"
,
source
);
this
.
context
.
getEnvironment
().
getPropertySources
().
addFirst
(
propertySource
);
this
.
context
.
register
(
this
.
configClass
);
this
.
context
.
refresh
();
assertThat
(
getEndpointBean
().
isEnabled
(),
equalTo
(
true
));
}
@SuppressWarnings
(
"unchecked"
)
protected
T
getEndpointBean
()
{
return
(
T
)
this
.
context
.
getBean
(
this
.
type
);
...
...
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