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
189e07e9
Commit
189e07e9
authored
May 04, 2017
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support values other than String in /env
Fixes gh-9079
parent
216506d2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
3 deletions
+38
-3
EnvironmentEndpoint.java
...gframework/boot/actuate/endpoint/EnvironmentEndpoint.java
+2
-1
EnvironmentMvcEndpoint.java
...ork/boot/actuate/endpoint/mvc/EnvironmentMvcEndpoint.java
+2
-2
EnvironmentEndpointTests.java
...ework/boot/actuate/endpoint/EnvironmentEndpointTests.java
+20
-0
EnvironmentMvcEndpointTests.java
...oot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java
+14
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpoint.java
View file @
189e07e9
...
...
@@ -69,7 +69,8 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
EnumerablePropertySource
<?>
enumerable
=
(
EnumerablePropertySource
<?>)
source
;
Map
<
String
,
Object
>
properties
=
new
LinkedHashMap
<
String
,
Object
>();
for
(
String
name
:
enumerable
.
getPropertyNames
())
{
properties
.
put
(
name
,
sanitize
(
name
,
resolver
.
getProperty
(
name
)));
Object
resolved
=
resolver
.
getProperty
(
name
,
Object
.
class
);
properties
.
put
(
name
,
sanitize
(
name
,
resolved
));
}
properties
=
postProcessSourceProperties
(
sourceName
,
properties
);
if
(
properties
!=
null
)
{
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpoint.java
View file @
189e07e9
...
...
@@ -93,7 +93,7 @@ public class EnvironmentMvcEndpoint extends EndpointMvcAdapter
@Override
protected
Object
getOptionalValue
(
Environment
source
,
String
name
)
{
Object
result
=
((
EnvironmentEndpoint
)
getDelegate
()).
getResolver
().
getProperty
(
name
);
Object
result
=
((
EnvironmentEndpoint
)
getDelegate
()).
getResolver
().
getProperty
(
name
,
Object
.
class
);
if
(
result
!=
null
)
{
result
=
((
EnvironmentEndpoint
)
getDelegate
()).
sanitize
(
name
,
result
);
}
...
...
@@ -102,7 +102,7 @@ public class EnvironmentMvcEndpoint extends EndpointMvcAdapter
@Override
protected
Object
getValue
(
Environment
source
,
String
name
)
{
String
result
=
source
.
getProperty
(
name
);
Object
result
=
source
.
getProperty
(
name
,
Object
.
class
);
if
(
result
==
null
)
{
throw
new
NoSuchPropertyException
(
"No such property: "
+
name
);
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpointTests.java
View file @
189e07e9
...
...
@@ -17,6 +17,7 @@
package
org
.
springframework
.
boot
.
actuate
.
endpoint
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.junit.After
;
...
...
@@ -29,6 +30,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.CompositePropertySource
;
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.MutablePropertySources
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -255,6 +257,24 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
assertThat
(
testProperties
.
get
(
"my.foo"
)).
isEqualTo
(
"http://${bar.password}://hello"
);
}
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
propertyWithTypeOtherThanStringShouldNotFail
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
MutablePropertySources
propertySources
=
this
.
context
.
getEnvironment
().
getPropertySources
();
Map
<
String
,
Object
>
source
=
new
HashMap
<
String
,
Object
>();
source
.
put
(
"foo"
,
Collections
.
singletonMap
(
"bar"
,
"baz"
));
propertySources
.
addFirst
(
new
MapPropertySource
(
"test"
,
source
));
this
.
context
.
register
(
Config
.
class
);
this
.
context
.
refresh
();
EnvironmentEndpoint
report
=
getEndpointBean
();
Map
<
String
,
Object
>
env
=
report
.
invoke
();
Map
<
String
,
Object
>
testProperties
=
(
Map
<
String
,
Object
>)
env
.
get
(
"test"
);
Map
<
String
,
String
>
foo
=
(
Map
<
String
,
String
>)
testProperties
.
get
(
"foo"
);
assertThat
(
foo
.
get
(
"bar"
)).
isEqualTo
(
"baz"
);
}
@Configuration
@EnableConfigurationProperties
public
static
class
Config
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java
View file @
189e07e9
...
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
boot
.
actuate
.
endpoint
.
mvc
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -39,6 +40,7 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.context.annotation.Import
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.MutablePropertySources
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.annotation.DirtiesContext
;
...
...
@@ -160,6 +162,18 @@ public class EnvironmentMvcEndpointTests {
.
andExpect
(
content
().
string
(
containsString
(
"\"my.foo\":\"******\""
)));
}
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
propertyWithTypeOtherThanStringShouldNotFail
()
throws
Exception
{
ConfigurableEnvironment
environment
=
(
ConfigurableEnvironment
)
this
.
context
.
getEnvironment
();
MutablePropertySources
propertySources
=
environment
.
getPropertySources
();
Map
<
String
,
Object
>
source
=
new
HashMap
<
String
,
Object
>();
source
.
put
(
"foo"
,
Collections
.
singletonMap
(
"bar"
,
"baz"
));
propertySources
.
addFirst
(
new
MapPropertySource
(
"test"
,
source
));
this
.
mvc
.
perform
(
get
(
"/env/foo.*"
)).
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
string
(
"{\"foo\":{\"bar\":\"baz\"}}"
));
}
@Configuration
@Import
({
JacksonAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
WebMvcAutoConfiguration
.
class
,
...
...
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