Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
535 views
in Technique[技术] by (71.8m points)

java - How should I record `HttpServletRequest`s that are sent to `doPost` in an `HttpServlet` for later playback?

I want to dump some requests (of type javax.servlet.http.HttpServletRequest) into a file and then later replay them from the file, so that I can test future changes to the HttpServlet. What's the best way to accomplish this?

So far, I'm trying to pull data out of the input stream associated with the request, and save this binary data into a file. Ultimately, this may require something like storing a byte-count prior to each saved input stream, so that I know where one request ends and the other begins.

Is there a simpler way to do this?

**EDIT: to clarify, these are not requests involving a browser. So far none of the answers solves my particular problem, which I suppose boils down to serializing and deserializing an HttpServletRequest. I've tried just pulling the bytes from the input stream returned by request.getInputStream(). Unfortunately, if I turn this into a string, it seems that the resulting bytes cannot be parsed by Message.Builder.mergeFrom(bytes).

I'm putting up a bounty for anyone who knows how to solve my problem.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Perhaps you should have a look at Selenium ( http://seleniumhq.org/ ).

I say this because I am presuming that the reason you want to play back the requests is for testing purposes. Selenium records what you do in your browser, and can then play it back.

If you're trying to accomplish something else, perhaps you could explain what you're ultimately trying to do.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...