TeeHttpServletRequest extends HttpServletRequestWrapper implements BodyLogger { @Override public String getBody() { if (ServletLogger.showAsText(getContentType())) { return new String(body); } return StringUtils.abbreviate(Util.toBase64(body), 100); } TeeHttpServletRequest(HttpServletRequest request); @Override ServletInputStream getInputStream(); @Override BufferedReader getReader(); @Override String getBody();  }
@Test public void getBodyTest() throws IOException { TeeHttpServletRequest tee = new TeeHttpServletRequest(request); Map<String, Boolean> types = new HashMap<>(); types.put(MediaType.APPLICATION_JSON, true); types.put(MediaType.APPLICATION_ATOM_XML, true); types.put(MediaType.TEXT_PLAIN, true); types.put(MediaType.TEXT_HTML, true); types.put(MediaType.TEXT_XML, true); types.put(MediaType.APPLICATION_FORM_URLENCODED, true); types.put(MediaType.APPLICATION_OCTET_STREAM, false); types.put("multipart/form-data", false); types.put("application/zip", false); for (String type : types.keySet()) { when(request.getContentType()).thenReturn(type); if (types.get(type)) { assertEquals("this is my body", tee.getBody()); } else { assertEquals(Util.toBase64("this is my body".getBytes()), tee.getBody()); } } }