Hi Andrei
On 30/01/13 10:21, Andrei Shakirin wrote:
Hi,

I see that registered ExceptionMapper is not invoked on the client side, if 
service interface returns Response.
Not sure is it JAX-RS specified or desired behaviour.

ExceptionMapper is only used on the server side, on the client side there's no concept of mapping error responses to custom exceptions when fluent API is used (standard 2.0, CXF WebClient), so in CXF it is custom ResponseExceptionMapper provider which can be used by the proxy client runtime to map an error status code to one of declared exception classes, for example

Book getBook() throws BookNotFoundException;

CXF client can register ResponseExceptionMapper and convert say 404 to BookNotFoundException;

 From one side client has enough information in Response to deal with errors.
 From other side, if service interface has mix of methods returning Response and normal 
objects, it causes code like this for all "Response" methods:
         Response response = connectorService.create(connectorTO);
         if (response.getStatus() != org.apache.http.HttpStatus.SC_CREATED) {
             throw (RuntimeException) 
clientExceptionMapper.fromResponse(response);
         }
Where is this code coming from ?



I can imagine that even for methods returning Response, client exception mapper 
is invoked for error response codes.
WDYT?

The expectation (consistent with 2.0 client API) is that if Response is returned then the client needs to handle it itself, including checking the headers and the status.

Do you need checking a client side mapper even for Response for consistency purposes, example, the application code is expected to have catch statements whether it is Response or MyCustomType which is returned from a method ?

Cheers, Sergey


Regards,
Andrei.


Reply via email to