Thanks for the response Christopher. 

Unfortunately I need to set a value in the header after the doFilter()
delegation. The reason is that header valuedepends on the result of the page
rendering.

So, if autoflush is disabled and the buffer size is not exceeded for the
page shouldn't a setHeader() call made after the doFilter() call be able to
set the value in the response header?

Or, to put it another way, does the j2ee spec (or tomcat design) always
start sending the response to the client when the page is rendered (after
the last filter has been executed in a filter chain), or after the
filterchain has completed its processing?

Mike



Christopher Schultz-2 wrote:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Michael,
> 
> Michael Larson wrote:
>> I'm debugging a tomcat filter. The filter has been designed as follows:
>> 
>> MyFilter::DoFilter(ServletRequest request, ServletResponse response,
>> FilterChain chain)
>> {
>>    do_some_stuff();
>> 
>>    //now delegate the call the chain
>>    chain.DoFilter();
>> 
>>    //the header value below doesn't always show up at the client
>>    response.setHeader("post-filter","true");
>> }
> 
> This might not work because the response could have been committed. If
> the response buffer is filled, then the headers will be sent back to the
> client. If you come along later and try to set a header, you'll get an
> exception.
> 
>> For the jsp page being accessed I've turned off AutoFlush (via a server
>> side directive). However, I'm still seeing this page (if it exceeds a
>> certain size but well below the jspwriter buffer size) will be sent back
>> to the client before the response header has been modified.
> 
> I'm not sure about autoFlush, but it may be that you're hitting a hard
> buffer limit and the data is being sent, anyway.
> 
>> If AutoFlush is turned off for the jsp page and the page doesn't exceed
>> the buffer size can it still send the response back to the client before
>> the filter chain has completed (and in this example before the header
>> has been modified)? Is it a bad idea to modify the response header after
>> the call to chain.DoFilter()?
> 
> It's much better to do it up front if you can. Why do you need the
> header to be set after the fact?
> 
> If you really must do this, you can always do your own buffering by
> wrapping the request along with your own OutputStream/Writer that
> buffers itself.
> 
>> The version of tomcat is v5.5.23, and no exceptions are thrown when the
>> setHeader call is made.
> 
> That's interesting that no exceptions are thrown. :(
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iEYEARECAAYFAkjrrxwACgkQ9CaO5/Lv0PAKdwCfbEXaoIj5cnMLIYZciiEXcAL8
> 0TMAn0CWqgdA8qQNsZwDabIQHbRHPoqY
> =Gqzj
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/setHeader-after-DoFilter-delegation-in-filter--tp19862960p19912296.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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to