users@jersey.java.net

Re: Adding a resource - HTTP POST

From: Florian Rosenberg <florian_at_vitalab.tuwien.ac.at>
Date: Tue, 23 Oct 2007 17:32:41 -0400 (EDT)

On Tue, October 23, 2007 17:27, Marc Hadley wrote:
> On Oct 23, 2007, at 3:15 PM, Nam Nguyen wrote:
>>
>> You need to have the method return Response and use
>> Response.Builder.created(uri) as return value.
>>
> Right. A 204 status is the default for a method that returns void, to
> get another status you need to return an instance of Response and
> Response.Builder provides an easy way to create one.

Thanks a lot, works fine.

I would also be cool to have an annotation for return codes. Foe example:
@ReturnCode(success="204", failure="500"), it would allow to leave the
method signature of a (delete) operation unchanged and get the desired
return code in case of a successful execution of an operation and an
internal exception.

Opinions?

Thanks,
-Florian

>> For sample codes, download NB 6.0 beta2
>> http://bits.nbextras.org/netbeans/6.0/beta2/latest/
>> and refer http://www.netbeans.org/kb/60/websvc/rest.html on how to
>> rapidly create database RESTful CRUD access.
>>
>> -Nam
>>
>> Florian Rosenberg wrote:
>>> Hi,
>>>
>>> I'm currently unit testing my resources. I have problems
>>> understanding the
>>> return code of a POST, for example, here is my method signature:
>>>
>>> @UriTemplate("customers/{id}")
>>> @HttpMethod("POST")
>>> public void addCustomer(@UriParam("id") String id, Customer data) {}
>>>
>>> Upon execution, the resource is created and returns a 204 code, which
>>> means "No content". This seems okay, but I rather expected a 201
>>> "Created"
>>> response.
>>>
>>> Is this the default return code for a successful HTTP POST? I
>>> checked the
>>> JavaDoc API, but I could not find any annotation that would allow
>>> me to
>>> set the return code I want to have.
>>>
>>> Thanks,
>>> -Florian
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
> ---
> Marc Hadley <marc.hadley at sun.com>
> CTO Office, Sun Microsystems.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>