RE: Re: JAX RS ExceptionMappers by MessageBodyWriter

2009-08-17 Thread Jerome Louvel
Hi Nicolas,

Stephan is right and there is nothing you can do once the headers are
written. If you want to look by yourself, check this method in the
org.restlet.engine.http.HttpServerCall class:
 - sendResponse(Response)
 - writeResponseHead(Response, OutputStream)

Regarding the 500 status you receive, I don't understand how is it possible.
The exception probably occurs before effectively writing the representation.
A reproducible sample would help.

BTW, this discussion made me create a RFE for the new resource API in
Restlet 2.0:

Add exception conversion to ConverterService
http://restlet.tigris.org/issues/show_bug.cgi?id=878

Your comments on it are welcome. I'd like to add this for 2.0 M5.

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com


-Message d'origine-
De : Nicolas Rinaudo [mailto:nico...@nrinaudo.com] 
Envoyé : lundi 3 août 2009 14:16
À : discuss@restlet.tigris.org
Objet : RE: Re: JAX RS ExceptionMappers by MessageBodyWriter

Actually, come to think of it, what I'm talking about *should* be possible.

I just ran a test and if I throw any sort of exception in a writeTo method,
the status code received by the client is a generic 500. RESTlet somehow
manages to catch the error and deal with it (maybe it caches headers until
the first byte of the response has been written?).

Since RESTlet appears to be capable of dealing with such errors, should it
not also try to find a relevant ExceptionMapper before triggering a generic
500 error?

I apologise if I'm talking rubbish here, maybe I'm missing something
obvious.

Nicolas

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=23795
10

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2384259


RE: Re: JAX RS ExceptionMappers by MessageBodyWriter

2009-08-04 Thread Nicolas Rinaudo
Actually, come to think of it, what I'm talking about *should* be possible.

I just ran a test and if I throw any sort of exception in a writeTo method, the 
status code received by the client is a generic 500. RESTlet somehow manages to 
catch the error and deal with it (maybe it caches headers until the first byte 
of the response has been written?).

Since RESTlet appears to be capable of dealing with such errors, should it not 
also try to find a relevant ExceptionMapper before triggering a generic 500 
error?

I apologise if I'm talking rubbish here, maybe I'm missing something obvious.

Nicolas

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2379510


RE: Re: JAX RS ExceptionMappers by MessageBodyWriter

2009-08-03 Thread Nicolas Rinaudo
Ah, yes, very good point. I feel a bit silly now :)

That's a bit of a pain, since it means that you have to manually check for the 
requested charset in each method that returns a Representation though. I liked 
the idea of just using the one specified in the request's media type and 
catching the possible UnsupportedEncodingException in an ExceptionMapper, but I 
guess that's not possible.

I'm not sure using the isWriteable method is a good idea for that particular 
problem - you don't have MIME type information there and just because the 
current instance doesn't support the requested charset doesn't mean no other 
does.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2377552