Hi all,
 
Let me try to reply to the rest on this thread in one mail.
 
1) Multiple POST/PUT methods for different types of request entity
 
It will be possible to specify the media type of the entity passed to POST
and PUT methods in the annotation value, in addition to specifying the
optional media type of the returned entity.
 
Again, you can find a bit more details in the specifications page (see
"Annotations parameter" paragraph):
http://wiki.restlet.org/developers/172-restlet/226-restlet.html
 
There are examples given:
@Get("xml") : Returns a representation in the "text/xml" media type

String toString();



@Put("xml") : Stores representations in the "text/xml" media type after
conversion to a DOM document

void store(Document doc)



@Put("text:xml") : Stores representations in the "text/xml" media type after
conversion to a DOM document and returns a plain text response

String store(Document doc)
This isn't implemented yet, this is the next step for 1.2 M3.
 
2) Exceptions caught
 
Currently (SVN trunk at least), the ResourceExceptions are caught and the
response status is updated accordingly. This is done in the
ServerResource#handle() method. Other exceptions will be caught upper in the
processing chain, by the StatusService for example. 
 
We do have some plans to extend the ConverterService in order to
automatically convert common exceptions into matching statuses, but I'm not
clear yet whether this is such a good idea (JAX-RS has this).
 
3) Variants declaration
 
Currently, there is a modifiable map (Map<Method, Object) that is used to
declare variants for either all methods or specific ones. We are considering
adding a new VariantDescriptor class that would allow to express more
complex ranges of variants like saying I accept all variants with a media
type in this set (XML or JSON or Atom or ...) and a language in this set.
This would be much more efficient that listing all the combinations
possible.
 
4) Method that don't return anything
 
For methods like POST that don't have to return an entity, it is possible to
annotate a Java method with just "@Get" as an annotation, and no value.
Depending on the input parameter of the method, the ServerResource should
invoke the proper method. It will also be possible to specify the accepted
variants with the following syntax:
 
@Post(":xml")
public void acceptXml(String value);
 
This could be simplified to this when no return type is present (":"
optional)
 
@Post("xml")
public void acceptXml(String value);
 
If the method has a return type, then this should be written:
 
@Post("xml:xml")
public String acceptXml(String value);
 
@Post("json:json")
public String acceptJson(String value);
 
Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~  <http://www.restlet.org/>
http://www.restlet.org
Noelios Technologies ~ Co-founder ~  <http://www.noelios.com/>
http://www.noelios.com

  _____  

De : Tal Liron [mailto:tal.li...@threecrickets.com] 
Envoyé : vendredi 3 avril 2009 09:46
À : discuss@restlet.tigris.org
Objet : Re: ServerResource conditional mode



You don't need to put a media type if you're using void (although, you could
potentially have more than one @Post handler, for several media types, to be
used depending on the expectation of a media type from the client...).




But, you do need to disable conditional mode:


@Post

public void handlePost(Representation rep) { ... }

@Override
protected void init()
{
    setConditional(false);
}





Why? I'm still a bit in the dark about this. My current instinct tells me
that there's a bug in how the preferred variant is calculated for
conditional mode, in that it doesn't gather variants for the particular
method. Thus, I suspect (I haven't tested this) that if you had a @Get with
a particular media type (say, @Get("txt")) then there would be a preferred
variant and your @Post would be called, even in conditional mode.




Please take that last paragraph with a truckload of salt. :)




-Tal



David Fogel wrote:


Hi Tal-



I will definitely take a look at your script extension, thanks for the

suggestion!



I think I understand the general deal with the mediatype annotation

argument.  But like I said, I was trying to define a Post method that

doesn't return content (and which therefore wouldn't make sense to

declare a mediatype for.  So what's the right annotation argument for

this method?



@Post("[what goes here?]")

public void handlePost(Representation rep) { ... }



what I found was that I had to put a return type or a mediatype, or

else ServerResource refuses to call the method, due to the lack of a

"preferredVariant".



-Dave



------------------------------------------------------

http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447
<http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1529
543> &dsMessageId=1529543

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

Reply via email to