Class Request
- java.lang.Object
-
- org.eclipse.jetty.server.Request
-
- All Implemented Interfaces:
HttpServletRequest,ServletRequest
public class Request extends Object implements HttpServletRequest
Jetty Request.Implements
HttpServletRequestfrom thejavax.servlet.httppackage.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 aContextHandlerwhich matches thegetPathInfo()with a context path and callssetContextPath(String)as a result. - the HTTP session methods will all return null sessions until such time as a request has been passed to a
SessionHandlerwhich checks for session cookies and enables the ability to create new sessions. - The
getServletPath()method will return null until the request has been passed to aorg.eclipse.jetty.servlet.ServletHandlerand the pathInfo matched against the servlet URL patterns andsetServletPath(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"Serverattribute. The number of parameters keys is limited byContextHandler.getMaxFormKeys()or if there is no context then the "org.eclipse.jetty.server.Request.maxFormKeys"Serverattribute.If IOExceptions or timeouts occur while reading form parameters, these are thrown as unchecked Exceptions: ether
RuntimeIOException,BadMessageExceptionorRuntimeExceptionas appropriate.
-
-
Field Summary
Fields Modifier and Type Field Description static String__MULTIPART_CONFIG_ELEMENTstatic String__MULTIPARTS-
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
-
-
Constructor Summary
Constructors Constructor Description Request(HttpChannel channel, HttpInput input)
-
Method Summary
-
-
-
Field Detail
-
__MULTIPART_CONFIG_ELEMENT
public static final String __MULTIPART_CONFIG_ELEMENT
- See Also:
- Constant Field Values
-
__MULTIPARTS
public static final String __MULTIPARTS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Request
public Request(HttpChannel channel, HttpInput input)
-
-
Method Detail
-
getBaseRequest
public static Request getBaseRequest(ServletRequest request)
Obtain the baseRequestinstance of aServletRequest, by coercion, unwrapping or special attribute.- Parameters:
request- The request- Returns:
- the base
Requestinstance of aServletRequest.
-
getHttpFields
public org.eclipse.jetty.http.HttpFields getHttpFields()
-
getTrailers
public org.eclipse.jetty.http.HttpFields getTrailers()
-
getHttpInput
public HttpInput getHttpInput()
-
isPush
public boolean isPush()
-
isPushSupported
public boolean isPushSupported()
-
getPushBuilder
public 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. If-Modified-Since)
- Range headers
- Expect headers
- Authorization headers
- Referrer headers
- If the request was Authenticated, an Authorization header will be set with a container generated token that will result in equivalent Authorization
- The query string from
getQueryString() - The
getRequestedSessionId()value, unless at the time of the callgetSession(boolean)has previously been called to create a newHttpSession, in which case the new session ID will be used as the PushBuilders requested session ID. - The source of the requested session id will be the same as for this request
- The builders Referer header will be set to
getRequestURL()plus anygetQueryString() - If
HttpServletResponse.addCookie(Cookie)has been called on the associated response, then a corresponding Cookie header will be added to the PushBuilder, unless theCookie.getMaxAge()is <=0, in which case the Cookie will be removed from the builder. - If this request has has the conditional headers If-Modified-Since or
If-None-Match then the
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.
- Returns:
- A new PushBuilder or null if push is not supported
-
addEventListener
public void addEventListener(EventListener listener)
-
extractFormParameters
public void extractFormParameters(org.eclipse.jetty.util.MultiMap<String> params)
-
getAsyncContext
public AsyncContext getAsyncContext()
- Specified by:
getAsyncContextin interfaceServletRequest
-
getHttpChannelState
public HttpChannelState getHttpChannelState()
-
getAttribute
public Object getAttribute(String name)
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:
getAttributein interfaceServletRequest- See Also:
ServletRequest.getAttribute(java.lang.String)
-
getAttributeNames
public Enumeration<String> getAttributeNames()
- Specified by:
getAttributeNamesin interfaceServletRequest
-
getAttributes
public org.eclipse.jetty.util.Attributes getAttributes()
-
getAuthentication
public Authentication getAuthentication()
Get the authentication.- Returns:
- the authentication
-
getAuthType
public String getAuthType()
- Specified by:
getAuthTypein interfaceHttpServletRequest
-
getCharacterEncoding
public String getCharacterEncoding()
- Specified by:
getCharacterEncodingin interfaceServletRequest
-
getHttpChannel
public HttpChannel getHttpChannel()
- Returns:
- Returns the connection.
-
getContentLength
public int getContentLength()
- Specified by:
getContentLengthin interfaceServletRequest
-
getContentLengthLong
public long getContentLengthLong()
- Specified by:
getContentLengthLongin interfaceServletRequest
-
getContentRead
public long getContentRead()
-
getContentType
public String getContentType()
- Specified by:
getContentTypein interfaceServletRequest
-
getContext
public ContextHandler.Context getContext()
- Returns:
- The current
contextused for this request, ornullifsetContext(org.eclipse.jetty.server.handler.ContextHandler.Context)has not yet been called.
-
getContextPath
public String getContextPath()
- Specified by:
getContextPathin interfaceHttpServletRequest
-
getCookies
public Cookie[] getCookies()
- Specified by:
getCookiesin interfaceHttpServletRequest
-
getDateHeader
public long getDateHeader(String name)
- Specified by:
getDateHeaderin interfaceHttpServletRequest
-
getDispatcherType
public DispatcherType getDispatcherType()
- Specified by:
getDispatcherTypein interfaceServletRequest
-
getHeader
public String getHeader(String name)
- Specified by:
getHeaderin interfaceHttpServletRequest
-
getHeaderNames
public Enumeration<String> getHeaderNames()
- Specified by:
getHeaderNamesin interfaceHttpServletRequest
-
getHeaders
public Enumeration<String> getHeaders(String name)
- Specified by:
getHeadersin interfaceHttpServletRequest
-
getInputState
public int getInputState()
- Returns:
- Returns the inputState.
-
getInputStream
public ServletInputStream getInputStream() throws IOException
- Specified by:
getInputStreamin interfaceServletRequest- Throws:
IOException
-
getIntHeader
public int getIntHeader(String name)
- Specified by:
getIntHeaderin interfaceHttpServletRequest
-
getLocale
public Locale getLocale()
- Specified by:
getLocalein interfaceServletRequest
-
getLocales
public Enumeration<Locale> getLocales()
- Specified by:
getLocalesin interfaceServletRequest
-
getLocalAddr
public String getLocalAddr()
- Specified by:
getLocalAddrin interfaceServletRequest
-
getLocalName
public String getLocalName()
- Specified by:
getLocalNamein interfaceServletRequest
-
getLocalPort
public int getLocalPort()
- Specified by:
getLocalPortin interfaceServletRequest
-
getMethod
public String getMethod()
- Specified by:
getMethodin interfaceHttpServletRequest
-
getParameter
public String getParameter(String name)
- Specified by:
getParameterin interfaceServletRequest
-
getParameterMap
public Map<String,String[]> getParameterMap()
- Specified by:
getParameterMapin interfaceServletRequest
-
getParameterNames
public Enumeration<String> getParameterNames()
- Specified by:
getParameterNamesin interfaceServletRequest
-
getParameterValues
public String[] getParameterValues(String name)
- Specified by:
getParameterValuesin interfaceServletRequest
-
getQueryParameters
public org.eclipse.jetty.util.MultiMap<String> getQueryParameters()
-
setQueryParameters
public void setQueryParameters(org.eclipse.jetty.util.MultiMap<String> queryParameters)
-
setContentParameters
public void setContentParameters(org.eclipse.jetty.util.MultiMap<String> contentParameters)
-
resetParameters
public void resetParameters()
-
getPathInfo
public String getPathInfo()
- Specified by:
getPathInfoin interfaceHttpServletRequest
-
getPathTranslated
public String getPathTranslated()
- Specified by:
getPathTranslatedin interfaceHttpServletRequest
-
getProtocol
public String getProtocol()
- Specified by:
getProtocolin interfaceServletRequest
-
getHttpVersion
public org.eclipse.jetty.http.HttpVersion getHttpVersion()
-
getQueryEncoding
public String getQueryEncoding()
-
getQueryString
public String getQueryString()
- Specified by:
getQueryStringin interfaceHttpServletRequest
-
getReader
public BufferedReader getReader() throws IOException
- Specified by:
getReaderin interfaceServletRequest- Throws:
IOException
-
getRealPath
public String getRealPath(String path)
- Specified by:
getRealPathin interfaceServletRequest
-
getRemoteInetSocketAddress
public InetSocketAddress getRemoteInetSocketAddress()
Access the underlying RemoteInetSocketAddressfor this request.- Returns:
- the remote
InetSocketAddressfor this request, or null if the request has no remote (seeServletRequest.getRemoteAddr()for conditions that result in no remote address)
-
getRemoteAddr
public String getRemoteAddr()
- Specified by:
getRemoteAddrin interfaceServletRequest
-
getRemoteHost
public String getRemoteHost()
- Specified by:
getRemoteHostin interfaceServletRequest
-
getRemotePort
public int getRemotePort()
- Specified by:
getRemotePortin interfaceServletRequest
-
getRemoteUser
public String getRemoteUser()
- Specified by:
getRemoteUserin interfaceHttpServletRequest
-
getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path)
- Specified by:
getRequestDispatcherin interfaceServletRequest
-
getRequestedSessionId
public String getRequestedSessionId()
- Specified by:
getRequestedSessionIdin interfaceHttpServletRequest
-
getRequestURI
public String getRequestURI()
- Specified by:
getRequestURIin interfaceHttpServletRequest
-
getRequestURL
public StringBuffer getRequestURL()
- Specified by:
getRequestURLin interfaceHttpServletRequest
-
getResponse
public Response getResponse()
-
getRootURL
public StringBuilder 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
public String getScheme()
- Specified by:
getSchemein interfaceServletRequest
-
getServerName
public String getServerName()
- Specified by:
getServerNamein interfaceServletRequest
-
getServerPort
public int getServerPort()
- Specified by:
getServerPortin interfaceServletRequest
-
getServletContext
public ServletContext getServletContext()
- Specified by:
getServletContextin interfaceServletRequest
-
getServletName
public String getServletName()
-
getServletPath
public String getServletPath()
- Specified by:
getServletPathin interfaceHttpServletRequest
-
getServletResponse
public ServletResponse getServletResponse()
-
changeSessionId
public String changeSessionId()
- Specified by:
changeSessionIdin interfaceHttpServletRequest
-
getSession
public HttpSession getSession()
- Specified by:
getSessionin interfaceHttpServletRequest
-
getSession
public HttpSession getSession(boolean create)
- Specified by:
getSessionin interfaceHttpServletRequest
-
getSessionHandler
public SessionHandler getSessionHandler()
- Returns:
- Returns the sessionManager.
-
getTimeStamp
public long getTimeStamp()
Get Request TimeStamp- Returns:
- The time that the request was received.
-
getHttpURI
public org.eclipse.jetty.http.HttpURI getHttpURI()
- Returns:
- Returns the uri.
-
getOriginalURI
public String getOriginalURI()
- Returns:
- Returns the original uri passed in metadata before customization/rewrite
-
setHttpURI
public void setHttpURI(org.eclipse.jetty.http.HttpURI uri)
- Parameters:
uri- the URI to set
-
getUserIdentity
public UserIdentity getUserIdentity()
-
getResolvedUserIdentity
public UserIdentity getResolvedUserIdentity()
- Returns:
- The resolved user Identity, which may be null if the
Authenticationis notAuthentication.User(eg.Authentication.Deferred).
-
getUserIdentityScope
public UserIdentity.Scope getUserIdentityScope()
-
getUserPrincipal
public Principal getUserPrincipal()
- Specified by:
getUserPrincipalin interfaceHttpServletRequest
-
isHandled
public boolean isHandled()
-
isAsyncStarted
public boolean isAsyncStarted()
- Specified by:
isAsyncStartedin interfaceServletRequest
-
isAsyncSupported
public boolean isAsyncSupported()
- Specified by:
isAsyncSupportedin interfaceServletRequest
-
isRequestedSessionIdFromCookie
public boolean isRequestedSessionIdFromCookie()
- Specified by:
isRequestedSessionIdFromCookiein interfaceHttpServletRequest
-
isRequestedSessionIdFromUrl
public boolean isRequestedSessionIdFromUrl()
- Specified by:
isRequestedSessionIdFromUrlin interfaceHttpServletRequest
-
isRequestedSessionIdFromURL
public boolean isRequestedSessionIdFromURL()
- Specified by:
isRequestedSessionIdFromURLin interfaceHttpServletRequest
-
isRequestedSessionIdValid
public boolean isRequestedSessionIdValid()
- Specified by:
isRequestedSessionIdValidin interfaceHttpServletRequest
-
isSecure
public boolean isSecure()
- Specified by:
isSecurein interfaceServletRequest
-
setSecure
public void setSecure(boolean secure)
-
isUserInRole
public boolean isUserInRole(String role)
- Specified by:
isUserInRolein interfaceHttpServletRequest
-
setMetaData
public void setMetaData(org.eclipse.jetty.http.MetaData.Request request)
- Parameters:
request- the Request metadata
-
getMetaData
public org.eclipse.jetty.http.MetaData.Request getMetaData()
-
hasMetaData
public boolean hasMetaData()
-
recycle
protected void recycle()
-
removeAttribute
public void removeAttribute(String name)
- Specified by:
removeAttributein interfaceServletRequest
-
removeEventListener
public void removeEventListener(EventListener listener)
-
setAsyncSupported
public void setAsyncSupported(boolean supported, String source)
-
setAttribute
public void setAttribute(String name, Object value)
- Specified by:
setAttributein interfaceServletRequest
-
setAttributes
public void setAttributes(org.eclipse.jetty.util.Attributes attributes)
-
setAuthentication
public void setAuthentication(Authentication authentication)
Set the authentication.- Parameters:
authentication- the authentication to set
-
setCharacterEncoding
public void setCharacterEncoding(String encoding) throws UnsupportedEncodingException
- Specified by:
setCharacterEncodingin interfaceServletRequest- Throws:
UnsupportedEncodingException
-
setCharacterEncodingUnchecked
public void setCharacterEncodingUnchecked(String encoding)
-
setContentType
public void setContentType(String contentType)
-
setContext
public void setContext(ContextHandler.Context context)
Set request context- Parameters:
context- context object
-
takeNewContext
public boolean takeNewContext()
- Returns:
- True if this is the first call of
takeNewContext()since the lastsetContext(org.eclipse.jetty.server.handler.ContextHandler.Context)call.
-
setContextPath
public void setContextPath(String contextPath)
Sets the "context path" for this request- Parameters:
contextPath- the context path for this request- See Also:
HttpServletRequest.getContextPath()
-
setCookies
public void setCookies(Cookie[] cookies)
- Parameters:
cookies- The cookies to set.
-
setDispatcherType
public void setDispatcherType(DispatcherType type)
-
setHandled
public void setHandled(boolean h)
-
setMethod
public void setMethod(String method)
- Parameters:
method- The method to set.
-
setHttpVersion
public void setHttpVersion(org.eclipse.jetty.http.HttpVersion version)
-
isHead
public boolean isHead()
-
setPathInfo
public void setPathInfo(String pathInfo)
- Parameters:
pathInfo- The pathInfo to set.
-
setQueryEncoding
public void setQueryEncoding(String queryEncoding)
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.server.Request.queryEncoding" may be set as an alternate method of calling setQueryEncoding.- Parameters:
queryEncoding- the URI query character encoding
-
setQueryString
public void setQueryString(String queryString)
- Parameters:
queryString- The queryString to set.
-
setRemoteAddr
public void setRemoteAddr(InetSocketAddress addr)
- Parameters:
addr- The address to set.
-
setRequestedSessionId
public void setRequestedSessionId(String requestedSessionId)
- Parameters:
requestedSessionId- The requestedSessionId to set.
-
setRequestedSessionIdFromCookie
public void setRequestedSessionIdFromCookie(boolean requestedSessionIdCookie)
- Parameters:
requestedSessionIdCookie- The requestedSessionIdCookie to set.
-
setURIPathQuery
public void setURIPathQuery(String requestURI)
-
setScheme
public void setScheme(String scheme)
- Parameters:
scheme- The scheme to set.
-
setAuthority
public void setAuthority(String host, int port)
- Parameters:
host- The host to set.port- the port to set
-
setServletPath
public void setServletPath(String servletPath)
- Parameters:
servletPath- The servletPath to set.
-
setSession
public void setSession(HttpSession session)
- Parameters:
session- The session to set.
-
setSessionHandler
public void setSessionHandler(SessionHandler sessionHandler)
- Parameters:
sessionHandler- The SessionHandler to set.
-
setTimeStamp
public void setTimeStamp(long ts)
-
setUserIdentityScope
public void setUserIdentityScope(UserIdentity.Scope scope)
-
startAsync
public AsyncContext startAsync() throws IllegalStateException
- Specified by:
startAsyncin interfaceServletRequest- Throws:
IllegalStateException
-
startAsync
public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException
- Specified by:
startAsyncin interfaceServletRequest- Throws:
IllegalStateException
-
authenticate
public boolean authenticate(HttpServletResponse response) throws IOException, ServletException
- Specified by:
authenticatein interfaceHttpServletRequest- Throws:
IOExceptionServletException
-
getPart
public Part getPart(String name) throws IOException, ServletException
- Specified by:
getPartin interfaceHttpServletRequest- Throws:
IOExceptionServletException
-
getParts
public Collection<Part> getParts() throws IOException, ServletException
- Specified by:
getPartsin interfaceHttpServletRequest- Throws:
IOExceptionServletException
-
login
public void login(String username, String password) throws ServletException
- Specified by:
loginin interfaceHttpServletRequest- Throws:
ServletException
-
logout
public void logout() throws ServletException- Specified by:
logoutin interfaceHttpServletRequest- Throws:
ServletException
-
mergeQueryParameters
public void mergeQueryParameters(String oldQuery, String newQuery, boolean updateQueryString)
-
upgrade
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException
- Specified by:
upgradein interfaceHttpServletRequest- Throws:
IOExceptionServletException- See Also:
HttpServletRequest.upgrade(java.lang.Class)
-
-