Sorry if this not directly related to tomcat itself. I have a swing app thatcommunicate with backend thru a web app deployed on tomcat. For testingpurposes, we want to be able to record some http responses and later on beable to simulate the same response when it gets the same request ( akasimulating the web sever). All tools we could find only record requests andsimulate the client not the sever. Any help/hint is appreciated. thnx

This sounds like something you could write yourself as a relativelysimple webapp:

1. Write an HTTP recorder filter. Configure it as the first filter thatgets run for any request. Wrap the request object with one that recordsthe input stream coming in, say, to a file. Wrap the response with onethat records the output to another file. Your request object can linkthese two files any way it wants. You probably want to do something likeuse Content-Length + SHA1(request) as a key to the request that youstore for later.

2. Run your application through this filter to generate some test data.

3. Write a servlet that does nothing but read requests, hash them, lookup the "test response" from your database of responses, and dump theresponse back to the client.

You'll have to watch out for a few things:

1. The recorded response is not directly playable because it includesthings like the status header, which you can't send twice. So you'llhave to record the status header and set it appropriately instead ofjust writing content.

2. Similar to #1, you have to send headers using setHeader() instead ofjust writing to the output stream, because the output stream is usedsolely for the response body.

3. If your requests include bodies, you might want to pre-process therequests to account for varying amounts of whitespace, etc.

In thinking about #1 and #2 above, I think a change to the "recorder" isin order: you probably want to store the headers, status code, etc.specially instead of just as text in your recorded file. This will makeit easier to "play back" the response.