Overriding getWriter(), server returns error 503 (weird?)
Hi I am following the code from this link: Capture and log the response body
However the server return error 503 which is really weird?
This is my code:
final CopyPrintWriter writer = new CopyPrintWriter(servletresponse.getWriter());
chain.doFilter(servletrequest, new MyResponseWrapper(
(HttpServletResponse) servletresponse){
@Override
public PrintWriter getWriter() {
return writer;
}
});
log.debug("Test - " + writer.getCopy());
writer.close();
Inside the filter class I a开发者_JAVA技巧dded some logging:
12:03:22,404 INFO MyFilter:43 - Before invoking chain
12:03:24,107 DEBUG MyFilter:59 - Test -
12:03:24,108 INFO MyFilter:73 - After invoking chain
The client side receives HTTP error 503 from this code. And also from the log writer.getCopy() returns an empty string? What could be the reason?
EDIT: Removing the CopyPrintWriter related codes and not overriding getWriter(), the server returns OK with html.
Could be because you are creating a writer , whereas the servlet invocation after filter invocation is writing the content to stream by getting it from HttpServletResponse.getOutputStream().
The error is probably in your MyResponseWrapper
class.
精彩评论