Class HttpServletRequestWrapper

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

    public class HttpServletRequestWrapper
    extends javax.servlet.http.HttpServletRequestWrapper
    An HttpServletRequest wrapper.
    Version:
    Coherence 2.3
    Author:
    cp 2003.07.24
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected javax.servlet.http.HttpServletResponse m_res
      The app server's response object.
      • Fields inherited from interface javax.servlet.http.HttpServletRequest

        BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpServletRequestWrapper​(SessionHelper helper, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String sSessionId, boolean fCookie, boolean fUrl)
      Construct an HttpServletRequestWrapper object to wrap an app server's request object.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      String changeSessionId()
      Change the session id of the current session associated with this request and return the new session ID.
      Object getAttribute​(String sName)
      Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
      Enumeration getAttributeNames()
      Returns an Enumeration containing the names of the attributes available to this request.
      protected String getDescription()
      Returns a string representation of this object's attributes.
      javax.servlet.http.HttpServletRequest getHttpServletRequest()
      Get the wrapped HttpServletRequest.
      javax.servlet.http.HttpServletResponse getHttpServletResponse()
      Get the HttpServletResponse associated with the wrapped HttpServletRequest.
      String getRequestedSessionId()
      Returns the session ID specified by the client.
      javax.servlet.http.HttpSession getSession()
      Returns the current session associated with this request, or if the request does not have a session, creates one.
      javax.servlet.http.HttpSession getSession​(boolean fCreate)
      Returns the current HttpSession associated with this request or, if there is no current session and fCreate is true, returns a new session.
      javax.servlet.http.HttpSession getSession​(boolean fCreate, boolean fCookie)
      Returns the current HttpSession associated with this request or, if there is no current session and fCreate is true, returns a new session.
      SessionHelper getSessionHelper()
      Get the SessionHelper.
      boolean isRequestedSessionIdFromCookie()
      Checks whether the requested session ID came in as a cookie.
      boolean isRequestedSessionIdFromUrl()
      Deprecated.
      As of Version 2.1 of the Java Servlet API, use isRequestedSessionIdFromURL() instead.
      boolean isRequestedSessionIdFromURL()
      Checks whether the requested session ID came in as part of the request URL.
      boolean isRequestedSessionIdValid()
      Checks whether the requested session ID is still valid.
      String toString()
      Returns a string representation of the object.
      • Methods inherited from class javax.servlet.http.HttpServletRequestWrapper

        authenticate, getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getHttpServletMapping, getIntHeader, getMethod, getPart, getParts, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestURI, getRequestURL, getServletPath, getTrailerFields, getUserPrincipal, isTrailerFieldsReady, isUserInRole, login, logout, newPushBuilder, upgrade
      • Methods inherited from class javax.servlet.ServletRequestWrapper

        getAsyncContext, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequest, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, isWrapperFor, isWrapperFor, removeAttribute, setAttribute, setCharacterEncoding, setRequest, startAsync, startAsync
      • Methods inherited from interface javax.servlet.ServletRequest

        getAsyncContext, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, removeAttribute, setAttribute, setCharacterEncoding, startAsync, startAsync
    • Field Detail

      • m_res

        protected javax.servlet.http.HttpServletResponse m_res
        The app server's response object.
    • Constructor Detail

      • HttpServletRequestWrapper

        public HttpServletRequestWrapper​(SessionHelper helper,
                                         javax.servlet.http.HttpServletRequest req,
                                         javax.servlet.http.HttpServletResponse res,
                                         String sSessionId,
                                         boolean fCookie,
                                         boolean fUrl)
        Construct an HttpServletRequestWrapper object to wrap an app server's request object.
        Parameters:
        helper - the SessionHelper for this application
        req - the app server's request object
        res - the app server's response object
        sSessionId - the session ID (if any) that came with the request
        fCookie - if the session ID came from a cookie
        fUrl - if the session ID came from the url
    • Method Detail

      • getAttribute

        public Object getAttribute​(String sName)
        Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

        Attributes can be set two ways. The servlet container may set attributes to make available custom information about a request. For example, for requests made using HTTPS, the attribute javax.servlet.request.X509Certificate can be used to retrieve information on the certificate of the client. Attributes can also be set programatically using ServletRequest.setAttribute(java.lang.String, java.lang.Object). This allows information to be embedded into a request before a RequestDispatcher call.

        Attribute names should follow the same conventions as package names. This specification reserves names matching java.*, javax.*, and sun.*.

        Specified by:
        getAttribute in interface javax.servlet.ServletRequest
        Overrides:
        getAttribute in class javax.servlet.ServletRequestWrapper
        Parameters:
        sName - a String specifying the name of the attribute
        Returns:
        an Object containing the value of the attribute, or null if the attribute does not exist
      • getAttributeNames

        public Enumeration getAttributeNames()
        Returns an Enumeration containing the names of the attributes available to this request. This method returns an empty Enumeration if the request has no attributes available to it.
        Specified by:
        getAttributeNames in interface javax.servlet.ServletRequest
        Overrides:
        getAttributeNames in class javax.servlet.ServletRequestWrapper
        Returns:
        an Enumeration of strings containing the names of the request's attributes
      • getRequestedSessionId

        public String getRequestedSessionId()
        Returns the session ID specified by the client. This may not be the same as the ID of the actual session in use. For example, if the request specified an old (expired) session ID and the server has started a new session, this method gets a new session with a new ID. If the request did not specify a session ID, this method returns null.
        Specified by:
        getRequestedSessionId in interface javax.servlet.http.HttpServletRequest
        Overrides:
        getRequestedSessionId in class javax.servlet.http.HttpServletRequestWrapper
        Returns:
        a String specifying the session ID, or null if the request did not specify a session ID
      • getSession

        public javax.servlet.http.HttpSession getSession()
        Returns the current session associated with this request, or if the request does not have a session, creates one.
        Specified by:
        getSession in interface javax.servlet.http.HttpServletRequest
        Overrides:
        getSession in class javax.servlet.http.HttpServletRequestWrapper
        Returns:
        the HttpSession associated with this request
      • getSession

        public javax.servlet.http.HttpSession getSession​(boolean fCreate)
        Returns the current HttpSession associated with this request or, if there is no current session and fCreate is true, returns a new session.

        If fCreate is false and the request has no valid HttpSession, this method returns null.

        To make sure the session is properly maintained, you must call this method before the response is committed. If the container is using cookies to maintain session integrity and is asked to create a new session when the response is committed, an IllegalStateException is thrown.

        Specified by:
        getSession in interface javax.servlet.http.HttpServletRequest
        Overrides:
        getSession in class javax.servlet.http.HttpServletRequestWrapper
        Parameters:
        fCreate - true to create a new session for this request if necessary; false to return null if there's no current session
        Returns:
        the HttpSession associated with this request or null if fCreate is false and the request has no valid session
      • getSession

        public javax.servlet.http.HttpSession getSession​(boolean fCreate,
                                                         boolean fCookie)
        Returns the current HttpSession associated with this request or, if there is no current session and fCreate is true, returns a new session.

        If fCreate is false and the request has no valid HttpSession, this method returns null.

        To make sure the session is properly maintained, you must call this method before the response is committed. If the container is using cookies to maintain session integrity and is asked to create a new session when the response is committed, an IllegalStateException is thrown.

        Parameters:
        fCreate - true to create a new session for this request if necessary; false to return null if there's no current session
        fCookie - true to create a session cookie in the response
        Returns:
        the HttpSession associated with this request or null if fCreate is false and the request has no valid session
      • isRequestedSessionIdFromCookie

        public boolean isRequestedSessionIdFromCookie()
        Checks whether the requested session ID came in as a cookie.
        Specified by:
        isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequest
        Overrides:
        isRequestedSessionIdFromCookie in class javax.servlet.http.HttpServletRequestWrapper
        Returns:
        true if the session ID came in as a cookie; otherwise, false
      • isRequestedSessionIdFromURL

        public boolean isRequestedSessionIdFromURL()
        Checks whether the requested session ID came in as part of the request URL.
        Specified by:
        isRequestedSessionIdFromURL in interface javax.servlet.http.HttpServletRequest
        Overrides:
        isRequestedSessionIdFromURL in class javax.servlet.http.HttpServletRequestWrapper
        Returns:
        true if the session ID came in as part of a URL; otherwise, false
      • isRequestedSessionIdFromUrl

        public boolean isRequestedSessionIdFromUrl()
        Deprecated.
        As of Version 2.1 of the Java Servlet API, use isRequestedSessionIdFromURL() instead.
        Checks whether the requested session ID came in as part of the request URL.
        Specified by:
        isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequest
        Overrides:
        isRequestedSessionIdFromUrl in class javax.servlet.http.HttpServletRequestWrapper
        Returns:
        true if the session ID came in as part of a URL; otherwise, false
      • isRequestedSessionIdValid

        public boolean isRequestedSessionIdValid()
        Checks whether the requested session ID is still valid.
        Specified by:
        isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequest
        Overrides:
        isRequestedSessionIdValid in class javax.servlet.http.HttpServletRequestWrapper
        Returns:
        true if this request has an id for a valid session in the current session context; false otherwise
      • changeSessionId

        public String changeSessionId()
        Change the session id of the current session associated with this request and return the new session ID.
        Specified by:
        changeSessionId in interface javax.servlet.http.HttpServletRequest
        Overrides:
        changeSessionId in class javax.servlet.http.HttpServletRequestWrapper
        Returns:
        the new session ID
      • toString

        public String toString()
        Returns a string representation of the object.
        Overrides:
        toString in class Object
        Returns:
        a string representation of the object
      • getDescription

        protected String getDescription()
        Returns a string representation of this object's attributes.
        Returns:
        a string representation of this object's attributes
      • getSessionHelper

        public SessionHelper getSessionHelper()
        Get the SessionHelper.
        Returns:
        the SessionHelper for this app
      • getHttpServletRequest

        public javax.servlet.http.HttpServletRequest getHttpServletRequest()
        Get the wrapped HttpServletRequest.
        Returns:
        the wrapped HttpServletRequest
      • getHttpServletResponse

        public javax.servlet.http.HttpServletResponse getHttpServletResponse()
        Get the HttpServletResponse associated with the wrapped HttpServletRequest.
        Returns:
        the associated HttpServletResponse