From bcdc2503fab69735337bcecb2d4a4d2f65d4f231 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 1 Sep 2020 10:27:04 +0200 Subject: [PATCH 1/2] Avoid repeated calls to getPathWithinApplication from getLookupPathForRequest Closes gh-25669 --- .../web/util/UrlPathHelper.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) 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 bad4e81cd63..fcac7db744e 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -164,17 +164,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) { - 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; } } @@ -198,6 +199,18 @@ public class UrlPathHelper { return getLookupPathForRequest(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, + * 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, @@ -209,11 +222,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; From d62202f464918e44bc2e84404b572ebd395a25f5 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 1 Sep 2020 10:27:36 +0200 Subject: [PATCH 2/2] Polishing --- .../springframework/beans/factory/support/ReplaceOverride.java | 2 +- .../web/server/adapter/WebHttpHandlerBuilder.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java index ea8c3495c54..1b51bf70655 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java @@ -49,7 +49,7 @@ public class ReplaceOverride extends MethodOverride { */ public ReplaceOverride(String methodName, String methodReplacerBeanName) { super(methodName); - Assert.notNull(methodName, "Method replacer bean name must not be null"); + Assert.notNull(methodReplacerBeanName, "Method replacer bean name must not be null"); this.methodReplacerBeanName = methodReplacerBeanName; } 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 7770a76a1b3..3a64308178b 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 @@ -226,7 +226,6 @@ public final class WebHttpHandlerBuilder { } private void updateFilters() { - if (this.filters.isEmpty()) { return; } @@ -349,7 +348,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);