org.barracudamvc.core.helper.servlet
Class DefaultServletRequestWrapper

java.lang.Object
  extended byjavax.servlet.ServletRequestWrapper
      extended byjavax.servlet.http.HttpServletRequestWrapper
          extended byorg.barracudamvc.core.helper.servlet.DefaultServletRequestWrapper
All Implemented Interfaces:
BarracudaServletRequestWrapper, javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest
Direct Known Subclasses:
FileUploadRequestWrapper, MultipartRequestWrapper

public class DefaultServletRequestWrapper
extends javax.servlet.http.HttpServletRequestWrapper
implements BarracudaServletRequestWrapper

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
static String DEFAULT_ENCODING
           
protected static org.apache.log4j.Logger logger
           
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
DefaultServletRequestWrapper(javax.servlet.http.HttpServletRequest ireq)
          Create a DefaultServletRequestWrapper around some other HttpServletRequest impl.
 
Method Summary
 void addParameter(String name, 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).
 javax.servlet.http.HttpServletRequest getCoreRequest()
          Get the underlying servlet request.
 String getMethod()
          Get the underlying request method.
 String getParameter(String name)
          Returns the value of a request parameter as a String, or null if the parameter does not exist.
 Map getParameterMap()
          Returns a java.util.Map of the parameters of this request.
 Enumeration getParameterNames()
          Returns an Enumeration of String objects containing the names of the parameters contained in this request.
 String[] getParameterValues(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.
 void removeAllParameters(String name)
          Remove all parameters for a specified name
 void removeParameter(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 setMethod(String imethod)
          Set the underlying request method.
 void setRequest(javax.servlet.ServletRequest ireq)
          Set the underlying request object.
 
Methods inherited from class javax.servlet.http.HttpServletRequestWrapper
getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getIntHeader, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isUserInRole
 
Methods inherited from class javax.servlet.ServletRequestWrapper
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocale, getLocales, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRequest, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.http.HttpServletRequest
getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getIntHeader, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isUserInRole
 
Methods inherited from interface javax.servlet.ServletRequest
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocale, getLocales, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding
 

Field Detail

logger

protected static final org.apache.log4j.Logger logger

DEFAULT_ENCODING

public static String DEFAULT_ENCODING
Constructor Detail

DefaultServletRequestWrapper

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

Parameters:
ireq - the underlying HttpServletRequest
Method Detail

setMethod

public void setMethod(String imethod)
Set the underlying request method.

Specified by:
setMethod in interface BarracudaServletRequestWrapper
Parameters:
imethod - the underlying request method (GET, POST, etc)

getMethod

public String getMethod()
Get the underlying request method.

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

addParameter

public void addParameter(String name,
                         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.

Specified by:
addParameter in interface BarracudaServletRequestWrapper
Parameters:
name - the key name for the parameter
value - the value associated with the given key

getParameter

public String getParameter(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 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

getParameterMap

public 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

getParameterValues

public String[] getParameterValues(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

removeParameter

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

Specified by:
removeParameter in interface BarracudaServletRequestWrapper
Parameters:
name - the key name for the parameter

removeAllParameters

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

Specified by:
removeAllParameters in interface BarracudaServletRequestWrapper
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)

Specified by:
resetParameters in interface BarracudaServletRequestWrapper

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

setRequest

public void setRequest(javax.servlet.ServletRequest ireq)
Set the underlying request object.

Parameters:
ireq - the underlying HttpServletRequest


Copyright © 2004 BarracudaMVC.org All Rights Reserved.