Hi Sergei,

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

I have discovered a little bit different behaviour in CXF 2.7.0: 
if service interface method returns object - client exception mapper is 
invoked, independent if exceptions are declared or not.
If service interface method returns Response, client exception mapper isn't 
invoked.

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

It is our code from Syncope project. Currently we should manually call 
exception mapper on client side for all methods returning Response.

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

Sure, client can do it (see code above), but need additional code for methods 
returning Response - looks a little bit ugly for me.

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

Yep, it is the case. Client code expects exceptions, they are coming 
automatically from mapper for all methods except returning Response ones (here 
we need extra code).

Regards,
Andrei.

> -----Original Message-----
> From: Sergey Beryozkin [mailto:[email protected]]
> Sent: Mittwoch, 30. Januar 2013 12:33
> To: [email protected]
> Subject: Re: [CXF.REST] Exception mapper on the client in case of Response
> retun value
> 
> 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