users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Re: Concerns about the client-side exception hierarchy

From: Santiago Pericas-Geertsen <Santiago.PericasGeertsen_at_oracle.com>
Date: Thu, 26 Jan 2012 09:38:46 -0500

Sergey,

 I think this is worth exploring. Can you turn this into a JIRA?

-- Santiago

On Jan 26, 2012, at 5:23 AM, Sergey Beryozkin wrote:

> Hi All,
>
> IMHO some refactoring would help to make [1] & [2] better represent the cause of exceptions on the client side.
>
> At the moment [2] is supposed to be thrown whenever some underlying exception is raised during the invocation.
>
> Effectively we have 4 possible cases:
>
> 1. Client fails to find a matching writer for non-empty request payloads
> 2. Client fails to connect or deliver the request to the server for whatever reasons
> 3. Client gets the server-side HTTP error code
> 4. Client fails to find a reader for non-empty response payloads
>
> We can get filters throwing exceptions too.
>
> I see [2] being a bit too coarse-grained with [1] giving no much info either. InvocationException docs say it is meant to be thrown whenever a problem during the request or response occurs which basically means throw it every time.
>
> I'd propose the following:
>
> - have the base Exception class named InvocationException, 1-4 above are to do with the current invocation.
>
> - have Client(WebApplication)Exception raised for 1 & 2, 4 and this exception can in time offer some hints such as with media type can nnot be matched, why the connection may have failed, etc
>
> - have Server(WebApplication)Exception raised for 3
>
>
> With this kind of hierarchy it might be easier to imagine the possible retries.
>
>
> Next, assuming something like this were supported then I'd suggest reusing WebApplicationException instead of the base InvocationException.
> With Response now being client-friendly, WebApplicationException does seem like a perfect candidate to represent a base fault; though I'd be happy even without this further optional optimization
>
> Sergey
>
> [1] http://java.net/projects/jax-rs-spec/sources/git/content/src/jax-rs-api/src/main/java/javax/ws/rs/client/ClientException.java?rev=acfb7ecf63799ab6d726ad206bcd6eb49e9142ee
> [2] http://java.net/projects/jax-rs-spec/sources/git/content/src/jax-rs-api/src/main/java/javax/ws/rs/client/InvocationException.java?rev=acfb7ecf63799ab6d726ad206bcd6eb49e9142ee