Merge branch '1.5.x'

pull/8889/head
Stephane Nicoll 8 years ago
commit 158b3dae16

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 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.
@ -46,7 +46,7 @@ import org.springframework.web.servlet.HandlerMapping;
@ConditionalOnClass({ Servlet.class, ServletRegistration.class, @ConditionalOnClass({ Servlet.class, ServletRegistration.class,
OncePerRequestFilter.class, HandlerMapping.class }) OncePerRequestFilter.class, HandlerMapping.class })
@AutoConfigureAfter(MetricRepositoryAutoConfiguration.class) @AutoConfigureAfter(MetricRepositoryAutoConfiguration.class)
@ConditionalOnProperty(name = "endpoints.metrics.filter.enabled", matchIfMissing = true) @ConditionalOnProperty(prefix = "endpoints.metrics.filter", name="enabled", matchIfMissing = true)
@EnableConfigurationProperties({ MetricFilterProperties.class }) @EnableConfigurationProperties({ MetricFilterProperties.class })
public class MetricFilterAutoConfiguration { public class MetricFilterAutoConfiguration {

@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorAttributes; import org.springframework.boot.autoconfigure.web.servlet.error.ErrorAttributes;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -40,10 +41,11 @@ import org.springframework.web.servlet.DispatcherServlet;
* *
* @author Dave Syer * @author Dave Syer
*/ */
@Configuration
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class, ServletRegistration.class }) @ConditionalOnClass({ Servlet.class, DispatcherServlet.class, ServletRegistration.class })
@AutoConfigureAfter(TraceRepositoryAutoConfiguration.class) @AutoConfigureAfter(TraceRepositoryAutoConfiguration.class)
@ConditionalOnProperty(prefix = "endpoints.trace.filter", name = "enabled", matchIfMissing = true)
@EnableConfigurationProperties(TraceProperties.class) @EnableConfigurationProperties(TraceProperties.class)
@Configuration
public class TraceWebFilterAutoConfiguration { public class TraceWebFilterAutoConfiguration {
private final TraceRepository traceRepository; private final TraceRepository traceRepository;

@ -22,7 +22,6 @@ import org.springframework.boot.actuate.endpoint.LoggersEndpoint;
import org.springframework.boot.actuate.endpoint.LoggersEndpoint.LoggerLevels; import org.springframework.boot.actuate.endpoint.LoggersEndpoint.LoggerLevels;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.logging.LogLevel; import org.springframework.boot.logging.LogLevel;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -33,6 +32,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
* *
* @author Ben Hale * @author Ben Hale
* @author Kazuki Shimizu * @author Kazuki Shimizu
* @author Eddú Meléndez
* @since 1.5.0 * @since 1.5.0
*/ */
@ConfigurationProperties(prefix = "endpoints.loggers") @ConfigurationProperties(prefix = "endpoints.loggers")
@ -68,10 +68,17 @@ public class LoggersMvcEndpoint extends EndpointMvcAdapter {
// disabled // disabled
return getDisabledResponse(); return getDisabledResponse();
} }
LogLevel logLevel;
try {
String level = configuration.get("configuredLevel"); String level = configuration.get("configuredLevel");
LogLevel logLevel = level == null ? null : LogLevel.valueOf(level.toUpperCase()); logLevel = level == null ? null : LogLevel.valueOf(level.toUpperCase());
}
catch (IllegalArgumentException ex) {
return ResponseEntity.badRequest().build();
}
this.delegate.setLogLevel(name, logLevel); this.delegate.setLogLevel(name, logLevel);
return HttpEntity.EMPTY; return ResponseEntity.ok().build();
} }
} }

