Skip to content

Regression: Handler method detection reporting ambiguous methods for explicit HEAD mapping [SPR-14182] #18753

Closed

Description

@spring-projects-issues

Oliver Drotbohm opened SPR-14182 and commented

Let's start with the reproducing sample first.

$ git clone https://github.com/spring-projects/spring-data-examples
$ cd spring-data-examples/rest/starbucks
$ mvn spring-boot:run

$ curl -v -X HEAD http://localhost:8080/api/stores
> HEAD /api/stores HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
> 
< HTTP/1.1 500 Internal Server Error
< Server: Apache-Coyote/1.1
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Sat, 16 Apr 2016 12:37:59 GMT
< Connection: close

The server produces the following exception:

java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/stores': {public org.springframework.http.ResponseEntity org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException, public org.springframework.hateoas.Resources org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException}
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:361) ~[spring-webmvc-4.3.0.RC1.jar:4.3.0.RC1]
	at org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping.lookupHandlerMethod(BasePathAwareHandlerMapping.java:110) ~[spring-data-rest-webmvc-2.5.1.RELEASE.jar:na]
	at org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.lookupHandlerMethod(RepositoryRestHandlerMapping.java:91) ~[spring-data-rest-webmvc-2.5.1.RELEASE.jar:na]
        …

I was caught by surprise to see that as the two methods mentioned — RepositoryEntityController.headCollectionResource(…) and RepositoryEntityController. getCollectionResource(…) are considered ambiguous as they actually declare request mappings for different HTTP methods. getCollectionResource clearly maps to GET, not HEAD.

On Spring 4.2 this works as expected as you can see by downgrading the example to Spring Boot 1.4.0.M1 (by tweaking the version number of the Boot parent in the root project's POM).


Affects: 4.3 RC1

Attachments:

Issue Links:

Referenced from: commits 1cb9f2c, 7cdcc10

Activity

  1. spring-projects-issues commented on Apr 16, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Oliver Drotbohm commented

    Added a screenshot showing the detected mappings in the Eclipse debugger. Note that the HTTP method mapping is reported to be HEAD where it actually is declared as GET in code.

  2. spring-projects-issues commented on Apr 17, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Rossen Stoyanchev, this looks like a side effect of our default HEAD handling against GET methods. While we treat it right invocation-wise if a dedicated HEAD mapping exists, we seem to get confused in the mapping registration phase when the mappings just differ in GET vs HEAD.

  3. spring-projects-issues commented on Apr 17, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    This should be fixed now.

  4. added
    type: bug
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions