Merge branch 'gh-4320'
This commit is contained in:
commit
eb3d64108e
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2015 the original author or authors.
|
* Copyright 2012-2016 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.
|
||||||
|
|
@ -42,6 +42,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||||
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
||||||
|
|
@ -87,6 +88,7 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Johannes Edmeier
|
* @author Johannes Edmeier
|
||||||
|
* @author Eddú Meléndez
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
||||||
|
|
@ -198,6 +200,7 @@ public class EndpointWebMvcAutoConfiguration
|
||||||
// Put Servlets and Filters in their own nested class so they don't force early
|
// Put Servlets and Filters in their own nested class so they don't force early
|
||||||
// instantiation of ManagementServerProperties.
|
// instantiation of ManagementServerProperties.
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ConditionalOnProperty(prefix = "management", name = "add-application-context-header", matchIfMissing = true, havingValue = "true")
|
||||||
protected static class ApplicationContextFilterConfiguration {
|
protected static class ApplicationContextFilterConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -222,8 +225,6 @@ public class EndpointWebMvcAutoConfiguration
|
||||||
|
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
|
|
||||||
private ManagementServerProperties properties;
|
|
||||||
|
|
||||||
ApplicationContextHeaderFilter(ApplicationContext applicationContext) {
|
ApplicationContextHeaderFilter(ApplicationContext applicationContext) {
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
@ -232,14 +233,7 @@ public class EndpointWebMvcAutoConfiguration
|
||||||
protected void doFilterInternal(HttpServletRequest request,
|
protected void doFilterInternal(HttpServletRequest request,
|
||||||
HttpServletResponse response, FilterChain filterChain)
|
HttpServletResponse response, FilterChain filterChain)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
if (this.properties == null) {
|
response.addHeader("X-Application-Context", this.applicationContext.getId());
|
||||||
this.properties = this.applicationContext
|
|
||||||
.getBean(ManagementServerProperties.class);
|
|
||||||
}
|
|
||||||
if (this.properties.getAddApplicationContextHeader()) {
|
|
||||||
response.addHeader("X-Application-Context",
|
|
||||||
this.applicationContext.getId());
|
|
||||||
}
|
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2015 the original author or authors.
|
* Copyright 2012-2016 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.
|
||||||
|
|
@ -98,6 +98,7 @@ import static org.mockito.Mockito.mock;
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
|
* @author Eddú Meléndez
|
||||||
*/
|
*/
|
||||||
public class EndpointWebMvcAutoConfigurationTests {
|
public class EndpointWebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
|
|
@ -136,6 +137,7 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||||
assertContent("/controller", ports.get().management, null);
|
assertContent("/controller", ports.get().management, null);
|
||||||
assertContent("/endpoint", ports.get().management, null);
|
assertContent("/endpoint", ports.get().management, null);
|
||||||
assertTrue(hasHeader("/endpoint", ports.get().server, "X-Application-Context"));
|
assertTrue(hasHeader("/endpoint", ports.get().server, "X-Application-Context"));
|
||||||
|
assertTrue(this.applicationContext.containsBean("applicationContextIdFilter"));
|
||||||
this.applicationContext.close();
|
this.applicationContext.close();
|
||||||
assertAllClosed();
|
assertAllClosed();
|
||||||
}
|
}
|
||||||
|
|
@ -149,6 +151,7 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||||
EndpointWebMvcAutoConfiguration.class);
|
EndpointWebMvcAutoConfiguration.class);
|
||||||
this.applicationContext.refresh();
|
this.applicationContext.refresh();
|
||||||
assertFalse(hasHeader("/endpoint", ports.get().server, "X-Application-Context"));
|
assertFalse(hasHeader("/endpoint", ports.get().server, "X-Application-Context"));
|
||||||
|
assertFalse(this.applicationContext.containsBean("applicationContextIdFilter"));
|
||||||
this.applicationContext.close();
|
this.applicationContext.close();
|
||||||
assertAllClosed();
|
assertAllClosed();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue