Sorry maybe I didn't explained well, but I don't get an empty String. The
ServerWebApplicationException looks like:
exception : ServerWebApplicationException (id=46)
---> cause : null
---> detailMessage : null
---> errorMessage : "{"errorDetail":{"message":{"$":"custom error message"}}}"
(id=54)
---> response : ResponseImpl (id=58)
---> ---> entity : HttpURLConnection$HttpInputStream (id=61)
---> ---> ---> cacheRequest : null
---> ---> ---> in : KeepAliveStream (id=70)
---> ---> ---> inCache : 0
---> ---> ---> markCount : 0
---> ---> ---> marked : false
---> ---> ---> outputStream : null
---> ---> ---> skipBuffer : null
---> ---> ---> this$0 : HttpURLConnection (id=74)
---> ---> metadata : MetadataMap<K,V> (id=64)
---> ---> status : 400
---> stackTrace : null
In the errorMessage I get the JSON of the object I need and, at first look, the
entity of the response seemed empty to me (probably I was wrong).
>From this, which would be the way to obtain the object I need? I thought I
>could get it from the response entity, since I insert it there in the server
>side, in an exceptionMapper, like:
return Response.status(code).entity(errorDetail).build();
btw, I do work with Camel. It's something like:
[client]<--->[JAXRS-Server]<--->[Camel-Pipeline]
When an exception occurs in the pipeline, jaxrs-server inserts this
'errorDetail' object as a response to the client. How do I retrieve it in the
client?
thanks
BR,
Marcos.
-----Mensaje original-----
De: Sergey Beryozkin [mailto:[email protected]]
Enviado el: martes, 15 de marzo de 2011 23:20
Para: [email protected]
Asunto: Re: Extracting object from Response when ServerWebApplicationException
occurs
I can see that the ServerWebApplicationException reports a non-empty String
in my test - do you work with Camel by any chance ?
However, ResponseReader is not checked in case of exceptions - so I'll try
to apply a little fix asap
Cheers, Sergey
2011/3/15 Marcos Díez Fernández <[email protected]>
> Ok, thank you Sergey, I'll wait for your reply.
>
> BR,
> Marcos.
>
> -----Mensaje original-----
> De: Sergey Beryozkin [mailto:[email protected]]
> Enviado el: martes, 15 de marzo de 2011 10:53
> Para: [email protected]
> Asunto: Re: Extracting object from Response when
> ServerWebApplicationException occurs
>
> Hi
>
> I haven't replied so far because I'll need to write a test but have yet
> another test in front of me to deal with...
>
> I'm not sure at the moment why the empty string is returned from
> ServerWebApplicationException so I'll have to investigate
>
> thanks, Sergey
>
>
> 2011/3/15 Marcos Díez Fernández <[email protected]>
>
> > 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
> >
> >
> >
>