org.exist.http.servlets
Class HttpServletRequestWrapper

java.lang.Object
  extended by org.exist.http.servlets.HttpServletRequestWrapper
All Implemented Interfaces:
HttpServletRequest, ServletRequest

public class HttpServletRequestWrapper
extends Object
implements HttpServletRequest

A wrapper for HttpServletRequest - differentiates between POST parameters in the URL or Content Body - keeps content Body of the POST request, making it available many times through getContentBodyInputStream() . A method of differentiating between POST parameters in the URL or Content Body of the request was needed. The standard javax.servlet.http.HTTPServletRequest does not differentiate between URL or content body parameters, this class does, the type is indicated in RequestParameter.type. To differentiate manually we need to read the URL (getQueryString()) and the Content body (getInputStream()), this is problematic with the standard javax.servlet.http.HTTPServletRequest as parameter functions (getParameterMap(), getParameterNames(), getParameter(String), getParameterValues(String)) affect the input stream functions (getInputStream(), getReader()) and vice versa. This class solves this by reading the Request Parameters initially from both the URL and the Content Body of the Request and storing them in the private variable params for later use.

Version:
1.1
Author:
Adam Retter

Field Summary
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
HttpServletRequestWrapper(HttpServletRequest request, String formEncoding)
          HttpServletRequestWrapper Constructor
 
Method Summary
 Object getAttribute(String name)
           
 Enumeration getAttributeNames()
           
 String getAuthType()
           
 String getCharacterEncoding()
           
 InputStream getContentBodyInputStream()
          making the content Body of the POST request available many times, for processing by , e.g.
 int getContentLength()
           
 String getContentType()
           
 String getContextPath()
           
 Cookie[] getCookies()
           
 long getDateHeader(String name)
           
 String getHeader(String name)
           
 Enumeration getHeaderNames()
           
 Enumeration getHeaders(String name)
           
 ServletInputStream getInputStream()
           
 int getIntHeader(String name)
           
 String getLocalAddr()
           
 Locale getLocale()
           
 Enumeration getLocales()
           
 String getLocalName()
           
 int getLocalPort()
           
 String getMethod()
           
 String getParameter(String name)
          get the value of a Request parameter by its name from the local parameter store
 Map getParameterMap()
          get a Map of Request parameters (keys and values) from the local parameter store
 Enumeration getParameterNames()
          get the names of the Request parameters from the local parameter store
 String[] getParameterValues(String name)
          get the values of the Request parameter indicated by name from the local parameter store
 String getPathInfo()
           
 String getPathTranslated()
           
 String getProtocol()
           
 String getQueryString()
           
 BufferedReader getReader()
           
 String getRealPath(String path)
          Deprecated. use use ServletContext#getRealPath(java.lang.String) instead.
 String getRemoteAddr()
           
 String getRemoteHost()
           
 int getRemotePort()
           
 String getRemoteUser()
           
 RequestDispatcher getRequestDispatcher(String name)
           
 String getRequestedSessionId()
           
 String getRequestURI()
           
 StringBuffer getRequestURL()
           
 String getScheme()
           
 String getServerName()
           
 int getServerPort()
           
 String getServletPath()
           
 HttpSession getSession()
           
 HttpSession getSession(boolean create)
           
 Principal getUserPrincipal()
           
 boolean isRequestedSessionIdFromCookie()
           
 boolean isRequestedSessionIdFromUrl()
          Deprecated. use isRequestedSessionIdFromURL() instead.
 boolean isRequestedSessionIdFromURL()
           
 boolean isRequestedSessionIdValid()
           
 boolean isSecure()
           
 boolean isUserInRole(String name)
           
 void removeAttribute(String name)
           
 void setAttribute(String name, Object o)
           
 void setCharacterEncoding(String env)
           
 String toString()
          Similar to javax.servlet.http.HttpServletRequest.toString() , except it includes output of the Request parameters from the Request's Content Body
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HttpServletRequestWrapper

public HttpServletRequestWrapper(HttpServletRequest request,
                                 String formEncoding)
                          throws UnsupportedEncodingException
HttpServletRequestWrapper Constructor

Parameters:
request - The HttpServletRequest to wrap
formEncoding - The encoding to use
Throws:
UnsupportedEncodingException
Method Detail

getAuthType

public String getAuthType()
Specified by:
getAuthType in interface HttpServletRequest
See Also:
HttpServletRequest.getAuthType()

getCookies

public Cookie[] getCookies()
Specified by:
getCookies in interface HttpServletRequest
See Also:
HttpServletRequest.getCookies()

getDateHeader

public long getDateHeader(String name)
Specified by:
getDateHeader in interface HttpServletRequest
See Also:
HttpServletRequest.getDateHeader(java.lang.String)

