Re: Using MetadataService to specify the default media type
Avi Flax <avif <at> arc90.com>
2012-02-01 17:05:19 GMT
On Thu, Jan 19, 2012 at 05:20, Jerome Louvel <jerome.louvel <at> noelios.com> wrote:
> The proper/standard way in HTTP to do this is to correctly set the
> preferences of your clients (via the “Accept” header typically)… Otherwise,
> the order of the annotated methods declaration might be taken into account
> by Restlet when deciding how to dispatch the method call, but I wouldn’t say
> it is a safe bet to solely rely on this default behavior.
>
> You could customize the ConnegService attached to your parent application to
> force the variant when client preferences are not explicitly given
> (MediaType.ALL), or plug a custom filter in the routing chain to enforce
> your policy.
Jerome,
I’m using 2.0, and I need a way to set the default variant of my
resources. I’m frustrated because I’d think this’d be a common need
and it really should be easier and clearer how to do this. I need to
support requests which don’t include an Accept header, and I need to
be able to set the default variant concisely on a resource-by-resource
basis — not in a centralized Service or Filter.
With the resource I’m working on now, I first tried to just use a
single annotation:
@Get(“html|xhtml”)
public Representation getRep(Variant variant) { … }
I assumed that when a request didn’t include an Accept header, the
conneg algorithm would take into account the order specified and use
html as the default. Unfortunately it does not — for some reason,
(Continue reading)