org.apache.cactus.server
Class AbstractServletContextWrapper

java.lang.Object
  extended byorg.apache.cactus.server.AbstractServletContextWrapper
All Implemented Interfaces:
javax.servlet.ServletContext
Direct Known Subclasses:
ServletContextWrapper

public abstract class AbstractServletContextWrapper
extends java.lang.Object
implements javax.servlet.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.9 2003/05/26 11:45:22 cmlenz Exp $
Author:
Vincent Massol

Field Summary
protected  javax.servlet.ServletContext originalContext
          The original servlet context object
 
Constructor Summary
AbstractServletContextWrapper(javax.servlet.ServletContext theOriginalContext)
           
 
Method Summary
 java.lang.Object getAttribute(java.lang.String theName)
           
 java.util.Enumeration getAttributeNames()
           
 javax.servlet.ServletContext getContext(java.lang.String theUripath)
           
 java.lang.String getInitParameter(java.lang.String theName)
           
 java.util.Enumeration getInitParameterNames()
           
 java.util.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()
           
 java.lang.String getMimeType(java.lang.String theFilename)
           
 int getMinorVersion()
           
 javax.servlet.RequestDispatcher getNamedDispatcher(java.lang.String theName)
           
 java.lang.String getRealPath(java.lang.String thePath)
           
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String thePath)
           
 java.net.URL getResource(java.lang.String thePath)
           
 java.io.InputStream getResourceAsStream(java.lang.String thePath)
           
 java.lang.String getServerInfo()
           
 javax.servlet.Servlet getServlet(java.lang.String theName)
           
 java.util.Enumeration getServletNames()
           
 java.util.Enumeration getServlets()
           
 void log(java.lang.Exception theException, java.lang.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.
 void log(java.lang.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.
 void log(java.lang.String theMessage, java.lang.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.
 void removeAttribute(java.lang.String theName)
           
 void setAttribute(java.lang.String theName, java.lang.Object theAttribute)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

originalContext

protected javax.servlet.ServletContext originalContext
The original servlet context object

Constructor Detail

AbstractServletContextWrapper

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

getLogs

public java.util.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).

setAttribute

public void setAttribute(java.lang.String theName,
                         java.lang.Object theAttribute)
Specified by:
setAttribute in interface javax.servlet.ServletContext
See Also:
ServletContext.setAttribute(String, Object)

removeAttribute

public void removeAttribute(java.lang.String theName)
Specified by:
removeAttribute in interface javax.servlet.ServletContext
See Also:
ServletContext.removeAttribute(String)

log

public void log(java.lang.String theMessage,
                java.lang.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 javax.servlet.ServletContext
Parameters:
theMessage - a String that describes the error or exception
theCause - the Throwable error or exception
See Also:
getLogs(), ServletContext.log(String, Throwable)

log

public void log(java.lang.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 javax.servlet.ServletContext
Parameters:
theMessage - a String that describes the error or exception
See Also:
getLogs(), ServletContext.log(String)

log

public void log(java.lang.Exception theException,
                java.lang.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 javax.servlet.ServletContext
Parameters:
theException - the exception to log
theMessage - a String that describes the error or exception
See Also:
getLogs(), ServletContext.log(Exception, String)

getServlets

public java.util.Enumeration getServlets()
Specified by:
getServlets in interface javax.servlet.ServletContext
See Also:
ServletContext.getServlets()

getServletNames

public java.util.Enumeration getServletNames()
Specified by:
getServletNames in interface javax.servlet.ServletContext
See Also:
ServletContext.getServletNames()

getServlet

public javax.servlet.Servlet getServlet(java.lang.String theName)
                                 throws javax.servlet.ServletException
Specified by:
getServlet in interface javax.servlet.ServletContext
Throws:
javax.servlet.ServletException
See Also:
ServletContext.getServlet(String)

getServerInfo

public java.lang.String getServerInfo()
Specified by:
getServerInfo in interface javax.servlet.ServletContext
See Also:
ServletContext.getServerInfo()

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String thePath)
Specified by:
getResourceAsStream in interface javax.servlet.ServletContext
See Also:
ServletContext.getResourceAsStream(String)

getResource

public java.net.URL getResource(java.lang.String thePath)
                         throws java.net.MalformedURLException
Specified by:
getResource in interface javax.servlet.ServletContext
Throws:
java.net.MalformedURLException
See Also:
ServletContext.getResource(String)

getRequestDispatcher

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

getNamedDispatcher

public javax.servlet.RequestDispatcher getNamedDispatcher(java.lang.String theName)
Specified by:
getNamedDispatcher in interface javax.servlet.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.getNamedDispatcher(String)

getRealPath

public java.lang.String getRealPath(java.lang.String thePath)
Specified by:
getRealPath in interface javax.servlet.ServletContext
See Also:
ServletContext.getRealPath(String)

getMinorVersion

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

getMimeType

public java.lang.String getMimeType(java.lang.String theFilename)
Specified by:
getMimeType in interface javax.servlet.ServletContext
See Also:
ServletContext.getMimeType(String)

getMajorVersion

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

getInitParameterNames

public java.util.Enumeration getInitParameterNames()
Specified by:
getInitParameterNames in interface javax.servlet.ServletContext
See Also:
ServletContext.getInitParameterNames()

getInitParameter

public java.lang.String getInitParameter(java.lang.String theName)
Specified by:
getInitParameter in interface javax.servlet.ServletContext
See Also:
ServletContext.getInitParameter(String)

getContext

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

getAttributeNames

public java.util.Enumeration getAttributeNames()
Specified by:
getAttributeNames in interface javax.servlet.ServletContext
See Also:
ServletContext.getAttributeNames()

getAttribute

public java.lang.Object getAttribute(java.lang.String theName)
Specified by:
getAttribute in interface javax.servlet.ServletContext
See Also:
ServletContext.getAttribute(String)


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