tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Barker" <billwbar...@verizon.net>
Subject Re: a servlet-related Java question
Date Thu, 22 Apr 2010 06:37:24 GMT


"Christopher Schultz" <chris@christopherschultz.net> wrote in message 
news:4BCF5F41.6060801@christopherschultz.net...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> André,
>
> 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 },
>                              this);
>
>    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.
>

If it 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.

> I'd still recommend the use of jad, honestly.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkvPX0EACgkQ9CaO5/Lv0PCKVQCdG5SMXiySnsFEowVF7/44KM8s
> b7kAoIAGSzxOIWmKt4+z6ATkqslTl5uW
> =ykwF
> -----END PGP SIGNATURE-----  



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


Mime
View raw message