Package org.apache.anteater.servlet
This package contains the server-side part of the testing framework.
See:
Description
Class Summary |
ListenerProxyServlet |
This is the servlet which is registered with Tomcat to receive all
the incoming HTTP requests. |
SimpleClasspathServlet |
Servlet for working out what our deployment environment looks like. |
Package org.apache.anteater.servlet Description
This package contains the server-side part of the testing framework. The
main class is ListenerProxyServlet,
The ability of Anteater to test incoming HTTP requests is it's most powerful aspect, and consequently it's most complex.
There is some pretty involved interactions between the ListenerProxyServlet, the Listener task, the SendResponse matchers, and the ServletContainer.
Given the following Anteater script:
<servletContainer port="${port}, 8101"/>
<listener path="/abc">
<match>
<method value="GET"/>
<sendResponse href="test/responses/good.html" contentType="text/html"/>
</match>
</listener>
The flow of action is as follows:
- A ServletContainer is set up, and it automatically deploys the ListenerProxyServlet
- A Listener instance is created, and it's execute() method called by Ant. This in turn calls createMatchObject.
- createMatchObject registers the listener with the ServletContainer, and calls the Queue.get() method, which blocks waiting for an incoming request
- When a request comes in, ListenerProxyServlet's service method is invoked. It does the following:
- Asks the ServletContainer for a list of registered Listeners
- Finds the listener that should deal with the current request, and removes it from the list
- Wraps the HttpServletRequest in a HttpMessage and puts it on the queue (obtained from the ServletContainer), causing the Listener thread to unblock.
- Passes the Listener the HttpServletResponse, and the writing end of a PipedWriter. The Listener will store all this info in the "Object model", a set of global variables.
- Goes into a loop, pumping bytes from the PipedWriter to the
HTTPServletResponse. In this way, bytes written by the Listener (through it's SendResponse matcher) to the
PipedWriter are used as the servlet's HTTP response.
- Going back to the Listener, recall that it was blocked in the createMatchObject
method, waiting for something to turn up in the queue. When the servlet
puts the HttpMessage in the queue, it now unblocks and the method returns
the HttpMessage. Control passes back to the Listener's execute()
method.
- The Listener then goes through the usual motions of setting up and invoking a set of Matchers (a MatcherSet). Typically, one of those Matchers will be a SendResponse task.
- If any of the Matchers preceding the SendResponse fails, the SendResponse will not be run. This is how conditional logic works; in the above example, if the <method value="GET"> matcher fails, the response is not sent.
- Assuming we get to the SendResponse, it's execute() method will retrieve the stored HttpServletResponse and PipedWriter, and use them to write an appropriate response. This involves reading bytes from the href-specified file and writing them to the PipedWriter, where the servlet will forward them on to the client.
Ant Functional Tester -- see Project home page for details