public class UrlPathHelper
extends java.lang.Object
Used by AbstractUrlHandlerMapping
and RequestContext
for path matching
and/or URI determination.
Modifier and Type | Field and Description |
---|---|
private boolean |
alwaysUseFullPath |
private java.lang.String |
defaultEncoding |
private static Log |
logger |
private boolean |
removeSemicolonContent |
private boolean |
urlDecode |
private static java.lang.String |
WEBSPHERE_URI_ATTRIBUTE
Special WebSphere request attribute, indicating the original request URI.
|
(package private) static java.lang.Boolean |
websphereComplianceFlag |
Constructor and Description |
---|
UrlPathHelper() |
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
decodeAndCleanUriString(HttpServletRequest request,
java.lang.String uri)
Decode the supplied URI string and strips any extraneous portion after a ';'.
|
private java.lang.String |
decodeInternal(HttpServletRequest request,
java.lang.String source) |
MultiValueMap<java.lang.String,java.lang.String> |
decodeMatrixVariables(HttpServletRequest request,
MultiValueMap<java.lang.String,java.lang.String> vars)
Decode the given matrix variables via
decodeRequestString(HttpServletRequest, String) unless
setUrlDecode(boolean) is set to true in which case it is
assumed the URL path from which the variables were extracted is already
decoded through a call to
getLookupPathForRequest(HttpServletRequest) . |
java.util.Map<java.lang.String,java.lang.String> |
decodePathVariables(HttpServletRequest request,
java.util.Map<java.lang.String,java.lang.String> vars)
Decode the given URI path variables via
decodeRequestString(HttpServletRequest, String) unless
setUrlDecode(boolean) is set to true in which case it is
assumed the URL path from which the variables were extracted is already
decoded through a call to
getLookupPathForRequest(HttpServletRequest) . |
java.lang.String |
decodeRequestString(HttpServletRequest request,
java.lang.String source)
Decode the given source string with a URLDecoder.
|
protected java.lang.String |
determineEncoding(HttpServletRequest request)
Determine the encoding for the given request.
|
java.lang.String |
getContextPath(HttpServletRequest request)
Return the context path for the given request, detecting an include request
URL if called within a RequestDispatcher include.
|
protected java.lang.String |
getDefaultEncoding()
Return the default character encoding to use for URL decoding.
|
java.lang.String |
getLookupPathForRequest(HttpServletRequest request)
Return the mapping lookup path for the given request, within the current
servlet mapping if applicable, else within the web application.
|
java.lang.String |
getOriginatingContextPath(HttpServletRequest request)
Return the context path for the given request, detecting an include request
URL if called within a RequestDispatcher include.
|
java.lang.String |
getOriginatingQueryString(HttpServletRequest request)
Return the query string part of the given request's URL.
|
java.lang.String |
getOriginatingRequestUri(HttpServletRequest request)
Return the request URI for the given request.
|
java.lang.String |
getOriginatingServletPath(HttpServletRequest request)
Return the servlet path for the given request, detecting an include request
URL if called within a RequestDispatcher include.
|
java.lang.String |
getPathWithinApplication(HttpServletRequest request)
Return the path within the web application for the given request.
|
java.lang.String |
getPathWithinServletMapping(HttpServletRequest request)
Return the path within the servlet mapping for the given request,
i.e.
|
private java.lang.String |
getRemainingPath(java.lang.String requestUri,
java.lang.String mapping,
boolean ignoreCase)
Match the given "mapping" to the start of the "requestUri" and if there
is a match return the extra part.
|
java.lang.String |
getRequestUri(HttpServletRequest request)
Return the request URI for the given request, detecting an include request
URL if called within a RequestDispatcher include.
|
private java.lang.String |
getSanitizedPath(java.lang.String path)
Sanitize the given path with the following rules:
replace all "//" by "/"
|
java.lang.String |
getServletPath(HttpServletRequest request)
Return the servlet path for the given request, regarding an include request
URL if called within a RequestDispatcher include.
|
private java.lang.String |
removeJsessionid(java.lang.String requestUri) |
java.lang.String |
removeSemicolonContent(java.lang.String requestUri)
Remove ";" (semicolon) content from the given request URI if the
removeSemicolonContent
property is set to "true".
|
private java.lang.String |
removeSemicolonContentInternal(java.lang.String requestUri) |
void |
setAlwaysUseFullPath(boolean alwaysUseFullPath)
Set if URL lookup should always use full path within current servlet
context.
|
void |
setDefaultEncoding(java.lang.String defaultEncoding)
Set the default character encoding to use for URL decoding.
|
void |
setRemoveSemicolonContent(boolean removeSemicolonContent)
Set if ";" (semicolon) content should be stripped from the request URI.
|
void |
setUrlDecode(boolean urlDecode)
Set if context path and request URI should be URL-decoded.
|
boolean |
shouldRemoveSemicolonContent()
Whether configured to remove ";" (semicolon) content from the request URI.
|
private boolean |
shouldRemoveTrailingServletPathSlash(HttpServletRequest request) |
private static final java.lang.String WEBSPHERE_URI_ATTRIBUTE
private static final Log logger
static volatile java.lang.Boolean websphereComplianceFlag
private boolean alwaysUseFullPath
private boolean urlDecode
private boolean removeSemicolonContent
private java.lang.String defaultEncoding
public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
public void setUrlDecode(boolean urlDecode)
Uses either the request encoding or the default encoding according to the Servlet spec (ISO-8859-1).
Default is "true", as of Spring 2.5.
getServletPath(HttpServletRequest)
,
getContextPath(HttpServletRequest)
,
getRequestUri(HttpServletRequest)
,
WebUtils.DEFAULT_CHARACTER_ENCODING
,
javax.servlet.ServletRequest#getCharacterEncoding()
,
URLDecoder.decode(String, String)
public void setRemoveSemicolonContent(boolean removeSemicolonContent)
Default is "true".
public boolean shouldRemoveSemicolonContent()
public void setDefaultEncoding(java.lang.String defaultEncoding)
If the request specifies a character encoding itself, the request
encoding will override this setting. This also allows for generically
overriding the character encoding in a filter that invokes the
ServletRequest.setCharacterEncoding
method.
defaultEncoding
- the character encoding to usedetermineEncoding(HttpServletRequest)
,
javax.servlet.ServletRequest#getCharacterEncoding()
,
javax.servlet.ServletRequest#setCharacterEncoding(String)
,
WebUtils.DEFAULT_CHARACTER_ENCODING
protected java.lang.String getDefaultEncoding()
public java.lang.String getLookupPathForRequest(HttpServletRequest request)
Detects include request URL if called within a RequestDispatcher include.
request
- current HTTP requestgetPathWithinApplication(HttpServletRequest)
,
getPathWithinServletMapping(HttpServletRequest)
public java.lang.String getPathWithinServletMapping(HttpServletRequest request)
Detects include request URL if called within a RequestDispatcher include.
E.g.: servlet mapping = "/*"; request URI = "/test/a" -> "/test/a".
E.g.: servlet mapping = "/"; request URI = "/test/a" -> "/test/a".
E.g.: servlet mapping = "/test/*"; request URI = "/test/a" -> "/a".
E.g.: servlet mapping = "/test"; request URI = "/test" -> "".
E.g.: servlet mapping = "/*.test"; request URI = "/a.test" -> "".
request
- current HTTP requestpublic java.lang.String getPathWithinApplication(HttpServletRequest request)
Detects include request URL if called within a RequestDispatcher include.
request
- current HTTP requestprivate java.lang.String getRemainingPath(java.lang.String requestUri, java.lang.String mapping, boolean ignoreCase)
private java.lang.String getSanitizedPath(java.lang.String path)
public java.lang.String getRequestUri(HttpServletRequest request)
As the value returned by request.getRequestURI()
is not
decoded by the servlet container, this method will decode it.
The URI that the web container resolves should be correct, but some containers like JBoss/Jetty incorrectly include ";" strings like ";jsessionid" in the URI. This method cuts off such incorrect appendices.
request
- current HTTP requestpublic java.lang.String getContextPath(HttpServletRequest request)
As the value returned by request.getContextPath()
is not
decoded by the servlet container, this method will decode it.
request
- current HTTP requestpublic java.lang.String getServletPath(HttpServletRequest request)
As the value returned by request.getServletPath()
is already
decoded by the servlet container, this method will not attempt to decode it.
request
- current HTTP requestpublic java.lang.String getOriginatingRequestUri(HttpServletRequest request)
public java.lang.String getOriginatingContextPath(HttpServletRequest request)
As the value returned by request.getContextPath()
is not
decoded by the servlet container, this method will decode it.
request
- current HTTP requestpublic java.lang.String getOriginatingServletPath(HttpServletRequest request)
request
- current HTTP requestpublic java.lang.String getOriginatingQueryString(HttpServletRequest request)
request
- current HTTP requestprivate java.lang.String decodeAndCleanUriString(HttpServletRequest request, java.lang.String uri)
public java.lang.String decodeRequestString(HttpServletRequest request, java.lang.String source)
The default implementation uses URLDecoder.decode(input, enc)
.
request
- current HTTP requestsource
- the String to decodeWebUtils.DEFAULT_CHARACTER_ENCODING
,
javax.servlet.ServletRequest#getCharacterEncoding
,
URLDecoder.decode(String, String)
,
URLDecoder.decode(String)
private java.lang.String decodeInternal(HttpServletRequest request, java.lang.String source)
protected java.lang.String determineEncoding(HttpServletRequest request)
The default implementation checks the request encoding, falling back to the default encoding specified for this resolver.
request
- current HTTP requestnull
)javax.servlet.ServletRequest#getCharacterEncoding()
,
setDefaultEncoding(java.lang.String)
public java.lang.String removeSemicolonContent(java.lang.String requestUri)
requestUri
- the request URI string to remove ";" content fromprivate java.lang.String removeSemicolonContentInternal(java.lang.String requestUri)
private java.lang.String removeJsessionid(java.lang.String requestUri)
public java.util.Map<java.lang.String,java.lang.String> decodePathVariables(HttpServletRequest request, java.util.Map<java.lang.String,java.lang.String> vars)
decodeRequestString(HttpServletRequest, String)
unless
setUrlDecode(boolean)
is set to true
in which case it is
assumed the URL path from which the variables were extracted is already
decoded through a call to
getLookupPathForRequest(HttpServletRequest)
.request
- current HTTP requestvars
- URI variables extracted from the URL pathpublic MultiValueMap<java.lang.String,java.lang.String> decodeMatrixVariables(HttpServletRequest request, MultiValueMap<java.lang.String,java.lang.String> vars)
decodeRequestString(HttpServletRequest, String)
unless
setUrlDecode(boolean)
is set to true
in which case it is
assumed the URL path from which the variables were extracted is already
decoded through a call to
getLookupPathForRequest(HttpServletRequest)
.request
- current HTTP requestvars
- URI variables extracted from the URL pathprivate boolean shouldRemoveTrailingServletPathSlash(HttpServletRequest request)