com.meterware.servletunit
Class ServletRunner

java.lang.Object
  extended bycom.meterware.servletunit.ServletRunner

public class ServletRunner
extends java.lang.Object

This class acts as a test environment for servlets.

Author:
Russell Gold

Nested Class Summary
static class ServletRunner.JasperJSPServletDescriptor
           
 
Field Summary
static JSPServletDescriptor JASPER_DESCRIPTOR
           
 
Constructor Summary
ServletRunner()
          Default constructor, which defines no servlets.
ServletRunner(java.io.File webXml)
          Constructor which expects a File object representing the web.xml for the application.
ServletRunner(java.io.File webXml, java.lang.String contextPath)
          Constructor which expects a File object representing the web.xml for the application and a context path under which to mount it.
ServletRunner(java.io.InputStream webXML)
          Constructor which expects an input stream containing the web.xml for the application.
ServletRunner(java.io.InputStream webXML, java.lang.String contextPath)
          Constructor which expects an input stream containing the web.xml for the application.
ServletRunner(java.lang.String webXMLFileSpec)
          Deprecated. as of 1.6, use ServletRunner(File)
ServletRunner(java.lang.String webXMLFileSpec, org.xml.sax.EntityResolver resolver)
          constructor with entity Resolver as asked for in Bug report 1222269 by jim - jafergus
ServletRunner(java.lang.String webXMLFileSpec, java.lang.String contextPath)
          Deprecated. as of 1.6, use ServletRunner(File,String)
 
Method Summary
 java.lang.String getContextParameter(java.lang.String name)
          Returns the value of the named context parameter found in the application definition.
 WebResponse getResponse(java.lang.String url)
          Returns the response from the specified servlet using GET.
 WebResponse getResponse(WebRequest request)
          Returns the response from the specified servlet.
 javax.servlet.http.HttpSession getSession(boolean create)
          Returns the session to be used by the next request.
 ServletUnitClient newClient()
          Creates and returns a new web client that communicates with this servlet runner.
 void registerServlet(java.lang.String resourceName, java.lang.String servletClassName)
          Registers a servlet class to be run.
 void registerServlet(java.lang.String resourceName, java.lang.String servletClassName, java.util.Hashtable initParameters)
          Registers a servlet class to be run, specifying initialization parameters.
 void setContextParameter(java.lang.String name, java.lang.Object value)
          Deprecated. - test case for this function deactivated wf 2007-12-30
 void shutDown()
          Shuts down the servlet container, returning any resources held by it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JASPER_DESCRIPTOR

public static final JSPServletDescriptor JASPER_DESCRIPTOR
Constructor Detail

ServletRunner

public ServletRunner()
Default constructor, which defines no servlets.


ServletRunner

public ServletRunner(java.lang.String webXMLFileSpec)
              throws java.io.IOException,
                     org.xml.sax.SAXException
Deprecated. as of 1.6, use ServletRunner(File)

Constructor which expects the full path to the web.xml for the application.

Parameters:
webXMLFileSpec - the full path to the web.xml file

ServletRunner

public ServletRunner(java.lang.String webXMLFileSpec,
                     java.lang.String contextPath)
              throws java.io.IOException,
                     org.xml.sax.SAXException
Deprecated. as of 1.6, use ServletRunner(File,String)

Constructor which expects the full path to the web.xml for the application and a context path under which to mount it.

Parameters:
webXMLFileSpec - the full path to the web.xml file
contextPath - the context path

ServletRunner

public ServletRunner(java.io.File webXml)
              throws java.io.IOException,
                     org.xml.sax.SAXException
Constructor which expects a File object representing the web.xml for the application.

Parameters:
webXml - the web.xml file
Since:
1.6

ServletRunner

public ServletRunner(java.io.File webXml,
                     java.lang.String contextPath)
              throws java.io.IOException,
                     org.xml.sax.SAXException
Constructor which expects a File object representing the web.xml for the application and a context path under which to mount it.

Parameters:
webXml - the web.xml file
contextPath - the context path
Since:
1.6

ServletRunner

public ServletRunner(java.lang.String webXMLFileSpec,
                     org.xml.sax.EntityResolver resolver)
              throws java.io.IOException,
                     org.xml.sax.SAXException
constructor with entity Resolver as asked for in Bug report 1222269 by jim - jafergus

Parameters:
webXMLFileSpec -
resolver -
Throws:
java.io.IOException
org.xml.sax.SAXException
Since:
1.7

ServletRunner

public ServletRunner(java.io.InputStream webXML)
              throws java.io.IOException,
                     org.xml.sax.SAXException
Constructor which expects an input stream containing the web.xml for the application.


ServletRunner

public ServletRunner(java.io.InputStream webXML,
                     java.lang.String contextPath)
              throws java.io.IOException,
                     org.xml.sax.SAXException
Constructor which expects an input stream containing the web.xml for the application.

Parameters:
webXML -
contextPath -
Throws:
java.io.IOException
org.xml.sax.SAXException
Method Detail

registerServlet

public void registerServlet(java.lang.String resourceName,
                            java.lang.String servletClassName)
Registers a servlet class to be run.


registerServlet

public void registerServlet(java.lang.String resourceName,
                            java.lang.String servletClassName,
                            java.util.Hashtable initParameters)
Registers a servlet class to be run, specifying initialization parameters.


getResponse

public WebResponse getResponse(WebRequest request)
                        throws java.net.MalformedURLException,
                               java.io.IOException,
                               org.xml.sax.SAXException
Returns the response from the specified servlet.

Throws:
org.xml.sax.SAXException - thrown if there is an error parsing the response
java.net.MalformedURLException
java.io.IOException

getResponse

public WebResponse getResponse(java.lang.String url)
                        throws java.net.MalformedURLException,
                               java.io.IOException,
                               org.xml.sax.SAXException
Returns the response from the specified servlet using GET.

Throws:
org.xml.sax.SAXException - thrown if there is an error parsing the response
java.net.MalformedURLException
java.io.IOException

getSession

public javax.servlet.http.HttpSession getSession(boolean create)
Returns the session to be used by the next request.

Parameters:
create - if true, will create a new session if no valid session is defined.
Since:
1.6

getContextParameter

public java.lang.String getContextParameter(java.lang.String name)
Returns the value of the named context parameter found in the application definition.

Parameters:
name - - the name of the parameter to get
Returns:
- the context parameter with the given name

setContextParameter

public void setContextParameter(java.lang.String name,
                                java.lang.Object value)
Deprecated. - test case for this function deactivated wf 2007-12-30

Sets a application context parameter.

Parameters:
name - - the name of the parameter to set
value - - the value of the parameter to set

shutDown

public void shutDown()
Shuts down the servlet container, returning any resources held by it. Calls the destroy method of each active servlet, then notifies ContextListeners of server shutdown.


newClient

public ServletUnitClient newClient()
Creates and returns a new web client that communicates with this servlet runner.


Copyright © 2000-2008 Russell Gold. See license agreement for rights granted.