-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Closed as not planned
Closed as not planned
Copy link
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.comin: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: invalidAn issue that we don't feel is validAn issue that we don't feel is valid
Description
ContentCachingRequestWrapper#getContentAsByteArray is empty before javax.servlet.FilterChain#doFilter
public class LogFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
throws IOException, ServletException {
ContentCachingRequestWrapper contentCachingRequestWrapper = new ContentCachingRequestWrapper((HttpServletRequest) servletRequest);
ContentCachingResponseWrapper contentCachingResponseWrapper = new ContentCachingResponseWrapper((HttpServletResponse) servletResponse);
byte[] contentAsByteArray = contentCachingRequestWrapper.getContentAsByteArray();
// but contentAsByteArray is empty
String s = new String(contentAsByteArray);
System.out.println("request body:" + s);
chain.doFilter(contentCachingRequestWrapper, contentCachingResponseWrapper);
byte[] contentAsBytes = contentCachingRequestWrapper.getContentAsByteArray();
// contentAsBytes is not empty
String str = new String(contentAsBytes);
System.out.println("request body:" + str);
byte[] contentAsByteArray1 = contentCachingResponseWrapper.getContentAsByteArray();
String s1 = new String(contentAsByteArray1);
System.out.println("response body:" + s1);
contentCachingResponseWrapper.copyBodyToResponse();
}
}
Metadata
Metadata
Assignees
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.comin: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: invalidAn issue that we don't feel is validAn issue that we don't feel is valid