@ -80,6 +80,12 @@
"type": "java.lang.String", "type": "java.lang.String",
"description": "Endpoint URL path." "description": "Endpoint URL path."
}, },
{
"name": "endpoints.trace.filter.enabled",
"type": "java.lang.Boolean",
"description": "Enable the trace servlet filter.",
"defaultValue": true
},
{ {
"name": "info", "name": "info",
"type": "java.util.Map<java.lang.String,java.lang.Object>", "type": "java.util.Map<java.lang.String,java.lang.Object>",

@ -18,12 +18,14 @@ package org.springframework.boot.actuate.autoconfigure;
import java.util.Map; import java.util.Map;
import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.actuate.trace.TraceProperties; import org.springframework.boot.actuate.trace.TraceProperties;
import org.springframework.boot.actuate.trace.TraceRepository; import org.springframework.boot.actuate.trace.TraceRepository;
import org.springframework.boot.actuate.trace.WebRequestTraceFilter; import org.springframework.boot.actuate.trace.WebRequestTraceFilter;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -34,28 +36,54 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link TraceWebFilterAutoConfiguration}. * Tests for {@link TraceWebFilterAutoConfiguration}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Stephane Nicoll
*/ */
public class TraceWebFilterAutoConfigurationTests { public class TraceWebFilterAutoConfigurationTests {
private AnnotationConfigApplicationContext context;
@After
public void close() {
if (this.context != null) {
this.context.close();
}
}
@Test @Test
public void configureFilter() { public void configureFilter() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( load();
PropertyPlaceholderAutoConfiguration.class, assertThat(this.context.getBean(WebRequestTraceFilter.class)).isNotNull();
TraceRepositoryAutoConfiguration.class,
TraceWebFilterAutoConfiguration.class);
assertThat(context.getBean(WebRequestTraceFilter.class)).isNotNull();
context.close();
} }
@Test @Test
public void overrideTraceFilter() throws Exception { public void overrideTraceFilter() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( load(CustomTraceFilterConfig.class);
CustomTraceFilterConfig.class, PropertyPlaceholderAutoConfiguration.class, WebRequestTraceFilter filter = this.context.getBean(WebRequestTraceFilter.class);
assertThat(filter).isInstanceOf(TestWebRequestTraceFilter.class);
}
@Test
public void skipsFilterIfPropertyDisabled() throws Exception {
load("endpoints.trace.filter.enabled:false");
assertThat(this.context.getBeansOfType(WebRequestTraceFilter.class).size())
.isEqualTo(0);
}
private void load(String... environment) {
load(null, environment);
}
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
if (config != null) {
ctx.register(config);
}
ctx.register(PropertyPlaceholderAutoConfiguration.class,
TraceRepositoryAutoConfiguration.class, TraceRepositoryAutoConfiguration.class,
TraceWebFilterAutoConfiguration.class); TraceWebFilterAutoConfiguration.class);
WebRequestTraceFilter filter = context.getBean(WebRequestTraceFilter.class); ctx.refresh();
assertThat(filter).isInstanceOf(TestWebRequestTraceFilter.class); this.context = ctx;
context.close();
} }
@Configuration @Configuration

@ -63,6 +63,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* *
* @author Ben Hale * @author Ben Hale
* @author Phillip Webb * @author Phillip Webb
* @author Eddú Meléndez
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
@ -168,6 +169,14 @@ public class LoggersMvcEndpointTests {
verifyZeroInteractions(this.loggingSystem); verifyZeroInteractions(this.loggingSystem);
} }
@Test
public void setLoggerWithWrongLogLevel() throws Exception {
this.mvc.perform(post("/loggers/ROOT").contentType(MediaType.APPLICATION_JSON)
.content("{\"configuredLevel\":\"other\"}"))
.andExpect(status().is4xxClientError());
verifyZeroInteractions(this.loggingSystem);
}
@Configuration @Configuration
@Import({ JacksonAutoConfiguration.class, @Import({ JacksonAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,

@ -1065,6 +1065,7 @@ content into your application; rather pick only the properties that you need.
endpoints.shutdown.path= # Endpoint path. endpoints.shutdown.path= # Endpoint path.
endpoints.shutdown.sensitive= # Mark if the endpoint exposes sensitive information. endpoints.shutdown.sensitive= # Mark if the endpoint exposes sensitive information.
endpoints.trace.enabled= # Enable the endpoint. endpoints.trace.enabled= # Enable the endpoint.
endpoints.trace.filter.enabled=true # Enable the trace servlet filter.
endpoints.trace.id= # Endpoint identifier. endpoints.trace.id= # Endpoint identifier.
endpoints.trace.path= # Endpoint path. endpoints.trace.path= # Endpoint path.
endpoints.trace.sensitive= # Mark if the endpoint exposes sensitive information. endpoints.trace.sensitive= # Mark if the endpoint exposes sensitive information.

Loading…
Cancel
Save