Hi Sherif,

.js is javascript
.json is json :0)

There is no need to add js or json to the MetadataService as it comes 
with a bunch of common ones already.
Remove that line, and try

http://localhost:8080/firstStepsServlet/Hello.json (Notice the JSON)


Jon

Sherif wrote:
>
> 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.
>
> */
>
> @Override
>
> *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
>
> router.attachDefault(HelloWorldResource.*class*);
>
> *this*.getTunnelService().setExtensionsTunnel(*true*);
>
> *this*.getTunnelService().setEncodingParameter("output");
>
> *this*.getMetadataService().addExtension("js", *new* 
> Metadata(MediaType./APPLICATION_JSON/.getName(), 
> 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.
>
> */
>
> @Override
>
> *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) 
> [mailto:ml-user+125526-1692215...@... 
> <http://n2.nabble.com/user/SendEmail.jtp?type=node&node=3043073&i=0>]
> *Sent:* Friday, June 05, 2009 1:29 PM
> *To:* Sherif
> *Subject:* Re: Multiple content types
>
> Have a look at
> http://www.restlet.org/documentation/2.0/api/org/restlet/service/TunnelService.html
>
> getTunnelService().setExtensionsTunnel(true);
>
> Jon
>
> 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 patter
> > e.g. http://mystores/items/1000.json or something like that ?
> >
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2359775
>  
> <http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2359775>
>
> ------------------------------------------------------------------------
>
> This email is a reply to your post @ 
> http://n2.nabble.com/Multiple-content-types-tp3031817p3031841.html
> You can reply by email or by visting the link above.
>
>
> ------------------------------------------------------------------------
> View this message in context: RE: Multiple content types 
> <http://n2.nabble.com/Multiple-content-types-tp3031817p3043073.html>
> Sent from the Restlet Discuss mailing list archive 
> <http://n2.nabble.com/Restlet-Discuss-f1400322.html> at Nabble.com.

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

Reply via email to