JaVa
   

Package org.apache. cactus.server

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.

Class FilterConfigWrapper

public class FilterConfigWrapper


Inheritance Information

Extends: Object

Implements: FilterConfig

Description

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.

Methods

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.

Class HttpServletRequestWrapper

public class HttpServletRequestWrapper


Inheritance Information

Extends: Object

Implements: javax.servlet.http.HttpServletRequest

Description

HttpServletRequestWrapper is a thin wrapper around the HttpServletRequest object passed to the redirector servlet by the container.

Constructor

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.

Methods

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.

Class PageContextWrapper

public class PageContextWrapper


Inheritance Information

Extends: AbstractPageContextWrapper (and thereby javax.servlet.jsp.PageContext.)

Description

Wraps a PageContext object so that the implicit objects it returns are the appropriate Cactus-wrapped version of those objects.

Class RequestDispatcherWrapper

public class RequestDispatcherWrapper


Inheritance Information

Extends: Object

Implements: javax.servlet.RequestDispatcher

Description

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.

Constructor

RequestDispatcherWrapper(RequestDispatcher theOriginalDispatcher)
public RequestDispatcherWrapper(RequestDispatcher
 theOriginalDispatcher)


Methods

The methods are as specified in RequestDispatcher, except that the include and forward methods will unwrap the “HttpServletRequest” parameter to use the underlying request.

Class ServletConfigWrapper

public class ServletConfigWrapper


Inheritance Information

Extends: Object

Implements: javax.servlet.ServletConfig

Description

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.

Constructor

ServletConfigWrapper(ServletConfig theOriginalConfig)
public ServletConfigWrapper(ServletConfig theOriginalConfig)


Methods

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).

Class ServletContextWrapper

public class ServletContextWrapper


Inheritance Information

Extends: AbstractServletContextWrapper

Implements: javax.servlet.ServletContext

Description

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.

Methods

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.


JaVa
   
Comments