score:1

Accepted answer

This problem with Apache Tomcat and it was fixed since 8.0.34.

Apache Tomcat 8.0.34 changelog:

59317: Ensure that HttpServletRequest.getRequestURI() returns an encoded URI rather than a decoded URI after a dispatch. (markt)

score:1

Resolution 1: urlDecode flag is set to false

@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    @Override
    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
        RequestMappingHandlerMapping requestMappingHandlerMapping = super.requestMappingHandlerMapping();
        requestMappingHandlerMapping.setUrlDecode(false);
        return requestMappingHandlerMapping;
    }

}

Resolution 2: ignore decoding after some result was set in DefferedResult

@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    private static final String AFTER_CONCURRENT_HANDLING_STARTED = "afterConcurrentHandlingStarted";

    @Override
    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
        RequestMappingHandlerMapping requestMappingHandlerMapping = super.requestMappingHandlerMapping();
        requestMappingHandlerMapping.setUrlPathHelper(new UrlPathHelper() {

            @Override
            public String decodeRequestString(HttpServletRequest request, String source) {
                return request.getAttribute(AFTER_CONCURRENT_HANDLING_STARTED) == null
                    ? super.decodeRequestString(request, source) : source;
            }

        });
        return requestMappingHandlerMapping;
    }

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new HandlerInterceptorAdapter() {

            @Override
            public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
                request.setAttribute(AFTER_CONCURRENT_HANDLING_STARTED, AFTER_CONCURRENT_HANDLING_STARTED);
            }

        }).addPathPatterns("/**");
    }

}

Related Query

More Query from same tag