users@jersey.java.net

[Jersey] Re: Response.getStatus() and code readability

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Wed, 13 Nov 2013 14:27:59 +0100

On 12 Nov 2013, at 22:32, cowwoc <cowwoc_at_bbs.darktech.org> wrote:

> On 12/11/2013 7:44 AM, Marek Potociar wrote:
>>
>>> Can you please explain the reasoning and suggest a way to use switch() statements on response codes while keeping things readable?
>>
>> Here are the reasons:
>>
>> 1. See above - existing JAX-RS Response API
>> 2. We have received several bug reports in Jersey 1.x that it is not possible to support custom reason phrase. This is indeed impossible with enum.
>> 3. You can still use switch with int.
>> Jerse 2.0 uses JAX-RS API. JAX-RS Response.getStatus() always returned int, there was no way to change it.
>
> Fair enough. How do you define custom reason phrases in Jersey 2.0? I read https://java.net/jira/browse/JERSEY-1744 but couldn't see example code here or in the user manual.

https://github.com/jersey/jersey/tree/master/tests/integration/jersey-1829

>
>> You can do
>>
>> switch (Response.Status.fromStatusCode(response.getStatus())) { ... }
>>
>> A little bit more verbose, but should solve your primary concern.
>
> That's fine. Do I have to worry about Response.getStatus() returning a code not supported by the enum?

Yes, of course.

Marek