Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility of creating multiple custom @RequestConditions [SPR-9350] #13988

Closed
spring-projects-issues opened this issue Apr 26, 2012 · 5 comments
Closed
Assignees
Labels
in: core in: web type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Apr 26, 2012

Marek Sebera opened SPR-9350 and commented

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.


Affects: 3.1.1

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 27, 2012

Rossen Stoyanchev commented

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.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 3, 2012

Marek Sebera commented

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.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 3, 2012

Rossen Stoyanchev commented

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?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 15, 2012

Rossen Stoyanchev commented

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.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 31, 2012

Marek Sebera commented

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

@spring-projects-issues spring-projects-issues added type: enhancement in: core in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.2 M1 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core in: web type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants