Class Request

  • All Implemented Interfaces:
    jakarta.servlet.http.HttpServletRequest, jakarta.servlet.ServletRequest

    public class Request
    extends java.lang.Object
    implements jakarta.servlet.http.HttpServletRequest
    Jetty Request.

    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

    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 Detail


        public static final java.lang.String __MULTIPART_CONFIG_ELEMENT
        See Also:
        Constant Field Values
    • Method Detail

      • getBaseRequest

        public static Request getBaseRequest​(jakarta.servlet.ServletRequest request)
        Obtain the base Request instance of a ServletRequest, by coercion, unwrapping or special attribute.
        request - The request
        the base Request instance of a ServletRequest.
      • getHttpFields

        public HttpFields getHttpFields()
      • setHttpFields

        public void setHttpFields​(HttpFields fields)
      • getTrailerFields

        public java.util.Map<java.lang.String,​java.lang.String> getTrailerFields()
        Specified by:
        getTrailerFields in interface jakarta.servlet.http.HttpServletRequest
      • setTrailerHttpFields

        public void setTrailerHttpFields​(HttpFields trailers)
      • getTrailerHttpFields

        public HttpFields getTrailerHttpFields()
      • getHttpInput

        public HttpInput getHttpInput()
      • isPush

        public boolean isPush()
      • isPushSupported

        public boolean isPushSupported()
      • newPushBuilder

        public jakarta.servlet.http.PushBuilder newPushBuilder()
        Specified by:
        newPushBuilder in interface jakarta.servlet.http.HttpServletRequest
      • addEventListener

        public void addEventListener​(java.util.EventListener listener)
      • enterSession

        public void enterSession​(jakarta.servlet.http.HttpSession s)
        Remember a session that this request has just entered.
        s - the session
      • extractFormParameters

        public void extractFormParameters​(MultiMap<java.lang.String> params)
      • getAsyncContext

        public jakarta.servlet.AsyncContext getAsyncContext()
        Specified by:
        getAsyncContext in interface jakarta.servlet.ServletRequest
      • getAttribute

        public java.lang.Object getAttribute​(java.lang.String name)
        Get Request Attribute.

        Also supports jetty specific attributes to gain access to Jetty APIs:

        The Jetty Server instance
        The HttpChannel for this request
        The HttpConnection or null if another transport is used
        While these attributes may look like security problems, they are exposing nothing that is not already available via reflection from a Request instance.
        Specified by:
        getAttribute in interface jakarta.servlet.ServletRequest
        See Also:
      • getAttributeNames

        public java.util.Enumeration<java.lang.String> getAttributeNames()
        Specified by:
        getAttributeNames in interface jakarta.servlet.ServletRequest
      • getAttributes

        public Attributes getAttributes()
      • getAuthentication

        public Authentication getAuthentication()
        Get the authentication.
        the authentication
      • getAuthType

        public java.lang.String getAuthType()
        Specified by:
        getAuthType in interface jakarta.servlet.http.HttpServletRequest
      • getCharacterEncoding

        public java.lang.String getCharacterEncoding()
        Specified by:
        getCharacterEncoding in interface jakarta.servlet.ServletRequest
      • getHttpChannel

        public HttpChannel getHttpChannel()
        Returns the connection.
      • getContentLength

        public int getContentLength()
        Specified by:
        getContentLength in interface jakarta.servlet.ServletRequest
      • getContentLengthLong

        public long getContentLengthLong()
        Specified by:
        getContentLengthLong in interface jakarta.servlet.ServletRequest
      • getContentRead

        public long getContentRead()
      • getContentType

        public java.lang.String getContentType()
        Specified by:
        getContentType in interface jakarta.servlet.ServletRequest
      • getErrorContext

        public ContextHandler.Context getErrorContext()
        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

        public java.lang.String getContextPath()
        Specified by:
        getContextPath in interface jakarta.servlet.http.HttpServletRequest
      • getCookies

        public jakarta.servlet.http.Cookie[] getCookies()
        Specified by:
        getCookies in interface jakarta.servlet.http.HttpServletRequest
      • getDateHeader

        public long getDateHeader​(java.lang.String name)
        Specified by:
        getDateHeader in interface jakarta.servlet.http.HttpServletRequest
      • getDispatcherType

        public jakarta.servlet.DispatcherType getDispatcherType()
        Specified by:
        getDispatcherType in interface jakarta.servlet.ServletRequest
      • getHeader

        public java.lang.String getHeader​(java.lang.String name)
        Specified by:
        getHeader in interface jakarta.servlet.http.HttpServletRequest
      • getHeaderNames

        public java.util.Enumeration<java.lang.String> getHeaderNames()
        Specified by:
        getHeaderNames in interface jakarta.servlet.http.HttpServletRequest
      • getHeaders

        public java.util.Enumeration<java.lang.String> getHeaders​(java.lang.String name)
        Specified by:
        getHeaders in interface jakarta.servlet.http.HttpServletRequest
      • getInputState

        public int getInputState()
        Returns the inputState.
      • getInputStream

        public jakarta.servlet.ServletInputStream getInputStream()
        Specified by:
        getInputStream in interface jakarta.servlet.ServletRequest
      • getIntHeader

        public int getIntHeader​(java.lang.String name)
        Specified by:
        getIntHeader in interface jakarta.servlet.http.HttpServletRequest
      • getLocale

        public java.util.Locale getLocale()
        Specified by:
        getLocale in interface jakarta.servlet.ServletRequest
      • getLocales

        public java.util.Enumeration<java.util.Locale> getLocales()
        Specified by:
        getLocales in interface jakarta.servlet.ServletRequest
      • getLocalAddr

        public java.lang.String getLocalAddr()
        Specified by:
        getLocalAddr in interface jakarta.servlet.ServletRequest
      • getLocalName

        public java.lang.String getLocalName()
        Specified by:
        getLocalName in interface jakarta.servlet.ServletRequest
      • getLocalPort

        public int getLocalPort()
        Specified by:
        getLocalPort in interface jakarta.servlet.ServletRequest
      • getMethod

        public java.lang.String getMethod()
        Specified by:
        getMethod in interface jakarta.servlet.http.HttpServletRequest
      • getParameter

        public java.lang.String getParameter​(java.lang.String name)
        Specified by:
        getParameter in interface jakarta.servlet.ServletRequest
      • getParameterMap

        public java.util.Map<java.lang.String,​java.lang.String[]> getParameterMap()
        Specified by:
        getParameterMap in interface jakarta.servlet.ServletRequest
      • getParameterNames

        public java.util.Enumeration<java.lang.String> getParameterNames()
        Specified by:
        getParameterNames in interface jakarta.servlet.ServletRequest
      • getParameterValues

        public java.lang.String[] getParameterValues​(java.lang.String name)
        Specified by:
        getParameterValues in interface jakarta.servlet.ServletRequest
      • getQueryParameters

        public MultiMap<java.lang.String> getQueryParameters()
      • setQueryParameters

        public void setQueryParameters​(MultiMap<java.lang.String> queryParameters)
      • setContentParameters

        public void setContentParameters​(MultiMap<java.lang.String> contentParameters)
      • resetParameters

        public void resetParameters()
      • getPathInfo

        public java.lang.String getPathInfo()
        Specified by:
        getPathInfo in interface jakarta.servlet.http.HttpServletRequest
      • getPathTranslated

        public java.lang.String getPathTranslated()
        Specified by:
        getPathTranslated in interface jakarta.servlet.http.HttpServletRequest
      • getProtocol

        public java.lang.String getProtocol()
        Specified by:
        getProtocol in interface jakarta.servlet.ServletRequest
      • getQueryEncoding

        public java.lang.String getQueryEncoding()
      • getQueryString

        public java.lang.String getQueryString()
        Specified by:
        getQueryString in interface jakarta.servlet.http.HttpServletRequest
      • getReader

        public getReader()
        Specified by:
        getReader in interface jakarta.servlet.ServletRequest
      • getRealPath

        @Deprecated(since="Servlet API 2.1")
        public java.lang.String getRealPath​(java.lang.String path)
        Specified by:
        getRealPath in interface jakarta.servlet.ServletRequest
      • getRemoteInetSocketAddress

        public getRemoteInetSocketAddress()
        Access the underlying Remote InetSocketAddress for this request.
        the remote InetSocketAddress for this request, or null if the request has no remote (see ServletRequest.getRemoteAddr() for conditions that result in no remote address)
      • getRemoteAddr

        public java.lang.String getRemoteAddr()
        Specified by:
        getRemoteAddr in interface jakarta.servlet.ServletRequest
      • getRemoteHost

        public java.lang.String getRemoteHost()
        Specified by:
        getRemoteHost in interface jakarta.servlet.ServletRequest
      • getRemotePort

        public int getRemotePort()
        Specified by:
        getRemotePort in interface jakarta.servlet.ServletRequest
      • getRemoteUser

        public java.lang.String getRemoteUser()
        Specified by:
        getRemoteUser in interface jakarta.servlet.http.HttpServletRequest
      • getRequestDispatcher

        public jakarta.servlet.RequestDispatcher getRequestDispatcher​(java.lang.String path)
        Specified by:
        getRequestDispatcher in interface jakarta.servlet.ServletRequest
      • getRequestedSessionId

        public java.lang.String getRequestedSessionId()
        Specified by:
        getRequestedSessionId in interface jakarta.servlet.http.HttpServletRequest
      • getRequestURI

        public java.lang.String getRequestURI()
        Specified by:
        getRequestURI in interface jakarta.servlet.http.HttpServletRequest
      • getRequestURL

        public java.lang.StringBuffer getRequestURL()
        Specified by:
        getRequestURL in interface jakarta.servlet.http.HttpServletRequest
      • getResponse

        public Response getResponse()
      • getRootURL

        public java.lang.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.

      • getScheme

        public java.lang.String getScheme()
        Specified by:
        getScheme in interface jakarta.servlet.ServletRequest
      • getServerName

        public java.lang.String getServerName()
        Specified by:
        getServerName in interface jakarta.servlet.ServletRequest
      • getServerPort

        public int getServerPort()
        Specified by:
        getServerPort in interface jakarta.servlet.ServletRequest
      • getServletContext

        public jakarta.servlet.ServletContext getServletContext()
        Specified by:
        getServletContext in interface jakarta.servlet.ServletRequest
      • getServletName

        public java.lang.String getServletName()
      • getServletPath

        public java.lang.String getServletPath()
        Specified by:
        getServletPath in interface jakarta.servlet.http.HttpServletRequest
      • getServletResponse

        public jakarta.servlet.ServletResponse getServletResponse()
      • changeSessionId

        public java.lang.String changeSessionId()
        Specified by:
        changeSessionId in interface jakarta.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

        public jakarta.servlet.http.HttpSession getSession​(SessionHandler sessionHandler)
        Find a session that this request has already entered for the given SessionHandler
        sessionHandler - the SessionHandler (ie context) to check
        the session for the passed session handler or null
      • getSession

        public jakarta.servlet.http.HttpSession getSession()
        Specified by:
        getSession in interface jakarta.servlet.http.HttpServletRequest
      • getSession

        public jakarta.servlet.http.HttpSession getSession​(boolean create)
        Specified by:
        getSession in interface jakarta.servlet.http.HttpServletRequest
      • getSessionHandler

        public SessionHandler getSessionHandler()
        Returns the sessionManager.
      • getTimeStamp

        public long getTimeStamp()
        Get Request TimeStamp
        The time that the request was received.
      • getHttpURI

        public HttpURI getHttpURI()
      • setHttpURI

        public void setHttpURI​(HttpURI uri)
      • getOriginalURI

        public java.lang.String getOriginalURI()
        Returns the original uri passed in metadata before customization/rewrite
      • getUserPrincipal

        public getUserPrincipal()
        Specified by:
        getUserPrincipal in interface jakarta.servlet.http.HttpServletRequest
      • isHandled

        public boolean isHandled()
      • isAsyncStarted

        public boolean isAsyncStarted()
        Specified by:
        isAsyncStarted in interface jakarta.servlet.ServletRequest
      • isAsyncSupported

        public boolean isAsyncSupported()
        Specified by:
        isAsyncSupported in interface jakarta.servlet.ServletRequest
      • isRequestedSessionIdFromCookie

        public boolean isRequestedSessionIdFromCookie()
        Specified by:
        isRequestedSessionIdFromCookie in interface jakarta.servlet.http.HttpServletRequest
      • isRequestedSessionIdFromUrl

        @Deprecated(since="Servlet API 2.1")
        public boolean isRequestedSessionIdFromUrl()
        Specified by:
        isRequestedSessionIdFromUrl in interface jakarta.servlet.http.HttpServletRequest
      • isRequestedSessionIdFromURL

        public boolean isRequestedSessionIdFromURL()
        Specified by:
        isRequestedSessionIdFromURL in interface jakarta.servlet.http.HttpServletRequest
      • isRequestedSessionIdValid

        public boolean isRequestedSessionIdValid()
        Specified by:
        isRequestedSessionIdValid in interface jakarta.servlet.http.HttpServletRequest
      • isSecure

        public boolean isSecure()
        Specified by:
        isSecure in interface jakarta.servlet.ServletRequest
      • setSecure

        public void setSecure​(boolean secure)
      • isUserInRole

        public boolean isUserInRole​(java.lang.String role)
        Specified by:
        isUserInRole in interface jakarta.servlet.http.HttpServletRequest
      • setMetaData

        public void setMetaData​(MetaData.Request request)
        request - the Request metadata
      • hasMetaData

        public boolean hasMetaData()
      • recycle

        protected void recycle()
      • removeAttribute

        public void removeAttribute​(java.lang.String name)
        Specified by:
        removeAttribute in interface jakarta.servlet.ServletRequest
      • removeEventListener

        public void removeEventListener​(java.util.EventListener listener)
      • setAsyncSupported

        public void setAsyncSupported​(boolean supported,
                                      java.lang.Object source)
      • setAttribute

        public void setAttribute​(java.lang.String name,
                                 java.lang.Object value)
        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 to setQueryEncoding(java.lang.String).
        Specified by:
        setAttribute in interface jakarta.servlet.ServletRequest
        See Also:
        ServletRequest.setAttribute(java.lang.String, java.lang.Object)
      • setAsyncAttributes

        public void setAsyncAttributes()
      • setAuthentication

        public void setAuthentication​(Authentication authentication)
        Set the authentication.
        authentication - the authentication to set
      • setCharacterEncoding

        public void setCharacterEncoding​(java.lang.String encoding)
        Specified by:
        setCharacterEncoding in interface jakarta.servlet.ServletRequest
      • setCharacterEncodingUnchecked

        public void setCharacterEncodingUnchecked​(java.lang.String encoding)
      • setContentType

        public void setContentType​(java.lang.String contentType)
      • setContext

        public void setContext​(ContextHandler.Context context,
                               java.lang.String pathInContext)
        Set request context and path in the context.
        context - context object
        pathInContext - the part of the URI path that is withing the context. For servlets, this is equal to servletPath + pathInfo
      • setCookies

        public void setCookies​(jakarta.servlet.http.Cookie[] cookies)
        cookies - The cookies to set.
      • setDispatcherType

        public void setDispatcherType​(jakarta.servlet.DispatcherType type)
      • setHandled

        public void setHandled​(boolean h)
      • setMethod

        public void setMethod​(java.lang.String method)
        method - The method to set.
      • isHead

        public boolean isHead()
      • setQueryEncoding

        public void setQueryEncoding​(java.lang.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.Request.queryEncoding" may be set as an alternate method of calling setQueryEncoding.
        queryEncoding - the URI query character encoding
      • setRemoteAddr

        public void setRemoteAddr​( addr)
        addr - The address to set.
      • setRequestedSessionId

        public void setRequestedSessionId​(java.lang.String requestedSessionId)
        requestedSessionId - The requestedSessionId to set.
      • setRequestedSessionIdFromCookie

        public void setRequestedSessionIdFromCookie​(boolean requestedSessionIdCookie)
        requestedSessionIdCookie - The requestedSessionIdCookie to set.
      • setSession

        public void setSession​(jakarta.servlet.http.HttpSession session)
        session - The session to set.
      • setSessionHandler

        public void setSessionHandler​(SessionHandler sessionHandler)
        sessionHandler - The SessionHandler to set.
      • setTimeStamp

        public void setTimeStamp​(long ts)
      • startAsync

        public jakarta.servlet.AsyncContext startAsync()
                                                throws java.lang.IllegalStateException
        Specified by:
        startAsync in interface jakarta.servlet.ServletRequest
      • startAsync

        public jakarta.servlet.AsyncContext startAsync​(jakarta.servlet.ServletRequest servletRequest,
                                                       jakarta.servlet.ServletResponse servletResponse)
                                                throws java.lang.IllegalStateException
        Specified by:
        startAsync in interface jakarta.servlet.ServletRequest
      • unwrap

        public static jakarta.servlet.http.HttpServletRequest unwrap​(jakarta.servlet.ServletRequest servletRequest)
      • toString

        public java.lang.String toString()
        toString in class java.lang.Object
      • authenticate

        public boolean authenticate​(jakarta.servlet.http.HttpServletResponse response)
        Specified by:
        authenticate in interface jakarta.servlet.http.HttpServletRequest
      • getPart

        public jakarta.servlet.http.Part getPart​(java.lang.String name)
        Specified by:
        getPart in interface jakarta.servlet.http.HttpServletRequest
      • getParts

        public java.util.Collection<jakarta.servlet.http.Part> getParts()
        Specified by:
        getParts in interface jakarta.servlet.http.HttpServletRequest
      • login

        public void login​(java.lang.String username,
                          java.lang.String password)
                   throws jakarta.servlet.ServletException
        Specified by:
        login in interface jakarta.servlet.http.HttpServletRequest
      • logout

        public void logout()
                    throws jakarta.servlet.ServletException
        Specified by:
        logout in interface jakarta.servlet.http.HttpServletRequest
      • mergeQueryParameters

        public void mergeQueryParameters​(java.lang.String oldQuery,
                                         java.lang.String newQuery)
      • upgrade

        public <T extends jakarta.servlet.http.HttpUpgradeHandler> T upgrade​(java.lang.Class<T> handlerClass)
        Specified by:
        upgrade in interface jakarta.servlet.http.HttpServletRequest
      • setServletPathMapping

        public void setServletPathMapping​(ServletPathMapping servletPathMapping)
        Set the servletPathMapping, the servletPath and the pathInfo.
        servletPathMapping - The mapping used to return from getHttpServletMapping()
      • getServletPathMapping

        public ServletPathMapping getServletPathMapping()
        The mapping for the current target servlet, regardless of dispatch type.
      • getHttpServletMapping

        public jakarta.servlet.http.HttpServletMapping getHttpServletMapping()
        Specified by:
        getHttpServletMapping in interface jakarta.servlet.http.HttpServletRequest