|
22 | 22 | import java.util.Properties;
|
23 | 23 |
|
24 | 24 | import javax.servlet.ServletRequest;
|
| 25 | +import javax.servlet.http.HttpServletMapping; |
25 | 26 | import javax.servlet.http.HttpServletRequest;
|
26 | 27 | import javax.servlet.http.MappingMatch;
|
27 | 28 |
|
@@ -60,9 +61,8 @@ public class UrlPathHelper {
|
60 | 61 | */
|
61 | 62 | public static final String PATH_ATTRIBUTE = UrlPathHelper.class.getName() + ".PATH";
|
62 | 63 |
|
63 |
| - private static final boolean isServlet4Present = |
64 |
| - ClassUtils.isPresent("javax.servlet.http.HttpServletMapping", |
65 |
| - UrlPathHelper.class.getClassLoader()); |
| 64 | + private static final boolean servlet4Present = |
| 65 | + ClassUtils.hasMethod(HttpServletRequest.class, "getHttpServletMapping"); |
66 | 66 |
|
67 | 67 | /**
|
68 | 68 | * Special WebSphere request attribute, indicating the original request URI.
|
@@ -260,12 +260,15 @@ public String getLookupPathForRequest(HttpServletRequest request) {
|
260 | 260 | }
|
261 | 261 | }
|
262 | 262 |
|
| 263 | + /** |
| 264 | + * Check whether servlet path determination can be skipped for the given request. |
| 265 | + * @param request current HTTP request |
| 266 | + * @return {@code true} if the request mapping has not been achieved using a path |
| 267 | + * or if the servlet has been mapped to root; {@code false} otherwise |
| 268 | + */ |
263 | 269 | private boolean skipServletPathDetermination(HttpServletRequest request) {
|
264 |
| - if (isServlet4Present) { |
265 |
| - if (request.getHttpServletMapping().getMappingMatch() != null) { |
266 |
| - return !request.getHttpServletMapping().getMappingMatch().equals(MappingMatch.PATH) || |
267 |
| - request.getHttpServletMapping().getPattern().equals("/*"); |
268 |
| - } |
| 270 | + if (servlet4Present) { |
| 271 | + return Servlet4Delegate.skipServletPathDetermination(request); |
269 | 272 | }
|
270 | 273 | return false;
|
271 | 274 | }
|
@@ -763,4 +766,18 @@ public String removeSemicolonContent(String requestUri) {
|
763 | 766 | rawPathInstance.setReadOnly();
|
764 | 767 | }
|
765 | 768 |
|
| 769 | + |
| 770 | + /** |
| 771 | + * Inner class to avoid a hard dependency on Servlet 4 {@link HttpServletMapping} |
| 772 | + * and {@link MappingMatch} at runtime. |
| 773 | + */ |
| 774 | + private static class Servlet4Delegate { |
| 775 | + |
| 776 | + public static boolean skipServletPathDetermination(HttpServletRequest request) { |
| 777 | + HttpServletMapping mapping = request.getHttpServletMapping(); |
| 778 | + MappingMatch match = mapping.getMappingMatch(); |
| 779 | + return (match != null && (!match.equals(MappingMatch.PATH) || mapping.getPattern().equals("/*"))); |
| 780 | + } |
| 781 | + } |
| 782 | + |
766 | 783 | }
|
0 commit comments