Hi Avi,

Sorry for the delay. We'll look at this issue tomorrow, this doesn't look right 
indeed. 

Best regards,
Jerome
--
http://www.restlet.org
http://twitter.com/#!/jlouvel


-----Message d'origine-----
De : Avi Flax [mailto:a...@arc90.com] 
Envoyé : mardi 14 février 2012 20:17
À : discuss@restlet.tigris.org
Objet : Re: Using MetadataService to specify the default media type

Ping?

On Wed, Feb 1, 2012 at 12:05, Avi Flax <a...@arc90.com> wrote:
> 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, 
> xhtml is chosen as the default.
>
> Unsurprisingly, the same is true if I use two separate methods:
>
> @Get(“html”)
> public Representation getHtml() { … }
>
> @Get(“xhtml”)
> public Representation getXhtml() { … }
>
> IIRC, in Restlet 1 this was fully supported — the first variant passed 
> to getVariants().add() was considered the default. I still need this 
> functionality.
>
> I don’t know if it’s too late to change this for 2.0 (I’d love to 
> submit a patch…) but I’d at least like to see this improved for 2.1 — 
> I think the order specified in the annotation parameter should be 
> significant, with the first one specified used as the default.
>
> For now, I’m not even sure how I’m going to make this work in the 
> resource I’m working on today — I might just do something hacky like
> this:
>
> if (acceptHeader != null &&
> acceptHeader.contains("application/xhtml+xml") && !
> acceptHeader.contains("text/html"))
>    representation.setMediaType(MediaType.APPLICATION_XHTML);
>
> Thanks,
> Avi

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2922447

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2925111

Reply via email to