This package contains several framework classes (such as the redirector servlet) that are not covered in this chapter because test developers do not interact with them directly. However, it also contains wrapper classes for several implicit servlet objects with additional or slightly changed behavior. These classes are covered briefly .
public class FilterConfigWrapper
Extends: Object
Implements: FilterConfig
Wraps the original FilterConfig passed by the container to the filter redirector. Like ServletConfigWrapper, FilterConfigWrapper returns a wrapped version of ServletContext from getServletContext and provides setter methods for the Filter name and init parameters.
The methods are as specified in FilterConfig along with the following:
getInitParameterNames() public Enumeration getInitParameterNames()
This method returns an enumeration containing both the init parameter names specified in the web.xml as well as those specified by a call to setInitParameter(). The values set by setInitParameter() take precedence.
setFilterName(String theFilterName) public void setFilterName(String theFilterName)
This method sets a simulated Filter name that will be returned by getFilterName().
setInitParameter(String theName, String theValue) public void setInitParameter(String theName, String theValue)
This method sets an init parameter for this FilterConfig as if it had been specified in the web.xml file. Initialization parameters set with this method will "shadow" those actually specified in the web.xml file.
public class HttpServletRequestWrapper
Extends: Object
Implements: javax.servlet.http.HttpServletRequest
HttpServletRequestWrapper is a thin wrapper around the HttpServletRequest object passed to the redirector servlet by the container.
HttpServletRequestWrapper(HttpServletRequest theRequest, ServletURL theURL) public HttpServletRequestWrapper(HttpServletRequest theRequest, ServletURL theURL)
This constructor constructs a wrapper around the given request with the simulated URL contained in the ServletURL parameter.
The methods are generally identical to those specified in HttpServletRequest, except that URL methods such as getQueryString() return the values specified by the ServletURL passed to the constructor rather than those of the actual URL used to invoke the redirector servlet (unless the ServletURL parameter was null).
Two other significant changes exist:
getOriginalRequest() public HttpServletRequest getOriginalRequest() This method returns the original request that arrived at the redirector. getRequestDispatcher(String thePath) public RequestDispatcher getRequestDispatcher(String thePath)
Returns a RequestDispatcherWrapper instead of a RequestDispatcher. See the section on RequestDispatcherWrapper for details.
public class PageContextWrapper
Extends: AbstractPageContextWrapper (and thereby javax.servlet.jsp.PageContext.)
Wraps a PageContext object so that the implicit objects it returns are the appropriate Cactus-wrapped version of those objects.
public class RequestDispatcherWrapper
Extends: Object
Implements: javax.servlet.RequestDispatcher
RequestDispatcherWrapper is a thin wrapper for a RequestDispatcher object. The wrapper's purpose is to ensure that forwards and includes are carried out with the original HttpServletRequest instead of the Cactus wrapper (which could cause problems). Any includes or forwards in the tested code will lose the URL simulation capacities of the Cactus request wrapper after the forward. (If A forwards to B, the request received by B will not be a wrapped Cactus request, but the original HttpServletRequest generated by the container.)
In Cactus 1.1 and earlier, this wrapper is returned from ServletContextWrapper.getRequestDispatcher(String) but not from HttpServletRequestWrapper.getRequestDispatcher(String). This inconsistency could yield unexpected results.
RequestDispatcherWrapper(RequestDispatcher theOriginalDispatcher) public RequestDispatcherWrapper(RequestDispatcher theOriginalDispatcher)
The methods are as specified in RequestDispatcher, except that the include and forward methods will unwrap the HttpServletRequest parameter to use the underlying request.
public class ServletConfigWrapper
Extends: Object
Implements: javax.servlet.ServletConfig
ServletConfigWrapper wraps a ServletConfig object provided by the container to the redirector servlet. Because this object is the config for the redirector servlet, static initialization parameters expected by test code must be included in the web.xml file used by the redirector servlet or they must be set manually using the setInitParameter() method.
ServletConfigWrapper(ServletConfig theOriginalConfig) public ServletConfigWrapper(ServletConfig theOriginalConfig)
Methods are as specified in ServletConfig, except the following:
getInitParameterNames() public Enumeration getInitParameterNames()
Will return an enumeration containing both the init parameter names specified in the web.xml as well as those specified by a call to setInitParameter. The values set by setInitParameter take precedence.
setInitParameter(String theName, String theValue) public void setInitParameter(String theName, String theValue)
This method sets an init parameter for this ServletConfig as if it had been specified in the web.xml file. Initialization parameters set with this method will "shadow" those actually specified in the web.xml file.
setServletName(String theServletName) public void setServletName(String theServletName)
This method sets the servlet's name (retrieved by the getName() method).
public class ServletContextWrapper
Extends: AbstractServletContextWrapper
Implements: javax.servlet.ServletContext
ServletContextWrapper is a simple wrapper that delegates almost all its calls to the wrapped ServletContext. One notable exception is that all messages passed to the wrapper's log methods are stored in a Vector of Strings (as well as being passed to the original log method) which can be retrieved with getLogs(). Beyond that, theonly differences are that getServletContext and getRequestDispatcher return the Cactus wrapper objects, and it supports both getResourcePaths() for Servlet 2.2, and getResourcePaths(String) for Servlet 2.3.
getLogs() public Vector getLogs()
This method returns a Vector of Strings containing each message that was logged with any of the ServletContext's log methods.