Print request body in PrintingResultHandler in Spring MVC Test

Prior to this commit, the PrintingResultHandler used by the various
print() and log() methods in Spring MVC Test printed the response body
but not the request body.

Since request bodies are sometimes generated programmatically, however,
it can be beneficial to have the dynamically generated request body
logged as well.

This commit therefore prints the request body in PrintingResultHandler
by delegating to the recently introduced getContentAsString() method in
MockHttpServletRequest.

Issue: SPR-14717
This commit is contained in:
Sam Brannen
2016-10-03 18:05:42 +02:00
parent 04b8ae921e
commit 487bc7505b
3 changed files with 13 additions and 5 deletions

View File

@@ -107,6 +107,7 @@ public class PrintingResultHandler implements ResultHandler {
this.printer.printValue("Request URI", request.getRequestURI());
this.printer.printValue("Parameters", getParamsMultiValueMap(request));
this.printer.printValue("Headers", getRequestHeaders(request));
this.printer.printValue("Body", request.getContentAsString());
}
protected final HttpHeaders getRequestHeaders(MockHttpServletRequest request) {