Re: Filter for logging request content?

Guido Casper <[email protected]>
Newsgroups gmane.comp.java.sun.servlet
Message-ID <02b701c2f475$a6297140$2b020a0a@hw0393>
Partha Ranjan Das wrote:
> Why don't you use:
>
> return super.getReader();

since HttpServletRequest allows you to call getReader() only once.

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

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