org.apache.cactus.server
class AbstractServletContextWrapper

java.lang.Object
  |
  +--org.apache.cactus.server.AbstractServletContextWrapper
All Implemented Interfaces:
ServletContext
Direct Known Subclasses:
ServletContextWrapper
Known Advisors:
LogAspect

public abstract class AbstractServletContextWrapper
extends java.lang.Object
implements ServletContext

Abstract wrapper around ServletContext. This class provides a common implementation of the wrapper for the different servlet API. In addition to implementing the ServletContext interface it provides additional features helpful for writing unit tests. More specifically the getRequestDispatcher() method is overrided to return an request dispatcher wrapper. In addition logs generated by calls to the log() methods can be retrieved and asserted by calling the getLogs() method.

Version:
$Id: AbstractServletContextWrapper.java,v 1.3 2002/03/28 22:00:14 vmassol Exp $
Author:
Vincent Massol

Constructor Summary
AbstractServletContextWrapper(ServletContext theOriginalContext)
           
 
Method Summary
 Object getAttribute(String theName)
           Affected by: LogAspect
 Enumeration getAttributeNames()
           
 ServletContext getContext(String theUripath)
           Affected by: LogAspect
 String getInitParameter(String theName)
           Affected by: LogAspect
 Enumeration getInitParameterNames()
           
 Vector getLogs()
          Returns all the text logs that have been generated using the log() methods so that it is possible to easily assert the content of the logs.
 int getMajorVersion()
           
 String getMimeType(String theFilename)
           Affected by: LogAspect
 int getMinorVersion()
           
 RequestDispatcher getNamedDispatcher(String theName)
           Affected by: LogAspect
 String getRealPath(String thePath)
           Affected by: LogAspect
 RequestDispatcher getRequestDispatcher(String thePath)
           Affected by: LogAspect
 URL getResource(String thePath)
           Affected by: LogAspect
 InputStream getResourceAsStream(String thePath)
           Affected by: LogAspect
 String getServerInfo()
           
 Servlet getServlet(String theName)
           Affected by: LogAspect
 Enumeration getServletNames()
           
 Enumeration getServlets()
           
 void log(String theMessage, Throwable theCause)
          Intercept the log call and add the message to an internal vector of log messages that can then later be retrieved and asserted by the test case writer.
          Affected by: LogAspect
 void log(String theMessage)
          Intercept the log call and add the message to an internal vector of log messages that can then later be retrieved and asserted by the test case writer.
          Affected by: LogAspect
 void log(Exception theException, String theMessage)
          Deprecated. As of Java Servlet API 2.1, use log(String message, Throwable throwable) instead. This method was originally defined to write an exception's stack trace and an explanatory error message to the servlet log file.
          Affected by: LogAspect
 void removeAttribute(String theName)
           Affected by: LogAspect
 void setAttribute(String theName, Object theAttribute)
           Affected by: LogAspect
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractServletContextWrapper

public AbstractServletContextWrapper(ServletContext theOriginalContext)
Parameters:
theOriginalContext - the original servlet context object
Method Detail

getAttribute

public Object getAttribute(String theName)
Specified by:
getAttribute in interface ServletContext
See Also:
ServletContext
Affected by:
around() in LogAspect.

getAttributeNames

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

getContext

public ServletContext getContext(String theUripath)
Specified by:
getContext in interface ServletContext
Parameters:
theUripath - a String specifying the context path of another web application in the container
Returns:
our servlet context wrapper
See Also:
ServletContext
Affected by:
around() in LogAspect.

getInitParameter

public String getInitParameter(String theName)
Specified by:
getInitParameter in interface ServletContext
See Also:
ServletContext
Affected by:
around() in LogAspect.

getInitParameterNames

public Enumeration getInitParameterNames()
Specified by:
getInitParameterNames in interface ServletContext
See Also:
ServletContext

getLogs

public Vector getLogs()
Returns all the text logs that have been generated using the log() methods so that it is possible to easily assert the content of the logs. This method does not return the exceptions or throwable sent for logging; it only returns the messages.
Returns:
the logs as a vector of strings (each string contains the message that was sent for logging).

