Any help? Thanks.

-----Mensaje original-----
De: Marcos Díez Fernández [mailto:[email protected]] 
Enviado el: lunes, 14 de marzo de 2011 13:43
Para: [email protected]
Asunto: Extracting object from Response when ServerWebApplicationException 
occurs

Hi,

I have a RESTful service provided by a JAXRS server that, when an exception 
occurs, returns a custom error class serialized as JSON:

ID: 763
Response-Code: 406
Content-Type: application/json
Headers: {Date=[Mon, 14 Mar 2011 11:44:50 GMT]}
Payload: {"errorDetail":{"message":{"$":"custom error message"}}}
--------------------------------------

This produces a ServerWebApplicationException on the client side, which I catch:

public ReturnType getOfNorm String fecha) throws RestClientException{
                ReturnType respuesta = null;
                try{
                               respuesta = proxy.getOfNorm(fecha);
                }
                catch(WebApplicationException e){
                               throwRestClientException(e);
                }
                return respuesta;
}

Proxy initialized like this:

List<Object> providers = new ArrayList<Object>();
JSONProvider jsonProvider = new RestClientJSONProvider();
jsonProvider.setConvention("badgerfish");
providers.add(jsonProvider);
proxy = JAXRSClientFactory.create(baseAddress, ConsultsService.class, 
providers);


What I'd like to do is throwing from the client my own RestClientException 
containing the info of the errorDetail, so I need to obtain the ErrorDetail 
object in order to extract this info...

First I thought I'd have to use the new ResponseReader, but the response I get 
from the ServerApplicationException does not contain the ErrorDetail (the 
entity looks empty), so I think I can't get it this way. However, the exception 
does contain an errorMessage which is no other than the JSON of the errorDetail 
that I need...

So, the (maybe noobie) question is: How can I get the object I need? Is 
unmarshalling it from the errorMessage the only way?

Thanks in advance,

BR,

Marcos




Reply via email to