-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Leon,

On 4/29/13 12:55 PM, Leon Rosenberg wrote:
> However, in my case, I am developing a library that is used by
> others in their projects (http://moskito.anotheria.net). It comes
> already with 8 filters and this is a lot.

If you want the effect of the filters without the stack trace(s), you
could implement your filters somewhat differently (but still implement
the Filter interface, so they can be used separately if desired) and
then wrap them into a single compound-filter... something like this:

public class SourceIPSessionFilter
    implements Filter, RequestSetUp
{
    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain)
    {
        setUpRequest(request);
        chain.doFilter(request, response);
    }

    public void setUpRequest(ServletRequest request)
    {
        HttpSession session =
((HttpServletRequest)request).getSession(false);

        if(null != session)
            session.setAttribute(SOURCE_IP, request.getRemoteAddr());
    }
}

public class MetaFilter
    implements Filter
{
    private List<SetUpFilter> subFilters;

    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain)
    {
        for(SetUpFilter f : subFilters)
            f.setUpRequest(request);

        chain.doFilter(request, response);
    }
}

Obviously, this is a small glimpse into what you can do -- maybe you
want "set up" and "tear down" filters, and maybe those that do both,
etc. But the point is that you call a method that /returns/ before the
filter chain is invoked. Instead of a classic interceptor pattern,
it's more like a phased-interceptor where the first phase runs
separately from the second phase.

Implementing the individual filters as formal Filters as well as your
other customized interface allows your users to use them in either
way: with the MetaFilter to reduce stack trace clutter or individually
so they can .. I dunno.. have more control or maybe they like long
stack traces.

One more thought: stack-trace length is really irrelevant. Honestly, I
think you are coding-around something that is totally unnecessary.
Stack traces for web applications are notoriously long -- sometimes
dozens and into the hundreds of calls (especially using Weblogic in my
experience). I wouldn't kill yourself over trying to reduce your
users' stack traces from 50 nested method calls to 42... nobody is
going to notice.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJRf9FUAAoJEBzwKT+lPKRYrkYP/3bBl19qVqgrfUTBAcsYxPR0
fZr+TLjL1qahymcstMyx0PMKpwV1syq2zJNHhAu/5vH0y5W+cu9IZIqiXdY48pSm
PEizqzQ37Mbnf+HbE57HU2rDwT1ZrgM80oLIWU22OGKxWf0XNuDsfpsZ/ksbm7gt
P5XIk/qEamrszJsNGF5qys4jaGaVV4btIi0+QCKD7CMRn8z+jGFZZOiScrQ0bdJZ
Ngnv6ljBx0Dqt6PlkLzJBteC8/FBaTaY/LighSQLXt1A7pKZz/WHhiucozmJ6ZQN
ae6klVr6AY0EQ/tRdGsZbbmlRIRuwlVhYASUbQ2bMaqeh9OtQIwpQAlUuqCR1jKj
s/9703NNUL7xicQ4RmU5JNF8iRJNmvu5h9GkKHNByGbi2y9JqbhVGXcp6i07zt9J
qqWCY0Km+3rzinRwZ38eEKjHI+Idl1WdqUMuPBxjXEqsMUFa+GFo0tS8Obvsg4Nl
H5qFVb2J0XyLlVbBMd+fbS/mncOMcnpDGU1lZjxWeBPL0yrXRpz+P5b45rJio5zi
VXMtUO0OYthjekmadA8QSTEapGbxvgxXHO2W7TfrfJizDeeORMxL/rgGkHlOTzuG
UUzLs/ek++VBzjOyTk6KXFqUMOSBbwRbIlX7k7hmP/uVyo2aef3uHNBjwI/Tkt3Z
iHTcuysdAyHbNlkf6cY5
=nXLy
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to