Class ServletRequestPathUtils
RequestPath
representation of the path when use of
parsed patterns
is enabled or a String path for use with a
PathMatcher
otherwise.- Since:
- 5.3
- Author:
- Rossen Stoyanchev, Stephane Nicoll
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Name of Servlet request attribute that holds the parsedRequestPath
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
clearParsedRequestPath
(ServletRequest request) static Object
getCachedPath
(ServletRequest request) static String
getCachedPathValue
(ServletRequest request) Variant ofgetCachedPath(ServletRequest)
that returns the path for request mapping as a String.static RequestPath
getParsedRequestPath
(ServletRequest request) Return apreviously
parsed and cachedRequestPath
.static String
getServletPathPrefix
(HttpServletRequest request) Check if the Servlet is mapped by a path prefix, and if so return that path prefix.static boolean
hasCachedPath
(ServletRequest request) static boolean
hasParsedRequestPath
(ServletRequest request) Check for apreviously
parsed and cachedRequestPath
.static RequestPath
parse
(HttpServletRequest request) Parse therequestURI
to aRequestPath
.static RequestPath
parseAndCache
(HttpServletRequest request) Variant ofparse(HttpServletRequest)
that also saves the parsed path in the request attributePATH_ATTRIBUTE
.static void
setParsedRequestPath
(RequestPath requestPath, ServletRequest request) Set the cached, parsedRequestPath
to the given value.
-
Field Details
-
PATH_ATTRIBUTE
Name of Servlet request attribute that holds the parsedRequestPath
.
-
-
Constructor Details
-
ServletRequestPathUtils
public ServletRequestPathUtils()
-
-
Method Details
-
parse
Parse therequestURI
to aRequestPath
.The returned
RequestPath
will have both the contextPath and any servletPath prefix omitted from thepathWithinApplication
it exposes.- Since:
- 6.2.12
-
parseAndCache
Variant ofparse(HttpServletRequest)
that also saves the parsed path in the request attributePATH_ATTRIBUTE
. -
getParsedRequestPath
Return apreviously
parsed and cachedRequestPath
.- Throws:
IllegalArgumentException
- if not found
-
setParsedRequestPath
Set the cached, parsedRequestPath
to the given value.- Parameters:
requestPath
- the value to set to, or ifnull
the cache value is cleared.request
- the current request- Since:
- 5.3.3
-
hasParsedRequestPath
Check for apreviously
parsed and cachedRequestPath
. -
clearParsedRequestPath
-
getCachedPath
Return either apre-resolved
String lookupPath or apre-parsed
RequestPath
.In Spring MVC, when at least one
HandlerMapping
has parsedPathPatterns
enabled, theDispatcherServlet
parses and caches theRequestPath
which can be also done even earlier withServletRequestPathFilter
. In other cases whereHandlerMapping
s use String pattern matching withPathMatcher
, the String lookupPath is resolved separately in eachHandlerMapping
.- Parameters:
request
- the current request- Returns:
- a String lookupPath or a
RequestPath
- Throws:
IllegalArgumentException
- if neither is available
-
getCachedPathValue
Variant ofgetCachedPath(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 howUrlPathHelper
that resolved is configured.- Parameters:
request
- the current request- Returns:
- the full request mapping path as a String
-
hasCachedPath
- Parameters:
request
- the current request- Returns:
- whether a pre-resolved or pre-parsed path is available
-
getServletPathPrefix
Check if the Servlet is mapped by a path prefix, and if so return that path prefix.- Parameters:
request
- the current request- Returns:
- the prefix, or
null
if the Servlet is not mapped by prefix - Since:
- 6.2.3
-