public class Request
extends java.lang.Object
implements javax.servlet.http.HttpServletRequest
Implements HttpServletRequest
from the javax.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
getContextPath()
method will return null, until the request has been passed to a ContextHandler
which matches the
getPathInfo()
with a context path and calls setContextPath(String)
as a result.SessionHandler
which checks for session cookies and enables the ability to create new sessions.getServletPath()
method will return null until the request has been passed to a org.eclipse.jetty.servlet.ServletHandler
and the pathInfo matched against the servlet URL patterns and setServletPath(String)
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.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
__MULTIPART_CONFIG_ELEMENT |
static java.lang.String |
__MULTIPARTS |
Constructor and Description |
---|
Request(HttpChannel channel,
HttpInput input) |
Modifier and Type | Method and Description |
---|---|
void |
addEventListener(java.util.EventListener listener) |
boolean |
authenticate(javax.servlet.http.HttpServletResponse response) |
java.lang.String |
changeSessionId() |
void |
extractFormParameters(MultiMap<java.lang.String> params) |
javax.servlet.AsyncContext |
getAsyncContext() |
java.lang.Object |
getAttribute(java.lang.String name)
Get Request Attribute.
|
java.util.Enumeration<java.lang.String> |
getAttributeNames() |
Attributes |
getAttributes() |
Authentication |
getAuthentication()
Get the authentication.
|
java.lang.String |
getAuthType() |
static Request |
getBaseRequest(javax.servlet.ServletRequest request)
Obtain the base
Request instance of a ServletRequest , by
coercion, unwrapping or special attribute. |
java.lang.String |
getCharacterEncoding() |
int |
getContentLength() |
long |
getContentLengthLong() |
long |
getContentRead() |
java.lang.String |
getContentType() |
ContextHandler.Context |
getContext() |
java.lang.String |
getContextPath() |
javax.servlet.http.Cookie[] |
getCookies() |
long |
getDateHeader(java.lang.String name) |
javax.servlet.DispatcherType |
getDispatcherType() |
java.lang.String |
getHeader(java.lang.String name) |
java.util.Enumeration<java.lang.String> |
getHeaderNames() |
java.util.Enumeration<java.lang.String> |
getHeaders(java.lang.String name) |
HttpChannel |
getHttpChannel() |
HttpChannelState |
getHttpChannelState() |
HttpFields |
getHttpFields() |
HttpInput |
getHttpInput() |
HttpURI |
getHttpURI() |
HttpVersion |
getHttpVersion() |
int |
getInputState() |
javax.servlet.ServletInputStream |
getInputStream() |
int |
getIntHeader(java.lang.String name) |
java.lang.String |
getLocalAddr() |
java.util.Locale |
getLocale() |
java.util.Enumeration<java.util.Locale> |
getLocales() |
java.lang.String |
getLocalName() |
int |
getLocalPort() |
MetaData.Request |
getMetaData() |
java.lang.String |
getMethod() |
java.lang.String |
getOriginalURI() |
java.lang.String |
getParameter(java.lang.String name) |
java.util.Map<java.lang.String,java.lang.String[]> |
getParameterMap() |
java.util.Enumeration<java.lang.String> |
getParameterNames() |
java.lang.String[] |
getParameterValues(java.lang.String name) |
javax.servlet.http.Part |
getPart(java.lang.String name) |
java.util.Collection<javax.servlet.http.Part> |
getParts() |
java.lang.String |
getPathInfo() |
java.lang.String |
getPathTranslated() |
java.lang.String |
getProtocol() |
PushBuilder |
getPushBuilder()
Get a PushBuilder associated with this request initialized as follows:
The method is initialized to "GET"
The headers from this request are copied to the Builder, except for:
Conditional headers (eg.
|
java.lang.String |
getQueryEncoding() |
MultiMap<java.lang.String> |
getQueryParameters() |
java.lang.String |
getQueryString() |
java.io.BufferedReader |
getReader() |
java.lang.String |
getRealPath(java.lang.String path) |
java.lang.String |
getRemoteAddr() |
java.lang.String |
getRemoteHost() |
java.net.InetSocketAddress |
getRemoteInetSocketAddress()
Access the underlying Remote
InetSocketAddress for this request. |
int |
getRemotePort() |
java.lang.String |
getRemoteUser() |
javax.servlet.RequestDispatcher |
getRequestDispatcher(java.lang.String path) |
java.lang.String |
getRequestedSessionId() |
java.lang.String |
getRequestURI() |
java.lang.StringBuffer |
getRequestURL() |
UserIdentity |
getResolvedUserIdentity() |
Response |
getResponse() |
java.lang.StringBuilder |
getRootURL()
Reconstructs the URL the client used to make the request.
|
java.lang.String |
getScheme() |
java.lang.String |
getServerName() |
int |
getServerPort() |
javax.servlet.ServletContext |
getServletContext() |
java.lang.String |
getServletName() |
java.lang.String |
getServletPath() |
javax.servlet.ServletResponse |
getServletResponse() |
javax.servlet.http.HttpSession |
getSession() |
javax.servlet.http.HttpSession |
getSession(boolean create) |
SessionHandler |
getSessionHandler() |
long |
getTimeStamp()
Get Request TimeStamp
|
HttpFields |
getTrailers() |
UserIdentity |
getUserIdentity() |
UserIdentity.Scope |
getUserIdentityScope() |
java.security.Principal |
getUserPrincipal() |
boolean |
hasMetaData() |
boolean |
isAsyncStarted() |
boolean |
isAsyncSupported() |
boolean |
isHandled() |
boolean |
isHead() |
boolean |
isPush() |
boolean |
isPushSupported() |
boolean |
isRequestedSessionIdFromCookie() |
boolean |
isRequestedSessionIdFromUrl() |
boolean |
isRequestedSessionIdFromURL() |
boolean |
isRequestedSessionIdValid() |
boolean |
isSecure() |
boolean |
isUserInRole(java.lang.String role) |
void |
login(java.lang.String username,
java.lang.String password) |
void |
logout() |
void |
mergeQueryParameters(java.lang.String oldQuery,
java.lang.String newQuery,
boolean updateQueryString) |
protected void |
recycle() |
void |
removeAttribute(java.lang.String name) |
void |
removeEventListener(java.util.EventListener listener) |
void |
resetParameters() |
void |
setAsyncSupported(boolean supported,
java.lang.String source) |
void |
setAttribute(java.lang.String name,
java.lang.Object value) |
void |
setAttributes(Attributes attributes) |
void |
setAuthentication(Authentication authentication)
Set the authentication.
|
void |
setAuthority(java.lang.String host,
int port) |
void |
setCharacterEncoding(java.lang.String encoding) |
void |
setCharacterEncodingUnchecked(java.lang.String encoding) |
void |
setContentParameters(MultiMap<java.lang.String> contentParameters) |
void |
setContentType(java.lang.String contentType) |
void |
setContext(ContextHandler.Context context)
Set request context
|
void |
setContextPath(java.lang.String contextPath)
Sets the "context path" for this request
|
void |
setCookies(javax.servlet.http.Cookie[] cookies) |
void |
setDispatcherType(javax.servlet.DispatcherType type) |
void |
setHandled(boolean h) |
void |
setHttpURI(HttpURI uri) |
void |
setHttpVersion(HttpVersion version) |
void |
setMetaData(MetaData.Request request) |
void |
setMethod(java.lang.String method) |
void |
setPathInfo(java.lang.String pathInfo) |
void |
setQueryEncoding(java.lang.String queryEncoding)
Set the character encoding used for the query string.
|
void |
setQueryParameters(MultiMap<java.lang.String> queryParameters) |
void |
setQueryString(java.lang.String queryString) |
void |
setRemoteAddr(java.net.InetSocketAddress addr) |
void |
setRequestedSessionId(java.lang.String requestedSessionId) |
void |
setRequestedSessionIdFromCookie(boolean requestedSessionIdCookie) |
void |
setScheme(java.lang.String scheme) |
void |
setSecure(boolean secure) |
void |
setServletPath(java.lang.String servletPath) |
void |
setSession(javax.servlet.http.HttpSession session) |
void |
setSessionHandler(SessionHandler sessionHandler) |
void |
setTimeStamp(long ts) |
void |
setURIPathQuery(java.lang.String requestURI) |
void |
setUserIdentityScope(UserIdentity.Scope scope) |
javax.servlet.AsyncContext |
startAsync() |
javax.servlet.AsyncContext |
startAsync(javax.servlet.ServletRequest servletRequest,
javax.servlet.ServletResponse servletResponse) |
boolean |
takeNewContext() |
java.lang.String |
toString() |
<T extends javax.servlet.http.HttpUpgradeHandler> |
upgrade(java.lang.Class<T> handlerClass) |
public static final java.lang.String __MULTIPART_CONFIG_ELEMENT
public static final java.lang.String __MULTIPARTS
public Request(HttpChannel channel, HttpInput input)
public static Request getBaseRequest(javax.servlet.ServletRequest request)
Request
instance of a ServletRequest
, by
coercion, unwrapping or special attribute.request
- The requestRequest
instance of a ServletRequest
.public HttpFields getHttpFields()
public HttpFields getTrailers()
public HttpInput getHttpInput()
public boolean isPush()
public boolean isPushSupported()
public PushBuilder getPushBuilder()
getQueryString()
getRequestedSessionId()
value, unless at the time
of the call getSession(boolean)
has previously been called to create a new HttpSession
, in
which case the new session ID will be used as the PushBuilders
requested session ID.getRequestURL()
plus any getQueryString()
HttpServletResponse.addCookie(Cookie)
has been called
on the associated response, then a corresponding Cookie header will be added
to the PushBuilder, unless the Cookie.getMaxAge()
is <=0, in which
case the Cookie will be removed from the builder.PushBuilderImpl.isConditional()
header is set
to true.
Each call to getPushBuilder() will return a new instance of a PushBuilder based off this Request. Any mutations to the returned PushBuilder are not reflected on future returns.
public void addEventListener(java.util.EventListener listener)
public void extractFormParameters(MultiMap<java.lang.String> params)
public javax.servlet.AsyncContext getAsyncContext()
getAsyncContext
in interface javax.servlet.ServletRequest
public HttpChannelState getHttpChannelState()
public java.lang.Object getAttribute(java.lang.String name)
Also supports jetty specific attributes to gain access to Jetty APIs:
getAttribute
in interface javax.servlet.ServletRequest
ServletRequest.getAttribute(java.lang.String)
public java.util.Enumeration<java.lang.String> getAttributeNames()
getAttributeNames
in interface javax.servlet.ServletRequest
public Attributes getAttributes()
public Authentication getAuthentication()
public java.lang.String getAuthType()
getAuthType
in interface javax.servlet.http.HttpServletRequest
public java.lang.String getCharacterEncoding()
getCharacterEncoding
in interface javax.servlet.ServletRequest
public HttpChannel getHttpChannel()
public int getContentLength()
getContentLength
in interface javax.servlet.ServletRequest
public long getContentLengthLong()
getContentLengthLong
in interface javax.servlet.ServletRequest
public long getContentRead()
public java.lang.String getContentType()
getContentType
in interface javax.servlet.ServletRequest
public ContextHandler.Context getContext()
context
used for this request, or null
if setContext(org.eclipse.jetty.server.handler.ContextHandler.Context)
has not yet been called.public java.lang.String getContextPath()
getContextPath
in interface javax.servlet.http.HttpServletRequest
public javax.servlet.http.Cookie[] getCookies()
getCookies
in interface javax.servlet.http.HttpServletRequest
public long getDateHeader(java.lang.String name)
getDateHeader
in interface javax.servlet.http.HttpServletRequest
public javax.servlet.DispatcherType getDispatcherType()
getDispatcherType
in interface javax.servlet.ServletRequest
public java.lang.String getHeader(java.lang.String name)
getHeader
in interface javax.servlet.http.HttpServletRequest
public java.util.Enumeration<java.lang.String> getHeaderNames()
getHeaderNames
in interface javax.servlet.http.HttpServletRequest
public java.util.Enumeration<java.lang.String> getHeaders(java.lang.String name)
getHeaders
in interface javax.servlet.http.HttpServletRequest
public int getInputState()
public javax.servlet.ServletInputStream getInputStream() throws java.io.IOException
getInputStream
in interface javax.servlet.ServletRequest
java.io.IOException
public int getIntHeader(java.lang.String name)
getIntHeader
in interface javax.servlet.http.HttpServletRequest
public java.util.Locale getLocale()
getLocale
in interface javax.servlet.ServletRequest
public java.util.Enumeration<java.util.Locale> getLocales()
getLocales
in interface javax.servlet.ServletRequest
public java.lang.String getLocalAddr()
getLocalAddr
in interface javax.servlet.ServletRequest
public java.lang.String getLocalName()
getLocalName
in interface javax.servlet.ServletRequest
public int getLocalPort()
getLocalPort
in interface javax.servlet.ServletRequest
public java.lang.String getMethod()
getMethod
in interface javax.servlet.http.HttpServletRequest
public java.lang.String getParameter(java.lang.String name)
getParameter
in interface javax.servlet.ServletRequest
public java.util.Map<java.lang.String,java.lang.String[]> getParameterMap()
getParameterMap
in interface javax.servlet.ServletRequest
public java.util.Enumeration<java.lang.String> getParameterNames()
getParameterNames
in interface javax.servlet.ServletRequest
public java.lang.String[] getParameterValues(java.lang.String name)
getParameterValues
in interface javax.servlet.ServletRequest
public MultiMap<java.lang.String> getQueryParameters()
public void setQueryParameters(MultiMap<java.lang.String> queryParameters)
public void setContentParameters(MultiMap<java.lang.String> contentParameters)
public void resetParameters()
public java.lang.String getPathInfo()
getPathInfo
in interface javax.servlet.http.HttpServletRequest
public java.lang.String getPathTranslated()
getPathTranslated
in interface javax.servlet.http.HttpServletRequest
public java.lang.String getProtocol()
getProtocol
in interface javax.servlet.ServletRequest
public HttpVersion getHttpVersion()
public java.lang.String getQueryEncoding()
public java.lang.String getQueryString()
getQueryString
in interface javax.servlet.http.HttpServletRequest
public java.io.BufferedReader getReader() throws java.io.IOException
getReader
in interface javax.servlet.ServletRequest
java.io.IOException
public java.lang.String getRealPath(java.lang.String path)
getRealPath
in interface javax.servlet.ServletRequest
public java.net.InetSocketAddress getRemoteInetSocketAddress()
InetSocketAddress
for this request.InetSocketAddress
for this request, or null if the request has no remote (see ServletRequest.getRemoteAddr()
for
conditions that result in no remote address)public java.lang.String getRemoteAddr()
getRemoteAddr
in interface javax.servlet.ServletRequest
public java.lang.String getRemoteHost()
getRemoteHost
in interface javax.servlet.ServletRequest
public int getRemotePort()
getRemotePort
in interface javax.servlet.ServletRequest
public java.lang.String getRemoteUser()
getRemoteUser
in interface javax.servlet.http.HttpServletRequest
public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
getRequestDispatcher
in interface javax.servlet.ServletRequest
public java.lang.String getRequestedSessionId()
getRequestedSessionId
in interface javax.servlet.http.HttpServletRequest
public java.lang.String getRequestURI()
getRequestURI
in interface javax.servlet.http.HttpServletRequest
public java.lang.StringBuffer getRequestURL()
getRequestURL
in interface javax.servlet.http.HttpServletRequest
public Response getResponse()
public java.lang.StringBuilder getRootURL()
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.
public java.lang.String getScheme()
getScheme
in interface javax.servlet.ServletRequest
public java.lang.String getServerName()
getServerName
in interface javax.servlet.ServletRequest
public int getServerPort()
getServerPort
in interface javax.servlet.ServletRequest
public javax.servlet.ServletContext getServletContext()
getServletContext
in interface javax.servlet.ServletRequest
public java.lang.String getServletName()
public java.lang.String getServletPath()
getServletPath
in interface javax.servlet.http.HttpServletRequest
public javax.servlet.ServletResponse getServletResponse()
public java.lang.String changeSessionId()
changeSessionId
in interface javax.servlet.http.HttpServletRequest
public javax.servlet.http.HttpSession getSession()
getSession
in interface javax.servlet.http.HttpServletRequest
public javax.servlet.http.HttpSession getSession(boolean create)
getSession
in interface javax.servlet.http.HttpServletRequest
public SessionHandler getSessionHandler()
public long getTimeStamp()
public HttpURI getHttpURI()
public java.lang.String getOriginalURI()
public void setHttpURI(HttpURI uri)
uri
- the URI to setpublic UserIdentity getUserIdentity()
public UserIdentity getResolvedUserIdentity()
Authentication
is not Authentication.User
(eg.
Authentication.Deferred
).public UserIdentity.Scope getUserIdentityScope()
public java.security.Principal getUserPrincipal()
getUserPrincipal
in interface javax.servlet.http.HttpServletRequest
public boolean isHandled()
public boolean isAsyncStarted()
isAsyncStarted
in interface javax.servlet.ServletRequest
public boolean isAsyncSupported()
isAsyncSupported
in interface javax.servlet.ServletRequest
public boolean isRequestedSessionIdFromCookie()
isRequestedSessionIdFromCookie
in interface javax.servlet.http.HttpServletRequest
public boolean isRequestedSessionIdFromUrl()
isRequestedSessionIdFromUrl
in interface javax.servlet.http.HttpServletRequest
public boolean isRequestedSessionIdFromURL()
isRequestedSessionIdFromURL
in interface javax.servlet.http.HttpServletRequest
public boolean isRequestedSessionIdValid()
isRequestedSessionIdValid
in interface javax.servlet.http.HttpServletRequest
public boolean isSecure()
isSecure
in interface javax.servlet.ServletRequest
public void setSecure(boolean secure)
public boolean isUserInRole(java.lang.String role)
isUserInRole
in interface javax.servlet.http.HttpServletRequest
public void setMetaData(MetaData.Request request)
request
- the Request metadatapublic MetaData.Request getMetaData()
public boolean hasMetaData()
protected void recycle()
public void removeAttribute(java.lang.String name)
removeAttribute
in interface javax.servlet.ServletRequest
public void removeEventListener(java.util.EventListener listener)
public void setAsyncSupported(boolean supported, java.lang.String source)
public void setAttribute(java.lang.String name, java.lang.Object value)
setAttribute
in interface javax.servlet.ServletRequest
public void setAttributes(Attributes attributes)
public void setAuthentication(Authentication authentication)
authentication
- the authentication to setpublic void setCharacterEncoding(java.lang.String encoding) throws java.io.UnsupportedEncodingException
setCharacterEncoding
in interface javax.servlet.ServletRequest
java.io.UnsupportedEncodingException
public void setCharacterEncodingUnchecked(java.lang.String encoding)
public void setContentType(java.lang.String contentType)
public void setContext(ContextHandler.Context context)
context
- context objectpublic boolean takeNewContext()
takeNewContext()
since the last
setContext(org.eclipse.jetty.server.handler.ContextHandler.Context)
call.public void setContextPath(java.lang.String contextPath)
contextPath
- the context path for this requestHttpServletRequest.getContextPath()
public void setCookies(javax.servlet.http.Cookie[] cookies)
cookies
- The cookies to set.public void setDispatcherType(javax.servlet.DispatcherType type)
public void setHandled(boolean h)
public void setMethod(java.lang.String method)
method
- The method to set.public void setHttpVersion(HttpVersion version)
public boolean isHead()
public void setPathInfo(java.lang.String pathInfo)
pathInfo
- The pathInfo to set.public void setQueryEncoding(java.lang.String queryEncoding)
queryEncoding
- the URI query character encodingpublic void setQueryString(java.lang.String queryString)
queryString
- The queryString to set.public void setRemoteAddr(java.net.InetSocketAddress addr)
addr
- The address to set.public void setRequestedSessionId(java.lang.String requestedSessionId)
requestedSessionId
- The requestedSessionId to set.public void setRequestedSessionIdFromCookie(boolean requestedSessionIdCookie)
requestedSessionIdCookie
- The requestedSessionIdCookie to set.public void setURIPathQuery(java.lang.String requestURI)
public void setScheme(java.lang.String scheme)
scheme
- The scheme to set.public void setAuthority(java.lang.String host, int port)
host
- The host to set.port
- the port to setpublic void setServletPath(java.lang.String servletPath)
servletPath
- The servletPath to set.public void setSession(javax.servlet.http.HttpSession session)
session
- The session to set.public void setSessionHandler(SessionHandler sessionHandler)
sessionHandler
- The SessionHandler to set.public void setTimeStamp(long ts)
public void setUserIdentityScope(UserIdentity.Scope scope)
public javax.servlet.AsyncContext startAsync() throws java.lang.IllegalStateException
startAsync
in interface javax.servlet.ServletRequest
java.lang.IllegalStateException
public javax.servlet.AsyncContext startAsync(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse) throws java.lang.IllegalStateException
startAsync
in interface javax.servlet.ServletRequest
java.lang.IllegalStateException
public java.lang.String toString()
toString
in class java.lang.Object
public boolean authenticate(javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
authenticate
in interface javax.servlet.http.HttpServletRequest
java.io.IOException
javax.servlet.ServletException
public javax.servlet.http.Part getPart(java.lang.String name) throws java.io.IOException, javax.servlet.ServletException
getPart
in interface javax.servlet.http.HttpServletRequest
java.io.IOException
javax.servlet.ServletException
public java.util.Collection<javax.servlet.http.Part> getParts() throws java.io.IOException, javax.servlet.ServletException
getParts
in interface javax.servlet.http.HttpServletRequest
java.io.IOException
javax.servlet.ServletException
public void login(java.lang.String username, java.lang.String password) throws javax.servlet.ServletException
login
in interface javax.servlet.http.HttpServletRequest
javax.servlet.ServletException
public void logout() throws javax.servlet.ServletException
logout
in interface javax.servlet.http.HttpServletRequest
javax.servlet.ServletException
public void mergeQueryParameters(java.lang.String oldQuery, java.lang.String newQuery, boolean updateQueryString)
public <T extends javax.servlet.http.HttpUpgradeHandler> T upgrade(java.lang.Class<T> handlerClass) throws java.io.IOException, javax.servlet.ServletException
upgrade
in interface javax.servlet.http.HttpServletRequest
java.io.IOException
javax.servlet.ServletException
HttpServletRequest.upgrade(java.lang.Class)
Copyright © 1995–2023 Webtide. All rights reserved.