use of org.springframework.web.util.ContentCachingRequestWrapper in project spring-framework by spring-projects.
the class RequestLoggingFilterTests method payloadMaxLength.
@Test
void payloadMaxLength() throws Exception {
filter.setIncludePayload(true);
filter.setMaxPayloadLength(3);
byte[] requestBody = "Hello World".getBytes(StandardCharsets.UTF_8);
request.setContent(requestBody);
FilterChain filterChain = (filterRequest, filterResponse) -> {
((HttpServletResponse) filterResponse).setStatus(HttpServletResponse.SC_OK);
byte[] buf = FileCopyUtils.copyToByteArray(filterRequest.getInputStream());
assertThat(buf).isEqualTo(requestBody);
ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(filterRequest, ContentCachingRequestWrapper.class);
assertThat(wrapper.getContentAsByteArray()).isEqualTo("Hel".getBytes(StandardCharsets.UTF_8));
};
filter.doFilter(request, response, filterChain);
assertThat(filter.afterRequestMessage).contains("Hel");
assertThat(filter.afterRequestMessage).doesNotContain("Hello World");
}
Aggregations