tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Logging filter (was RE: [next] What's next ?)
Date Thu, 02 Oct 2003 17:14:54 GMT
Shapira, Yoav wrote:

>>--- "Shapira, Yoav" <> wrote:
>>>1. Convert AccessLogValve to be a servlet
>>>specification 2.3 filter, i.e.
>>That sounds wonderful and useful, but there are a few
>>problems here.  Filters don't have access to all the
>>information that is needed to make a log entry the way
>>the AccessLogValve does it.  Content length, response
>>code and content type variables may not be known when
>>the filter is processing, and (last time I checked)
>>there is no byte[] Response.getContentType() method.
>>There is setContentType() but no getContentType().
>That's unfortunate ;(
>getContentType() is there, actually, in ServletResponse.  But not
>getContentLength() nor getStatusCode().  I was planning the
>AccessLogFilter just support the Common and Combined access log files
>patterns, and I imagined all the required fields for those patterns are
>part of standard interfaces.
>In fact, why aren't there methods like getHeader(String name) and
>getContentLength() in the ServletResponse interface?  Can someone
>familiar with the Servlet Specification comment on this?
That's what HttpServletResponseWrapper is for.  Simply have your logging 
filter wrap the response (on the way in) with a wrapper class that adds 
the necessary getters, and overrides the setters to store what you need 
where the getters can get to it.  Skeleton implementation for just the 
content length:

    public class MyResponseWrapper implements HttpServletResponseWrapper {


        // Local variable in which to cache the content length
        private int saveContentLength;

        // The standard response method
        public void setContentLength(int contentLength) {
            saveContentLength = contentLength;

        // Added method in my wrapper class
        public int getContentLength() { return saveContentLength; }


>Yoav Shapira

>This e-mail, including any attachments, is a confidential business communication, and
may contain information that is confidential, proprietary and/or privileged.  This e-mail
is intended only for the individual(s) to whom it is addressed, and may not be saved, copied,
printed, disclosed or used by anyone else.  If you are not the(an) intended recipient, please
immediately delete this e-mail from your computer system and notify the sender.  Thank you.
>To unsubscribe, e-mail:
>For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message