tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slioch <m...@lrlart.com>
Subject RE: setHeader after DoFilter delegation in filter?
Date Sat, 11 Oct 2008 03:59:33 GMT

Sorry all--I'm still stumped. Tried the suggestions and here's what I found. 

I've subclass HttpServletResponseWrapper and overloaded the following
methods:

    public void flushBuffer();
    public void sendRedirect(String str);
    public void sendError(int sc);
    public void sendError(int sc, String msg);

in my new response wrapper. These methods have been disabled while
processing is in the scope of my filter (I also record if these methods are
called). I've replaced the response object with my new wrapper:

    public void doFilter(ServletRequest req, ServletResponse res,
FilterChain fc)
    throws java.io.IOException, javax.servlet.ServletException {
	ResponseWrapper resp = new ResponseWrapper((HttpServletResponse)(res));


And I've found that sendError(), sendRedirect(), and flushBuffer() are not
being called while in the processing is in the scope of my filter. In other
words the filter looks something like:

dofilter(ServletRequest req, ServletResponse res, FilterChain fc)
{
   ResponseWrapper resp = new ResponseWrapper((HttpServletResponse)(res));
   //resp.isCommitted() returns false
   //some processing work
   //resp.isCommitted() returns false;
   fc.doFilter(req,resp);
   //resp.isCommitted() returns TRUE
  //some more process work
  return;
}

If I know that sendError(), sendRedirect(), and flushBuffer() are not being
called how would response be sent (provided autoflush is false and the
buffer size is large enough for the print writer). Thanks for the help (and
patience)!

mike


Caldarale, Charles R wrote:
> 
>> From: André Warnier [mailto:aw@ice-sa.com]
>> Subject: Re: setHeader after DoFilter delegation in filter?
>>
>> To create output for the client, the application calls
>> something, right? (I mean a method of HttpRequest).
> 
> Not quite - you're confusing request with response.  There are methods in
> HttpServletResponse - an Interface, not a class - to obtain a PrintWriter
> or ServletOutputStream that the webapp uses to generate data to be sent to
> the client at some point in the future.  The data isn't sent until
> flushBuffer(), sendError(), or sendRedirect() are called.  Since the
> HttpServletResponseWrapper class implements the interface, those methods
> are available via the wrapper.  The filter needs to subclass the wrapper
> in order to subvert anything else in the filter/servlet chain.
> 
>  - Chuck
> 
> 
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/setHeader-after-DoFilter-delegation-in-filter--tp19862960p19929361.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message