Thanks Jonathan..


1.       Here's what I did to support lets say ".js" as an extension to
indicate JSON as the content type


public class FirstStepsApplication extends Application {


    * Creates a root Restlet that will receive all incoming calls.



   public Restlet createRoot() {

         // Create a router Restlet that routes each call to a

         // new instance of HelloWorldResource.

         Router router = new Router(getContext());

         // Defines only one route




         this.getMetadataService().addExtension("js", new
MediaType.APPLICATION_JSON.getDescription()), true );

         return router;




public class HelloWorldResource extends Resource {

      public HelloWorldResource(Context context, Request request, Response
response) {

            super(context, request, response);

            // This representation has only one type of representation.

            getVariants().add(new Variant(MediaType.TEXT_PLAIN));

            getVariants().add(new Variant(MediaType.APPLICATION_JSON));





       * Returns a full representation for a given variant.



      public Representation represent(Variant variant) throws
ResourceException {

            Representation representation = null;

            if(variant.getMediaType() == MediaType.APPLICATION_JSON){

                  representation = new JsonRepresentation("Hello World");

            }else if ( variant.getMediaType() == MediaType.TEXT_PLAIN){

                  representation = new StringRepresentation(

                              "hello, world", MediaType.TEXT_PLAIN);


            return representation;




However when I call the service using the following URL
http://localhost:8080/firstStepsServlet/Hello.js the Variant type in the
HelloWorldResource is of MediaType.TEXT_PLAIN


Thanks for Your help


From: Jonathan Hall (via Nabble)
Sent: Friday, June 05, 2009 1:29 PM
To: Sherif
Subject: Re: Multiple content types


Have a look at



Sherif wrote: 
> I realize RESTLet supports multiple encodings based on the Accept Encoding

> headers. Does Restlet also have a way to allow encodings based on URI
> e.g. http://mystores/items/1000.json or something like that ? 

775> &dsMessageId=2359775


This email is a reply to your post @
You can reply by email or by visting the link above.


View this message in context:
Sent from the Restlet Discuss mailing list archive at


Reply via email to