users@jersey.java.net

Re: [Jersey] Response status forced to 204 when body empty

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 09 May 2008 10:55:09 -0700

Jersey also modifies the status code to 200 if the status is 204 but
there is an entity. I suppose we should not modify this either for
consistency but it seems wrong since a client may ignore a
representation in that case (for a 204 to 200 it is really harmless,
but the other way around could have unintended side effects).
Alternatively an exception could be thrown in such a case.

Paul.


On May 9, 2008, at 8:41 AM, Marc Hadley wrote:

> I've confirmed this behavior and agree that if you specify a status
> code, we shouldn't force it to something else. Would you mind
> creating an issue to track this problem in issue tracker:
>
> https://jersey.dev.java.net/issues/
>
> Sorry for the slow reply, the team is attending JavaOne this week,
> normal service will be resumed next week :-).
>
> Thanks,
> Marc.
>
> On May 9, 2008, at 8:18 AM, Bruno Luiz Pereira da Silva wrote:
>
>> It is indeed a valid response, but I want to be able to decide
>> which status I'm going to return. Being able to decide the
>> returned status gives me more flexibility, so I'd definitely like
>> to have this option.
>>
>> And thinking about the API, there is Response.ok() and there is
>> Response.noContent(). I think the implementation should use the
>> status corresponding to the method I used. Not doing this is
>> counter intuitive in my opinion. Don't you agree with that?
>>
>> Regards,
>>
>> Bruno
>>
>> On Fri, May 9, 2008 at 2:04 AM, Tatu Saloranta
>> <cowtowncoder_at_yahoo.com> wrote:
>> --- Bruno Luiz Pereira da Silva <blpsilva_at_gmail.com>
>> wrote:
>>
>> > Hi guys, I have started using Jersey recently, but I
>> > have a reasonable
>> > experience with RESTFul web services.
>> >
>> > I have a doubt regarding the response status. I'm
>> > trying to return an HTTP
>> > 200 when the operation goes OK on the server, but
>> > when the response body is
>> > empty the status is always set to 204 (No Content).
>> >
>> > I tried using
>> > Response.status(Response.Status.OK).build(),
>> > Response..ok().status(Response.Status.OK).build()
>> > and several other
>> > variations of this, trying to force the status to
>> > 200.
>> >
>> > If I use Response.ok(object).build() the response
>> > status is set to 200.
>> > Can't I return 200 with an empty response body?
>>
>> But isn't 204 (EMPTY_CONTENT) sort of "right" response
>> to give? It is a success code, after all (not a
>> failure), and indicates that there is no content to
>> return (as opposed to a failure to produce content or
>> so).
>>
>> -+ Tatu +-
>>
>>
>>
>>
>> _____________________________________________________________________
>> _______________
>> Be a better friend, newshound, and
>> know-it-all with Yahoo! Mobile. Try it now. http://
>> mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>>
>>
>> --
>> Atenciosamente,
>>
>> Bruno Luiz Pereira da Silva
>> blpsilva_at_gmail.com
>> http://brunopereira.com.br
>
> ---
> 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
>