Package com.helger.web.scope.impl
Class RequestWebScope
- java.lang.Object
-
- com.helger.scope.AbstractScope
-
- com.helger.web.scope.impl.RequestWebScope
-
- All Implemented Interfaces:
com.helger.commons.id.IHasID<String>,com.helger.datetime.domain.IHasCreationDateTime,com.helger.scope.IRequestScope,com.helger.scope.IScope,IRequestWebScope,IRequestWebScopeWithoutResponse,IWebScope
- Direct Known Subclasses:
RequestWebScopeMultipart
public class RequestWebScope extends com.helger.scope.AbstractScope implements IRequestWebScope
A request web scopes that does not parse multipart requests.- Author:
- Philip Helger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRequestWebScope.IParamValueCleanserThe param value cleanser interface to be used globally.static classRequestWebScope.ParamContainerSpecial implementation ifIRequestParamContainerbased onAttributeContainerAny.
-
Field Summary
Fields Modifier and Type Field Description protected jakarta.servlet.http.HttpServletRequestm_aHttpRequestprotected jakarta.servlet.http.HttpServletResponsem_aHttpResponse
-
Constructor Summary
Constructors Constructor Description RequestWebScope(jakarta.servlet.http.HttpServletRequest aHttpRequest, jakarta.servlet.http.HttpServletResponse aHttpResponse)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.helger.commons.state.EChangeaddSpecialRequestParams()Callback method to add special parameters.StringencodeRedirectURL(String sURL)Encodes the specified URL for use in thesendRedirectmethod or, if encoding is not needed, returns the URL unchanged.StringencodeURL(String sURL)Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.booleanequals(Object o)StringgetContextAndServletPath()StringgetContextPath()LocalDateTimegetCreationDateTime()StringgetFullContextAndServletPath()static RequestWebScope.IParamValueCleansergetParamValueCleanser()jakarta.servlet.http.HttpServletRequestgetRequest()com.helger.servlet.request.IRequestParamMapgetRequestParamMap()jakarta.servlet.http.HttpServletResponsegetResponse()static StringgetWithoutForbiddenChars(String s)Remove all chars from the input that cannot be serialized as XML.static StringgetWithoutForbiddenCharsAndNormalized(String s)First normalize the input according to Unicode rules, so that "O 0xcc 0x88" (O with COMBINING DIAERESIS) becomes "Ö" (Capital O with umlaut).inthashCode()com.helger.commons.http.HttpHeaderMapheaders()voidinitScope()static booleanisFileBasedRequest(String sServletPath)This is a heuristic method to determine whether a request is for a file (e.g. x.jsp) or for a servlet.static booleanisForbiddenParamValueChar(char c)Check if the provided char is forbidden in a request value or not.IRequestParamContainerparams()protected voidpostDestroy()static voidsetParamValueCleanser(RequestWebScope.IParamValueCleanser aParamValueCleanser)Set the param value cleanser function that is applied on all parameter values.StringtoString()-
Methods inherited from class com.helger.scope.AbstractScope
attrs, destroyScope, getID, isDestroyed, isInDestruction, isInPreDestruction, isValid, preDestroy, runAtomic, runAtomic
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.datetime.domain.IHasCreationDateTime
getCreationDate, getCreationTime, hasCreationDateTime, isCreatedAt
-
Methods inherited from interface com.helger.web.scope.IRequestWebScope
getOutputStream
-
Methods inherited from interface com.helger.web.scope.IRequestWebScopeWithoutResponse
areCookiesEnabled, encodeRedirectURL, encodeURL, getAuthType, getBrowserInfo, getCharacterEncoding, getCharset, getContentLength, getContentType, getCookies, getFullContextPath, getFullServerPath, getHttpMethod, getHttpVersion, getLocalAddr, getLocalName, getLocalPort, getMethod, getPathInfo, getPathTranslated, getPathWithinServlet, getPathWithinServletContext, getProtocol, getQueryString, getRemoteAddr, getRemoteHost, getRemotePort, getRemoteUser, getRequestURIDecoded, getRequestURIEncoded, getRequestURLDecoded, getRequestURLEncoded, getScheme, getServerName, getServerPort, getServletPath, getSession, getSessionID, getURIDecoded, getURIEncoded, getURLDecoded, getURLEncoded, getUserAgent, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isSecure, isUserInRole
-
-
-
-
Method Detail
-
getParamValueCleanser
@Nullable public static RequestWebScope.IParamValueCleanser getParamValueCleanser()
- Returns:
- The current value cleanser function. May be
null. By defaultgetWithoutForbiddenCharsAndNormalized(String)is invoked. - Since:
- 9.0.6
- See Also:
setParamValueCleanser(IParamValueCleanser)
-
setParamValueCleanser
public static void setParamValueCleanser(@Nullable RequestWebScope.IParamValueCleanser aParamValueCleanser)
Set the param value cleanser function that is applied on all parameter values. By default onlygetWithoutForbiddenCharsAndNormalized(String)is invoked.- Parameters:
aParamValueCleanser- The function to be applied. May benull. The function itself must be able to handlenullvalues.- Since:
- 9.0.6
- See Also:
getParamValueCleanser()
-
getCreationDateTime
@Nonnull public final LocalDateTime getCreationDateTime()
- Specified by:
getCreationDateTimein interfacecom.helger.datetime.domain.IHasCreationDateTime- Specified by:
getCreationDateTimein interfaceIWebScope- Returns:
- The date and time when this web scope was created. Never
null.
-
addSpecialRequestParams
@OverrideOnDemand @Nonnull protected com.helger.commons.state.EChange addSpecialRequestParams()
Callback method to add special parameters.- Returns:
EChange.CHANGEDif some attributes were added,falseif not. If special attributes were added, existing attributes are kept and will not be overwritten with HTTP servlet request parameters!
-
isForbiddenParamValueChar
public static boolean isForbiddenParamValueChar(char c)
Check if the provided char is forbidden in a request value or not.- Parameters:
c- Char to check- Returns:
trueif it is forbidden,falseif not.- Since:
- 9.0.6
- See Also:
getWithoutForbiddenChars(String)
-
getWithoutForbiddenChars
@Nullable public static String getWithoutForbiddenChars(@Nullable String s)
Remove all chars from the input that cannot be serialized as XML.- Parameters:
s- The source value. May benull.- Returns:
nullif the source value isnull.- Since:
- 9.0.4
- See Also:
isForbiddenParamValueChar(char)
-
getWithoutForbiddenCharsAndNormalized
@Nullable public static String getWithoutForbiddenCharsAndNormalized(@Nullable String s)
First normalize the input according to Unicode rules, so that "O 0xcc 0x88" (O with COMBINING DIAERESIS) becomes "Ö" (Capital O with umlaut).- Parameters:
s- Source string. May benull.- Returns:
nullif the source string isnull.- Since:
- 9.0.6
- See Also:
Normalizer.normalize(CharSequence, java.text.Normalizer.Form),getWithoutForbiddenChars(String)
-
initScope
public final void initScope()
- Specified by:
initScopein interfacecom.helger.scope.IScope
-
postDestroy
protected void postDestroy()
- Overrides:
postDestroyin classcom.helger.scope.AbstractScope
-
headers
@Nonnull public final com.helger.commons.http.HttpHeaderMap headers()
- Specified by:
headersin interfaceIRequestWebScopeWithoutResponse- Returns:
- A cached header map for this request. Never
null. Alterations to this map are visible everywhere. Clone the object if you need to modify it.
-
params
@Nonnull @ReturnsMutableObject public final IRequestParamContainer params()
- Specified by:
paramsin interfaceIRequestWebScopeWithoutResponse- Returns:
- The external URL parameters. Never
null.
-
getRequestParamMap
@Nonnull public final com.helger.servlet.request.IRequestParamMap getRequestParamMap()
- Specified by:
getRequestParamMapin interfaceIRequestWebScopeWithoutResponse- Returns:
- A cached request param map for this request. Never
null.
-
isFileBasedRequest
public static boolean isFileBasedRequest(@Nonnull String sServletPath)
This is a heuristic method to determine whether a request is for a file (e.g. x.jsp) or for a servlet. This method returntrueif the last dot is after the last slash- Parameters:
sServletPath- The non-nullservlet path to check- Returns:
trueif it is assumed that the request is file based,falseif it can be assumed to be a regular servlet.
-
getContextPath
@Nonnull public String getContextPath()
- Specified by:
getContextPathin interfaceIRequestWebScopeWithoutResponse- Returns:
- Returns the portion of the request URI that indicates the context
of the request. The context path always comes first in a request
URI. The path starts with a "/" character but does not end with a
"/" character. For servlets in the default (root) context, this
method returns "". The container does not decode this string. E.g.
/contextor an empty string for the root context. Never with a trailing slash. - See Also:
IRequestWebScopeWithoutResponse.getFullContextPath()
-
getContextAndServletPath
@Nonnull public String getContextAndServletPath()
- Specified by:
getContextAndServletPathin interfaceIRequestWebScopeWithoutResponse- Returns:
- Return the absolute servlet path. E.g.
/context/config.jspor/context/action/
-
getFullContextAndServletPath
@Nonnull public String getFullContextAndServletPath()
- Specified by:
getFullContextAndServletPathin interfaceIRequestWebScopeWithoutResponse- Returns:
- Return the absolute servlet path. E.g.
http://localhost:8080/context/config.jsporhttp://localhost:8080/context/action/
-
getRequest
@Nonnull public final jakarta.servlet.http.HttpServletRequest getRequest()
- Specified by:
getRequestin interfaceIRequestWebScopeWithoutResponse- Returns:
- The underlying HTTP servlet request object. Never
null.
-
getResponse
@Nonnull public final jakarta.servlet.http.HttpServletResponse getResponse()
- Specified by:
getResponsein interfaceIRequestWebScope- Returns:
- The underlying HTTP servlet response object
-
encodeURL
@Nonnull public String encodeURL(@Nonnull String sURL)
Description copied from interface:IRequestWebScopeWithoutResponseEncodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.For robust session tracking, all URLs emitted by a servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.
- Specified by:
encodeURLin interfaceIRequestWebScopeWithoutResponse- Parameters:
sURL- the url to be encoded. May not benull.- Returns:
- the encoded URL if encoding is needed; the unchanged URL otherwise.
-
encodeRedirectURL
@Nonnull public String encodeRedirectURL(@Nonnull String sURL)
Description copied from interface:IRequestWebScopeWithoutResponseEncodes the specified URL for use in thesendRedirectmethod or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is separated from theencodeURLmethod.All URLs sent to the
HttpServletResponse.sendRedirectmethod should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.- Specified by:
encodeRedirectURLin interfaceIRequestWebScopeWithoutResponse- Parameters:
sURL- the url to be encoded.- Returns:
- the encoded URL if encoding is needed; the unchanged URL otherwise.
- See Also:
IRequestWebScopeWithoutResponse.encodeURL(String)
-
equals
public boolean equals(Object o)
- Overrides:
equalsin classcom.helger.scope.AbstractScope
-
hashCode
public int hashCode()
- Overrides:
hashCodein classcom.helger.scope.AbstractScope
-
toString
public String toString()
- Overrides:
toStringin classcom.helger.scope.AbstractScope
-
-