Spring Framework
  1. Spring Framework
  2. SPR-9350

Possibility of creating multiple custom @RequestConditions

    Details

    • Last commented by a User:
      true

      Description

      Inspired on this link: https://github.com/rstoyanchev/spring-mvc-31-demo
      I made my custom implementation of @RequestCondition can be seen on this link: http://stackoverflow.com/a/10336769/492624

      As of now, we have to use subclass of RequestMappingHandlerMapping.
      Used `@Override` functions are getCustomTypeCondition, getCustomMethodCondition.

      But both of these are designed to handle only single RequestCondition

          @Override
          protected RequestCondition<?> getCustomMethodCondition(Method method) { ... }
      
          @Override
          protected RequestCondition<?> getCustomTypeCondition(Class<?> handlerType) { ... }
      

      This should be changed so, that it can map multiple @RequestCondition classes.

        Activity

        Hide
        Rossen Stoyanchev added a comment - - edited

        You can only return one condition indeed. However, the condition can delegate to others. See for example how org.springframework.web.servlet.mvc.method.RequestMappingInfo combines all conditions from @RequestMapping plus the custom condition. I am leaving this ticket open though since we could provide a CompositeRequestCondition implementation to make it easier.

        Show
        Rossen Stoyanchev added a comment - - edited You can only return one condition indeed. However, the condition can delegate to others. See for example how org.springframework.web.servlet.mvc.method.RequestMappingInfo combines all conditions from @RequestMapping plus the custom condition. I am leaving this ticket open though since we could provide a CompositeRequestCondition implementation to make it easier.
        Hide
        Marek Sebera added a comment - - edited

        That's little bit unfortunate.
        I'd like to (for example) combine mine SubdomainMapping and yours RoleMapping to two different rules, as it is quite clear.

        such annotation would need two annotation elements

        @RoleMapping(args1)
        @SubdomainMapping(args2)
        public function handlingFunction(...){
            ...
        }
        

        But we cannot provide this so far. Instead we're forced to combine them to simple annotation rule, such as

        @SubdomainRoleMapping(args1,args2)
        

        And that seems to me as not very extensible solution.

        Show
        Marek Sebera added a comment - - edited That's little bit unfortunate. I'd like to (for example) combine mine SubdomainMapping and yours RoleMapping to two different rules, as it is quite clear. such annotation would need two annotation elements @RoleMapping(args1) @SubdomainMapping(args2) public function handlingFunction(...){ ... } But we cannot provide this so far. Instead we're forced to combine them to simple annotation rule, such as @SubdomainRoleMapping(args1,args2) And that seems to me as not very extensible solution.
        Hide
        Rossen Stoyanchev added a comment -

        I'd like to (for example) combine mine SubdomainMapping and yours RoleMapping to two different rules, as it is quite clear such annotation would need two annotation elements

        The number of annotations is not relevant. You can have one annotation with two RequestCondition implementations wrapped in a CompositeRequestCondition. Maybe I should have made it more clear that by CompositeRequestCondition I mean a RequestCondition that delegates to any number of other RequestCondition implementations.

        A CompositeRequestCondition is trivial to create yourself. Just look at RequestMappingInfo, it's a RequestCondition that's implemented by delegating to 6-7 other RequestCondition types. Hopefully that makes more sense?

        Show
        Rossen Stoyanchev added a comment - I'd like to (for example) combine mine SubdomainMapping and yours RoleMapping to two different rules, as it is quite clear such annotation would need two annotation elements The number of annotations is not relevant. You can have one annotation with two RequestCondition implementations wrapped in a CompositeRequestCondition. Maybe I should have made it more clear that by CompositeRequestCondition I mean a RequestCondition that delegates to any number of other RequestCondition implementations. A CompositeRequestCondition is trivial to create yourself. Just look at RequestMappingInfo, it's a RequestCondition that's implemented by delegating to 6-7 other RequestCondition types. Hopefully that makes more sense?
        Hide
        Rossen Stoyanchev added a comment - - edited

        I've added a CompositeRequestCondition to the master branch to make it available for Spring 3.2. Since it is one class only, you could copy and use it in your source code until the 3.2 release becomes available.

        Show
        Rossen Stoyanchev added a comment - - edited I've added a CompositeRequestCondition to the master branch to make it available for Spring 3.2. Since it is one class only, you could copy and use it in your source code until the 3.2 release becomes available.
        Hide
        Marek Sebera added a comment -

        Thanks @Rossen, now it is clear, and far more usable.

        Show
        Marek Sebera added a comment - Thanks @Rossen, now it is clear, and far more usable.

          People

          • Assignee:
            Rossen Stoyanchev
            Reporter:
            Marek Sebera
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              1 year, 47 weeks ago