org.enhydra.barracuda.core.helper.servlet
Class HttpServletRequestWrapper

java.lang.Object
  |
  +--org.enhydra.barracuda.core.helper.servlet.HttpServletRequestWrapper
All Implemented Interfaces:
javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest

public class HttpServletRequestWrapper
extends java.lang.Object
implements javax.servlet.http.HttpServletRequest

This class acts as a thin wrapper around a ServletRequest. Most calls are simply passed through to the underlying request object. This object does however, expose a method which allows you to set parameters in the request object. This was necessary for cases where we needed to be able to do a POST, save the parameters somewhere, and then do a GET and reconstitute the parameters from that.

When you instantiate this object, it will automatically check the clients session to see if there are any parameter state information that needs to be reconstituted into the current request.


Field Summary
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
HttpServletRequestWrapper(javax.servlet.http.HttpServletRequest ireq)
          Create an HttpServletRequestWrapper around some other HttpServletRequest impl.
 
Method Summary
 void addParameter(java.lang.String name, java.lang.String value)
          Set a given parameter (note that this is backed by a hashmap, so the structure is slightly different than that of the underlying ServletRequest which allows multiple paramters with the same name).
 java.lang.Object getAttribute(java.lang.String name)
          Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
 java.util.Enumeration getAttributeNames()
          Returns an Enumeration containing the names of the attributes available to this request.
 java.lang.String getAuthType()
          Returns the name of the authentication scheme used to protect the servlet, for example, "BASIC" or "SSL," or null if the servlet was not protected.
 java.lang.String getCharacterEncoding()
          Returns the name of the character encoding used in the body of this request.
 int getContentLength()
          Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known.
 java.lang.String getContentType()
          Returns the MIME type of the body of the request, or null if the type is not known.
 java.lang.String getContextPath()
          Returns the portion of the request URI that indicates the context of the request.
 javax.servlet.http.Cookie[] getCookies()
          Returns an array containing all of the Cookie objects the client sent with this request.
 javax.servlet.http.HttpServletRequest getCoreRequest()
          Get the underlying servlet request.
 long getDateHeader(java.lang.String name)
          Returns the value of the specified request header as a long value that represents a Date object.
 java.lang.String getHeader(java.lang.String name)
          Returns the value of the specified request header as a String.
 java.util.Enumeration getHeaderNames()
          Returns an enumeration of all the header names this request contains.
 java.util.Enumeration getHeaders(java.lang.String name)
          Returns all the values of the specified request header as an Enumeration of String objects.
 javax.servlet.ServletInputStream getInputStream()
          Retrieves the body of the request as binary data using a ServletInputStream.
 int getIntHeader(java.lang.String name)
          Returns the value of the specified request header as an int.
 java.util.Locale getLocale()
          Returns the preferred Locale that the client will accept content in, based on the Accept-Language header.
 java.util.Enumeration getLocales()
          Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header.
 java.lang.String getMethod()
          Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
 java.lang.String getParameter(java.lang.String name)
          Returns the value of a request parameter as a String, or null if the parameter does not exist.
 java.util.Map getParameterMap()
          Returns a java.util.Map of the parameters of this request.
 java.util.Enumeration getParameterNames()
          Returns an Enumeration of String objects containing the names of the parameters contained in this request.
 java.lang.String[] getParameterValues(java.lang.String name)
          Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.
 java.lang.String getPathInfo()
          Returns any extra path information associated with the URL the client sent when it made this request.
 java.lang.String getPathTranslated()
          Returns any extra path information after the servlet name but before the query string, and translates it to a real path.
 java.lang.String getProtocol()
          Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.
 java.lang.String getQueryString()
          Returns the query string that is contained in the request URL after the path.
 java.io.BufferedReader getReader()
          Retrieves the body of the request as character data using a BufferedReader.
 java.lang.String getRealPath(java.lang.String path)
          Deprecated.
 java.lang.String getRemoteAddr()
          Returns the Internet Protocol (IP) {return req.();}address of the client that sent the request.
 java.lang.String getRemoteHost()
          Returns the fully qualified name of the client that sent the request, or the IP address of the client if the name cannot be determined.
 java.lang.String getRemoteUser()
          Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
          Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.
 java.lang.String getRequestedSessionId()
          Returns the session ID specified by the client.
 java.lang.String getRequestURI()
          Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.
 java.lang.StringBuffer getRequestURL()
          Reconstructs the URL the client used to make the request.
 java.lang.String getScheme()
          Returns the name of the scheme used to make this request, for example, http, https, or ftp.
 java.lang.String getServerName()
          Returns the host name of the server that received the request.
 int getServerPort()
          Returns the port number on which this request was received.
 java.lang.String getServletPath()
          Returns the part of this request's URL that calls the servlet.
 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 create)
          Returns the current HttpSession associated with this request or, if if there is no current session and create is true, returns a new session.
 java.security.Principal getUserPrincipal()
          Returns a java.security.Principal object containing the name of the current authenticated user.
 boolean isRequestedSessionIdFromCookie()
          Checks whether the requested session ID came in as a cookie.
 boolean isRequestedSessionIdFromUrl()
          Deprecated.
 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.
 boolean isSecure()
          Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.
 boolean isUserInRole(java.lang.String role)
          Returns a boolean indicating whether the authenticated user is included in the specified logical "role".
 void removeAllParameters(java.lang.String name)
          Remove all parameters for a specified name
 void removeAttribute(java.lang.String name)
          Removes an attribute from this request.
 void removeParameter(java.lang.String name)
          Remove the first parameter whose key matches the specified name
 void resetParameters()
          Reset the parameter values to their original state (ie. the actual values in the request)
 void setAttribute(java.lang.String name, java.lang.Object o)
          Stores an attribute in this request.
 void setCharacterEncoding(java.lang.String env)
          Overrides the name of the character encoding used in the body of this request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpServletRequestWrapper

