Is it possible for us to handle http media types dynamically or handle multiple media types using “ByteArrayHttpMessageConverter”?
My requirement is such that i won’t get to know the exact media type until i retrieve the document from server! so either i should try to handle it dynamically or i should go for including all the possible media types to be handled 🙁
Could you please suggest me some ideas?
here is the link to the spring forum where i have posted it long back without any response.
http://forum.springsource.org/showthread.php?124301-Handling-multiple-media-types
Thanks in Advance!
Paary
Changing media types dynamically is not natural for message convertors as (strictly speaking) each message convertor is bound to some specific media type. If several message convertors would blindly support same media types, Spring MVC will not be able to choose the right one based on
Accept-typeclient header.You need to write your specific message convertor which could extend
ByteArrayHttpMessageConverter. You need to override theAbstractHttpMessageConverter#getDefaultContentType(T t)method, which is passed the object to be written, and thus you can dynamically define the returnedContent-type.