|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.jetty.testing.ServletTester
public class ServletTester
Testing support for servlets and filters.
Allows a programatic setup of a context with servlets and filters for
testing. Raw HTTP requests may be sent to the context and responses received.
To avoid handling raw HTTP see HttpTester
.
ServletTester tester=new ServletTester(); tester.setContextPath("/context"); tester.addServlet(TestServlet.class, "/servlet/*"); tester.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/"); tester.start(); String response = tester.getResponses("GET /context/servlet/info HTTP/1.0\r\n\r\n");
HttpTester
Constructor Summary | |
---|---|
ServletTester()
|
Method Summary | |
---|---|
void |
addEventListener(EventListener listener)
|
FilterHolder |
addFilter(Class filterClass,
String pathSpec,
int dispatches)
|
FilterHolder |
addFilter(String filterClass,
String pathSpec,
int dispatches)
|
ServletHolder |
addServlet(Class servlet,
String pathSpec)
|
ServletHolder |
addServlet(String className,
String pathSpec)
|
String |
createChannelConnector(boolean localhost)
Create a SelectChannel connector. |
LocalConnector |
createLocalConnector()
Create a local connector. |
String |
createSocketConnector(boolean localhost)
Create a Socket connector. |
Object |
getAttribute(String name)
|
Enumeration |
getAttributeNames()
|
Attributes |
getAttributes()
|
ServletContextHandler |
getContext()
|
String |
getResourceBase()
|
ByteArrayBuffer |
getResponses(ByteArrayBuffer rawRequests)
Get raw HTTP responses from raw HTTP requests. |
String |
getResponses(String rawRequests)
Get raw HTTP responses from raw HTTP requests. |
String |
getResponses(String rawRequests,
LocalConnector connector)
Get raw HTTP responses from raw HTTP requests. |
void |
setAttribute(String name,
Object value)
|
void |
setClassLoader(ClassLoader classLoader)
|
void |
setContextPath(String contextPath)
|
void |
setEventListeners(EventListener[] eventListeners)
|
void |
setResourceBase(String resourceBase)
|
void |
start()
|
void |
stop()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ServletTester()
Method Detail |
---|
public void start() throws Exception
Exception
public void stop() throws Exception
Exception
public ServletContextHandler getContext()
public String getResponses(String rawRequests) throws Exception
rawRequests
- String of raw HTTP requests
Exception
public String getResponses(String rawRequests, LocalConnector connector) throws Exception
rawRequests
- String of raw HTTP requestsconnector
- The connector to handle the responses
Exception
public ByteArrayBuffer getResponses(ByteArrayBuffer rawRequests) throws Exception
rawRequests
- String of raw HTTP requests
Exception
public String createSocketConnector(boolean localhost) throws Exception
localhost
- if true, only listen on local host, else listen on all interfaces.
Exception
public String createChannelConnector(boolean localhost) throws Exception
Exception
public LocalConnector createLocalConnector() throws Exception
Exception
public void addEventListener(EventListener listener)
listener
- ContextHandler.addEventListener(java.util.EventListener)
public FilterHolder addFilter(Class filterClass, String pathSpec, int dispatches)
filterClass
- pathSpec
- dispatches
-
ServletContextHandler.addFilter(java.lang.Class, java.lang.String, int)
public FilterHolder addFilter(String filterClass, String pathSpec, int dispatches)
filterClass
- pathSpec
- dispatches
-
ServletContextHandler.addFilter(java.lang.String, java.lang.String, int)
public ServletHolder addServlet(Class servlet, String pathSpec)
servlet
- pathSpec
-
ServletContextHandler.addServlet(java.lang.Class, java.lang.String)
public ServletHolder addServlet(String className, String pathSpec)
className
- pathSpec
-
ServletContextHandler.addServlet(java.lang.String, java.lang.String)
public Object getAttribute(String name)
name
-
ContextHandler.getAttribute(java.lang.String)
public Enumeration getAttributeNames()
ContextHandler.getAttributeNames()
public Attributes getAttributes()
ContextHandler.getAttributes()
public String getResourceBase()
ContextHandler.getResourceBase()
public void setAttribute(String name, Object value)
name
- value
- ContextHandler.setAttribute(java.lang.String, java.lang.Object)
public void setClassLoader(ClassLoader classLoader)
classLoader
- ContextHandler.setClassLoader(java.lang.ClassLoader)
public void setContextPath(String contextPath)
contextPath
- ContextHandler.setContextPath(java.lang.String)
public void setEventListeners(EventListener[] eventListeners)
eventListeners
- ContextHandler.setEventListeners(java.util.EventListener[])
public void setResourceBase(String resourceBase)
resourceBase
- ContextHandler.setResourceBase(java.lang.String)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |