public class Request
extends java.lang.Object
Implements javax.servlet.http.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 |
__MULTIPART_CONTEXT |
static java.lang.String |
__MULTIPART_INPUT_STREAM |
| Constructor and Description |
|---|
Request(HttpChannel channel,
HttpInput input) |
| Modifier and Type | Method and Description |
|---|---|
void |
addEventListener(java.util.EventListener listener) |
boolean |
authenticate(HttpServletResponse response) |
java.lang.String |
changeSessionId() |
void |
extractFormParameters(<any> params) |
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(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() |
Cookie[] |
getCookies() |
long |
getDateHeader(java.lang.String name) |
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() |
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() |
org.eclipse.jetty.http.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) |
Part |
getPart(java.lang.String name) |
java.util.Collection<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() |
<any> |
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() |
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() |
ServletContext |
getServletContext() |
java.lang.String |
getServletName() |
java.lang.String |
getServletPath() |
ServletResponse |
getServletResponse() |
HttpSession |
getSession() |
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(<any> 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(Cookie[] cookies) |
void |
setDispatcherType(DispatcherType type) |
void |
setHandled(boolean h) |
void |
setHttpURI(HttpURI uri) |
void |
setHttpVersion(HttpVersion version) |
void |
setMetaData(org.eclipse.jetty.http.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(<any> 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(HttpSession session) |
void |
setSessionHandler(SessionHandler sessionHandler) |
void |
setTimeStamp(long ts) |
void |
setURIPathQuery(java.lang.String requestURI) |
void |
setUserIdentityScope(UserIdentity.Scope scope) |
AsyncContext |
startAsync() |
AsyncContext |
startAsync(ServletRequest servletRequest,
ServletResponse servletResponse) |
boolean |
takeNewContext() |
java.lang.String |
toString() |
<T extends HttpUpgradeHandler> |
upgrade(java.lang.Class<T> handlerClass) |
public static final java.lang.String __MULTIPART_CONFIG_ELEMENT
public static final java.lang.String __MULTIPART_INPUT_STREAM
public static final java.lang.String __MULTIPART_CONTEXT
public Request(HttpChannel channel, HttpInput input)
public static Request getBaseRequest(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(<any> params)
public AsyncContext getAsyncContext()
public HttpChannelState getHttpChannelState()
public java.lang.Object getAttribute(java.lang.String name)
Also supports jetty specific attributes to gain access to Jetty APIs:
javax.servlet.ServletRequest#getAttribute(java.lang.String)public java.util.Enumeration<java.lang.String> getAttributeNames()
public Attributes getAttributes()
public Authentication getAuthentication()
public java.lang.String getAuthType()
public java.lang.String getCharacterEncoding()
public HttpChannel getHttpChannel()
public int getContentLength()
public long getContentLengthLong()
public long getContentRead()
public java.lang.String getContentType()
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()
public Cookie[] getCookies()
public long getDateHeader(java.lang.String name)
public DispatcherType getDispatcherType()
public java.lang.String getHeader(java.lang.String name)
public java.util.Enumeration<java.lang.String> getHeaderNames()
public java.util.Enumeration<java.lang.String> getHeaders(java.lang.String name)
public int getInputState()
public ServletInputStream getInputStream()
throws java.io.IOException
java.io.IOExceptionpublic int getIntHeader(java.lang.String name)
public java.util.Locale getLocale()
public java.util.Enumeration<java.util.Locale> getLocales()
public java.lang.String getLocalAddr()
public java.lang.String getLocalName()
public int getLocalPort()
public java.lang.String getMethod()
public java.lang.String getParameter(java.lang.String name)
public java.util.Map<java.lang.String,java.lang.String[]> getParameterMap()
public java.util.Enumeration<java.lang.String> getParameterNames()
public java.lang.String[] getParameterValues(java.lang.String name)
public <any> getQueryParameters()
public void setQueryParameters(<any> queryParameters)
public void setContentParameters(<any> contentParameters)
public void resetParameters()
public java.lang.String getPathInfo()
public java.lang.String getPathTranslated()
public java.lang.String getProtocol()
public HttpVersion getHttpVersion()
public java.lang.String getQueryEncoding()
public java.lang.String getQueryString()
public java.io.BufferedReader getReader()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getRealPath(java.lang.String path)
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()
public java.lang.String getRemoteHost()
public int getRemotePort()
public java.lang.String getRemoteUser()
public RequestDispatcher getRequestDispatcher(java.lang.String path)
public java.lang.String getRequestedSessionId()
public java.lang.String getRequestURI()
public java.lang.StringBuffer getRequestURL()
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()
public java.lang.String getServerName()
public int getServerPort()
public ServletContext getServletContext()
public java.lang.String getServletName()
public java.lang.String getServletPath()
public ServletResponse getServletResponse()
public java.lang.String changeSessionId()
public HttpSession getSession()
public HttpSession getSession(boolean create)
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()
public boolean isHandled()
public boolean isAsyncStarted()
public boolean isAsyncSupported()
public boolean isRequestedSessionIdFromCookie()
public boolean isRequestedSessionIdFromUrl()
public boolean isRequestedSessionIdFromURL()
public boolean isRequestedSessionIdValid()
public boolean isSecure()
public void setSecure(boolean secure)
public boolean isUserInRole(java.lang.String role)
public void setMetaData(org.eclipse.jetty.http.MetaData.Request request)
request - the Request metadatapublic org.eclipse.jetty.http.MetaData.Request getMetaData()
public boolean hasMetaData()
protected void recycle()
public void removeAttribute(java.lang.String name)
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)
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
java.io.UnsupportedEncodingExceptionpublic 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(Cookie[] cookies)
cookies - The cookies to set.public void setDispatcherType(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(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 AsyncContext startAsync()
throws java.lang.IllegalStateException
java.lang.IllegalStateExceptionpublic AsyncContext startAsync(ServletRequest servletRequest,
ServletResponse servletResponse)
throws java.lang.IllegalStateException
java.lang.IllegalStateExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean authenticate(HttpServletResponse response)
throws java.io.IOException,
ServletException
java.io.IOExceptionServletExceptionpublic Part getPart(java.lang.String name)
throws java.io.IOException,
ServletException
java.io.IOExceptionServletExceptionpublic java.util.Collection<Part> getParts()
throws java.io.IOException,
ServletException
java.io.IOExceptionServletExceptionpublic void login(java.lang.String username,
java.lang.String password)
throws ServletException
ServletExceptionpublic void logout()
throws ServletException
ServletExceptionpublic void mergeQueryParameters(java.lang.String oldQuery,
java.lang.String newQuery,
boolean updateQueryString)
public <T extends HttpUpgradeHandler> T upgrade(java.lang.Class<T> handlerClass)
throws java.io.IOException,
ServletException
java.io.IOExceptionServletExceptionjavax.servlet.http.HttpServletRequest#upgrade(java.lang.Class)