tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: a servlet-related Java question
Date Wed, 21 Apr 2010 20:25:37 GMT
Hash: SHA1


On 4/21/2010 3:46 PM, André Warnier wrote:
> Mark Thomas wrote:
>> On 21/04/2010 20:24, André Warnier wrote:
>>> Mark Thomas wrote:
>>> ...
>>>> I'd just use JAD and decompile it.
>>> Thanks.  But although my intentions are not obnoxious nor illegal nor
>>> anything of the kind, I would not want to even come under suspicion of
>>> reverse-engineering.  So is there something that just lists the standard
>>> calls/methods used in it ?
>> No. You can see the methods it exposes, but not the methods it uses.
>> Time to add some  debug code to your wrapper to see what is being called?
> Mmmm. :-(
> How do I do that, assuming I do not know in advance which methods it
> calls ?
> Do I need to define all the methods of HttpServletRequest in my wrapper,
> just to make them trace their call ?
> Or does there exist some more dummy-user-friendly methodology ?

It's pretty inaccessible for novice Java programmers, but you could use
the "proxy" API which is jsut about the coolest thing available in Java IMO.

This is how you do the wrapping of the request:

import java.lang.reflect.Proxy;
import java.lang.reflect.InvocationHandler;

public class RequestMethodCallLogger
  implements InvocationHandler, Filter
  public void doFilter(...) {
    HttpServletRequest wrappedRequest
     = Proxy.newProxyInstance(HttpServletRequest.class.getClassLoader(),
                              new Class[] { HttpServletRequest.class },

    chain.doFilter(wrappedRequest, response);

  public Object invoke(Object proxy, Method method, Object[] args)
    // Log to your favorite logger here

    return method.invoke(proxy, args);

Basically, the Proxy class allows you to intercept the calls to
interface methods. The implementation of the "invoke" method is just a
pass-through to the "real" method after logging (an exercise left for
the reader).

This can be optimized a bit if you need to use it long-term, but the
above is about as compact as it gets.

I'd still recommend the use of jad, honestly.

- -chris
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message