dev@jersey.java.net

Re: [Jersey] HttpContext does not return the MediaType

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Tue, 7 Sep 2010 17:50:18 +0200

On Sep 7, 2010, at 5:06 PM, exxos wrote:

> Hi Paul,
>
> About the HTTP codes above 399 (errors), this is more a question of
> assisstance offered to clients. For example, even if for the error
> 406 it is not useful, for others it could be interesting:
>
> <error>
> <reference>FG123</reference>
> <message>Internal issue recorded, please keep the reference for
> further assistance with our help desk</message>
> </error>
>
> and for the HTML version: Viewable("/error.jsp", error);
>
> <html>
> <header><title>Error 500</title></header>
> <body>
> Error reference FG123.
> Internal issue recorded, please keep the reference for further
> assistance with our help desk.
> </body>
> </html>
>

Agreed.


> Regarding MessageBodyWriter, it could be hard to go with it for
> "composition of resources" and where the same wrapper is reused for
> each of them:
>
> <wrapper><EntityA/><EntityB/><wrapper>
> Viewable("/template1.jsp", wrapper);
>
> <wrapper><entityC/><entityD/></wrapper>
> Viewable("/template2.jsp", wrapper);
>
> In order to resume and to have the ideas clear, the following can be
> consider as "the" correct approaches:
>
> 1- httpContext.getRequest().getAcceptableMediaTypes().get(0)

The acceptable media types are also available from HttpHeaders, so you
don't have to use the Jersey specific interface.


> 2- Variant v = request.selectVariant(vs);
>
> Could you please confirm?


Either could be sufficient, it depends on how flexible you want to be.

For example you may decide that if text/html is acceptable and not
necessarily the most acceptable to use that, otherwise f HTML is not
accepted perform a second check for XML and JSON, and if neither of
those are acceptable default to XML. Using variants can make it easier
to this type of thing rather the processing the media types directly
from list returned from HttpHeaders. getAcceptableMediaTypes().


>
> Once again, thank you for your support and your time.

Np,
Paul.