The problem I am trying to solve is that I want to check all incoming GET urls against a database. If the the url exist in the database it shall be passed to a certein controller. I'm using Spring 3.0.
First I tried to make an interceptor and add that to DefaultAnnotationsHandlerMapping. Turns out i couldn't modify the url in preHandle(). The plan was to modify the url in the request and then let an annotated controller handle the rest.
Next I tried to make a custom HandleMapping. I extended AbstractUrlHandlerMapping and made my own getHandlerInternal() that returns a String with the name of the Controller and this is working. But I'd prefer a solution where I can modify the url in the request and let an annotated controller handle it.
While writing this I got thinking that maybe a servlet filter is the most proper solution. If that's the case can I get Spring to inject an EntityManager into the filter? Any Spring class I can extend that makes this easier?
What's the most proper way to solve the problem in the first paragraph? If it's the servlet filter please give me some pointers on how to write it.