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):
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?
Following #23205 I found a similar issue.
If you declare a controller like this:
And make a request like this (httpie):
Then the result will be:
AbstractMessageConverterMethodProcessor#writeWithMessageConvertersmethod will throworg.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-typeapplication/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
Acceptheader was taken into account but it wasAccept: */*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/xmlis acceptable for a client, that requsted it withAccept: */*).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 producesapplication/xml, but at the same time it didn't register anyHttpMessageConverterthat can return this content type. How can this be a 4xx then?