Commit 513c6a1d authored by Phillip Webb's avatar Phillip Webb

Polish

parent 85fb1cba
......@@ -57,7 +57,7 @@ public class ConfigurationPropertiesReportEndpoint extends
return this.keysToSanitize;
}
public void setKeysToSanitize(String[] keysToSanitize) {
public void setKeysToSanitize(String... keysToSanitize) {
Assert.notNull(keysToSanitize, "KeysToSanitize must not be null");
this.keysToSanitize = keysToSanitize;
}
......@@ -69,10 +69,10 @@ public class ConfigurationPropertiesReportEndpoint extends
.getBeansWithAnnotation(ConfigurationProperties.class);
// Serialize beans into map structure and sanitize values
ObjectMapper mapper = new ObjectMapper();
for (Map.Entry<String, Object> entry : beans.entrySet()) {
ObjectMapper m = new ObjectMapper();
beans.put(entry.getKey(),
sanitize(m.convertValue(entry.getValue(), Map.class)));
Map<String, Object> value = mapper.convertValue(entry.getValue(), Map.class);
beans.put(entry.getKey(), sanitize(value));
}
return beans;
......@@ -94,7 +94,7 @@ public class ConfigurationPropertiesReportEndpoint extends
private Object sanitize(String name, Object object) {
for (String keyToSanitize : this.keysToSanitize) {
if (name.toLowerCase().endsWith(keyToSanitize)) {
return object == null ? null : "******";
return (object == null ? null : "******");
}
}
return object;
......
......@@ -26,6 +26,7 @@ import javax.annotation.PostConstruct;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
......@@ -39,6 +40,8 @@ import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link HttpMessageConverter}s.
*
* @author Dave Syer
*/
@Configuration
......
......@@ -39,6 +39,8 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link HttpMessageConverters}.
*
* @author Dave Syer
* @author Phillip Webb
*/
......
......@@ -35,8 +35,6 @@ import org.eclipse.aether.repository.RemoteRepository;
/**
* (Copied from aether source code - not available yet in Maven repo.)
*
* @author dsyer
*/
public final class JreProxySelector implements ProxySelector {
......
# Spring Boot Actuator Sample
You can build this sample using Maven (>3) or Gradle (1.6).
With Maven:
......@@ -9,7 +8,8 @@ $ mvn package
$ java -jar target/*.jar
```
Then access the app via a browser (or curl) on http://localhost:8080 (the user name is "user" and look at the INFO log output for the password to login).
Then access the app via a browser (or curl) on http://localhost:8080 (the user name is
"user" and look at the INFO log output for the password to login).
With gradle:
......@@ -18,4 +18,6 @@ $ gradle build
$ java -jar build/libs/*.jar
```
The gradle build contains an intentionally odd configuration to exclude the security dependencies from the executable JAR. So the app run like this behaves differently than the one run from the Maven-built JAR file. See comments in the `build.gradle` for details.
\ No newline at end of file
The gradle build contains an intentionally odd configuration to exclude the security
dependencies from the executable JAR. So the app run like this behaves differently than
the one run from the Maven-built JAR file. See comments in the `build.gradle` for details.
......@@ -16,8 +16,6 @@
package org.springframework.boot.sample.actuator.log4j;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.Callable;
......@@ -36,6 +34,8 @@ import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals;
/**
* Basic integration tests for service demo application.
*
......@@ -77,7 +77,6 @@ public class SampleActuatorApplicationTests {
assertEquals("Hello Phil", body.get("message"));
}
private RestTemplate getRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
......
......@@ -68,7 +68,6 @@ public class PropertiesConfigurationFactoryTests {
assertEquals("blah", foo.name);
}
@Test
public void testUnderscore() throws Exception {
Foo foo = createFoo("spring_foo_baz: blah\nname: blah");
......@@ -141,7 +140,7 @@ public class PropertiesConfigurationFactoryTests {
private String spring_foo_baz;
public String getSpringFooBaz() {
return spring_foo_baz;
return this.spring_foo_baz;
}
public void setSpringFooBaz(String spring_foo_baz) {
......
......@@ -28,9 +28,14 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ContextConfiguration;
/**
* Class-level annotation that is used to determine how to load and configure an
* ApplicationContext for integration tests. Similar to the standard
* {@link ContextConfiguration} but uses Spring Boot's
* {@link SpringApplicationContextLoader}.
*
* @author Dave Syer
* @see SpringApplicationContextLoader
*/
@ContextConfiguration(loader = SpringApplicationContextLoader.class)
@Documented
@Inherited
......
......@@ -58,27 +58,15 @@ public class SpringApplicationContextLoader extends AbstractContextLoader {
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig)
throws Exception {
Set<Object> sources = new LinkedHashSet<Object>();
sources.addAll(Arrays.asList(mergedConfig.getClasses()));
sources.addAll(Arrays.asList(mergedConfig.getLocations()));
SpringApplication application = new SpringApplication();
application.setSources(sources);
Map<String, Object> args = new LinkedHashMap<String, Object>();
application.setSources(getSources(mergedConfig));
if (!ObjectUtils.isEmpty(mergedConfig.getActiveProfiles())) {
application.setAdditionalProfiles(Arrays.asList(mergedConfig
.getActiveProfiles()));
}
// Not running an embedded server, just setting up web context
args.put("server.port", "0");
args.put("management.port", "0");
application.setDefaultProperties(args);
List<ApplicationContextInitializer<?>> initializers = new ArrayList<ApplicationContextInitializer<?>>(
application.getInitializers());
for (Class<? extends ApplicationContextInitializer<?>> type : mergedConfig
.getContextInitializerClasses()) {
initializers.add(BeanUtils.instantiate(type));
}
application.setDefaultProperties(getArgs(mergedConfig));
List<ApplicationContextInitializer<?>> initializers = getInitializers(
mergedConfig, application);
if (mergedConfig instanceof WebMergedContextConfiguration) {
new WebConfigurer().setup(mergedConfig, application, initializers);
}
......@@ -86,9 +74,36 @@ public class SpringApplicationContextLoader extends AbstractContextLoader {
application.setWebEnvironment(false);
}
application.setInitializers(initializers);
return application.run();
}
private Set<Object> getSources(MergedContextConfiguration mergedConfig) {
Set<Object> sources = new LinkedHashSet<Object>();
sources.addAll(Arrays.asList(mergedConfig.getClasses()));
sources.addAll(Arrays.asList(mergedConfig.getLocations()));
return sources;
}
private Map<String, Object> getArgs(MergedContextConfiguration mergedConfig) {
Map<String, Object> args = new LinkedHashMap<String, Object>();
// Not running an embedded server, just setting up web context
args.put("server.port", "0");
args.put("management.port", "0");
return args;
}
private List<ApplicationContextInitializer<?>> getInitializers(
MergedContextConfiguration mergedConfig, SpringApplication application) {
List<ApplicationContextInitializer<?>> initializers = new ArrayList<ApplicationContextInitializer<?>>();
initializers.addAll(application.getInitializers());
for (Class<? extends ApplicationContextInitializer<?>> initializerClass : mergedConfig
.getContextInitializerClasses()) {
initializers.add(BeanUtils.instantiate(initializerClass));
}
return initializers;
}
@Override
public ApplicationContext loadContext(String... locations) throws Exception {
throw new UnsupportedOperationException(
......
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