public abstract class ServletRequestPathUtils extends Object
HttpServletRequest
to a
RequestPath
and cache it in a request attribute for further access.
This can then be used for URL path matching with
PathPattern
s.
Also includes helper methods to return either a previously
resolved
String lookupPath
or a previously parsed
RequestPath
depending
on which is cached in request attributes.
Modifier and Type | Field and Description |
---|---|
static String |
PATH_ATTRIBUTE
Name of Servlet request attribute that holds the parsed
RequestPath . |
Constructor and Description |
---|
ServletRequestPathUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
clearParsedRequestPath(ServletRequest request)
|
static Object |
getCachedPath(ServletRequest request)
|
static String |
getCachedPathValue(ServletRequest request)
Variant of
getCachedPath(ServletRequest) that returns the path
for request mapping as a String. |
static RequestPath |
getParsedRequestPath(ServletRequest request)
Return a
previously parsed and cached RequestPath . |
static boolean |
hasCachedPath(ServletRequest request)
|
static boolean |
hasParsedRequestPath(ServletRequest request)
Check for a
previously parsed and cached RequestPath . |
static RequestPath |
parseAndCache(HttpServletRequest request)
Parse the
requestURI of the
request and its contextPath to create a RequestPath and
cache it in the request attribute PATH_ATTRIBUTE . |
static void |
setParsedRequestPath(RequestPath requestPath,
ServletRequest request)
Set the cached, parsed
RequestPath to the given value. |
public static final String PATH_ATTRIBUTE
RequestPath
.public static RequestPath parseAndCache(HttpServletRequest request)
requestURI
of the
request and its contextPath
to create a RequestPath
and
cache it in the request attribute PATH_ATTRIBUTE
.
This method ignores the servletPath
and the pathInfo
.
Therefore in case of a Servlet mapping by prefix, the
RequestPath.pathWithinApplication()
will always include the
Servlet prefix.
public static RequestPath getParsedRequestPath(ServletRequest request)
previously
parsed and cached RequestPath
.IllegalArgumentException
- if not foundpublic static void setParsedRequestPath(@Nullable RequestPath requestPath, ServletRequest request)
RequestPath
to the given value.requestPath
- the value to set to, or if null
the cache
value is cleared.request
- the current requestpublic static boolean hasParsedRequestPath(ServletRequest request)
previously
parsed and cached RequestPath
.public static void clearParsedRequestPath(ServletRequest request)
public static Object getCachedPath(ServletRequest request)
pre-resolved
String lookupPath or the pre-parsed
RequestPath
.
In Spring MVC, when at least one HandlerMapping
has parsed
PathPatterns
enabled, the DispatcherServlet
eagerly parses
and caches the RequestPath
and the same can be also done earlier with
ServletRequestPathFilter
. In other cases where HandlerMapping
s
use String pattern matching with PathMatcher
, the String
lookupPath is resolved separately by each HandlerMapping
.
request
- the current requestRequestPath
IllegalArgumentException
- if neither is availablepublic static String getCachedPathValue(ServletRequest request)
getCachedPath(ServletRequest)
that returns the path
for request mapping as a String.
If the cached path is a pre-parsed
RequestPath
then the returned String path value is
encoded and with path parameters removed.
If the cached path is a pre-resolved
String lookupPath, then the returned String path value
depends on how UrlPathHelper
that resolved is configured.
request
- the current requestpublic static boolean hasCachedPath(ServletRequest request)
request
- the current request