getHeader

public String getHeader(String name)
Specified by:
getHeader in interface HttpServletRequest
See Also:
HttpServletRequest.getHeader(java.lang.String)

getHeaders

public Enumeration getHeaders(String name)
Specified by:
getHeaders in interface HttpServletRequest
See Also:
HttpServletRequest.getHeaders(java.lang.String)

getHeaderNames

public Enumeration getHeaderNames()
Specified by:
getHeaderNames in interface HttpServletRequest
See Also:
HttpServletRequest.getHeaderNames()

getIntHeader

public int getIntHeader(String name)
Specified by:
getIntHeader in interface HttpServletRequest
See Also:
HttpServletRequest.getIntHeader(java.lang.String)

getMethod

public String getMethod()
Specified by:
getMethod in interface HttpServletRequest
See Also:
HttpServletRequest.getMethod()

getPathInfo

public String getPathInfo()
Specified by:
getPathInfo in interface HttpServletRequest
See Also:
HttpServletRequest.getPathInfo()

getPathTranslated

public String getPathTranslated()
Specified by:
getPathTranslated in interface HttpServletRequest
See Also:
HttpServletRequest.getPathTranslated()

getContextPath

public String getContextPath()
Specified by:
getContextPath in interface HttpServletRequest
See Also:
HttpServletRequest.getContextPath()

getQueryString

public String getQueryString()
Specified by:
getQueryString in interface HttpServletRequest
See Also:
HttpServletRequest.getQueryString()

getRemoteUser

public String getRemoteUser()
Specified by:
getRemoteUser in interface HttpServletRequest
See Also:
HttpServletRequest.getRemoteUser()

isUserInRole

public boolean isUserInRole(String name)
Specified by:
isUserInRole in interface HttpServletRequest
See Also:
HttpServletRequest.isUserInRole(java.lang.String)

getUserPrincipal

public Principal getUserPrincipal()
Specified by:
getUserPrincipal in interface HttpServletRequest
See Also:
HttpServletRequest.getUserPrincipal()

getRequestedSessionId

public String getRequestedSessionId()
Specified by:
getRequestedSessionId in interface HttpServletRequest
See Also:
HttpServletRequest.getRequestedSessionId()

getRequestURI

public String getRequestURI()
Specified by:
getRequestURI in interface HttpServletRequest
See Also:
HttpServletRequest.getRequestURI()

getRequestURL

public StringBuffer getRequestURL()
Specified by:
getRequestURL in interface HttpServletRequest
See Also:
HttpServletRequest.getRequestURL()

getServletPath

public String getServletPath()
Specified by:
getServletPath in interface HttpServletRequest
See Also:
HttpServletRequest.getServletPath()

getSession

public HttpSession getSession(boolean create)
Specified by:
getSession in interface HttpServletRequest
See Also:
HttpServletRequest.getSession(boolean)

getSession

public HttpSession getSession()
Specified by:
getSession in interface HttpServletRequest
See Also:
HttpServletRequest.getSession(boolean)

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()
Specified by:
isRequestedSessionIdValid in interface HttpServletRequest
See Also:
HttpServletRequest.isRequestedSessionIdValid()

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()
Specified by:
isRequestedSessionIdFromCookie in interface HttpServletRequest
See Also:
HttpServletRequest.isRequestedSessionIdFromCookie()

isRequestedSessionIdFromURL

public boolean isRequestedSessionIdFromURL()
Specified by:
isRequestedSessionIdFromURL in interface HttpServletRequest
See Also:
HttpServletRequest.isRequestedSessionIdFromURL()

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()
Deprecated. use isRequestedSessionIdFromURL() instead.

Specified by:
isRequestedSessionIdFromUrl in interface HttpServletRequest
See Also:
HttpServletRequest.isRequestedSessionIdFromUrl()

getAttribute

public Object getAttribute(String name)
Specified by:
getAttribute in interface ServletRequest
See Also:
ServletRequest.getAttribute(java.lang.String)

getAttributeNames

public Enumeration getAttributeNames()
Specified by:
getAttributeNames in interface ServletRequest
See Also:
ServletRequest.getAttributeNames()

getCharacterEncoding

public String getCharacterEncoding()
Specified by:
getCharacterEncoding in interface ServletRequest
See Also:
ServletRequest.getCharacterEncoding()

setCharacterEncoding

public void setCharacterEncoding(String env)
                          throws UnsupportedEncodingException
Specified by:
setCharacterEncoding in interface ServletRequest
Throws:
UnsupportedEncodingException
See Also:
ServletRequest.setCharacterEncoding(java.lang.String)

getContentLength