getMajorVersion

public int getMajorVersion()
Specified by:
getMajorVersion in interface ServletContext
See Also:
ServletContext

getMimeType

public String getMimeType(String theFilename)
Specified by:
getMimeType in interface ServletContext
See Also:
ServletContext
Affected by:
around() in LogAspect.

getMinorVersion

public int getMinorVersion()
Specified by:
getMinorVersion in interface ServletContext
See Also:
ServletContext

getNamedDispatcher

public RequestDispatcher getNamedDispatcher(String theName)
Specified by:
getNamedDispatcher in interface ServletContext
Parameters:
theName - a string specifying the name of a servlet to wrap
Returns:
our request dispatcher wrapper or null if the servlet cannot be found.
See Also:
ServletContext
Affected by:
around() in LogAspect.

getRealPath

public String getRealPath(String thePath)
Specified by:
getRealPath in interface ServletContext
See Also:
ServletContext
Affected by:
around() in LogAspect.

getRequestDispatcher

public RequestDispatcher getRequestDispatcher(String thePath)
Specified by:
getRequestDispatcher in interface ServletContext
Parameters:
thePath - a string specifying the pathname to the resource
Returns:
our request dispatcher wrapper
See Also:
ServletContext
Affected by:
around() in LogAspect.

getResource

public URL getResource(String thePath)
                throws java.net.MalformedURLException
Specified by:
getResource in interface ServletContext
See Also:
ServletContext
Affected by:
around() in LogAspect.

getResourceAsStream

public InputStream getResourceAsStream(String thePath)
Specified by:
getResourceAsStream in interface ServletContext
See Also:
ServletContext
Affected by:
around() in LogAspect.

getServerInfo

public String getServerInfo()
Specified by:
getServerInfo in interface ServletContext
See Also:
ServletContext

getServlet

public Servlet getServlet(String theName)
                   throws javax.servlet.ServletException
Specified by:
getServlet in interface ServletContext
See Also:
ServletContext
Affected by:
around() in LogAspect.

getServletNames

public Enumeration getServletNames()
Specified by:
getServletNames in interface ServletContext
See Also:
ServletContext

getServlets

public Enumeration getServlets()
Specified by:
getServlets in interface ServletContext
See Also:
ServletContext

log

public void log(String theMessage,
                Throwable theCause)
Intercept the log call and add the message to an internal vector of log messages that can then later be retrieved and asserted by the test case writer. Note that the throwable is not saved.
Specified by:
log in interface ServletContext
Parameters:
theMessage - a String that describes the error or exception
theCause - the Throwable error or exception
See Also:
getLogs(), ServletContext
Affected by:
around() in LogAspect.

log

public void log(String theMessage)
Intercept the log call and add the message to an internal vector of log messages that can then later be retrieved and asserted by the test case writer. Note that the throwable is not saved.
Specified by:
log in interface ServletContext
Parameters:
theMessage - a String that describes the error or exception
See Also:
getLogs(), ServletContext
Affected by:
around() in LogAspect.

log

public void log(Exception theException,
                String theMessage)
Deprecated. As of Java Servlet API 2.1, use log(String message, Throwable throwable) instead. This method was originally defined to write an exception's stack trace and an explanatory error message to the servlet log file.

Intercept the log call and add the message to an internal vector of log messages that can then later be retrieved and asserted by the test case writer. Note that the throwable is not saved.
Specified by:
log in interface ServletContext
Parameters:
theException - the exception to log
theMessage - a String that describes the error or exception
See Also:
getLogs(), ServletContext
Affected by:
around() in LogAspect.

removeAttribute

public void removeAttribute(String theName)
Specified by:
removeAttribute in interface ServletContext
See Also:
ServletContext
Affected by:
around() in LogAspect.

setAttribute

public void setAttribute(String theName,
                         Object theAttribute)
Specified by:
setAttribute in interface ServletContext
See Also:
ServletContext
Affected by:
around() in LogAspect.


Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.