Closed
Description
Hi,
Working version: 2.5.7
Broken version: 2.6.x
I have a Filter that will check if the matched handler method has a particular annotation and wrap the servlet response if that is the case.
In 2.6.x requestMappingHandlerMapping.getHandler(httpServletRequest)
throws
java.lang.IllegalArgumentException: Expected parsed RequestPath in request attribute "org.springframework.web.util.ServletRequestPathUtils.PATH".
at org.springframework.util.Assert.notNull(Assert.java:201) ~[spring-core-5.3.13.jar!/:5.3.13]
at org.springframework.web.util.ServletRequestPathUtils.getParsedRequestPath(ServletRequestPathUtils.java:77) ~[spring-web-5.3.13.jar!/:5.3.13]
at org.springframework.web.servlet.handler.AbstractHandlerMapping.initLookupPath(AbstractHandlerMapping.java:574) ~[spring-webmvc-5.3.13.jar!/:5.3.13]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:380) ~[spring-webmvc-5.3.13.jar!/:5.3.13]
at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getHandlerInternal(RequestMappingInfoHandlerMapping.java:125) ~[spring-webmvc-5.3.13.jar!/:5.3.13]
at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getHandlerInternal(RequestMappingInfoHandlerMapping.java:67) ~[spring-webmvc-5.3.13.jar!/:5.3.13]
at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:498) ~[spring-webmvc-5.3.13.jar!/:5.3.13]
A minimal example of how we are using this code
@Component
@ConditionalOnWebApplication
public class DataFilter implements Filter {
@Autowired
private RequestMappingHandlerMapping requestMappingHandlerMapping;
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
try {
Optional<HandlerExecutionChain> handlerExecutionChain = Optional.ofNullable(requestMappingHandlerMapping.getHandler(httpServletRequest));
if (handlerExecutionChain.isPresent()) {
HandlerMethod handlerMethod = (HandlerMethod) handlerExecutionChain.get().getHandler();
if (handlerMethod.getMethod().isAnnotationPresent(MonitorData.class)) {
//wrap the response
chain.doFilter(request, wrappedResponse);
}
...
I that the default matching strategy has been changed in #24805, but I've been unable to resolve this issue in my codebase.