Announcement Announcement Module
No announcement yet.
Request Path mapped to multiple controllers Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Request Path mapped to multiple controllers

    Hi everyone!
    I'm currently working on a spring based web application and have a special requirement that seems not (at least not out of the box) be provided by spring MVC. The application serves data for multiple users each organized in their own "company". Once a user has logged in, I'm able to identify to which company he belongs to.
    The application itself is built with multiple "modules", each with it's own domain objects, DAO, Service and Controller classes. The idea behind this concept is that I can for example extend a certain controller class (let's say to use a different service class) based upon the user and here is my problem.
    Since i do not want to change my request paths for certain users, I'm currently looking for a way how to serve a request issued on a certain request path with different instances of a controller based upon the user issuing the request.
    I came up with the idea to attach a HTTP Header Field for the company


    and have my controllers configured like this:

    public class FooController { 
     // ...
    @RequestMapping(value="/foo" headers="X-Company=12345")
    public class SpecialFooController extends FooController {
     // ...
    However this is not possible, since spring MVC treats each header (except Content-Type and Accept) as a kind of restriction, so in my case it would handle all requests with the FooController instead of the SpecialFooController unless i add a "headers" restriction on the FooController as well, which is not practicable.
    Is there some way how to customize this behaviour or some direction one could point me to look for? Or maybe someone has another idea how to achieve this. It'll be highly appreciated.

  • #2
    I was able to solve this issue using a customized RequestCondition and a customized RequestMappingHandlerMapping.
    Detailed description to this topic can be found here.