Re: Detecting requested variant based upon file extension

2008-03-06 Thread Thierry Boileau
Hi Chuck,

These setters have been introduced in Restlet 1.1:
http://www.restlet.org/documentation/1.1/api/org/restlet/data/ClientInfo.html

Restlet  1.0 allows you to handle the set directly:
- request.getClientInfo.getAcceptedMediaTypes().add(...)
- request.getClientInfo.getAcceptedMediaTypes().clear()
- etc.

best regards,
Thierry Boileau


On Thu, Mar 6, 2008 at 7:47 PM, Chuck Mortimore
<[EMAIL PROTECTED]> wrote:
>
>  > I think you mean request.getClientInfo.setAcceptedMediaTypes(...) and
>  > request.getClientInfo.setAcceptedLanguages(...) .
>  >
>  > Let me now, if you are ready; I need this filter also.
>
>
>  I don't actually see that setter in the API.   Any other advise?
>
>  http://www.restlet.org/documentation/1.0/api/org/
>  restlet/data/ClientInfo.html
>
>


Re: Detecting requested variant based upon file extension

2008-03-06 Thread Chuck Mortimore

> I think you mean request.getClientInfo.setAcceptedMediaTypes(...) and 
> request.getClientInfo.setAcceptedLanguages(...) .
> 
> Let me now, if you are ready; I need this filter also.


I don't actually see that setter in the API.   Any other advise?

http://www.restlet.org/documentation/1.0/api/org/
restlet/data/ClientInfo.html



Re: Detecting requested variant based upon file extension

2008-03-06 Thread Thierry Boileau
Hi Chuck,

I send you a sample code where a resource generates a representation
according to the file extension.
It doesn't rely on a Filter, but seems to work.
the code illustrate 2 cases, the first one where the Resource knows
the mappings between extensions and metadata, the second one where the
resource relies on the parent application metadataService:

**
// Case 1 - without the Application metadata service
if ("js".equals(ext)) {
getVariants().add(new Variant(MediaType.APPLICATION_JSON));
} else if ("xml".equals(ext)) {
getVariants().add(new Variant(MediaType.APPLICATION_ATOM_XML));
} else {
// What you want, even let the Variants set empty (will return 404
// response)
getVariants().add(new Variant(MediaType.TEXT_PLAIN));
}

// Case 2 - uses the Application metadata service
Application application = (Application) context.getAttributes().get(
Application.KEY);
Metadata metadata = application.getMetadataService().getMetadata(ext);
if (metadata != null && metadata instanceof MediaType) {
getVariants().add(new Variant((MediaType) metadata));
} else {
// What you want, even let the Variants set empty (will return 404
// response)
getVariants().add(new Variant(MediaType.TEXT_PLAIN));
}

**
I hope this will help you.

Best regards,
Thierry Boileau


On Thu, Mar 6, 2008 at 9:48 AM, Stephan Koops <[EMAIL PROTECTED]> wrote:
> Hello Chuck,
>
> > Thanks - I'll crank out a filter.
>  >
>  > One quick question...it's clear to me how I'd get the extension, and how to
>  > lookup the metadata, but it's not clear how to propagate that to the 
> resource.
>  >  How do I properly set the variant.
>  I think you mean request.getClientInfo.setAcceptedMediaTypes(...) and
>  request.getClientInfo.setAcceptedLanguages(...) .
>
>  Let me now, if you are ready; I need this filter also.
>
>   best regards
>Stephan
>


testExtension.jar
Description: application/java


Re: Detecting requested variant based upon file extension

2008-03-06 Thread Stephan Koops

Hello Chuck,

Thanks - I'll crank out a filter.

One quick question...it's clear to me how I'd get the extension, and how to
lookup the metadata, but it's not clear how to propagate that to the resource. 
 How do I properly set the variant.
I think you mean request.getClientInfo.setAcceptedMediaTypes(...) and 
request.getClientInfo.setAcceptedLanguages(...) .


Let me now, if you are ready; I need this filter also.

best regards
  Stephan


Re: Detecting requested variant based upon file extension

2008-03-06 Thread Thierry Boileau
Hello Chuck,

if you are serving static files, you should use the Directory Restlet
and customize the MetadataService service of your application.
Let me complete the answer later if you intend to serve your file dynamically.

best regards,
Thierry Boileau


On Thu, Mar 6, 2008 at 2:53 AM, Chuck Mortimore
<[EMAIL PROTECTED]> wrote:
> Stephan Koops  web.de> writes:
>
>  >
>  > Hello Chuck,
>  >
>  > there is a start for a solution for included in Restlet: the Metadata
>  > Service. It is for now only used by the
>  > com.noelios.restlet.application.TunnelFilter. But you can create a
>  > filter that does this, and use the MetadataService. It includes a lot of
>  > file extensions.
>  >
>  > I think, other people are happy, if they can use this filter also. I
>  > think it is good if you open an enhancement issue for this and add your
>  > Filter class file as attachment, so that Jerome or Thierry could include
>  > this in the official version. (Jerome, I hope it's ok that I wrote this
>  >  )
>  >
>  > BTW: ".js" is the typical file extension for javascript. Use ".json"
>  >
>  > best regards
>  >Stephan
>  >
>  Thanks - I'll crank out a filter.
>
>  One quick question...it's clear to me how I'd get the extension, and how to
>  lookup the metadata, but it's not clear how to propagate that to the 
> resource.
>   How do I properly set the variant?
>
>  - cmort
>
>
>
>


Re: Detecting requested variant based upon file extension

2008-03-05 Thread Chuck Mortimore
Stephan Koops  web.de> writes:

> 
> Hello Chuck,
> 
> there is a start for a solution for included in Restlet: the Metadata 
> Service. It is for now only used by the 
> com.noelios.restlet.application.TunnelFilter. But you can create a 
> filter that does this, and use the MetadataService. It includes a lot of 
> file extensions.
> 
> I think, other people are happy, if they can use this filter also. I 
> think it is good if you open an enhancement issue for this and add your 
> Filter class file as attachment, so that Jerome or Thierry could include 
> this in the official version. (Jerome, I hope it's ok that I wrote this 
>  )
> 
> BTW: ".js" is the typical file extension for javascript. Use ".json"
> 
> best regards
>Stephan
> 
Thanks - I'll crank out a filter.

One quick question...it's clear to me how I'd get the extension, and how to
lookup the metadata, but it's not clear how to propagate that to the resource. 
 How do I properly set the variant?

- cmort





Re: Detecting requested variant based upon file extension

2008-03-05 Thread Stephan Koops

Hello Chuck,

there is a start for a solution for included in Restlet: the Metadata 
Service. It is for now only used by the 
com.noelios.restlet.application.TunnelFilter. But you can create a 
filter that does this, and use the MetadataService. It includes a lot of 
file extensions.


I think, other people are happy, if they can use this filter also. I 
think it is good if you open an enhancement issue for this and add your 
Filter class file as attachment, so that Jerome or Thierry could include 
this in the official version. (Jerome, I hope it's ok that I wrote this 
:-) )


BTW: ".js" is the typical file extension for javascript. Use ".json"

best regards
  Stephan

Chuck Mortimore schrieb:

I'm trying to serve different representations based upon the file extension
provided in the URI.   


For instance, if I get

http://server/user/cmort.js

I want to return this variant: MediaType.APPLICATION_JSON

but if I get http://server/user/cmort.rss

I want to return this variant: MediaType.APPLICATION_ATOM_XML

Anyone have advise on how I effect the variant passed into my resource to meet
this use case?

thanks!