public HttpServletRequestWrapper(javax.servlet.http.HttpServletRequest ireq)
Create an HttpServletRequestWrapper around some other HttpServletRequest impl. The wrapper adds the ability to add/remove parameter values.

Method Detail

addParameter

public void addParameter(java.lang.String name,
                         java.lang.String value)
Set a given parameter (note that this is backed by a hashmap, so the structure is slightly different than that of the underlying ServletRequest which allows multiple paramters with the same name). This means that if you attempt to set a parameter whose key already exists you will effectively overwrite the existing value.

Parameters:
name - the key name for the parameter
value - the value associated with the given key

removeParameter

public void removeParameter(java.lang.String name)
Remove the first parameter whose key matches the specified name

Parameters:
name - the key name for the parameter

removeAllParameters

public void removeAllParameters(java.lang.String name)
Remove all parameters for a specified name

Parameters:
name - the key name for the parameter

resetParameters

public void resetParameters()
Reset the parameter values to their original state (ie. the actual values in the request)


getAuthType

public java.lang.String getAuthType()
Returns the name of the authentication scheme used to protect the servlet, for example, "BASIC" or "SSL," or null if the servlet was not protected.

Specified by:
getAuthType in interface javax.servlet.http.HttpServletRequest

getContextPath

public java.lang.String getContextPath()
Returns the portion of the request URI that indicates the context of the request.

Specified by:
getContextPath in interface javax.servlet.http.HttpServletRequest

getCookies

public javax.servlet.http.Cookie[] getCookies()
Returns an array containing all of the Cookie objects the client sent with this request.

Specified by:
getCookies in interface javax.servlet.http.HttpServletRequest

getDateHeader

public long getDateHeader(java.lang.String name)
Returns the value of the specified request header as a long value that represents a Date object.

Specified by:
getDateHeader in interface javax.servlet.http.HttpServletRequest

getHeader

public java.lang.String getHeader(java.lang.String name)
Returns the value of the specified request header as a String.

Specified by:
getHeader in interface javax.servlet.http.HttpServletRequest

