I wanted to log the time it took to complete requests sent to our HTTP API. This particular API uses JBoss’ RESTEasy framework for REST-like request dispatching. I wanted to intercept the request prior to it being executed:
Alas, RESTEasy does not seem to provide the ability to insert your own code in the routing/dispatching process. However, it does have the ability to create pre and post filter classes (called Interceptors) that are executed before and after a request. The mechanism works as follows:
I ended up using the following hack to time my API requests:
I set a StopWatch on the request and start it inside the pre-filter. During post-filtering, I inject the request into the filter, grab the timer, stop it and log the duration. It’s totally hacky, but at least I don’t have to add timing code into the our RESTEasy classes and I don’t have to introduce an AOP framework into the codebase. Definitely not my favorite implementation, but it’ll do for now.
-B-