Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cactus.server
Class AbstractServletContextWrapper

    java.lang.Object
      org.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 239054 2004-10-24 01:30:23Z felipeal $

Field Summary
`protected java.util.Hashtable` | `initParameters` List of parameters set using the `setInitParameter()` method.
`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)`
`javax.servlet.ServletContext` | `getOriginalContext()`
`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)`
`void` | `setInitParameter(java.lang.String theName, java.lang.String theValue)` Sets a parameter as if it were set in the `web.xml` file (using the <context-param> element).

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

### initParameters

    protected java.util.Hashtable initParameters

  List of parameters set using the `setInitParameter()` method.

Constructor Detail

### AbstractServletContextWrapper

    public AbstractServletContextWrapper(javax.servlet.ServletContext theOriginalContext)

Parameters:
  `theOriginalContext` - the original servlet context object

Method Detail

### getOriginalContext

    public javax.servlet.ServletContext getOriginalContext()

  Returns:
    the original unmodified config object
  Since:
    1.6

### setInitParameter

    public void setInitParameter(java.lang.String theName,
                                 java.lang.String theValue)

  Sets a parameter as if it were set in the `web.xml` file (using the <context-param> element).

  Parameters:
    `theName` - the parameter's name
    `theValue` - the parameter's value

### 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`
  Returns:
    the union of the parameters defined in the Redirector `web.xml` file and the one set using the `setInitParameter()` method.

### getInitParameter

    public java.lang.String getInitParameter(java.lang.String theName)

  Specified by:
    `getInitParameter` in interface `javax.servlet.ServletContext`
  Parameters:
    `theName` - the name of the parameter's value to return
  Returns:
    the value of the parameter, looking for it first in the list of parameters set using the `setInitParameter()` method and then in those set in `web.xml`.

### 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)`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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