Class Request
- All Implemented Interfaces:
jakarta.servlet.http.HttpServletRequest
,jakarta.servlet.ServletRequest
Implements HttpServletRequest
from the jakarta.servlet.http
package.
The standard interface of mostly getters, is extended with setters so that the request is mutable by the handlers that it is passed to. This allows the request object to be as lightweight as possible and not actually implement any significant behavior. For example
- the
getContextPath()
method will return null, until the request has been passed to aContextHandler
which matches thegetPathInfo()
with a context path and callssetContext(Context,String)
as a result. For some dispatch types (ie include and named dispatch) the context path may not reflect theServletContext
set bysetContext(Context, String)
. - the HTTP session methods will all return null sessions until such time as a request has been passed to a
SessionHandler
which checks for session cookies and enables the ability to create new sessions. - The
getServletPath()
method will return "" until the request has been passed to aorg.eclipse.jetty.servlet.ServletHandler
and the pathInfo matched against the servlet URL patterns andsetServletPathMapping(ServletPathMapping)
called as a result.
A request instance is created for each connection accepted by the server and recycled for each HTTP request received via that connection. An effort is made to avoid reparsing headers and cookies that are likely to be the same for requests from the same connection.
Request instances are recycled, which combined with badly written asynchronous applications can result in calls on requests that have been reset. The code is written in a style to avoid NPE and ISE when such calls are made, as this has often proved generate exceptions that distraction from debugging such bad asynchronous applications. Instead, request methods attempt to not fail when called in an illegal state, so that hopefully the bad application will proceed to a major state event (eg calling AsyncContext.onComplete) which has better asynchronous guards, true atomic state and better failure behaviour that will assist in debugging.
The form content that a request can process is limited to protect from Denial of Service attacks. The size in bytes is limited by
ContextHandler.getMaxFormContentSize()
or if there is no context then the "org.eclipse.jetty.server.Request.maxFormContentSize" Server
attribute. The number of parameters keys is limited by ContextHandler.getMaxFormKeys()
or if there is no context then the
"org.eclipse.jetty.server.Request.maxFormKeys" Server
attribute.
If IOExceptions or timeouts occur while reading form parameters, these are thrown as unchecked Exceptions: ether RuntimeIOException
,
BadMessageException
or RuntimeException
as appropriate.
-
Field Summary
Fields inherited from interface jakarta.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addEventListener
(EventListener listener) boolean
authenticate
(jakarta.servlet.http.HttpServletResponse response) void
enterSession
(jakarta.servlet.http.HttpSession s) Remember a session that this request has just entered.void
extractFormParameters
(MultiMap<String> params) jakarta.servlet.AsyncContext
getAttribute
(String name) Get Request Attribute.Get the authentication.static Request
getBaseRequest
(jakarta.servlet.ServletRequest request) Obtain the baseRequest
instance of aServletRequest
, by coercion, unwrapping or special attribute.long
Get the nanoTime at which the request arrived to a connector, obtained viaSystem.nanoTime()
.int
long
long
jakarta.servlet.http.Cookie[]
long
getDateHeader
(String name) jakarta.servlet.DispatcherType
getHeaders
(String name) jakarta.servlet.http.HttpServletMapping
int
jakarta.servlet.ServletInputStream
int
getIntHeader
(String name) int
getParameter
(String name) String[]
getParameterValues
(String name) jakarta.servlet.http.Part
Collection<jakarta.servlet.http.Part>
getParts()
Get the path in the context.getRealPath
(String path) Deprecated.Access the underlying RemoteInetSocketAddress
for this request.int
jakarta.servlet.RequestDispatcher
getRequestDispatcher
(String path) Reconstructs the URL the client used to make the request.int
jakarta.servlet.ServletContext
jakarta.servlet.ServletResponse
jakarta.servlet.http.HttpSession
jakarta.servlet.http.HttpSession
getSession
(boolean create) jakarta.servlet.http.HttpSession
getSession
(SessionHandler sessionHandler) Find a session that this request has already entered for the given SessionHandlerlong
Get Request TimeStampboolean
boolean
boolean
boolean
boolean
isHead()
boolean
isPush()
boolean
boolean
boolean
Deprecated.boolean
boolean
boolean
isSecure()
boolean
isUserInRole
(String role) void
void
logout()
void
mergeQueryParameters
(String oldQuery, String newQuery) jakarta.servlet.http.PushBuilder
void
Called when the request is fully finished being handled.void
Called when a response is about to be committed, ie sent back to the clientprotected void
recycle()
void
removeAttribute
(String name) void
removeEventListener
(EventListener listener) void
void
void
setAsyncSupported
(boolean supported, Object source) void
setAttribute
(String name, Object value) Set a request attribute.void
setAttributes
(Attributes attributes) Set the attributes for the request.void
setAuthentication
(Authentication authentication) Set the authentication.void
setCharacterEncoding
(String encoding) void
setCharacterEncodingUnchecked
(String encoding) void
setContentParameters
(MultiMap<String> contentParameters) void
setContentType
(String contentType) void
setContext
(ContextHandler.Context context, String pathInContext) Set request context and path in the context.void
setCookies
(jakarta.servlet.http.Cookie[] cookies) void
setDispatcherType
(jakarta.servlet.DispatcherType type) void
setHandled
(boolean h) void
setHttpFields
(HttpFields fields) void
setHttpURI
(HttpURI uri) void
setMetaData
(MetaData.Request request) void
void
setQueryEncoding
(String queryEncoding) Set the character encoding used for the query string.void
setQueryParameters
(MultiMap<String> queryParameters) void
void
setRequestedSessionId
(String requestedSessionId) void
setRequestedSessionIdFromCookie
(boolean requestedSessionIdCookie) void
setSecure
(boolean secure) void
setServletPathMapping
(ServletPathMapping servletPathMapping) Set the servletPathMapping, the servletPath and the pathInfo.void
setSession
(jakarta.servlet.http.HttpSession session) void
setSessionHandler
(SessionHandler sessionHandler) void
setTimeStamp
(long ts) void
setTrailerHttpFields
(HttpFields trailers) void
jakarta.servlet.AsyncContext
jakarta.servlet.AsyncContext
startAsync
(jakarta.servlet.ServletRequest servletRequest, jakarta.servlet.ServletResponse servletResponse) boolean
toString()
static jakarta.servlet.http.HttpServletRequest
unwrap
(jakarta.servlet.ServletRequest servletRequest) <T extends jakarta.servlet.http.HttpUpgradeHandler>
TMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface jakarta.servlet.http.HttpServletRequest
isTrailerFieldsReady
-
Field Details
-
__MULTIPART_CONFIG_ELEMENT
- See Also:
-
-
Constructor Details
-
Request
-
-
Method Details
-
getBaseRequest
Obtain the baseRequest
instance of aServletRequest
, by coercion, unwrapping or special attribute.- Parameters:
request
- The request- Returns:
- the base
Request
instance of aServletRequest
.
-
getHttpFields
-
setHttpFields
-
getTrailerFields
- Specified by:
getTrailerFields
in interfacejakarta.servlet.http.HttpServletRequest
-
setTrailerHttpFields
-
getTrailerHttpFields
-
getHttpInput
-
isPush
public boolean isPush() -
isPushSupported
public boolean isPushSupported() -
newPushBuilder
public jakarta.servlet.http.PushBuilder newPushBuilder()- Specified by:
newPushBuilder
in interfacejakarta.servlet.http.HttpServletRequest
-
addEventListener
-
enterSession
public void enterSession(jakarta.servlet.http.HttpSession s) Remember a session that this request has just entered.- Parameters:
s
- the session
-
extractFormParameters
-
getAsyncContext
public jakarta.servlet.AsyncContext getAsyncContext()- Specified by:
getAsyncContext
in interfacejakarta.servlet.ServletRequest
-
getHttpChannelState
-
getComplianceViolationListener
-
getAttribute
Get Request Attribute.Also supports jetty specific attributes to gain access to Jetty APIs:
- org.eclipse.jetty.server.Server
- The Jetty Server instance
- org.eclipse.jetty.server.HttpChannel
- The HttpChannel for this request
- org.eclipse.jetty.server.HttpConnection
- The HttpConnection or null if another transport is used
- Specified by:
getAttribute
in interfacejakarta.servlet.ServletRequest
- See Also:
-
ServletRequest.getAttribute(java.lang.String)
-
getAttributeNames
- Specified by:
getAttributeNames
in interfacejakarta.servlet.ServletRequest
-
getAttributes
-
getAuthentication
Get the authentication.- Returns:
- the authentication
-
getAuthType
- Specified by:
getAuthType
in interfacejakarta.servlet.http.HttpServletRequest
-
getCharacterEncoding
- Specified by:
getCharacterEncoding
in interfacejakarta.servlet.ServletRequest
-
getHttpChannel
- Returns:
- Returns the connection.
-
getContentLength
public int getContentLength()- Specified by:
getContentLength
in interfacejakarta.servlet.ServletRequest
-
getContentLengthLong
public long getContentLengthLong()- Specified by:
getContentLengthLong
in interfacejakarta.servlet.ServletRequest
-
getContentRead
public long getContentRead() -
getContentType
- Specified by:
getContentType
in interfacejakarta.servlet.ServletRequest
-
getContext
- Returns:
- The current
context
used for this request, ornull
ifsetContext(org.eclipse.jetty.server.handler.ContextHandler.Context, java.lang.String)
has not yet been called.
-
getErrorContext
- Returns:
- The current
context
used for this error handling for this request. If the request is asynchronous, then it is the context that called async. Otherwise it is the last non-null context passed to #setContext
-
getContextPath
- Specified by:
getContextPath
in interfacejakarta.servlet.http.HttpServletRequest
-
getPathInContext
Get the path in the context. The path relative to the context path, analogous togetServletPath()
+getPathInfo()
. If no context is set, then the path in context is the full path.- Returns:
- The decoded part of the
getRequestURI()
path after anygetContextPath()
up to anygetQueryString()
, excluding path parameters. - See Also:
-
getCookies
public jakarta.servlet.http.Cookie[] getCookies()- Specified by:
getCookies
in interfacejakarta.servlet.http.HttpServletRequest
-
getDateHeader
- Specified by:
getDateHeader
in interfacejakarta.servlet.http.HttpServletRequest
-
getDispatcherType
public jakarta.servlet.DispatcherType getDispatcherType()- Specified by:
getDispatcherType
in interfacejakarta.servlet.ServletRequest
-
getHeader
- Specified by:
getHeader
in interfacejakarta.servlet.http.HttpServletRequest
-
getHeaderNames
- Specified by:
getHeaderNames
in interfacejakarta.servlet.http.HttpServletRequest
-
getHeaders
- Specified by:
getHeaders
in interfacejakarta.servlet.http.HttpServletRequest
-
getInputState
public int getInputState()- Returns:
- Returns the inputState.
-
getInputStream
- Specified by:
getInputStream
in interfacejakarta.servlet.ServletRequest
- Throws:
IOException
-
getIntHeader
- Specified by:
getIntHeader
in interfacejakarta.servlet.http.HttpServletRequest
-
getLocale
- Specified by:
getLocale
in interfacejakarta.servlet.ServletRequest
-
getLocales
- Specified by:
getLocales
in interfacejakarta.servlet.ServletRequest
-
getLocalAddr
- Specified by:
getLocalAddr
in interfacejakarta.servlet.ServletRequest
-
getLocalName
- Specified by:
getLocalName
in interfacejakarta.servlet.ServletRequest
-
getLocalPort
public int getLocalPort()- Specified by:
getLocalPort
in interfacejakarta.servlet.ServletRequest
-
getMethod
- Specified by:
getMethod
in interfacejakarta.servlet.http.HttpServletRequest
-
getParameter
- Specified by:
getParameter
in interfacejakarta.servlet.ServletRequest
-
getParameterMap
- Specified by:
getParameterMap
in interfacejakarta.servlet.ServletRequest
-
getParameterNames
- Specified by:
getParameterNames
in interfacejakarta.servlet.ServletRequest
-
getParameterValues
- Specified by:
getParameterValues
in interfacejakarta.servlet.ServletRequest
-
getQueryParameters
-
setQueryParameters
-
setContentParameters
-
resetParameters
public void resetParameters() -
getPathInfo
- Specified by:
getPathInfo
in interfacejakarta.servlet.http.HttpServletRequest
-
getPathTranslated
- Specified by:
getPathTranslated
in interfacejakarta.servlet.http.HttpServletRequest
-
getProtocol
- Specified by:
getProtocol
in interfacejakarta.servlet.ServletRequest
-
getHttpVersion
-
getQueryEncoding
-
getQueryString
- Specified by:
getQueryString
in interfacejakarta.servlet.http.HttpServletRequest
-
getReader
- Specified by:
getReader
in interfacejakarta.servlet.ServletRequest
- Throws:
IOException
-
getRealPath
Deprecated.- Specified by:
getRealPath
in interfacejakarta.servlet.ServletRequest
-
getRemoteInetSocketAddress
Access the underlying RemoteInetSocketAddress
for this request.- Returns:
- the remote
InetSocketAddress
for this request, or null if the request has no remote (seeServletRequest.getRemoteAddr()
for conditions that result in no remote address)
-
getRemoteAddr
- Specified by:
getRemoteAddr
in interfacejakarta.servlet.ServletRequest
-
getRemoteHost
- Specified by:
getRemoteHost
in interfacejakarta.servlet.ServletRequest
-
getRemotePort
public int getRemotePort()- Specified by:
getRemotePort
in interfacejakarta.servlet.ServletRequest
-
getRemoteUser
- Specified by:
getRemoteUser
in interfacejakarta.servlet.http.HttpServletRequest
-
getRequestDispatcher
- Specified by:
getRequestDispatcher
in interfacejakarta.servlet.ServletRequest
-
getRequestedSessionId
- Specified by:
getRequestedSessionId
in interfacejakarta.servlet.http.HttpServletRequest
-
getRequestURI
- Specified by:
getRequestURI
in interfacejakarta.servlet.http.HttpServletRequest
-
getRequestURL
- Specified by:
getRequestURL
in interfacejakarta.servlet.http.HttpServletRequest
-
getResponse
-
getRootURL
Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and, but it does not include a path.Because this method returns a
StringBuffer
, not a string, you can modify the URL easily, for example, to append path and query parameters. This method is useful for creating redirect messages and for reporting errors.- Returns:
- "scheme://host:port"
-
getScheme
- Specified by:
getScheme
in interfacejakarta.servlet.ServletRequest
-
getServerName
- Specified by:
getServerName
in interfacejakarta.servlet.ServletRequest
-
getServerPort
public int getServerPort()- Specified by:
getServerPort
in interfacejakarta.servlet.ServletRequest
-
getServletContext
public jakarta.servlet.ServletContext getServletContext()- Specified by:
getServletContext
in interfacejakarta.servlet.ServletRequest
-
getServletName
-
getServletPath
- Specified by:
getServletPath
in interfacejakarta.servlet.http.HttpServletRequest
-
getServletResponse
public jakarta.servlet.ServletResponse getServletResponse() -
changeSessionId
- Specified by:
changeSessionId
in interfacejakarta.servlet.http.HttpServletRequest
-
onCompleted
public void onCompleted()Called when the request is fully finished being handled. For every session in any context that the session has accessed, ensure that the session is completed. -
onResponseCommit
public void onResponseCommit()Called when a response is about to be committed, ie sent back to the client -
getSession
Find a session that this request has already entered for the given SessionHandler- Parameters:
sessionHandler
- the SessionHandler (ie context) to check- Returns:
- the session for the passed session handler or null
-
getSession
public jakarta.servlet.http.HttpSession getSession()- Specified by:
getSession
in interfacejakarta.servlet.http.HttpServletRequest
-
getSession
public jakarta.servlet.http.HttpSession getSession(boolean create) - Specified by:
getSession
in interfacejakarta.servlet.http.HttpServletRequest
-
getSessionHandler
- Returns:
- Returns the sessionManager.
-
getTimeStamp
public long getTimeStamp()Get Request TimeStamp- Returns:
- The time that the request was received.
-
getHttpURI
-
setHttpURI
-
getOriginalURI
- Returns:
- Returns the original uri passed in metadata before customization/rewrite
-
getUserIdentity
-
getResolvedUserIdentity
- Returns:
- The resolved user Identity, which may be null if the
Authentication
is notAuthentication.User
(eg.Authentication.Deferred
).
-
getUserIdentityScope
-
getUserPrincipal
- Specified by:
getUserPrincipal
in interfacejakarta.servlet.http.HttpServletRequest
-
isHandled
public boolean isHandled() -
isAsyncStarted
public boolean isAsyncStarted()- Specified by:
isAsyncStarted
in interfacejakarta.servlet.ServletRequest
-
isAsyncSupported
public boolean isAsyncSupported()- Specified by:
isAsyncSupported
in interfacejakarta.servlet.ServletRequest
-
isRequestedSessionIdFromCookie
public boolean isRequestedSessionIdFromCookie()- Specified by:
isRequestedSessionIdFromCookie
in interfacejakarta.servlet.http.HttpServletRequest
-
isRequestedSessionIdFromUrl
Deprecated.- Specified by:
isRequestedSessionIdFromUrl
in interfacejakarta.servlet.http.HttpServletRequest
-
isRequestedSessionIdFromURL
public boolean isRequestedSessionIdFromURL()- Specified by:
isRequestedSessionIdFromURL
in interfacejakarta.servlet.http.HttpServletRequest
-
isRequestedSessionIdValid
public boolean isRequestedSessionIdValid()- Specified by:
isRequestedSessionIdValid
in interfacejakarta.servlet.http.HttpServletRequest
-
isSecure
public boolean isSecure()- Specified by:
isSecure
in interfacejakarta.servlet.ServletRequest
-
setSecure
public void setSecure(boolean secure) -
getBeginNanoTime
public long getBeginNanoTime()Get the nanoTime at which the request arrived to a connector, obtained via
System.nanoTime()
. This method can be used when measuring latencies.- Returns:
- The nanoTime at which the request was received/created in nanoseconds
-
isUserInRole
- Specified by:
isUserInRole
in interfacejakarta.servlet.http.HttpServletRequest
-
setMetaData
- Parameters:
request
- the Request metadata
-
getMetaData
-
hasMetaData
public boolean hasMetaData() -
recycle
protected void recycle() -
removeAttribute
- Specified by:
removeAttribute
in interfacejakarta.servlet.ServletRequest
-
removeEventListener
-
setAsyncSupported
-
setAttribute
Set a request attribute. if the attribute name is "org.eclipse.jetty.server.server.Request.queryEncoding" then the value is also passed in a call tosetQueryEncoding(java.lang.String)
.- Specified by:
setAttribute
in interfacejakarta.servlet.ServletRequest
- See Also:
-
ServletRequest.setAttribute(java.lang.String, java.lang.Object)
-
setAttributes
Set the attributes for the request.- Parameters:
attributes
- The attributes, which must be aAttributes.Wrapper
for whichAttributes.unwrap(Attributes)
will return the originalServletAttributes
.
-
setAsyncAttributes
public void setAsyncAttributes() -
setAuthentication
Set the authentication.- Parameters:
authentication
- the authentication to set
-
setCharacterEncoding
- Specified by:
setCharacterEncoding
in interfacejakarta.servlet.ServletRequest
- Throws:
UnsupportedEncodingException
-
setCharacterEncodingUnchecked
-
setContentType
-
setContext
Set request context and path in the context.- Parameters:
context
- context objectpathInContext
- the part of the URI path that is withing the context. For servlets, this is equal to servletPath + pathInfo
-
takeNewContext
public boolean takeNewContext()- Returns:
- True if this is the first call of
takeNewContext()
since the lastsetContext(org.eclipse.jetty.server.handler.ContextHandler.Context, String)
call.
-
setCookies
public void setCookies(jakarta.servlet.http.Cookie[] cookies) - Parameters:
cookies
- The cookies to set.
-
setDispatcherType
public void setDispatcherType(jakarta.servlet.DispatcherType type) -
setHandled
public void setHandled(boolean h) -
setMethod
- Parameters:
method
- The method to set.
-
isHead
public boolean isHead() -
setQueryEncoding
Set the character encoding used for the query string. This call will effect the return of getQueryString and getParamaters. It must be called before any getParameter methods. The request attribute "org.eclipse.jetty.server.Request.queryEncoding" may be set as an alternate method of calling setQueryEncoding.- Parameters:
queryEncoding
- the URI query character encoding
-
setRemoteAddr
- Parameters:
addr
- The address to set.
-
setRequestedSessionId
- Parameters:
requestedSessionId
- The requestedSessionId to set.
-
setRequestedSessionIdFromCookie
public void setRequestedSessionIdFromCookie(boolean requestedSessionIdCookie) - Parameters:
requestedSessionIdCookie
- The requestedSessionIdCookie to set.
-
setSession
public void setSession(jakarta.servlet.http.HttpSession session) - Parameters:
session
- The session to set.
-
setSessionHandler
- Parameters:
sessionHandler
- The SessionHandler to set.
-
setTimeStamp
public void setTimeStamp(long ts) -
setUserIdentityScope
-
startAsync
- Specified by:
startAsync
in interfacejakarta.servlet.ServletRequest
- Throws:
IllegalStateException
-
startAsync
public jakarta.servlet.AsyncContext startAsync(jakarta.servlet.ServletRequest servletRequest, jakarta.servlet.ServletResponse servletResponse) throws IllegalStateException - Specified by:
startAsync
in interfacejakarta.servlet.ServletRequest
- Throws:
IllegalStateException
-
unwrap
public static jakarta.servlet.http.HttpServletRequest unwrap(jakarta.servlet.ServletRequest servletRequest) -
toString
-
authenticate
public boolean authenticate(jakarta.servlet.http.HttpServletResponse response) throws IOException, jakarta.servlet.ServletException - Specified by:
authenticate
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
IOException
jakarta.servlet.ServletException
-
getPart
public jakarta.servlet.http.Part getPart(String name) throws IOException, jakarta.servlet.ServletException - Specified by:
getPart
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
IOException
jakarta.servlet.ServletException
-
getParts
public Collection<jakarta.servlet.http.Part> getParts() throws IOException, jakarta.servlet.ServletException- Specified by:
getParts
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
IOException
jakarta.servlet.ServletException
-
login
- Specified by:
login
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
jakarta.servlet.ServletException
-
logout
public void logout() throws jakarta.servlet.ServletException- Specified by:
logout
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
jakarta.servlet.ServletException
-
mergeQueryParameters
-
upgrade
public <T extends jakarta.servlet.http.HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, jakarta.servlet.ServletException - Specified by:
upgrade
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
IOException
jakarta.servlet.ServletException
-
setServletPathMapping
Set the servletPathMapping, the servletPath and the pathInfo.- Parameters:
servletPathMapping
- The mapping used to return fromgetHttpServletMapping()
-
getServletPathMapping
- Returns:
- The mapping for the current target servlet, regardless of dispatch type.
-
getHttpServletMapping
public jakarta.servlet.http.HttpServletMapping getHttpServletMapping()- Specified by:
getHttpServletMapping
in interfacejakarta.servlet.http.HttpServletRequest
-