users@jersey.java.net

MessageBodyWriter for multiple media types

From: Christian Helmbold <christian.helmbold_at_yahoo.de>
Date: Wed, 4 Aug 2010 20:33:21 +0000 (GMT)

I want to write a MessageBodyWriter to render Viewable instances with FreeMarker templates. Usually the media type would be html, but FreeMarker templates could be used to render almost any media type. My idea is to use file extensions to specify what media type will be rendered by a template, for example "template.html", "template.txt" and so on. In principle this could be done with a single MessageBodyWriter that processes the templates. But ... * Is it possible that a MessageBodyWriter contains multiple media types in the @Produces annotation? * Since it would be a configuration of the actual environment, the @Produces annotation couldn't be placed on a general MessageBodyWriter class. Do I have to subclass my FreeMarker MessageBodyWriter for each concrete configuration only to add a @Produces annotation? Is there another way to tell what media types could be produced? * Would it be appropriate to throw a WebApplicationException(406) (Not Acceptable) if the FreeMarkerMessageBodyWriter tries to render an entity but there is no matching template? The FreeMarkerMessageBodyWriter could for example say that it is able to produce "text/plain", but then there is no template for the given entity. Would it be possible to resume the lookup for an appropriate MessageBodyWriter then? Regards Christian -- http://scala-forum.org/