From 24471bc51e080e1fbf1c3f059316265c4f212bb2 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 16 Jun 2014 12:39:15 -0700 Subject: [PATCH] Polish --- .../actuate/endpoint/EnvironmentEndpoint.java | 30 +++++++++++-------- .../EndpointMvcIntegrationTests.java | 5 +++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpoint.java index 502bcba6f9a..1547b8353c9 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpoint.java @@ -17,6 +17,7 @@ package org.springframework.boot.actuate.endpoint; import java.lang.reflect.Field; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; @@ -99,19 +100,9 @@ public class EnvironmentEndpoint extends AbstractEndpoint> i private void extract(String root, Map> map, PropertySource source) { if (source instanceof CompositePropertySource) { - try { - Field field = ReflectionUtils.findField(CompositePropertySource.class, - "propertySources"); - field.setAccessible(true); - @SuppressWarnings("unchecked") - Set> nested = (Set>) field - .get(source); - for (PropertySource nest : nested) { - extract(source.getName() + ":", map, nest); - } - } - catch (Exception e) { - // ignore + Set> nested = getNestedPropertySources((CompositePropertySource) source); + for (PropertySource nest : nested) { + extract(source.getName() + ":", map, nest); } } else { @@ -119,6 +110,19 @@ public class EnvironmentEndpoint extends AbstractEndpoint> i } } + @SuppressWarnings("unchecked") + private Set> getNestedPropertySources(CompositePropertySource source) { + try { + Field field = ReflectionUtils.findField(CompositePropertySource.class, + "propertySources"); + field.setAccessible(true); + return (Set>) field.get(source); + } + catch (Exception ex) { + return Collections.emptySet(); + } + } + public Object sanitize(String name, Object object) { for (String keyToSanitize : this.keysToSanitize) { if (name.toLowerCase().endsWith(keyToSanitize)) { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java index e2d02a96bf6..740b190c79c 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java @@ -1,5 +1,5 @@ /* - * 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"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; 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.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; @@ -51,6 +52,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; /** + * Integration tests for MVC {@link Endpoint}s. + * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class)