public class Request extends Object implements 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.
| Modifier and Type | Field and Description |
|---|---|
static String |
__MULTIPART_CONFIG_ELEMENT |
static String |
__MULTIPART_CONTEXT |
static String |
__MULTIPART_INPUT_STREAM |
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH| Constructor and Description |
|---|
Request(HttpChannel channel,
HttpInput input) |
public static final String __MULTIPART_CONFIG_ELEMENT
public static final String __MULTIPART_INPUT_STREAM
public static final 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 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(EventListener listener)
public AsyncContext getAsyncContext()
getAsyncContext in interface ServletRequestpublic HttpChannelState getHttpChannelState()
public Object getAttribute(String name)
Also supports jetty specific attributes to gain access to Jetty APIs:
getAttribute in interface ServletRequestServletRequest.getAttribute(java.lang.String)public Enumeration<String> getAttributeNames()
getAttributeNames in interface ServletRequestpublic Attributes getAttributes()
public Authentication getAuthentication()
public String getAuthType()
getAuthType in interface HttpServletRequestpublic String getCharacterEncoding()
getCharacterEncoding in interface ServletRequestpublic HttpChannel getHttpChannel()
public int getContentLength()
getContentLength in interface ServletRequestpublic long getContentLengthLong()
getContentLengthLong in interface ServletRequestpublic long getContentRead()
public String getContentType()
getContentType in interface ServletRequestpublic 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 String getContextPath()
getContextPath in interface HttpServletRequestpublic Cookie[] getCookies()
getCookies in interface HttpServletRequestpublic long getDateHeader(String name)
getDateHeader in interface HttpServletRequestpublic DispatcherType getDispatcherType()
getDispatcherType in interface ServletRequestpublic String getHeader(String name)
getHeader in interface HttpServletRequestpublic Enumeration<String> getHeaderNames()
getHeaderNames in interface HttpServletRequestpublic Enumeration<String> getHeaders(String name)
getHeaders in interface HttpServletRequestpublic int getInputState()
public ServletInputStream getInputStream() throws IOException
getInputStream in interface ServletRequestIOExceptionpublic int getIntHeader(String name)
getIntHeader in interface HttpServletRequestpublic Locale getLocale()
getLocale in interface ServletRequestpublic Enumeration<Locale> getLocales()
getLocales in interface ServletRequestpublic String getLocalAddr()
getLocalAddr in interface ServletRequestpublic String getLocalName()
getLocalName in interface ServletRequestpublic int getLocalPort()
getLocalPort in interface ServletRequestpublic String getMethod()
getMethod in interface HttpServletRequestpublic String getParameter(String name)
getParameter in interface ServletRequestpublic Map<String,String[]> getParameterMap()
getParameterMap in interface ServletRequestpublic Enumeration<String> getParameterNames()
getParameterNames in interface ServletRequestpublic String[] getParameterValues(String name)
getParameterValues in interface ServletRequestpublic void resetParameters()
public String getPathInfo()
getPathInfo in interface HttpServletRequestpublic String getPathTranslated()
getPathTranslated in interface HttpServletRequestpublic String getProtocol()
getProtocol in interface ServletRequestpublic HttpVersion getHttpVersion()
public String getQueryEncoding()
public String getQueryString()
getQueryString in interface HttpServletRequestpublic BufferedReader getReader() throws IOException
getReader in interface ServletRequestIOExceptionpublic String getRealPath(String path)
getRealPath in interface ServletRequestpublic 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 String getRemoteAddr()
getRemoteAddr in interface ServletRequestpublic String getRemoteHost()
getRemoteHost in interface ServletRequestpublic int getRemotePort()
getRemotePort in interface ServletRequestpublic String getRemoteUser()
getRemoteUser in interface HttpServletRequestpublic RequestDispatcher getRequestDispatcher(String path)
getRequestDispatcher in interface ServletRequestpublic String getRequestedSessionId()
getRequestedSessionId in interface HttpServletRequestpublic String getRequestURI()
getRequestURI in interface HttpServletRequestpublic StringBuffer getRequestURL()
getRequestURL in interface HttpServletRequestpublic Response getResponse()
public 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 String getScheme()
getScheme in interface ServletRequestpublic String getServerName()
getServerName in interface ServletRequestpublic int getServerPort()
getServerPort in interface ServletRequestpublic ServletContext getServletContext()
getServletContext in interface ServletRequestpublic String getServletName()
public String getServletPath()
getServletPath in interface HttpServletRequestpublic ServletResponse getServletResponse()
public String changeSessionId()
changeSessionId in interface HttpServletRequestpublic HttpSession getSession()
getSession in interface HttpServletRequestpublic HttpSession getSession(boolean create)
getSession in interface HttpServletRequestpublic SessionManager getSessionManager()
public long getTimeStamp()
public HttpURI getHttpURI()
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 Principal getUserPrincipal()
getUserPrincipal in interface HttpServletRequestpublic boolean isHandled()
public boolean isAsyncStarted()
isAsyncStarted in interface ServletRequestpublic boolean isAsyncSupported()
isAsyncSupported in interface ServletRequestpublic boolean isRequestedSessionIdFromCookie()
isRequestedSessionIdFromCookie in interface HttpServletRequestpublic boolean isRequestedSessionIdFromUrl()
isRequestedSessionIdFromUrl in interface HttpServletRequestpublic boolean isRequestedSessionIdFromURL()
isRequestedSessionIdFromURL in interface HttpServletRequestpublic boolean isRequestedSessionIdValid()
isRequestedSessionIdValid in interface HttpServletRequestpublic boolean isSecure()
isSecure in interface ServletRequestpublic void setSecure(boolean secure)
public boolean isUserInRole(String role)
isUserInRole in interface HttpServletRequestpublic HttpSession recoverNewSession(Object key)
public void setMetaData(MetaData.Request request)
request - the Request metadatapublic MetaData.Request getMetaData()
public boolean hasMetaData()
protected void recycle()
public void removeAttribute(String name)
removeAttribute in interface ServletRequestpublic void removeEventListener(EventListener listener)
public void saveNewSession(Object key, HttpSession session)
public void setAsyncSupported(boolean supported,
String source)
public void setAttribute(String name, Object value)
setAttribute in interface ServletRequestpublic void setAttributes(Attributes attributes)
public void setAuthentication(Authentication authentication)
authentication - the authentication to setpublic void setCharacterEncoding(String encoding) throws UnsupportedEncodingException
setCharacterEncoding in interface ServletRequestUnsupportedEncodingExceptionpublic void setCharacterEncodingUnchecked(String encoding)
public void setContentType(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(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(String method)
method - The method to set.public void setHttpVersion(HttpVersion version)
public boolean isHead()
public void setPathInfo(String pathInfo)
pathInfo - The pathInfo to set.public void setQueryEncoding(String queryEncoding)
queryEncoding - the URI query character encodingpublic void setQueryString(String queryString)
queryString - The queryString to set.public void setRemoteAddr(InetSocketAddress addr)
addr - The address to set.public void setRequestedSessionId(String requestedSessionId)
requestedSessionId - The requestedSessionId to set.public void setRequestedSessionIdFromCookie(boolean requestedSessionIdCookie)
requestedSessionIdCookie - The requestedSessionIdCookie to set.public void setURIPathQuery(String requestURI)
public void setScheme(String scheme)
scheme - The scheme to set.public void setAuthority(String host, int port)
host - The host to set.port - the port to setpublic void setServletPath(String servletPath)
servletPath - The servletPath to set.public void setSession(HttpSession session)
session - The session to set.public void setSessionManager(SessionManager sessionManager)
sessionManager - The sessionManager to set.public void setTimeStamp(long ts)
public void setUserIdentityScope(UserIdentity.Scope scope)
public AsyncContext startAsync() throws IllegalStateException
startAsync in interface ServletRequestIllegalStateExceptionpublic AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException
startAsync in interface ServletRequestIllegalStateExceptionpublic boolean authenticate(HttpServletResponse response) throws IOException, ServletException
authenticate in interface HttpServletRequestIOExceptionServletExceptionpublic Part getPart(String name) throws IOException, ServletException
getPart in interface HttpServletRequestIOExceptionServletExceptionpublic Collection<Part> getParts() throws IOException, ServletException
getParts in interface HttpServletRequestIOExceptionServletExceptionpublic void login(String username, String password) throws ServletException
login in interface HttpServletRequestServletExceptionpublic void logout()
throws ServletException
logout in interface HttpServletRequestServletExceptionpublic void mergeQueryParameters(String oldQuery, String newQuery, boolean updateQueryString)
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException
upgrade in interface HttpServletRequestIOExceptionServletExceptionHttpServletRequest.upgrade(java.lang.Class)Copyright © 1995–2017 Webtide. All rights reserved.