I want to create a filter that would log the time spent for particular web request along with the operation name. However, some URLs have path parameters and I'm looking for something that would allow me to get a URL pattern that corresponds to the particular method instead of URL itself.
For example, for method that handles GET requests for URLs like /users/{id}/accounts/{type}
I want to see operation name like GET /users/{}/accounts/{}
instead of, say: GET /users/1/accounts/facebook
or GET /users/2/accounts/twitter?someParam=3
.
Right now I solve this by matching URL with predefined patterns in the tool that parses log records but to me it looks like a hack.
I didn’t find an easy way to access URL pattern associated with a method that handles incoming request, so one possible solution that I’m considering right now is setting a thread local variable in the controller method itself and access it in my HTTP filter but this also doesn’t seem like a clean way to solve this.
Is there any better solution to this problem?
To set up some context: I'm using Spring MVC 4.