There is no request or response chain. Its 1 chain. You probably can't set headers after doChain() because the response was committed. If anything - you should see IllegalStateExceptions in the logs.

If your filter is being executed multiple times (via bad mappings or using the 2.4 API incorrectly) - then you might see too many headers.

-Tim

Keith Bottner wrote:

Previously I was calling doChain at the end of my doFilter method.

Making the change you suggest, calling doChain at the top like

public void doFilter(...)
{
    // pass the request/response on
    chain.doFilter(req, res);

        HttpServletResponse response = (HttpServletResponse) res;
                
        // set the provided HTTP response parameters
        Enumeration e = fc.getInitParameterNames();
        while ( e.hasMoreElements() )
        {
                String headerName = (String)e.nextElement();
                response.addHeader(headerName,
fc.getInitParameter(headerName));
        }
}       

DOES NOT INSERT any of my changes into the response stream. If I do it like
this:

public void doFilter(...)
{
        HttpServletResponse response = (HttpServletResponse) res;
                
        // set the provided HTTP response parameters
        Enumeration e = fc.getInitParameterNames();
        while ( e.hasMoreElements() )
        {
                String headerName = (String)e.nextElement();
                response.addHeader(headerName,
fc.getInitParameter(headerName));
        }

    // pass the request/response on
    chain.doFilter(req, res);
}

Then I get two additions in the response stream.

Any more ideas?

Keith
-----Original Message-----
From: Shapira, Yoav [mailto:[EMAIL PROTECTED] Sent: Friday, July 30, 2004 8:20 AM
To: Tomcat Users List
Subject: RE: How do you set cache-control for static (gif, jpg) resources




Hi,
You have to call chain.doFilter from inside your filter or the request
doesn't get processed.  If you set the header before the call to
chain.doFilter, than you're doing it during the request chain.  If you set
the header after the call to chain.doFilter, then you're doing it during the
response chain.  In your case the latter is what you want, so after the
chain.doFilter call.

Yoav Shapira
Millennium Research Informatics



-----Original Message-----
From: Keith Bottner [mailto:[EMAIL PROTECTED]
Sent: Friday, July 30, 2004 9:18 AM
To: 'Tomcat Users List'
Subject: RE: How do you set cache-control for static (gif, jpg)

resources

Ok, I wrote a simple filter. No problem. It works!

One question. Is there a standard way to determine if your filter is

being

called during the request chain or during the response chain?

If I use

response.putHeader(headerName, fc.getInitParameter(headerName));

It will add the header once during the request chain and once during

the

response chain, therefore, anything I add is in their twice.

If I use

response.setHeader(headerName, fc.getInitParameter(headerName));

It will overwrite the current setting, but setting the value twice just seems like bad form. If I could detect which chain is currently being processed then I could only insert it once.



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



Reply via email to