getHeaderNames

public java.util.Enumeration getHeaderNames()
Returns an enumeration of all the header names this request contains.

Specified by:
getHeaderNames in interface javax.servlet.http.HttpServletRequest

getHeaders

public java.util.Enumeration getHeaders(java.lang.String name)
Returns all the values of the specified request header as an Enumeration of String objects.

Specified by:
getHeaders in interface javax.servlet.http.HttpServletRequest

getIntHeader

public int getIntHeader(java.lang.String name)
Returns the value of the specified request header as an int.

Specified by:
getIntHeader in interface javax.servlet.http.HttpServletRequest

getMethod

public java.lang.String getMethod()
Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.

Specified by:
getMethod in interface javax.servlet.http.HttpServletRequest

getPathInfo

public java.lang.String getPathInfo()
Returns any extra path information associated with the URL the client sent when it made this request.

Specified by:
getPathInfo in interface javax.servlet.http.HttpServletRequest

getPathTranslated

public java.lang.String getPathTranslated()
Returns any extra path information after the servlet name but before the query string, and translates it to a real path.

Specified by:
getPathTranslated in interface javax.servlet.http.HttpServletRequest

getQueryString

public java.lang.String getQueryString()
Returns the query string that is contained in the request URL after the path.

Specified by:
getQueryString in interface javax.servlet.http.HttpServletRequest

getRemoteUser

public java.lang.String getRemoteUser()
Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.

Specified by:
getRemoteUser in interface javax.servlet.http.HttpServletRequest

getRequestedSessionId

public java.lang.String getRequestedSessionId()
Returns the session ID specified by the client.

Specified by:
getRequestedSessionId in interface javax.servlet.http.HttpServletRequest

getRequestURI

public java.lang.String getRequestURI()
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.

Specified by:
getRequestURI in interface javax.servlet.http.HttpServletRequest

getRequestURL

public java.lang.StringBuffer getRequestURL()
Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.

Specified by:
getRequestURL in interface javax.servlet.http.HttpServletRequest

getServletPath

public java.lang.String getServletPath()
Returns the part of this request's URL that calls the servlet.

Specified by:
getServletPath in interface javax.servlet.http.HttpServletRequest

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

getSession

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

Specified by:
getSession in interface javax.servlet.http.HttpServletRequest

getUserPrincipal

public java.security.Principal getUserPrincipal()
Returns a java.security.Principal object containing the name of the current authenticated user.

Specified by:
getUserPrincipal in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()
Checks whether the requested session ID came in as a cookie.

Specified by:
isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()
Deprecated. As of Version 2.1 of the Java Servlet API, use isRequestedSessionIdFromURL() {return req.();}instead.

Specified by:
isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequest

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

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()
Checks whether the requested session ID is still valid.

Specified by:
isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequest

isUserInRole

public boolean isUserInRole(java.lang.String role)
Returns a boolean indicating whether the authenticated user is included in the specified logical "role".

Specified by:
isUserInRole in interface javax.servlet.http.HttpServletRequest

getAttribute

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

Specified by:
getAttribute in interface javax.servlet.ServletRequest

getAttributeNames

public java.util.Enumeration getAttributeNames()
Returns an Enumeration containing the names of the attributes available to this request.

Specified by:
getAttributeNames in interface javax.servlet.ServletRequest

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Returns the name of the character encoding used in the body of this request.

Specified by:
getCharacterEncoding in interface javax.servlet.ServletRequest

getContentLength

public int getContentLength()
Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known.

Specified by:
getContentLength in interface javax.servlet.ServletRequest

getContentType

public java.lang.String getContentType()
Returns the MIME type of the body of the request, or null if the type is not known.

Specified by:
getContentType in interface javax.servlet.ServletRequest

getInputStream

public javax.servlet.ServletInputStream getInputStream()
                                                throws java.io.IOException
Retrieves the body of the request as binary data using a ServletInputStream.