public int getContentLength()
Specified by:
getContentLength in interface ServletRequest
See Also:
ServletRequest.getContentLength()

getContentType

public String getContentType()
Specified by:
getContentType in interface ServletRequest
See Also:
ServletRequest.getContentType()

getInputStream

public ServletInputStream getInputStream()
                                  throws IOException
Specified by:
getInputStream in interface ServletRequest
Throws:
IOException
See Also:
ServletRequest.getInputStream()

getContentBodyInputStream

public InputStream getContentBodyInputStream()
                                      throws IOException
making the content Body of the POST request available many times, for processing by , e.g. Rpc processor .

Throws:
IOException

getParameter

public String getParameter(String name)
get the value of a Request parameter by its name from the local parameter store

Specified by:
getParameter in interface ServletRequest
Parameters:
name - The name of the Request parameter to get the value for
Returns:
The value of the Request parameter with the specified name

getParameterNames

public Enumeration getParameterNames()
get the names of the Request parameters from the local parameter store

Specified by:
getParameterNames in interface ServletRequest
Returns:
An enumeration of string values representing the Request parameters names

getParameterValues

public String[] getParameterValues(String name)
get the values of the Request parameter indicated by name from the local parameter store

Specified by:
getParameterValues in interface ServletRequest
Parameters:
name - The name of the Request parameter to get the values for
Returns:
The String array of the Request parameter's values

getParameterMap

public Map getParameterMap()
get a Map of Request parameters (keys and values) from the local parameter store

Specified by:
getParameterMap in interface ServletRequest
Returns:
Map of Request Parameters. Key is of type String and Value is of type String[].

getProtocol

public String getProtocol()
Specified by:
getProtocol in interface ServletRequest
See Also:
ServletRequest.getProtocol()

getScheme

public String getScheme()
Specified by:
getScheme in interface ServletRequest
See Also:
ServletRequest.getScheme()

getServerName

public String getServerName()
Specified by:
getServerName in interface ServletRequest
See Also:
ServletRequest.getServerName()

getServerPort

public int getServerPort()
Specified by:
getServerPort in interface ServletRequest
See Also:
ServletRequest.getServerPort()

getReader

public BufferedReader getReader()
                         throws IOException
Specified by:
getReader in interface ServletRequest
Throws:
IOException

getRemoteAddr

public String getRemoteAddr()
Specified by:
getRemoteAddr in interface ServletRequest
See Also:
ServletRequest.getRemoteAddr()

getRemoteHost

public String getRemoteHost()
Specified by:
getRemoteHost in interface ServletRequest
See Also:
ServletRequest.getRemoteHost()

setAttribute

public void setAttribute(String name,
                         Object o)
Specified by:
setAttribute in interface ServletRequest
See Also:
ServletRequest.setAttribute(java.lang.String, java.lang.Object)

removeAttribute

public void removeAttribute(String name)
Specified by:
removeAttribute in interface ServletRequest
See Also:
ServletRequest.removeAttribute(java.lang.String)

getLocale

public Locale getLocale()
Specified by:
getLocale in interface ServletRequest
See Also:
ServletRequest.getLocale()

getLocales

public Enumeration getLocales()
Specified by:
getLocales in interface ServletRequest
See Also:
ServletRequest.getLocales()

isSecure

public boolean isSecure()
Specified by:
isSecure in interface ServletRequest
See Also:
ServletRequest.isSecure()

getRequestDispatcher

public RequestDispatcher getRequestDispatcher(String name)
Specified by:
getRequestDispatcher in interface ServletRequest
See Also:
ServletRequest.getRequestDispatcher(java.lang.String)

getRealPath

public String getRealPath(String path)
Deprecated. use use ServletContext#getRealPath(java.lang.String) instead.

Specified by:
getRealPath in interface ServletRequest
See Also:
ServletRequest.getRealPath(java.lang.String)

getRemotePort

public int getRemotePort()
Specified by:
getRemotePort in interface ServletRequest
See Also:
ServletRequest.getRemotePort()

getLocalName

public String getLocalName()
Specified by:
getLocalName in interface ServletRequest
See Also:
ServletRequest.getLocalName()

getLocalAddr

public String getLocalAddr()
Specified by:
getLocalAddr in interface ServletRequest
See Also:
ServletRequest.getLocalAddr()

getLocalPort

public int getLocalPort()
Specified by:
getLocalPort in interface ServletRequest
See Also:
ServletRequest.getLocalPort()

toString

public String toString()
Similar to javax.servlet.http.HttpServletRequest.toString() , except it includes output of the Request parameters from the Request's Content Body

Overrides:
toString in class Object
Returns:
String representation of HttpServletRequestWrapper


Copyright (C) Wolfgang Meier. All rights reserved.