From 1366216b7ff886b4524b41dde0ece77d53109a84 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 5 Sep 2013 09:55:30 +0100 Subject: [PATCH] Add X-Application-Context header to identify app --- .../EndpointWebMvcAutoConfiguration.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java index d27d2c8e0b..16acc25e5f 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java @@ -16,7 +16,14 @@ package org.springframework.boot.actuate.autoconfigure; +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; import javax.servlet.Servlet; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; @@ -43,6 +50,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.servlet.DispatcherServlet; /** @@ -100,6 +108,20 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware, } } + @Bean + public Filter applicationContextIdFilter(ApplicationContext context) { + final String id = context.getId(); + return new OncePerRequestFilter() { + @Override + protected void doFilterInternal(HttpServletRequest request, + HttpServletResponse response, FilterChain filterChain) + throws ServletException, IOException { + response.addHeader("X-Application-Context", id); + filterChain.doFilter(request, response); + } + }; + } + private void createChildManagementContext() { final AnnotationConfigEmbeddedWebApplicationContext childContext = new AnnotationConfigEmbeddedWebApplicationContext();