for a purpose of performance testing I need to write a servlet that will call a number of servlets in a existing web application.
It will measure a average execution time of each servlet. The sequence of servlet names and arguments is stored in a xml file, which is accessed by the testing servlet.
Moreover such testing scenario will be executed simultaneously for several user - I will create a thread for each user and call the sequence of servlets from the xml file. Results of measurements will be stored in a file.
In our web application a gatway between client and server in a Dispatcher class which forwards client requests to a specific servlet according to provided command parameter.
So having a servlet name and parameter I do as follows:
This way I can measure time of servlet execution and moreover I can store the result of execution in StringBuffer.
The problem is that each time I call the Dispatcher this way I get a different sessionId - so that objects stored in the session object by previous servlet cannot be accessed by the following one.
I tried calling the Dispatcher using an other RequestDispatcher, like this:
But this throws java.lang.IllegalStateException: Cannot forward after response has been committed.
So the question is: How can I call various servlets, provide request parameters and keep the same sessionId for each call? And BTW sorry for such a long post, but I wanted to explain the problem is details, because it might be that you will provide a completely different solution.
Thank you in advance for answering!
Anyway, you need to do whatever the server wants you to do, to preserve the session. Normally servers send cookies to clients to preserve a session, so you should do that too. (Remember, you are the client here.) That involves adding suitable headers to your HTTP requests and reading them from the responses.
You might want to use the Apache HttpClient package instead of trying to do this yourself with the standard Java API classes like HttpURLConnection.
David Newton wrote:I'd add only that unless there's a compelling reason to do this with a servlet it might be easier to just use any number of existing load/performance testing tools that are already written, debugged, and provide a lot of functionality for simulating user interactions.
May I ask you to suggest one?