Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7557119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:02:46+00:00 2026-05-30T12:02:46+00:00

I’m trying to serve an image in my application as a java.awt.BufferedImage object. When

  • 0

I’m trying to serve an image in my application as a java.awt.BufferedImage object. When I attempt to perform a GET, here are the results:

  • Accept:image/jpeg renders a valid picture
  • Accept:*/* returns an HTTP 406

Here is the relevant part of my servlet-context.xml:

    <beans:bean id="messageAdapter"
    class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <beans:property name="order" value="1" />
    <beans:property name="messageConverters">
        <beans:array>
            <beans:bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
        </beans:array>
    </beans:property>

</beans:bean>

And here is my Controller:

    @RequestMapping(value = "photo/{photoId:[0-9]+}", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE)
    @ResponseBody
    public BufferedImage getPhoto(
        @PathVariable long photoId) {
        return photoService.getPhoto(photoId);
    }

MediaType.IMAGE_JPEG_VALUE is “image/jpeg”. It is my understanding that an accept header of */* would never generate a HTTP 406, which according to this page tells us that the caller doesn’t accept content of that type.

This is an issue because most browsers have “*/*” in their accept headers, and would not be able to view this image unless the user hard-coded the accept header.

Am I missing something here?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:02:47+00:00Added an answer on May 30, 2026 at 12:02 pm

    Message converters are picky about the Accept header, and they have to be since they are applied to all handlers annotated with @ResponseBody.

    A couple of ways you can get around this:

    Option 1: Extend the BufferedImageHttpMessageConverter to handle */* as well, NOTE: this can have unintended consequences if you add other message-converters later on as all of a sudden, handlers you want to produce JSON starts producing images instead.

    public class ExtendedBufferedImageHttpMessageConverter extends BufferedImageHttpMessageConverter {
    
        @Override
        public boolean canWrite(Class<?> clazz, MediaType mediaType) {
        if (mediaType.equals(MediaType.ALL)) {
            return super.canWrite(clazz, MediaType.IMAGE_JPEG);
        } else {
            return super.canWrite(clazz, mediaType);
        }
    }
    

    Then use this instead of the normal BufferedImageHttpMessageConverter in your spring config.

    Option 2: Create a filter or interceptor that is applied to your image requests and wrap the request in such a way the Accept header looks like image/jpeg instead of */*. This will “trick” spring into thinking that the client accepts jpeg and trigger the BufferedImageHttpMessageConverter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.