users@jersey.java.net

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

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Tue, 12 Nov 2013 16:32:20 -0500

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.

> 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?

Gili