Class EntityHttpServletRequest

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

    public class EntityHttpServletRequest
    extends Object
    implements javax.servlet.http.HttpServletRequest
    Makes a copy of the data in a servlet request into a new request object
    Author:
    Aaron Zeckoski (azeckoski @ gmail.com)
    • Field Detail

      • DEFAULT_SERVER_ADDR

        public static final String DEFAULT_SERVER_ADDR
        default server address: 127.0.0.1
        See Also:
        Constant Field Values
      • DEFAULT_SERVER_PORT

        public static final int DEFAULT_SERVER_PORT
        default server port: 80
        See Also:
        Constant Field Values
      • DEFAULT_REMOTE_ADDR

        public static final String DEFAULT_REMOTE_ADDR
        default remote address: 127.0.0.1
        See Also:
        Constant Field Values
      • DEFAULT_REMOTE_HOST

        public static final String DEFAULT_REMOTE_HOST
        The default remote host: 'localhost'.
        See Also:
        Constant Field Values
      • copy

        public javax.servlet.http.HttpServletRequest copy
      • pathQueryParams

        public Map<String,​String[]> pathQueryParams
        This stores all the query params found when the request was created
    • Constructor Detail

      • EntityHttpServletRequest

        public EntityHttpServletRequest​(javax.servlet.http.HttpServletRequest req)
        Create a new request from a given request
        Parameters:
        req - any request
      • EntityHttpServletRequest

        public EntityHttpServletRequest​(javax.servlet.http.HttpServletRequest req,
                                        String pathString)
        Create a new request from a given request and modify it based on the path string
        Parameters:
        req - any request
        pathString - any full path or URL (/direct/prefix/id.xml)
      • EntityHttpServletRequest

        public EntityHttpServletRequest​(javax.servlet.http.HttpServletRequest req,
                                        String method,
                                        String pathString)
        Create a new request from a given request and modify it based on the path string and method
        Parameters:
        req - any request
        method - GET, POST, PUT, DELETE (PUT and DELETE not supported by browsers), this will be set to POST if null or unset
        pathString - any full path or URL (/direct/prefix/id.xml)
      • EntityHttpServletRequest

        public EntityHttpServletRequest​(String pathString)
        Create a request using the pathString
        Parameters:
        pathString - any path or URL
      • EntityHttpServletRequest

        public EntityHttpServletRequest​(String method,
                                        String pathString)
        Create a request using the pathString and setting the method
        Parameters:
        pathString - any path or URL
        method - GET, POST, PUT, DELETE (PUT and DELETE not supported by browsers), this will be set to POST if null or unset
      • EntityHttpServletRequest

        public EntityHttpServletRequest​(String method,
                                        String pathString,
                                        String... params)
        Create a request using the pathString and setting the method and params
        Parameters:
        method - GET, POST, PUT, DELETE (PUT and DELETE not supported by browsers), this will be set to POST if null or unset
        pathString - any path or URL
        params - alternating keys and values (starting with keys) to place into the request parameters
    • Method Detail

      • setRequestValues

        public void setRequestValues​(javax.servlet.http.HttpServletRequest req)
        Set all the values from a request on this request object and set this request as the one which the values were copied from
        Parameters:
        req - any request
      • setPathString

        public URLData setPathString​(String pathString)
        This will set the given url/path string values into this request, this will override any values that are currently set
        Parameters:
        pathString - any url or path string
        Returns:
        the url data object based on the input object OR null if the string is null or empty
      • setContent

        public void setContent​(InputStream contentStream,
                               int contentLength)
        Allows control over the content data which is used in this request, all data should be UTF-8 encoded
        Parameters:
        content - any IS content, UTF-8 encoded, replaces existing content
      • setContent

        public void setContent​(byte[] content)
        Allows control over the content data which is used in this request, all data should be UTF-8 encoded
        Parameters:
        content - any byte[] content, UTF-8 encoded, replaces existing content
      • setContent

        public void setContent​(String content)
        Allows control over the content data which is used in this request, all data should be UTF-8 encoded
        Parameters:
        content - any string content, UTF-8 encoded, replaces existing content
      • getContent

        public javax.servlet.ServletInputStream getContent()
                                                    throws IOException
        Gets the content data out of the request, ensures that the data can be retrieved somehow
        Returns:
        the content data from the request
        Throws:
        IOException - if there is a failure
      • getAttribute

        public Object getAttribute​(String name)
        Specified by:
        getAttribute in interface javax.servlet.ServletRequest
      • getAttributeNames

        public Enumeration getAttributeNames()
        Specified by:
        getAttributeNames in interface javax.servlet.ServletRequest
      • removeAttribute

        public void removeAttribute​(String name)
        Specified by:
        removeAttribute in interface javax.servlet.ServletRequest
      • setAttribute

        public void setAttribute​(String name,
                                 Object o)
        Specified by:
        setAttribute in interface javax.servlet.ServletRequest
      • clearAttributes

        public void clearAttributes()
        Remove all attributes
      • getCharacterEncoding

        public String getCharacterEncoding()
        Specified by:
        getCharacterEncoding in interface javax.servlet.ServletRequest
      • setContentType

        public void setContentType​(String contentType)
        Sets the content type for this request content
        Parameters:
        contentType -
      • getContentType

        public String getContentType()
        Specified by:
        getContentType in interface javax.servlet.ServletRequest
      • getContentLength

        public int getContentLength()
        Specified by:
        getContentLength in interface javax.servlet.ServletRequest
      • getInputStream

        public javax.servlet.ServletInputStream getInputStream()
                                                        throws IOException
        Specified by:
        getInputStream in interface javax.servlet.ServletRequest
        Throws:
        IOException
      • setLocale

        public void setLocale​(Locale locale)
      • getLocale

        public Locale getLocale()
        Specified by:
        getLocale in interface javax.servlet.ServletRequest
      • setMethod

        public void setMethod​(String method)
      • getMethod

        public String getMethod()
        Specified by:
        getMethod in interface javax.servlet.http.HttpServletRequest
      • setContextPath

        public void setContextPath​(String contextPath)
      • getContextPath

        public String getContextPath()
        Specified by:
        getContextPath in interface javax.servlet.http.HttpServletRequest
      • setPathInfo

        public void setPathInfo​(String pathInfo)
      • getPathInfo

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

        public String getPathTranslated()
        Specified by:
        getPathTranslated in interface javax.servlet.http.HttpServletRequest
      • setQueryString

        public void setQueryString​(String queryString)
      • getQueryString

        public String getQueryString()
        Specified by:
        getQueryString in interface javax.servlet.http.HttpServletRequest
      • getRequestURI

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

        public StringBuffer getRequestURL()
        Specified by:
        getRequestURL in interface javax.servlet.http.HttpServletRequest
      • setServletPath

        public void setServletPath​(String servletPath)
      • getServletPath

        public String getServletPath()
        Specified by:
        getServletPath in interface javax.servlet.http.HttpServletRequest
      • addCookie

        public void addCookie​(javax.servlet.http.Cookie cookie)
        Adds a new cookie to the request
        Parameters:
        cookie - a cookie to add, will displace existing cookies with the same name
      • removeCookie

        public void removeCookie​(String name)
        Removes the cookie with the given name from the request
        Parameters:
        name - the name of a cookie
      • getCookies

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

        public void clearCookies()
        Remove all cookies
      • addHeader

        public void addHeader​(String name,
                              String... content)
      • removeHeader

        public void removeHeader​(String name)
      • getHeader

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

        public Enumeration getHeaderNames()
        Specified by:
        getHeaderNames in interface javax.servlet.http.HttpServletRequest
      • getHeaders

        public Enumeration getHeaders​(String name)
        Specified by:
        getHeaders in interface javax.servlet.http.HttpServletRequest
      • getDateHeader

        public long getDateHeader​(String name)
        Specified by:
        getDateHeader in interface javax.servlet.http.HttpServletRequest
      • getIntHeader

        public int getIntHeader​(String name)
        Specified by:
        getIntHeader in interface javax.servlet.http.HttpServletRequest
      • clearHeaders

        public void clearHeaders()
        Remove all headers
      • getAuthType

        public String getAuthType()
        Specified by:
        getAuthType in interface javax.servlet.http.HttpServletRequest
      • getLocalAddr

        public String getLocalAddr()
        Specified by:
        getLocalAddr in interface javax.servlet.ServletRequest
      • getLocales

        public Enumeration getLocales()
        Specified by:
        getLocales in interface javax.servlet.ServletRequest
      • getLocalName

        public String getLocalName()
        Specified by:
        getLocalName in interface javax.servlet.ServletRequest
      • getLocalPort

        public int getLocalPort()
        Specified by:
        getLocalPort in interface javax.servlet.ServletRequest
      • getParameters

        public Map<String,​String[]> getParameters()
        Returns:
        all parameters in this request
      • getStringParameters

        public Map<String,​String> getStringParameters()
        Returns:
        all parameters in this request as single strings
      • getParameter

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

        public Map getParameterMap()
        Specified by:
        getParameterMap in interface javax.servlet.ServletRequest
      • getParameterNames

        public Enumeration getParameterNames()
        Specified by:
        getParameterNames in interface javax.servlet.ServletRequest
      • getParameterValues

        public String[] getParameterValues​(String name)
        Specified by:
        getParameterValues in interface javax.servlet.ServletRequest
      • addParameter

        public void addParameter​(String name,
                                 String value)
        Add a single parameter, this will append to an existing one
      • addParameter

        public void addParameter​(String name,
                                 String[] values)
        Add an array of values for a parameter, these will append to existing ones
      • setParameter

        public void setParameter​(String name,
                                 String[] values)
        Set a new parameter (overwrite an existing one)
      • setParameters

        public void setParameters​(Map<String,​String[]> params)
        Set a large number of params at once, replaces existing params
        Parameters:
        params - map of params
      • removeParameter

        public void removeParameter​(String name)
        Removes a parameter and all values for it
        Parameters:
        name -
      • clearParameters

        public void clearParameters()
        Remove all parameters
      • getProtocol

        public String getProtocol()
        Specified by:
        getProtocol in interface javax.servlet.ServletRequest
      • getRealPath

        public String getRealPath​(String path)
        Specified by:
        getRealPath in interface javax.servlet.ServletRequest
      • getRemoteAddr

        public String getRemoteAddr()
        Specified by:
        getRemoteAddr in interface javax.servlet.ServletRequest
      • getRemoteHost

        public String getRemoteHost()
        Specified by:
        getRemoteHost in interface javax.servlet.ServletRequest
      • getRemotePort

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

        public String getRemoteUser()
        Specified by:
        getRemoteUser in interface javax.servlet.http.HttpServletRequest
      • setUseRealDispatcher

        public void setUseRealDispatcher​(boolean real)
        Parameters:
        real - if true and there is a real RequestDispatcher available then use it, otherwise just emulate a forward/include call using the fake one (will always use the fake one if no real one is found)
      • getRequestDispatcher

        public javax.servlet.RequestDispatcher getRequestDispatcher​(String path)
        Specified by:
        getRequestDispatcher in interface javax.servlet.ServletRequest
      • getScheme

        public String getScheme()
        Specified by:
        getScheme in interface javax.servlet.ServletRequest
      • getServerName

        public String getServerName()
        Specified by:
        getServerName in interface javax.servlet.ServletRequest
      • getServerPort

        public int getServerPort()
        Specified by:
        getServerPort in interface javax.servlet.ServletRequest
      • getRequestedSessionId

        public String getRequestedSessionId()
        Specified by:
        getRequestedSessionId in interface javax.servlet.http.HttpServletRequest
      • getSession

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

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

        public Principal getUserPrincipal()
        Specified by:
        getUserPrincipal in interface javax.servlet.http.HttpServletRequest
      • isRequestedSessionIdFromCookie

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

        public boolean isRequestedSessionIdFromUrl()
        Specified by:
        isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequest
      • isRequestedSessionIdFromURL

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

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

        public boolean isSecure()
        Specified by:
        isSecure in interface javax.servlet.ServletRequest
      • isUserInRole

        public boolean isUserInRole​(String role)
        Specified by:
        isUserInRole in interface javax.servlet.http.HttpServletRequest