Hi Simon,

Resource#getPreferredVariant() is exactly what you what to use. It will
indicate you the best variant for the current request. Then you can look at
the variant's media type to build your redirect URI.

Of course, you first need to declare the list of all available variants (you
need to know them in order to negotiate anything).

Best regards,
Jérôme Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com
 

-----Message d'origine-----
De : Simon Reinhardt [mailto:[EMAIL PROTECTED] 
Envoyé : mardi 12 août 2008 16:48
À : [email protected]
Objet : Content negotiation with redirect

Hi,

I want to implement a Restlet that basically does the same as content
negotiation just instead of returning the appropriate representation, it
should redirect the client (using 303) to the URI of the specific resource
which fulfils the clients preferences. The reason is that the specific
resources are on different (unrelated) domains and I don't want to republish
the other domain's data but instead tell the client where it is. Using
conneg would also mean that the representations have certain properties in
common with the generic resource (the one I'm doing the conneg from) but I
don't want this relatedness, it would lead to copyright problems and
whatnot.

Anyway, I'm having difficulties implementing that. My idea so far is that I
have a Restlet for the generic resource which, in the handle method,
inspects the different accept values available in the ClientInfo object
(Restlet.getClientInfo()), decides which resource is most appropriate, gets
the URI for that resource and then calls response.redirectSeeOther(uri);
Then I would attach the Restlet for the generic resource as well as the
specific Resource classes to a router and would be done.

The problem is the deciding bit. I don't want to re-implement all the conneg
logic. Is there a way to use what's there already? I'd rather use a Resource
class than a raw Restlet. And if not, where would I find the code for how
the conneg logic is implemented at the moment?
Resource.getPreferredVariant()? Maybe I can copy the needed bits from there
before starting from scratch. :-)

Thanks,
  Simon

Reply via email to