I was planning to do this with HttpURLConnection in a filter. The filter would modify the incoming url to make it the url of the application under test. All of these urls are gets so this part is simple. For this type of testing I don't care about the response, I just want to subject the application under test to the same load as the production site. So I don't want the filter to wait for a response and tie up the original request. In my filter do I just do nothing after calling HttpURLConnection.openConnection() or do I need to call HttpURLConnection.disconnect()?
The other half of this test scenario would be filter on the application under test that just throws away the response after some logging. I'm also unsure about this, how does a Servlet just swallow a response and send nothing out?
Thanks for any help, advice and/or references to how to do this,
Originally posted by William Stafford:
... The other half of this test scenario would be filter on the application under test that just throws away the response after some logging. I'm also unsure about this, how does a Servlet just swallow a response and send nothing out?
One you close the ServletOutputStream or the PrintWriter, the connection will be closed. As long as you don't try to write to it after that, you can do anything else in your servlet's doPost method that you want.
If you run the following servlet while tailing the server's logs, you'll see the browser connection finish right away. Five seconds later, you'll see your servlet write to the log.
Note: If you comment out lines 17 through 19, the servlet will wait until the end of the doPost method before completing the transaction with the browser.
[ January 28, 2008: Message edited by: Ben Souther ]
In other words, if you call getReqeustStream in your filter before passing the request to one of your servlets, it will not be able to call any of the getParameterXxx methods, and vice versa.
If all your application does is handle plain HTTP GETS and POSTS with form-encoded data, you're OK, just don't call getRequestStream from your filter. If, on the other hand, your app has to handle multipart posts (file uploads) or parses large XML posts, your filter might make the request useless to the servlet behind it.