Re: Forcing a preferred variant in ServerResource

2010-10-06 Thread Ron Gomes
Thierry: declaring the json method doesn't appear to solve the problem.  I've 
ordered three representations in this way:

@Get(json)
public Representation
representAsJSON() {
}

@Get(txt)
public Representation
representAsText()  {
}

@Get(xml)
public Representation
representAsXML() {
}

But XML is still preferred in the absence of an Accept header from the client 
specifying a different variant.

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


RE: Forcing a preferred variant in ServerResource

2010-09-22 Thread Thierry Boileau
Hello Ron,

I think you can declare the json method before the other ones. At this time, 
the scoring algorithm gives precedence to the first declared method.

Best regards,
thierry boileau

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


Forcing a preferred variant in ServerResource

2010-09-21 Thread Ron Gomes
I posted this question to the wrong list, where it might not be noticed or 
addressed, so I'm re-posting it here; please excuse the duplication.

I have a ServerResource that can produce three variants in response to a GET: 
application/json, application/xml, and text/plain.  I want the JSON variant to 
be preferred over the others, so that in the absence of a specific request (via 
the Accept header) for another variant, the JSON representation and 
application/json Content-Type will always be returned.

I'm having trouble achieving this in Restlet 2.0.0.  Unless the client 
explicitly passes Accept: application/json, the Variant presented to the 
get(Variant) method is always application/xml.  This happens when the Accept 
list includes */* and also when no Accept header is sent at all.

I've experimented with using @Get annotations with variants specified as 
parameters to the annotation (@Get('json'), @Get('xml'), @Get('txt')), as well 
as with get(Variant), but the result is the same: the xml variant is always 
preferred.

I've overridden getPreferredVariant() to indicate that application/json is 
preferred, but it makes no difference (nothing ever causes that method to be 
invoked anyway).

How can I make application/json be the default while still returning 
application/xml if that's explicitly requested by the client?

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


Re: preferred variant

2010-02-22 Thread Thierry Boileau
Hello Zsolt,

you can specify a default media type on the metadata service of the 
application:
your app.getMetadataService().setDefaultMediaType(MediaType.TEXT_HTML);

Best regards,
Thierry Boileau

 Hello

 I'm sure I'm missing something trivial, but I can't figure it out.

 I have this simple interface:

 public interface EntryResource {
  @Get(html)
  public Representation asHtml();
   
  @Get(json|xml)
  public Entry retrieve();
   
  @Put
  public void store(Entry entry);

  @Delete
  public void remove();
 }

 I have a server resource class which implements these methods (no @Get
 annotation there). When I don't set the Accept header in request, I
 always get application/json response. How can I set the preferred
 media type to text/html?

 When I set Accept: text/html, it returns the html representation.



 Thank you in advance

 zsolt

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



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


Re: preferred variant

2010-02-22 Thread Zsolt Czinkos
Hi Thierry,

Thanks for your help.

Best,

Zsolt

On Mon, Feb 22, 2010 at 1:11 PM, Thierry Boileau
thierry.boil...@noelios.com wrote:
 Hello Zsolt,

 you can specify a default media type on the metadata service of the
 application:
 your app.getMetadataService().setDefaultMediaType(MediaType.TEXT_HTML);

 Best regards,
 Thierry Boileau

 Hello

 I'm sure I'm missing something trivial, but I can't figure it out.

 I have this simple interface:

 public interface EntryResource {
     �...@get(html)
      public Representation asHtml();

     �...@get(json|xml)
      public Entry retrieve();

     �...@put
      public void store(Entry entry);

     �...@delete
      public void remove();
 }

 I have a server resource class which implements these methods (no @Get
 annotation there). When I don't set the Accept header in request, I
 always get application/json response. How can I set the preferred
 media type to text/html?

 When I set Accept: text/html, it returns the html representation.



 Thank you in advance

 zsolt

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



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


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


preferred variant

2010-02-21 Thread Zsolt Czinkos
Hello

I'm sure I'm missing something trivial, but I can't figure it out.

I have this simple interface:

public interface EntryResource {
@Get(html)
public Representation asHtml();

@Get(json|xml)
public Entry retrieve();

@Put
public void store(Entry entry);

@Delete
public void remove();
}

I have a server resource class which implements these methods (no @Get
annotation there). When I don't set the Accept header in request, I
always get application/json response. How can I set the preferred
media type to text/html?

When I set Accept: text/html, it returns the html representation.



Thank you in advance

zsolt

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