question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
xak2000commented, 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.

0reactions
rstoyanchevcommented, Jan 7, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot RequestMapping with non-standard produces ...
You need to provide Spring MVC with an HttpMessageConverter for your custom media type. To do so, I'd take advantage of Spring Boot ......
Read more >
17. Web MVC framework - Spring
The default handler is based on the @Controller and @RequestMapping annotations ... The produces condition is supported on the type and on the...
Read more >
spring-projects/spring-framework v5.2.3.RELEASE on GitHub
... AbstractMessageConverterMethodProcessor results in 406 with "Accept: /" when @RequestMapping produces condition determined the content type #23287 ...
Read more >
Spring MVC @RequestMapping Annotation Example with ...
@RequestMapping with Produces and Consumes: We can use header Content-Type and Accept to find out request contents and what is the mime ...
Read more >
Index (spring-webmvc 5.2.9.RELEASE API) - Javadoc.io
Abstract base class for Jackson based and content type independent AbstractView ... Compares this and another "produces" condition as follows: Sort 'Accept' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found