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 StringName of Servlet request attribute that holds the parsedRequestPath. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclearParsedRequestPath(ServletRequest request) static ObjectgetCachedPath(ServletRequest request) static StringgetCachedPathValue(ServletRequest request) Variant ofgetCachedPath(ServletRequest)that returns the path for request mapping as a String.static RequestPathgetParsedRequestPath(ServletRequest request) Return apreviouslyparsed and cachedRequestPath.static booleanhasCachedPath(ServletRequest request) static booleanhasParsedRequestPath(ServletRequest request) Check for apreviouslyparsed and cachedRequestPath.static RequestPathparseAndCache(HttpServletRequest request) Parse therequestURIto aRequestPathand save it in the request attributePATH_ATTRIBUTEfor subsequent use withparsed patterns.static voidsetParsedRequestPath(RequestPath requestPath, ServletRequest request) Set the cached, parsedRequestPathto the given value.
-
Field Details
-
PATH_ATTRIBUTE
Name of Servlet request attribute that holds the parsedRequestPath.
-
-
Constructor Details
-
ServletRequestPathUtils
public ServletRequestPathUtils()
-
-
Method Details
-
parseAndCache
Parse therequestURIto aRequestPathand save it in the request attributePATH_ATTRIBUTEfor subsequent use withparsed patterns.The returned
RequestPathwill have both the contextPath and any servletPath prefix omitted from thepathWithinApplicationit exposes.This method is typically called by the
DispatcherServletto determine if anyHandlerMappingindicates that it uses parsed patterns. After that the pre-parsed and cachedRequestPathcan be accessed throughgetParsedRequestPath(ServletRequest). -
getParsedRequestPath
Return apreviouslyparsed and cachedRequestPath.- Throws:
IllegalArgumentException- if not found
-
setParsedRequestPath
Set the cached, parsedRequestPathto the given value.- Parameters:
requestPath- the value to set to, or ifnullthe cache value is cleared.request- the current request- Since:
- 5.3.3
-
hasParsedRequestPath
Check for apreviouslyparsed and cachedRequestPath. -
clearParsedRequestPath
-
getCachedPath
Return either apre-resolvedString lookupPath or apre-parsedRequestPath.In Spring MVC, when at least one
HandlerMappinghas parsedPathPatternsenabled, theDispatcherServletparses and caches theRequestPathwhich can be also done even earlier withServletRequestPathFilter. In other cases whereHandlerMappings 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-parsedRequestPaththen the returned String path value is encoded and with path parameters removed.If the cached path is a
pre-resolvedString lookupPath, then the returned String path value depends on howUrlPathHelperthat 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
-