0

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 added 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.

Community
  • 1
  • 1
quarks
  • 33,478
  • 73
  • 290
  • 513

2 Answers2

0

The error is probably in your MyResponseWrapper class.

Femi
  • 64,273
  • 8
  • 118
  • 148
  • i'm not sure if the error is within the wrapper class, because its just a wrapper that overrides getOutputStream, where I use TeeOutputStream to branch the stream and log it from there. – quarks Jun 09 '11 at 05:45
0

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().

Ramesh PVK
  • 15,200
  • 2
  • 46
  • 50