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

AnnotationMethodHandlerAdapter gives priority to media type order over quality when selecting a method [SPR-7000] #11665

Closed
spring-projects-issues opened this issue Mar 17, 2010 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 17, 2010

Mike Youngstrom opened SPR-7000 and commented

AnnotationMethodHandlerAdapter.RequestMappingInfoComparator doesn't appear to order the requested accept value by quality. Meaning that if I submit a request value like the following:

(Taken from Webkit's standard accept header)

application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

And I have a controller like the following:

@Controller
public class ExampleController {
    @RequestMapping(value="/secure/example", headers="accept=text/html", method=RequestMethod.GET)
    public String showHtml() {
        ...
    }

    @RequestMapping(value="/secure/example", headers="accept=image/png", method=RequestMethod.GET)
    public String showPng() {
        ...
    }
}

Then the showHtml method is selected because it is closest to the left where the showPng method should have been selected as it expresses a higher preferred quality level from the client (default quality=1).

This issue is related to #11663 but the order of the header media types should probably be taken into account AFTER the quality is taken into account.

This issue is also related to #11617 though since it appears #11617 won't make it into 3.0.x I think that this issue represents a more direct problem with a more straight forward solution that I believe should be included in to a 3.0.x release.

I think the order of media type method resolution should be the following:

  1. Quality
  2. Specificity
  3. Order of content types from left to right (Provide mechanism for injecting a Serializable Provider<T> or ObjectFactory<T> via XML [SPR-6998] #11663)

FYI, the patch for #11617 includes a MediaType comparator that will sort by quality before specificity if you want to use it.


Affects: 3.0.1

Issue Links:

Referenced from: commits 753a540

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Fixed. Thanks for spotting this and providing us with a patch!

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: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants