Filter for logging request content?

Guido Casper <[email protected]>
Newsgroups gmane.comp.java.sun.servlet
Message-ID <00d501c2f454$23f76040$2b020a0a@hw0393>
Hi all,

I want to build a logging filter that does not only log the user/method/url
but also the content of the request (i.e. for PUT requests).

I easily can extract the content of the request via getReader().
The problem is that I always get:
java.lang.IllegalStateException: getReader() has already been called for
this request

I already tried to create a RequestWrapper (see below) but the getReader()
method of my wrapper never gets called and I still get the above exception.
Unfortunately I don't have access to the source code of the called servlet.

Am I doing something wrong?
Does anybody have a possible reason/solution?

Any hint is much appreciated

Guido



    chain.doFilter(new BodyWrapper((HttpServletRequest)request, body),
response);
    // body is a String containing the body of the request

}
private class BodyWrapper extends HttpServletRequestWrapper {
    private String body;
    private BodyWrapper(HttpServletRequest req, String bo) {
        super(req);
        body = bo;
    }
    public BufferedReader getReader()
    throws java.io.IOException {
        System.out.println("BodyWrapper.getReader() called");
        return new BufferedReader(new StringReader(body));
    }
}

___________________________________________________________________________
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.