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

HandlerInterceptorAdapter should honor ordering #22434

Closed
fededonna opened this issue Feb 19, 2019 · 10 comments
Closed

HandlerInterceptorAdapter should honor ordering #22434

fededonna opened this issue Feb 19, 2019 · 10 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@fededonna
Copy link
Contributor

Affects: <Spring Framework version>


Hi, I've found that this feature was introduced in in Spring 5.x. Would it be possible to backport this to Spring 4.x and also to Spring boot 1.5.x?

this is the fix that needs to be backported.

782c595

Thanks.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 19, 2019
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Mar 6, 2019

It wasn't a fix really, but more of a clean-up. Can you explain the problem you're having?

@fededonna
Copy link
Contributor Author

fededonna commented Mar 6, 2019

It’s a feature to be honest. The problem is that I’m importing a starter that we have and I need to put an interceptor in the middle of those and since interceptors don’t honor @Order in SB 1.x I can’t do this without doing nasty things.

@rstoyanchev
Copy link
Contributor

I think you're referring to #20179 which is a change in the Spring Framework. To my knowledge there isn't anything specific in Boot on top of that.

If we did backport that how would it help your case? Wouldn't the interceptors in the imported starter have to make use of the (new) order property so you can insert in the middle?

@fededonna
Copy link
Contributor Author

They are all using ordered but since I checked the class I mention in this case the class is only using an array list and inserting in the order they came. This will really help my case if you make it honor ordered. Thanks in advance.

@fededonna
Copy link
Contributor Author

I also think that making it respect the order interface as you are doing in all the other places is a more clear solution that to hack it calling a method that receives the order provided by the method implemented in the class that implements the interface. Just my two cents here.

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Mar 7, 2019

The ac68cc3 change sorts HandlerInterceptorRegistration instances based on the order property, and that property was added as part of the change, it did not exist before. What do you mean "they are all using ordered"? Or am I missing what you're referring to?

@fededonna
Copy link
Contributor Author

fededonna commented Mar 7, 2019

Ok, let me explain a little bit. I'm using spring boot 1.5.15 which depends on spring-webmvc 4.3.18

When I register my Handler interceptor in the class:

InterceptorRegistry

I see this code that is not honoring @order which all of my HandlerInterceptorAdapters are implementing

/**
* Return all registered interceptors.
*/
protected List<Object> getInterceptors() {
    List<Object> interceptors = new ArrayList<Object>(this.registrations.size());
    for (InterceptorRegistration registration : this.registrations) {
        interceptors.add(registration.getInterceptor());
    }
        return interceptors ;
}  

I'm facing the problem that, despite of having the correct order in my config, another HandlerInterceptor is being called before the one that is supposed to be called. Does this explanation makes more sense?

To give a little more context, if you check the latest version of the registry it does honor @ordered

https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistry.java#L70

Would it be possible to backport this to the latest version of 4.x that is or will be included in the latest version of the spring boot starter 1.x that includes mvc?

Thanks for your time.

@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Mar 7, 2019
@rstoyanchev
Copy link
Contributor

Okay thanks.

BTW the reason for InterceptorRegistration to not implement Ordered is because it's part of the public config API where we aim to show options to change only. Accessors are protected for internal use. This is consistent with the rest of the Java MVC config.

@rstoyanchev rstoyanchev added this to the 4.3.23 milestone Mar 9, 2019
@rstoyanchev rstoyanchev added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 9, 2019
@fededonna
Copy link
Contributor Author

It makes sense but it won’t hurt having extra options. Do you think that this change is going to be part of 4.x or you won’t port this back?
Thanks.

@spring-projects-issues
Copy link
Collaborator

Fixed via dba9c90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants