• Post Reply Bookmark Topic Watch Topic
  • New Topic

Call a number of servlets within the same session  RSS feed

 
Krzysztof Jurkowski
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
For example:

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!

 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"gnom gnom", please check your private messages regarding an important administrative matter.

Thank you.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, this really isn't a "servlets" question because it doesn't matter that you are doing this series of HTTP requests in a servlet. You could equally well be doing it in a standalone Java program. (And you might want to test it in one, to simplify the process.)

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
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Krzysztof Jurkowski
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use JMeter, but only because I'm used to it.
 
Krzysztof Jurkowski
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will investigate both solutions. Thank you for help! JavaRanch is the best!!!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!