Why don't you use:

return super.getReader();

instead of:

return new BufferedReader(new StringReader(body));

I think, since the getReader() already has the handle to the body , a second
BuffredRedaer cannot be given.

Just try.

REgards,
Partha


-----Original Message-----
From: Guido Casper [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 27, 2003 5:00 PM
To: [EMAIL PROTECTED]
Subject: Filter for logging request content?


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
*********************************************************************
Disclaimer: The information in this e-mail and any attachments is
confidential / privileged. It is intended solely for the addressee or
addressees. If you are not the addressee indicated in this message, you may
not copy or deliver this message to anyone. In such case, you should destroy
this message and kindly notify the sender by reply email. Please advise
immediately if you or your employer does not consent to Internet email for
messages of this kind.
*********************************************************************

___________________________________________________________________________
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

Reply via email to