Merge branch '1.5.x'
This commit is contained in:
commit
2519d73f5e
|
|
@ -69,7 +69,8 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
|||
EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source;
|
||||
Map<String, Object> properties = new LinkedHashMap<>();
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -90,6 +92,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
|
|||
assertThat(systemProperties.get("mySecret")).isEqualTo("******");
|
||||
assertThat(systemProperties.get("myCredentials")).isEqualTo("******");
|
||||
assertThat(systemProperties.get("VCAP_SERVICES")).isEqualTo("******");
|
||||
clearSystemProperties("dbPassword", "apiKey", "mySecret", "myCredentials");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -109,7 +112,8 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
|
|||
assertThat(systemProperties.get("my.services.cleardb-free.credentials"))
|
||||
.isEqualTo("******");
|
||||
assertThat(systemProperties.get("foo.mycredentials.uri")).isEqualTo("******");
|
||||
|
||||
clearSystemProperties("my.services.amqp-free.credentials.uri", "credentials.http_api_uri",
|
||||
"my.services.cleardb-free.credentials", "foo.mycredentials.uri");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -124,6 +128,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
|
|||
.get("systemProperties");
|
||||
assertThat(systemProperties.get("dbPassword")).isEqualTo("123456");
|
||||
assertThat(systemProperties.get("apiKey")).isEqualTo("******");
|
||||
clearSystemProperties("dbPassword", "apiKey");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -138,6 +143,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
|
|||
.get("systemProperties");
|
||||
assertThat(systemProperties.get("dbPassword")).isEqualTo("******");
|
||||
assertThat(systemProperties.get("apiKey")).isEqualTo("123456");
|
||||
clearSystemProperties("dbPassword", "apiKey");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -156,6 +162,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
|
|||
.get("systemProperties");
|
||||
assertThat(systemProperties.get("dbPassword")).isEqualTo("123456");
|
||||
assertThat(systemProperties.get("apiKey")).isEqualTo("******");
|
||||
clearSystemProperties("dbPassword", "apiKey");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -174,6 +181,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
|
|||
.get("systemProperties");
|
||||
assertThat(systemProperties.get("dbPassword")).isEqualTo("******");
|
||||
assertThat(systemProperties.get("apiKey")).isEqualTo("123456");
|
||||
clearSystemProperties("dbPassword", "apiKey");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -193,6 +201,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
|
|||
.get("systemProperties");
|
||||
assertThat(systemProperties.get("dbPassword")).isEqualTo("******");
|
||||
assertThat(systemProperties.get("apiKey")).isEqualTo("******");
|
||||
clearSystemProperties("dbPassword", "apiKey");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -255,6 +264,30 @@ 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");
|
||||
}
|
||||
|
||||
private void clearSystemProperties(String... properties) {
|
||||
for (String property : properties) {
|
||||
System.clearProperty(property);
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
public static class Config {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.endpoint.mvc;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -38,6 +39,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;
|
||||
|
|
@ -159,6 +161,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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue