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

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

Closed
spring-issuemaster opened this issue Apr 16, 2016 · 3 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Apr 16, 2016

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:

  • #17721 Spring should have default support for OPTIONS, HEAD and Allow
  • #22125 Regression: IllegalStateException: Ambiguous handler methods is thrown for explicit HEAD mapping

Referenced from: commits 1cb9f2c, 7cdcc10

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Apr 16, 2016

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.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Apr 17, 2016

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.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Apr 17, 2016

Rossen Stoyanchev commented

This should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.