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
pull/20222/head
Brian Clozel 5 years ago
parent bf8ed44453
commit e59d3fbb86

@ -198,6 +198,12 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi
return this.corsConfiguration;
}
@Override
public Mono<HandlerMethod> getHandlerInternal(ServerWebExchange exchange) {
return super.getHandlerInternal(exchange)
.doOnTerminate(() -> ProducesRequestCondition.clearMediaTypesAttribute(exchange));
}
@Override
protected boolean isHandler(Class<?> beanType) {
return false;

@ -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;

Loading…
Cancel
Save