Commit 24471bc5 authored by Phillip Webb's avatar Phillip Webb

Polish

parent 299311d7
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.springframework.boot.actuate.endpoint; package org.springframework.boot.actuate.endpoint;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
...@@ -99,19 +100,9 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> i ...@@ -99,19 +100,9 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> i
private void extract(String root, Map<String, PropertySource<?>> map, private void extract(String root, Map<String, PropertySource<?>> map,
PropertySource<?> source) { PropertySource<?> source) {
if (source instanceof CompositePropertySource) { if (source instanceof CompositePropertySource) {
try { Set<PropertySource<?>> nested = getNestedPropertySources((CompositePropertySource) source);
Field field = ReflectionUtils.findField(CompositePropertySource.class, for (PropertySource<?> nest : nested) {
"propertySources"); extract(source.getName() + ":", map, nest);
field.setAccessible(true);
@SuppressWarnings("unchecked")
Set<PropertySource<?>> nested = (Set<PropertySource<?>>) field
.get(source);
for (PropertySource<?> nest : nested) {
extract(source.getName() + ":", map, nest);
}
}
catch (Exception e) {
// ignore
} }
} }
else { else {
...@@ -119,6 +110,19 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> i ...@@ -119,6 +110,19 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> i
} }
} }
@SuppressWarnings("unchecked")
private Set<PropertySource<?>> getNestedPropertySources(CompositePropertySource source) {
try {
Field field = ReflectionUtils.findField(CompositePropertySource.class,
"propertySources");
field.setAccessible(true);
return (Set<PropertySource<?>>) field.get(source);
}
catch (Exception ex) {
return Collections.emptySet();
}
}
public Object sanitize(String name, Object object) { public Object sanitize(String name, Object object) {
for (String keyToSanitize : this.keysToSanitize) { for (String keyToSanitize : this.keysToSanitize) {
if (name.toLowerCase().endsWith(keyToSanitize)) { if (name.toLowerCase().endsWith(keyToSanitize)) {
......
/* /*
* Copyright 2012-2013 the original author or authors. * Copyright 2012-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -28,6 +28,7 @@ import org.junit.Test; ...@@ -28,6 +28,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.EndpointMvcIntegrationTests.Application; import org.springframework.boot.actuate.autoconfigure.EndpointMvcIntegrationTests.Application;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
...@@ -51,6 +52,8 @@ import static org.junit.Assert.assertNotNull; ...@@ -51,6 +52,8 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
* Integration tests for MVC {@link Endpoint}s.
*
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment