diff --git a/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java b/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java index aa0b32eb7fb..5839f4fa215 100644 --- a/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java @@ -231,7 +231,6 @@ public final class WebHttpHandlerBuilder { } private void updateFilters() { - if (this.filters.isEmpty()) { return; } @@ -378,7 +377,6 @@ public final class WebHttpHandlerBuilder { * Build the {@link HttpHandler}. */ public HttpHandler build() { - WebHandler decorated = new FilteringWebHandler(this.webHandler, this.filters); decorated = new ExceptionHandlingWebHandler(decorated, this.exceptionHandlers); diff --git a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java index 44b74611cbc..96ddf07a51e 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java +++ b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java @@ -227,17 +227,18 @@ public class UrlPathHelper { * @see #getPathWithinApplication */ public String getLookupPathForRequest(HttpServletRequest request) { + String pathWithinApp = getPathWithinApplication(request); // Always use full path within current servlet context? if (this.alwaysUseFullPath || skipServletPathDetermination(request)) { - return getPathWithinApplication(request); + return pathWithinApp; } // Else, use path within current servlet mapping if applicable - String rest = getPathWithinServletMapping(request); + String rest = getPathWithinServletMapping(request, pathWithinApp); if (StringUtils.hasLength(rest)) { return rest; } else { - return getPathWithinApplication(request); + return pathWithinApp; } } @@ -251,6 +252,18 @@ public class UrlPathHelper { return false; } + /** + * Return the path within the servlet mapping for the given request, + * i.e. the part of the request's URL beyond the part that called the servlet, + * or "" if the whole URL has been used to identify the servlet. + * @param request current HTTP request + * @return the path within the servlet mapping, or "" + * @see #getPathWithinServletMapping(HttpServletRequest, String) + */ + public String getPathWithinServletMapping(HttpServletRequest request) { + return getPathWithinServletMapping(request, getPathWithinApplication(request)); + } + /** * Return the path within the servlet mapping for the given request, * i.e. the part of the request's URL beyond the part that called the servlet, @@ -262,11 +275,12 @@ public class UrlPathHelper { *

E.g.: servlet mapping = "/test"; request URI = "/test" -> "". *

E.g.: servlet mapping = "/*.test"; request URI = "/a.test" -> "". * @param request current HTTP request + * @param pathWithinApp a precomputed path within the application * @return the path within the servlet mapping, or "" + * @since 5.2.9 * @see #getLookupPathForRequest */ - public String getPathWithinServletMapping(HttpServletRequest request) { - String pathWithinApp = getPathWithinApplication(request); + protected String getPathWithinServletMapping(HttpServletRequest request, String pathWithinApp) { String servletPath = getServletPath(request); String sanitizedPathWithinApp = getSanitizedPath(pathWithinApp); String path;