-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Bill,
On 4/22/2010 2:37 AM, Bill Barker wrote: > If [the request/filter] does a forward or include done the line, this > won't work with any remotely recent version of Tomcat. These > versions enforce the spec requirement that the Request has to be a > subclass of HttpServletWrapper wrapping the original request, or the > original request. The following filter works as expected on Tomcat 6.0.26 (some changes were required to make it actually work... my off-the-cuff implementation was lacking a few details). I can confirm that this filter operates properly across a forward() call: I have a struts action handles by the Struts servlet that forwards to a Velocity template handled by the Velocity servlet. All calls are logged to stdout. (Wow, lots of calls to Request.getAttribute!) import java.io.IOException; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class RequestMethodCallLogger implements Filter { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException { if(request instanceof HttpServletRequest) request = (ServletRequest)Proxy .newProxyInstance(HttpServletRequest.class.getClassLoader(), new Class[] { HttpServletRequest.class }, new Wrapper(request)); chain.doFilter(request, response); } public void init(FilterConfig config) { } public void destroy() { } static class Wrapper implements InvocationHandler { private Object _target; Wrapper(Object target) { _target = target; } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { System.out.print("Intercepted: "); System.out.println(method); return method.invoke(_target, args); } } } -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkvQsjUACgkQ9CaO5/Lv0PA65ACgiR4tiSji6MElZr9/Z0ibXdtX WJQAnRoB/GZbrSwdfPjcf50IpHFmW4L9 =Stkm -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org