Shapira, Yoav wrote:

Howdy,



--- "Shapira, Yoav" <[EMAIL PROTECTED]> 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;
           super.setContentLength(contentLength);
       }

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

}

Yoav Shapira


Craig



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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to