Class Request

  • All Implemented Interfaces:
    HttpServletRequest, ServletRequest

    public class Request
    extends java.lang.Object
    implements HttpServletRequest
    Jetty Request.

    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

    • The 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.
    • the HTTP session methods will all return null sessions until such time as a request has been passed to a SessionHandler which 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 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.

    • Field Detail

      • MULTIPART_CONFIG_ELEMENT

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

      • getHttpFields

        public HttpFields getHttpFields()
      • 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 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.
        • 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 any getQueryString()
        • If 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.
        • 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​(java.util.EventListener listener)
      • enterSession

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

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

        public java.lang.Object getAttribute​(java.lang.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
        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 ServletRequest
        See Also:
        ServletRequest.getAttribute(java.lang.String)
      • getAttributes

        public Attributes getAttributes()
      • getAuthentication

        public Authentication getAuthentication()
        Get the authentication.
        Returns:
        the authentication
      • getHttpChannel

        public HttpChannel getHttpChannel()
        Returns:
        Returns the connection.
      • getContentRead

        public long getContentRead()
      • getErrorContext

        public ContextHandler.Context getErrorContext()
        Returns:
        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
      • getHeaders

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

        public int getInputState()
        Returns:
        Returns the inputState.
      • getLocales

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

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

        public java.util.Map<java.lang.String,​java.lang.String[]> getParameterMap()
        Specified by:
        getParameterMap in interface 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()
      • getQueryEncoding

        public java.lang.String getQueryEncoding()
      • getReader

        public java.io.BufferedReader getReader()
                                         throws java.io.IOException
        Specified by:
        getReader in interface ServletRequest
        Throws:
        java.io.IOException
      • getRealPath

        public java.lang.String getRealPath​(java.lang.String path)
        Specified by:
        getRealPath in interface ServletRequest
      • getRemoteInetSocketAddress

        public java.net.InetSocketAddress getRemoteInetSocketAddress()
        Access the underlying Remote InetSocketAddress for this request.
        Returns:
        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)
      • 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.

        Returns:
        "scheme://host:port"
      • getServletName

        public java.lang.String getServletName()
      • 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 HttpSession getSession​(SessionHandler sessionHandler)
        Find a session that this request has already entered for the given SessionHandler
        Parameters:
        sessionHandler - the SessionHandler (ie context) to check
        Returns:
      • 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 HttpURI getHttpURI()
        Returns:
        Returns the uri.
      • getOriginalURI

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

        public void setHttpURI​(HttpURI uri)
        Parameters:
        uri - the URI to set
      • isHandled

        public boolean isHandled()
      • setSecure

        public void setSecure​(boolean secure)
      • setMetaData

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

        public boolean hasMetaData()
      • removeEventListener

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

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

        public void setAttribute​(java.lang.String name,
                                 java.lang.Object value)
        Specified by:
        setAttribute in interface ServletRequest
      • setAttributes

        public void setAttributes​(Attributes attributes)
      • setAsyncAttributes

        public void setAsyncAttributes()
      • setAuthentication

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

        public void setCharacterEncoding​(java.lang.String encoding)
                                  throws java.io.UnsupportedEncodingException
        Specified by:
        setCharacterEncoding in interface ServletRequest
        Throws:
        java.io.UnsupportedEncodingException
      • setCharacterEncodingUnchecked

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

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

        public void setContext​(ContextHandler.Context context)
        Set request context
        Parameters:
        context - context object
      • setContextPath

        public void setContextPath​(java.lang.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​(java.lang.String method)
        Parameters:
        method - The method to set.
      • setHttpVersion

        public void setHttpVersion​(HttpVersion version)
      • isHead

        public boolean isHead()
      • setPathInfo

        public void setPathInfo​(java.lang.String pathInfo)
        Parameters:
        pathInfo - The pathInfo to set.
      • 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.server.Request.queryEncoding" may be set as an alternate method of calling setQueryEncoding.
        Parameters:
        queryEncoding - the URI query character encoding
      • setQueryString

        public void setQueryString​(java.lang.String queryString)
        Parameters:
        queryString - The queryString to set.
      • setRemoteAddr

        public void setRemoteAddr​(java.net.InetSocketAddress addr)
        Parameters:
        addr - The address to set.
      • setRequestedSessionId

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

        public void setRequestedSessionIdFromCookie​(boolean requestedSessionIdCookie)
        Parameters:
        requestedSessionIdCookie - The requestedSessionIdCookie to set.
      • setURIPathQuery

        public void setURIPathQuery​(java.lang.String requestURI)
      • setScheme

        public void setScheme​(java.lang.String scheme)
        Parameters:
        scheme - The scheme to set.
      • setAuthority

        public void setAuthority​(java.lang.String host,
                                 int port)
        Parameters:
        host - The host to set.
        port - the port to set
      • setServletPath

        public void setServletPath​(java.lang.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)
      • startAsync

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • mergeQueryParameters

        public void mergeQueryParameters​(java.lang.String oldQuery,
                                         java.lang.String newQuery,
                                         boolean updateQueryString)