Drop Servlet 4 classpath check

This commit is contained in:
rstoyanchev 2022-10-07 18:14:23 +01:00
parent 1afc1fc90d
commit 16ea4692ba
2 changed files with 13 additions and 32 deletions

View File

@ -249,7 +249,7 @@ public abstract class ServletRequestPathUtils {
if (requestUri == null) {
requestUri = request.getRequestURI();
}
if (UrlPathHelper.servlet4Present) {
String servletPathPrefix = Servlet4Delegate.getServletPathPrefix(request);
if (StringUtils.hasText(servletPathPrefix)) {
if (servletPathPrefix.endsWith("/")) {
@ -257,7 +257,7 @@ public abstract class ServletRequestPathUtils {
}
return new ServletRequestPath(requestUri, request.getContextPath(), servletPathPrefix);
}
}
return RequestPath.parse(requestUri, request.getContextPath());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@ -31,7 +31,6 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@ -61,9 +60,6 @@ public class UrlPathHelper {
*/
public static final String PATH_ATTRIBUTE = UrlPathHelper.class.getName() + ".PATH";
static final boolean servlet4Present =
ClassUtils.hasMethod(HttpServletRequest.class, "getHttpServletMapping");
/**
* Special WebSphere request attribute, indicating the original request URI.
* Preferable over the standard Servlet 2.4 forward attribute on WebSphere,
@ -266,10 +262,12 @@ public class UrlPathHelper {
* or if the servlet has been mapped to root; {@code false} otherwise
*/
private boolean skipServletPathDetermination(HttpServletRequest request) {
if (servlet4Present) {
return Servlet4Delegate.skipServletPathDetermination(request);
HttpServletMapping mapping = (HttpServletMapping) request.getAttribute(RequestDispatcher.INCLUDE_MAPPING);
if (mapping == null) {
mapping = request.getHttpServletMapping();
}
return false;
MappingMatch match = mapping.getMappingMatch();
return (match != null && (!match.equals(MappingMatch.PATH) || mapping.getPattern().equals("/*")));
}
/**
@ -767,21 +765,4 @@ public class UrlPathHelper {
rawPathInstance.setReadOnly();
}
/**
* Inner class to avoid a hard dependency on Servlet 4 {@link HttpServletMapping}
* and {@link MappingMatch} at runtime.
*/
private static class Servlet4Delegate {
public static boolean skipServletPathDetermination(HttpServletRequest request) {
HttpServletMapping mapping = (HttpServletMapping) request.getAttribute(RequestDispatcher.INCLUDE_MAPPING);
if (mapping == null) {
mapping = request.getHttpServletMapping();
}
MappingMatch match = mapping.getMappingMatch();
return (match != null && (!match.equals(MappingMatch.PATH) || mapping.getPattern().equals("/*")));
}
}
}