On Aug 7, 2010, at 9:03 PM, Christian Helmbold wrote:
> Hi Paul,
>
> thanks for your answer.
>
> I agree that it would be easier to follow the usual JAX-RS content
> negotiation
> model with @Produces on resource methods. Furthermore I decided to
> restrict each
> MessageBodyWriter to a single content type, what makes conneg
> straight forward
> and simple.
>
> But there are new questions:
>
> * If a template cannot be found in my MessageBodyWriter I throw a
> WebApplicationException(406), but it would be possible that there is
> another
> (second best) matching representation which would be ignored then.
>
> - Is it possible to resume the lookup for a matching
> MessageBodyWriter?
Yes, you can inject Providers:
https://jsr311.dev.java.net/nonav/releases/1.1/javax/ws/rs/ext/Providers.html
and look up another MBW.
> - Is it possible to tell the client what other representations he
> could get?
> see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.7
>
Yes, but it is application specific. You have to supply your own entity.
You can inject MessageBodyWorks to get more information of MBWs:
https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/spi/MessageBodyWorkers.html
#getMessageBodyWriterMediaTypes%28java.lang.Class,
%20java.lang.reflect.Type,%20java.lang.annotation.Annotation[]%29
If you have WADL enabled, you can get information from the WADL
returned by the OPTIONS method.
> * How can I set the "charset"? I tried @Produces("text/html;
> charset=UTF-8") but
> that was ignored. Then I tried to add another ContentType header in
> the writeTo
> method of the MessageBodyWriter, but then I got only the charset
> without the
> content type (I'd like to use the ContentType from @Produces
> automatically).
>
See my reply to your other email.
Paul.