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

AbstractMessageConverterMethodProcessor results in 406 with "Accept: */*" when @RequestMapping produces condition determined the content type #23287

Closed
xak2000 opened this issue Jul 13, 2019 · 6 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@xak2000
Copy link
Contributor

xak2000 commented Jul 13, 2019

Following #23205 I found a similar issue.

If you declare a controller like this:

@GetMapping(path = "/xml", produces = "application/xml")
public Map<String, Object> producesContentTypeThatIsNotSupportedByAnyConverter() {
	return ImmutableMap.of("foo", "bar");
}

And make a request like this (httpie):

http -v :9080/xml

Then the result will be:

GET /xml HTTP/1.1
Accept: */*
...



HTTP/1.1 406
...

AbstractMessageConverterMethodProcessor#writeWithMessageConverters method will throw org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation.

This is very similar case to a case with ResponseEntity - the server is responsible for selecting content-type application/xml (if it is acceptable by a client, and in this case - it is) and no converters found that can write the result using this content-type.

The Accept header was taken into account but it was Accept: */* so it is obviously not "Could not find acceptable representation" case, but more like a "Cound not find http message converter for totally acceptable representation" (application/xml is acceptable for a client, that requsted it with Accept: */*).

So it is strange to receive a 406 result for a request with Accept: */* header. The real problem in this case is a server misconfiguration: the server declares that it produces application/xml, but at the same time it didn't register any HttpMessageConverter that can return this content type. How can this be a 4xx then?

@xak2000 xak2000 changed the title AbstractMessageConverterMethodProcessor results in 406 when @RequestMapping presets content type AbstractMessageConverterMethodProcessor results in 406 when @RequestMapping presets content type that acceptable for a client Jul 13, 2019
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 13, 2019
@xak2000 xak2000 changed the title AbstractMessageConverterMethodProcessor results in 406 when @RequestMapping presets content type that acceptable for a client AbstractMessageConverterMethodProcessor results in 406 when @RequestMapping selects content type that acceptable for a client Jul 13, 2019
@membersound
Copy link

membersound commented Aug 6, 2019

This is a serious problem in reporting error the client users!
Could you check if you have any ContentNegotiationConfigurer active, and in case post the configuration?

@xak2000
Copy link
Contributor Author

xak2000 commented Aug 6, 2019

This is an empty spring-boot application with one dependency on org.springframework.boot:spring-boot-starter-web and no other custom beans except one controller with one method.

I not remember exact spring-boot version, but it is between 2.1.3 and 2.1.6 I think.
Spring 5.1.8.RELEASE.

@rstoyanchev
Copy link
Contributor

@xak2000 your point here is that just like in #23205 this should similarly result in a 500 error because the server choice the media type (client takes any) and failed to write it?

@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Dec 20, 2019
@rstoyanchev rstoyanchev self-assigned this Dec 20, 2019
@rstoyanchev rstoyanchev added this to the 5.2.3 milestone Dec 20, 2019
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Dec 20, 2019
@rstoyanchev
Copy link
Contributor

Tentatively scheduled for 5.2.3.

@rstoyanchev rstoyanchev removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 20, 2019
@xak2000
Copy link
Contributor Author

xak2000 commented Dec 20, 2019

@xak2000 your point here is that just like in #23205 this should similarly result in a 500 error because the server choice the media type (client takes any) and failed to write it?

Yes, that is my point. 406 should be returned only when server is unable to select the type requested by a client. But in the mentioned case the server can select it. It just unable to write the response because of server misconfiguration.

@rstoyanchev rstoyanchev changed the title AbstractMessageConverterMethodProcessor results in 406 when @RequestMapping selects content type that acceptable for a client AbstractMessageConverterMethodProcessor results in 406 with "Accept: */*" when @RequestMapping produces condition determined the content type Jan 7, 2020
@rstoyanchev
Copy link
Contributor

Re-opening, closed in error due to incorrect issue reference from above commit.

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