public abstract class ServletRequestPathUtils extends Object
RequestPath
representation of the path when use of
parsed patterns
is enabled or a String path for use with a
PathMatcher
otherwise.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 to a
RequestPath and save it in the request attribute
PATH_ATTRIBUTE for subsequent use with
parsed patterns . |
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
to a
RequestPath
and save it in the request attribute
PATH_ATTRIBUTE
for subsequent use with
parsed patterns
.
The returned RequestPath
will have both the contextPath and any
servletPath prefix omitted from the pathWithinApplication
it exposes.
This method is typically called by the DispatcherServlet
to
if any HandlerMapping
indicates that it uses parsed patterns.
After that the pre-parsed and cached RequestPath
can be accessed
through getParsedRequestPath(ServletRequest)
.
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