Specified by:
getInputStream in interface javax.servlet.ServletRequest
java.io.IOException

getLocale

public java.util.Locale getLocale()
Returns the preferred Locale that the client will accept content in, based on the Accept-Language header.

Specified by:
getLocale in interface javax.servlet.ServletRequest

getLocales

public java.util.Enumeration getLocales()
Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header.

Specified by:
getLocales in interface javax.servlet.ServletRequest

getParameter

public java.lang.String getParameter(java.lang.String name)
Returns the value of a request parameter as a String, or null if the parameter does not exist.

Specified by:
getParameter in interface javax.servlet.ServletRequest
Parameters:
name - the key name for the parameter
Returns:
the parameter value associated with a key name

getParameterNames

public java.util.Enumeration getParameterNames()
Returns an Enumeration of String objects containing the names of the parameters contained in this request.

Specified by:
getParameterNames in interface javax.servlet.ServletRequest
Returns:
an Enumeration of all the parameter names

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.

Specified by:
getParameterValues in interface javax.servlet.ServletRequest
Parameters:
name - the key name for the parameter
Returns:
an array of Strings for the given key name

getProtocol

public java.lang.String getProtocol()
Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.

Specified by:
getProtocol in interface javax.servlet.ServletRequest

getReader

public java.io.BufferedReader getReader()
                                 throws java.io.IOException
Retrieves the body of the request as character data using a BufferedReader.

Specified by:
getReader in interface javax.servlet.ServletRequest
java.io.IOException

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Deprecated. As of Version 2.1 of the Java Servlet API, use ServletContext.getRealPath(String) {return req.();}instead.

Specified by:
getRealPath in interface javax.servlet.ServletRequest

getRemoteAddr

public java.lang.String getRemoteAddr()
Returns the Internet Protocol (IP) {return req.();}address of the client that sent the request.

Specified by:
getRemoteAddr in interface javax.servlet.ServletRequest

getRemoteHost

public java.lang.String getRemoteHost()
Returns the fully qualified name of the client that sent the request, or the IP address of the client if the name cannot be determined.

Specified by:
getRemoteHost in interface javax.servlet.ServletRequest

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.

Specified by:
getRequestDispatcher in interface javax.servlet.ServletRequest

getScheme

public java.lang.String getScheme()
Returns the name of the scheme used to make this request, for example, http, https, or ftp.

Specified by:
getScheme in interface javax.servlet.ServletRequest

getServerName

public java.lang.String getServerName()
Returns the host name of the server that received the request.

Specified by:
getServerName in interface javax.servlet.ServletRequest

getServerPort

public int getServerPort()
Returns the port number on which this request was received.

Specified by:
getServerPort in interface javax.servlet.ServletRequest

isSecure

public boolean isSecure()
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.

Specified by:
isSecure in interface javax.servlet.ServletRequest

removeAttribute

public void removeAttribute(java.lang.String name)
Removes an attribute from this request.

Specified by:
removeAttribute in interface javax.servlet.ServletRequest

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object o)
Stores an attribute in this request.

Specified by:
setAttribute in interface javax.servlet.ServletRequest

setCharacterEncoding

public void setCharacterEncoding(java.lang.String env)
                          throws java.io.UnsupportedEncodingException
Overrides the name of the character encoding used in the body of this request. This method must be called prior to reading request parameters or reading input using getReader().

Specified by:
setCharacterEncoding in interface javax.servlet.ServletRequest
java.io.UnsupportedEncodingException

getParameterMap

public java.util.Map getParameterMap()
Returns a java.util.Map of the parameters of this request. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.

Specified by:
getParameterMap in interface javax.servlet.ServletRequest

getCoreRequest

public javax.servlet.http.HttpServletRequest getCoreRequest()
Get the underlying servlet request. The only reason you should ever have to do this is if you are trying to forward a request. Some containers check to make sure that the request object being forwarded is an instance of their own implementation...

Returns:
the underlying servlet request object


Copyright © 2001 Enhydra.org