Lazily Check the Body of an HttpServletResponse



This site utilizes Google Analytics, Google AdSense, as well as participates in affiliate partnerships with various companies including Amazon. Please view the privacy policy for more details.

A week or so ago I wrote about how I was helping junior developer analyze the incoming parameters of an HTTP request in a Spring/Java Servlet application.

It turns out she also needed to analyze the body of the corresponding request. Here’s how I suggested she do that:

You see above that I overrode two methods of HttpServletResponse: getOutputStream() and getWriter(). In practice, I only noticed that the getWriter() method was called, so you might only need to use that override.

You’ll still need to watch out in the event the response gets unwrapped via getResponse() method of the ServletResponseWrapper superclass.

Leave a Reply

Note that comments won't appear until approved.