Package com.meterware.servletunit
Class ServletRunner
java.lang.Object
com.meterware.servletunit.ServletRunner
This class acts as a test environment for servlets.
- Author:
- Russell Gold
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, which defines no servlets.ServletRunner
(File webXml) Constructor which expects a File object representing the web.xml for the application.ServletRunner
(File webXml, 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
(InputStream webXML) Constructor which expects an input stream containing the web.xml for the application.ServletRunner
(InputStream webXML, String contextPath) Constructor which expects an input stream containing the web.xml for the application.ServletRunner
(String webXMLFileSpec) Deprecated.ServletRunner
(String webXMLFileSpec, String contextPath) Deprecated.as of 1.6, useServletRunner(File,String)
ServletRunner
(String webXMLFileSpec, EntityResolver resolver) constructor with entity Resolver as asked for in Bug report 1222269 by jim - jafergus -
Method Summary
Modifier and TypeMethodDescriptiongetContextParameter
(String name) Returns the value of the named context parameter found in the application definition.getResponse
(WebRequest request) Returns the response from the specified servlet.getResponse
(String url) Returns the response from the specified servlet using GET.javax.servlet.http.HttpSession
getSession
(boolean create) Returns the session to be used by the next request.Creates and returns a new web client that communicates with this servlet runner.void
registerServlet
(String resourceName, String servletClassName) Registers a servlet class to be run.void
registerServlet
(String resourceName, String servletClassName, Hashtable initParameters) Registers a servlet class to be run, specifying initialization parameters.void
setContextParameter
(String name, Object value) Deprecated.- test case for this function deactivated wf 2007-12-30void
shutDown()
Shuts down the servlet container, returning any resources held by it.
-
Field Details
-
JASPER_DESCRIPTOR
-
-
Constructor Details
-
ServletRunner
public ServletRunner()Default constructor, which defines no servlets. -
ServletRunner
Deprecated.as of 1.6, useServletRunner(File)
Constructor which expects the full path to the web.xml for the application.- Parameters:
webXMLFileSpec
- the full path to the web.xml file- Throws:
IOException
SAXException
-
ServletRunner
Deprecated.as of 1.6, useServletRunner(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 filecontextPath
- the context path- Throws:
IOException
SAXException
-
ServletRunner
Constructor which expects a File object representing the web.xml for the application.- Parameters:
webXml
- the web.xml file- Throws:
IOException
SAXException
- Since:
- 1.6
-
ServletRunner
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 filecontextPath
- the context path- Throws:
IOException
SAXException
- Since:
- 1.6
-
ServletRunner
public ServletRunner(String webXMLFileSpec, EntityResolver resolver) throws IOException, SAXException constructor with entity Resolver as asked for in Bug report 1222269 by jim - jafergus- Parameters:
webXMLFileSpec
-resolver
-- Throws:
IOException
SAXException
- Since:
- 1.7
-
ServletRunner
Constructor which expects an input stream containing the web.xml for the application.- Throws:
IOException
SAXException
-
ServletRunner
Constructor which expects an input stream containing the web.xml for the application.- Parameters:
webXML
-contextPath
-- Throws:
IOException
SAXException
-
-
Method Details
-
registerServlet
Registers a servlet class to be run. -
registerServlet
Registers a servlet class to be run, specifying initialization parameters. -
getResponse
public WebResponse getResponse(WebRequest request) throws MalformedURLException, IOException, SAXException Returns the response from the specified servlet.- Throws:
SAXException
- thrown if there is an error parsing the responseMalformedURLException
IOException
-
getResponse
Returns the response from the specified servlet using GET.- Throws:
SAXException
- thrown if there is an error parsing the responseMalformedURLException
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
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
Deprecated.- test case for this function deactivated wf 2007-12-30Sets a application context parameter.- Parameters:
name
- - the name of the parameter to setvalue
- - 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
Creates and returns a new web client that communicates with this servlet runner.
-
ServletRunner(File)