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

前端 未结 3 920
别那么骄傲
别那么骄傲 2020-12-20 16:21

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 cha

相关标签:
3条回答
  • 2020-12-20 16:48

    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.

    0 讨论(0)
  • 2020-12-20 17:08

    In my particular case, I eventually solved the problem by using a CodedOutputStream to write the com.google.protobuf.GeneratedMessage (foo below):

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    CodedOutputStream cos = CodedOutputStream.newInstance(bos);
    foo.writeTo(cos);
    

    This can be read in using a CodedInputStream with something like:

    byte[] ba = readBytesFromOutputFile();
    CodedInputStream cis = CodedInputStream.newInstance(ba);
    

    The CodedInputStream can then be passed to a message builder to complete the deserialization.

    0 讨论(0)
  • 2020-12-20 17:10

    There are many local reverse-proxy tools that can 'record-and-playback' a HTTP session. Typically you setup your browser to use a localhost proxy server, perform the actions, save the session, then replay it. JMeter and Charles are two tools that are Java based.

    Another option would be to use HttpClient to programmatically exercise your servlet. Using JUnit to execute the tests has an advantage in that it's easier to verify you are getting the 'correct' response.

    0 讨论(0)
提交回复
热议问题