From e59d3fbb861560de372f8bd186e199f0c7d5e42a Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Mon, 17 Feb 2020 10:41:34 +0100 Subject: [PATCH] Clear ProducesRequestCondition cache attribute As of spring-projects/spring-framework#22644, Spring Framework caches the "produces" condition when matching for endpoints in the `HandlerMapping` infrastructure. This has been improved in spring-projects/spring-framework#23091 to prevent side-effects in other implementations. Prior to this commit, the Spring Boot actuator infrastructure for `EndpointHandlerMapping` would not clear the cached attribute, presenting the same issue as Spring Framework's infrastructure. This means that a custom arrangement with custom `HandlerMapping` or `ContentTypeResolver` would not work properly and reuse the cached produced conditions for other, unintented, parts of the handler mapping process. This commit clears the cached data and ensures that other handler mapping implementations are free of that side-effect. Fixes gh-20150 --- .../AbstractWebFluxEndpointHandlerMapping.java | 6 ++++++ .../servlet/AbstractWebMvcEndpointHandlerMapping.java | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java index a9aaff3664f..9ae97add142 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java @@ -198,6 +198,12 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi return this.corsConfiguration; } + @Override + public Mono getHandlerInternal(ServerWebExchange exchange) { + return super.getHandlerInternal(exchange) + .doOnTerminate(() -> ProducesRequestCondition.clearMediaTypesAttribute(exchange)); + } + @Override protected boolean isHandler(Class beanType) { return false; diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java index 0b7f9970516..d2e1fca8de2 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java @@ -231,6 +231,16 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin return this.corsConfiguration; } + @Override + protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception { + try { + return super.getHandlerInternal(request); + } + finally { + ProducesRequestCondition.clearMediaTypesAttribute(request); + } + } + @Override protected boolean isHandler(Class beanType) { return false;