Shared read-only instance of UrlPathHelper

In many places UrlPathHelper is created and used without any
customizations, in some cases repeatedly. This commit adds a
shared read-only UrlPathHelper instance with default settings.

See gh-25100
This commit is contained in:
Rossen Stoyanchev
2020-05-19 07:38:56 +01:00
parent 92f7587a40
commit 23233c3041
11 changed files with 83 additions and 66 deletions

View File

@@ -83,9 +83,6 @@ import org.springframework.web.util.UrlPathHelper;
public class MockHttpServletRequestBuilder
implements ConfigurableSmartRequestBuilder<MockHttpServletRequestBuilder>, Mergeable {
private static final UrlPathHelper urlPathHelper = new UrlPathHelper();
private final String method;
private final URI url;
@@ -781,7 +778,7 @@ public class MockHttpServletRequestBuilder
}
String extraPath = requestUri.substring(this.contextPath.length() + this.servletPath.length());
this.pathInfo = (StringUtils.hasText(extraPath) ?
urlPathHelper.decodeRequestString(request, extraPath) : null);
UrlPathHelper.defaultInstance.decodeRequestString(request, extraPath) : null);
}
request.setPathInfo(this.pathInfo);
}

View File

@@ -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.
@@ -45,8 +45,6 @@ final class PatternMappingFilterProxy implements Filter {
private static final String PATH_MAPPING_PATTERN = "/*";
private static final UrlPathHelper urlPathHelper = new UrlPathHelper();
private final Filter delegate;
/** Patterns that require an exact match, e.g. "/test" */
@@ -96,7 +94,7 @@ final class PatternMappingFilterProxy implements Filter {
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestPath = urlPathHelper.getPathWithinApplication(httpRequest);
String requestPath = UrlPathHelper.defaultInstance.getPathWithinApplication(httpRequest);
if (matches(requestPath)) {
this.delegate.doFilter(request, response, filterChain);