On 2013-11-12 22:32, cowwoc 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.
Note that reason phrases are not guaranteed to be passed through
intermediaries, and they are gone in HTTP/2.0 (AFAIR). So do not rely on
them.
>> 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, unless the enum supports all syntactically legal status codes.
Best regards, Julian