users@jersey.java.net

[Jersey] Re: InvocationException

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Thu, 14 Jun 2012 00:03:26 +0200

Hi,

we are currently working in the JAX-RS expert group on revisiting the proposed exception hierarchy. The general idea is something like this:

Client-side exceptions will be wrapped into an InvocationException and rethrown. Invocation exception will not have the Response anymore.
Server-side error responses will be converted to a subclass of the WebApplicationException only in case the user tries to directly convert the response entity to a Java type, e.g.:
String content = client.target(...).request().get(String.class) // may throw WAE

This is to make sure users don't confuse error responses for normal ones during response content processing. To avoid the exception in the case #2, a user could access the whole Response instance instead:

Response response = client.target(...).request().get();
String content = response.readEntity(String.class); // does not throw WAE

In the case above, an exception will not be thrown as it is expected the user can check the response status to make sure the response is not an error.

Alas, the above is not yet implemented in Jersey as well as the problem with the request context is not fixed yet. We should have it fixed in a few weeks.

Stay tuned,
Marek

On Jun 11, 2012, at 5:15 PM, Luis Gervaso wrote:

> Hi,
>
> What is the recommended way to handle InvocationException on the client side?
>
> Every Error Response comes to me with an error description in the response entity.
>
> 1) If i handle on a filter:
>
> throw readEntity(CustomException.class)
>
> is wrapped with an InvocationException
>
> 2) if i handle on my client
>
> I can not perform readEntity since I'm not in a request context
>
> Any clues?
>
> Regards
>
>
> --
> -------------------------------------------
> Luis Alberto Gervaso Martin
> Woorea Solutions, S.L
> CEO & CTO
> mobile: (+34) 627983344
> luis_at_woorea.es
>