Interface SlingHttpServletRequest
-
- All Superinterfaces:
Adaptable,javax.servlet.http.HttpServletRequest,javax.servlet.ServletRequest
- All Known Implementing Classes:
CustomParameterRequest,FormsHandlingRequest,RedirectRequest,SlingHttpServletRequestWrapper
@ProviderType public interface SlingHttpServletRequest extends javax.servlet.http.HttpServletRequest, Adaptable
TheSlingHttpServletRequestdefines the interface to provide client request information to a servlet.Request Parameters Generally request parameters are transmitted as part of the URL string such as
GET /some/path?param=valueor as request data of content type application/x-www-form-urlencoded or multipart/form-data. The Sling Framework must decode parameters transferred as request data and make them available through the various parameter accessor methods. Generally parameters transferred as multipart/form-data will be accessed by one of the methods returningRequestParameterinstances.In any case, the
ServletRequest.getReader()andServletRequest.getInputStream()methods will throw anIllegalStateExceptionif called after any methods returning request parameters if the request content type is either application/x-www-form-urlencoded or multipart/form-data because the request data has already been processed.Starting with Sling API 2.0.6, this interface als extends the
Adaptableinterface.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description @Nullable java.lang.StringgetAuthType()Returns the name of the authentication scheme used to protect the servlet.@Nullable javax.servlet.http.CookiegetCookie(java.lang.String name)Returns the named cookie from the HTTP request ornullif no such cookie exists in the request.@Nullable java.lang.StringgetRemoteUser()Returns the login of the user making this request, if the user has been authenticated, ornullif the user has not been authenticated.@Nullable javax.servlet.RequestDispatchergetRequestDispatcher(@NotNull java.lang.String path, RequestDispatcherOptions options)Returns aRequestDispatcherobject that acts as a wrapper for the resource located at the given path.@Nullable javax.servlet.RequestDispatchergetRequestDispatcher(@NotNull Resource resource)Same asgetRequestDispatcher(Resource,RequestDispatcherOptions)but using empty options.@Nullable javax.servlet.RequestDispatchergetRequestDispatcher(@NotNull Resource resource, RequestDispatcherOptions options)Returns aRequestDispatcherobject that acts as a wrapper for the resource located at the given resource.@Nullable RequestParametergetRequestParameter(@NotNull java.lang.String name)Returns the value of a request parameter as aRequestParameter, ornullif the parameter does not exist.@NotNull java.util.List<RequestParameter>getRequestParameterList()Returns the request parameters as instances of theRequestParameterinterface in the order or the request where the query string parameters are first and the POST request parameters are second.@NotNull RequestParameterMapgetRequestParameterMap()Returns aMapof the parameters of this request.@Nullable RequestParameter[]getRequestParameters(@NotNull java.lang.String name)Returns an array ofRequestParameterobjects containing all of the values the given request parameter has, ornullif the parameter does not exist.@NotNull RequestPathInfogetRequestPathInfo()Returns theRequestPathInfopertaining to this request.@NotNull RequestProgressTrackergetRequestProgressTracker()Returns theRequestProgressTrackerof this request.@NotNull ResourcegetResource()Returns theResourceobject on whose behalf the servlet acts.@Nullable java.util.ResourceBundlegetResourceBundle(java.lang.String baseName, java.util.Locale locale)Returns the resource bundle of the given base name for the given locale.@Nullable java.util.ResourceBundlegetResourceBundle(java.util.Locale locale)Returns the resource bundle for the given locale.@NotNull ResourceResolvergetResourceResolver()Returns theResourceResolverwhich resolved theresourceof this request.@Nullable java.lang.StringgetResponseContentType()Returns the framework preferred content type for the response.@NotNull java.util.Enumeration<java.lang.String>getResponseContentTypes()Gets a list of content types which the framework accepts for the response.java.security.PrincipalgetUserPrincipal()Returns ajava.security.Principalobject containing the name of the current authenticated user.-
Methods inherited from interface javax.servlet.http.HttpServletRequest
authenticate, changeSessionId, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getHttpServletMapping, getIntHeader, getMethod, getPart, getParts, getPathInfo, getPathTranslated, getQueryString, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getTrailerFields, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isTrailerFieldsReady, isUserInRole, login, logout, newPushBuilder, upgrade
-
Methods inherited from interface javax.servlet.ServletRequest
getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, removeAttribute, setAttribute, setCharacterEncoding, startAsync, startAsync
-
-
-
-
Method Detail
-
getResource
@NotNull @NotNull Resource getResource()
Returns theResourceobject on whose behalf the servlet acts.- Returns:
- The
Resourceobject of this request.
-
getResourceResolver
@NotNull @NotNull ResourceResolver getResourceResolver()
Returns theResourceResolverwhich resolved theresourceof this request.- Returns:
- The resource resolver
-
getRequestPathInfo
@NotNull @NotNull RequestPathInfo getRequestPathInfo()
Returns theRequestPathInfopertaining to this request.- Returns:
- the request path info.
-
getRequestParameter
@Nullable @Nullable RequestParameter getRequestParameter(@NotNull @NotNull java.lang.String name)
Returns the value of a request parameter as aRequestParameter, ornullif the parameter does not exist.This method should only be used if the parameter has only one value. If the parameter might have more than one value, use
getRequestParameters(String).If this method is used with a multivalued parameter, the value returned is equal to the first value in the array returned by
getRequestParameters.This method is a shortcut for
getRequestParameterMap().getValue(String).- Parameters:
name- aStringspecifying the name of the parameter- Returns:
- a
RequestParameterrepresenting the single value of the parameter - Throws:
java.lang.IllegalArgumentException- if name isnull.- See Also:
getRequestParameters(String),RequestParameterMap.getValue(String)
-
getRequestParameters
@Nullable @Nullable RequestParameter[] getRequestParameters(@NotNull @NotNull java.lang.String name)
Returns an array ofRequestParameterobjects containing all of the values the given request parameter has, ornullif the parameter does not exist.If the parameter has a single value, the array has a length of 1.
This method is a shortcut for
getRequestParameterMap().getValues(String).- Parameters:
name- aStringcontaining the name of the parameter the value of which is requested- Returns:
- an array of
RequestParameterobjects containing the parameter values. - Throws:
java.lang.IllegalArgumentException- if name isnull.- See Also:
getRequestParameter(String),RequestParameterMap.getValues(String)
-
getRequestParameterMap
@NotNull @NotNull RequestParameterMap getRequestParameterMap()
Returns aMapof the parameters of this request.The values in the returned
Mapare from typeRequestParameterarray (RequestParameter[]).If no parameters exist this method returns an empty
Map.- Returns:
- an immutable
Mapcontaining parameter names as keys and parameter values as map values, or an emptyMapif no parameters exist. The keys in the parameter map are of type String. The values in the parameter map are of typeRequestParameterarray (RequestParameter[]).
-
getRequestParameterList
@NotNull @NotNull java.util.List<RequestParameter> getRequestParameterList()
Returns the request parameters as instances of theRequestParameterinterface in the order or the request where the query string parameters are first and the POST request parameters are second.- Returns:
- The list of
RequestParameterin request declaration order. - Since:
- 2.3 (Sling API Bundle 2.6.0)
-
getRequestDispatcher
@Nullable @Nullable javax.servlet.RequestDispatcher getRequestDispatcher(@NotNull @NotNull java.lang.String path, RequestDispatcherOptions options)Returns aRequestDispatcherobject that acts as a wrapper for the resource located at the given path. ARequestDispatcherobject can be used to include the resource in a response.Returns
nullif aRequestDispatchercannot be returned for any reason.- Parameters:
path- aStringspecifying the pathname to the resource. If it is relative, it must be relative against the current servlet.options- influence the rendering of the included Resource- Returns:
- a
RequestDispatcherobject that acts as a wrapper for theresourceornullif an error occurs preparing the dispatcher.
-
getRequestDispatcher
@Nullable @Nullable javax.servlet.RequestDispatcher getRequestDispatcher(@NotNull @NotNull Resource resource, RequestDispatcherOptions options)Returns aRequestDispatcherobject that acts as a wrapper for the resource located at the given resource. ARequestDispatcherobject can be used to include the resource in a response.Returns
nullif aRequestDispatchercannot be returned for any reason.- Parameters:
resource- TheResourceinstance whose response content may be included by the returned dispatcher.options- influence the rendering of the included Resource- Returns:
- a
RequestDispatcherobject that acts as a wrapper for theresourceornullif an error occurs preparing the dispatcher.
-
getRequestDispatcher
@Nullable @Nullable javax.servlet.RequestDispatcher getRequestDispatcher(@NotNull @NotNull Resource resource)Same asgetRequestDispatcher(Resource,RequestDispatcherOptions)but using empty options.- Parameters:
resource- TheResourceinstance whose response content may be included by the returned dispatcher.- Returns:
- a
RequestDispatcherobject that acts as a wrapper for theresourceornullif an error occurs preparing the dispatcher.
-
getCookie
@Nullable @Nullable javax.servlet.http.Cookie getCookie(java.lang.String name)
Returns the named cookie from the HTTP request ornullif no such cookie exists in the request.- Parameters:
name- The name of the cookie to return.- Returns:
- The named cookie or
nullif no such cookie exists.
-
getResponseContentType
@Nullable @Nullable java.lang.String getResponseContentType()
Returns the framework preferred content type for the response. The content type only includes the MIME type, not the character set.For included resources this method will returned the same string as returned by the
ServletResponse.getContentType()without the character set.- Returns:
- preferred MIME type of the response
-
getResponseContentTypes
@NotNull @NotNull java.util.Enumeration<java.lang.String> getResponseContentTypes()
Gets a list of content types which the framework accepts for the response. This list is ordered with the most preferable types listed first. The content type only includes the MIME type, not the character set.For included resources this method will returned an enumeration containing a single entry which is the same string as returned by the
ServletResponse.getContentType()without the character set.- Returns:
- ordered list of MIME types for the response
-
getResourceBundle
@Nullable @Nullable java.util.ResourceBundle getResourceBundle(java.util.Locale locale)
Returns the resource bundle for the given locale.- Parameters:
locale- the locale for which to retrieve the resource bundle. If this isnull, the locale returned byServletRequest.getLocale()is used to select the resource bundle.- Returns:
- the resource bundle for the given locale
-
getResourceBundle
@Nullable @Nullable java.util.ResourceBundle getResourceBundle(java.lang.String baseName, java.util.Locale locale)Returns the resource bundle of the given base name for the given locale.- Parameters:
baseName- The base name of the resource bundle to returned. If this parameter isnull, the same resource bundle must be returned as if thegetResourceBundle(Locale)method is called.locale- the locale for which to retrieve the resource bundle. If this isnull, the locale returned byServletRequest.getLocale()is used to select the resource bundle.- Returns:
- the resource bundle for the given locale
-
getRequestProgressTracker
@NotNull @NotNull RequestProgressTracker getRequestProgressTracker()
Returns theRequestProgressTrackerof this request.- Returns:
- The request progress tracker.
-
getUserPrincipal
@Nullable java.security.Principal getUserPrincipal()
Returns ajava.security.Principalobject containing the name of the current authenticated user.Note: This method deviates from the parent interface and might return a prinicpal even for anonymous users. Therefore it cannot be used to determine whether the user is authenticated.
- Specified by:
getUserPrincipalin interfacejavax.servlet.http.HttpServletRequest- Returns:
- a
java.security.Principalornull. - See Also:
getAuthType(),getRemoteUser()
-
getAuthType
@Nullable @Nullable java.lang.String getAuthType()
Returns the name of the authentication scheme used to protect the servlet. All servlet containers support basic, form and client certificate authentication, and may additionally support digest authentication. If the request is not authenticatednullis returned.- Specified by:
getAuthTypein interfacejavax.servlet.http.HttpServletRequest- Returns:
- the authentication scheme or {code null}
- See Also:
getRemoteUser(),HttpServletRequest.getAuthType()
-
getRemoteUser
@Nullable @Nullable java.lang.String getRemoteUser()
Returns the login of the user making this request, if the user has been authenticated, ornullif the user has not been authenticated.- Specified by:
getRemoteUserin interfacejavax.servlet.http.HttpServletRequest- Returns:
- a
Stringspecifying the login of the user making this request, ornull - See Also:
getAuthType(),HttpServletRequest.getRemoteUser()
-
-