You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Glen Nakamura <gl...@imodulo.com> on 2002/02/07 05:59:13 UTC

Filters and HttpServletResponse.close();

Aloha,

When does the HttpServletResponse object get closed if the servlet doGet()
method doesn't call HttpServletResponse.close() explicitly?
For example, suppose a servlet filter creates a HttpServletResponseWrapper
to wrap the initial HttpServletResponse and passes on this new response
object down the doFilter() chain.  The servlet doGet() method eventually
gets called, but doesn't explicitly call close() of the wrapped
response object.  After tomcat returns from the container's invoke() method,
it calls finishResponse() which is supposed to flush and close the response
object, but isn't this the original response object?  What about the
wrapped response object created by the filter?  It appears it never gets
closed and is not flushed properly.  I think this explains why I'm not
getting any output from my filter when doGet() doesn't explicitly call
HttpServletResponse.close().  Did I miss something?

- Glen Nakamura


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Filters and HttpServletResponse.close();

Posted by Glen Nakamura <gl...@imodulo.com>.
Aloha,

Thanks for the pointer...  I was initially under the impression that
the servlet doGet() method was called *after* returning from my doFilter()
method, but now realize that the servlet doGet() method is indeed called
from "recursively" invoking FilterChain.doFilter() and should be completed
before my doFilter() returns.  It was staring right at me and I couldn't
see it.  Thanks for the tip!

- Glen Nakamura


On Wed, Feb 06, 2002 at 09:12:19PM -0800, Craig R. McClanahan wrote:
> 
> 
> On Wed, 6 Feb 2002, Glen Nakamura wrote:
> 
> > Date: Wed, 6 Feb 2002 18:59:13 -1000
> > From: Glen Nakamura <gl...@imodulo.com>
> > Reply-To: Tomcat Developers List <to...@jakarta.apache.org>
> > To: tomcat-dev@jakarta.apache.org
> > Subject: Filters and HttpServletResponse.close();
> >
> > Aloha,
> >
> > When does the HttpServletResponse object get closed if the servlet doGet()
> > method doesn't call HttpServletResponse.close() explicitly?
> > For example, suppose a servlet filter creates a HttpServletResponseWrapper
> > to wrap the initial HttpServletResponse and passes on this new response
> > object down the doFilter() chain.  The servlet doGet() method eventually
> > gets called, but doesn't explicitly call close() of the wrapped
> > response object.  After tomcat returns from the container's invoke() method,
> > it calls finishResponse() which is supposed to flush and close the response
> > object, but isn't this the original response object?  What about the
> > wrapped response object created by the filter?  It appears it never gets
> > closed and is not flushed properly.  I think this explains why I'm not
> > getting any output from my filter when doGet() doesn't explicitly call
> > HttpServletResponse.close().  Did I miss something?
> >
> 
> As you noted, Tomcat calls finishResponse() after the servlet returns.
> However, this is called only on the *original* response that Tomcat
> provided to the servlet -- not to any wrappers that your application has
> created.
> 
> It is your application's responsibility to ensure that anything it has
> buffered in a response wrapper is flushed to the "real" response prior to
> your filter returning from its doFilter() method.
> 
> > - Glen Nakamura
> >
> 
> Craig McClanahan
> 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Filters and HttpServletResponse.close();

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 6 Feb 2002, Glen Nakamura wrote:

> Date: Wed, 6 Feb 2002 18:59:13 -1000
> From: Glen Nakamura <gl...@imodulo.com>
> Reply-To: Tomcat Developers List <to...@jakarta.apache.org>
> To: tomcat-dev@jakarta.apache.org
> Subject: Filters and HttpServletResponse.close();
>
> Aloha,
>
> When does the HttpServletResponse object get closed if the servlet doGet()
> method doesn't call HttpServletResponse.close() explicitly?
> For example, suppose a servlet filter creates a HttpServletResponseWrapper
> to wrap the initial HttpServletResponse and passes on this new response
> object down the doFilter() chain.  The servlet doGet() method eventually
> gets called, but doesn't explicitly call close() of the wrapped
> response object.  After tomcat returns from the container's invoke() method,
> it calls finishResponse() which is supposed to flush and close the response
> object, but isn't this the original response object?  What about the
> wrapped response object created by the filter?  It appears it never gets
> closed and is not flushed properly.  I think this explains why I'm not
> getting any output from my filter when doGet() doesn't explicitly call
> HttpServletResponse.close().  Did I miss something?
>

As you noted, Tomcat calls finishResponse() after the servlet returns.
However, this is called only on the *original* response that Tomcat
provided to the servlet -- not to any wrappers that your application has
created.

It is your application's responsibility to ensure that anything it has
buffered in a response wrapper is flushed to the "real" response prior to
your filter returning from its doFilter() method.

> - Glen Nakamura
>

Craig McClanahan


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>