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

BufferedImageHttpMessageConverter cannot convert to a media type it claims it can [SPR-15037] #19603

Open
spring-projects-issues opened this issue Dec 21, 2016 · 1 comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Dec 21, 2016

Dave Syer opened SPR-15037 and commented

The samples in spring-secuirty-oauth2 suffer from this problem. I think it is probably platform/browser dependent because I couldn't reproduce it till today, and now I can (Ubuntu 14.04, Chrome 50.0.2661.86). The browser sends

[text/html, application/xhtml+xml, image/webp, application/xml;q=0.9, */*;q=0.8]

and the app sends back a response entity with Content-Type: image/jpeg. The converter comes in and claims that it can convert to

[image/vnd.wap.wbmp, image/png, image/x-png, image/jpeg, image/bmp, image/gif]

And then fails to do the conversion to the highest priority media type:

Dec 21, 2016 8:35:20 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/tonr2] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: Only integral single-band bilevel image is supported.] with root cause
java.lang.IllegalArgumentException: Only integral single-band bilevel image is supported.
	at com.sun.imageio.plugins.wbmp.WBMPImageWriter.checkSampleModel(WBMPImageWriter.java:313)
	at com.sun.imageio.plugins.wbmp.WBMPImageWriter.write(WBMPImageWriter.java:171)
	at org.springframework.http.converter.BufferedImageHttpMessageConverter.write(BufferedImageHttpMessageConverter.java:225)
	at org.springframework.http.converter.BufferedImageHttpMessageConverter.write(BufferedImageHttpMessageConverter.java:67)
...

The sample is old and still uses Spring 4.0.9, but I tried with 4.3.4 (just add <spring.version>4.3.4.RELEASE</spring.version> to the properties in the tonr2 pom.xml) and the problem is the same.


Affects: 4.3.4

Reference URL: spring-attic/spring-security-oauth#427

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jan 3, 2017

Rossen Stoyanchev commented

This looks like another variation of #18985 where an image needs to be rendered but we are not considering the actual image type. The main difference is that in #18985 the return value is a Resource. The root cause however is the same which is that content negotiation uses a generic list of producible media types (i.e. HttpMessageConverter#getSupportedMediaTypes) which is based on the return value type and does not consider the actual value instance.

We need some fix. Clearly rendering a JPEG as WBMP when the browser says it will accept anything isn't quite right and can cause failures.

As a workaround in the case of the Spring Security OAuth2 example the request mapping can explicitly influence the producible media type with @RequestMapping(producible="image/jpeg". That's not always the case though such as is the case of #18985 where the image to be rendered is not known ahead of time.

@spring-projects-issues spring-projects-issues added the type: enhancement A general enhancement label Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.x Backlog milestone Jan 11, 2019
@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jul 26, 2021
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

2 participants