Hi Jim and Adam,

As the connectors in the Restlet API are protocol-neutral (HTTP-centric
indeed but usable for other protocols/schemes like file:// and ftp://) and
as we allow for switchable implementations of those connectors (JDK's
HttpURLConnection, Apache HTTP, etc.), we don't control all the potential
exceptions being thrown. 

The only way to expose those exceptions would be to add a "throws Exception"
to the Uniform.handle() method as suggested by Adam. But, as noticed by Jim,
we couldn't do anything useful with those exceptions caught beside logging
them. 

As HTTP already has a mechanism to dealing with 'exceptions', the status, we
thought that this would be better and more consistent to solely rely on
those statuses to deal with all exceptions/errors/success info that could
arise during the handling of a request.

As Adam said, some errors are out of the traditional HTTP status scope,
because the request may not have even left the client connector (bad
request, invalid URI, host not found, etc.).

To cover those exceptions, we have already proposed some extension statuses,
specific to the connector:
 - CONNECTOR_ERROR_COMMUNICATION 
 - CONNECTOR_ERROR_CONNECTION 
 - CONNECTOR_ERROR_INTERNAL 

This design seems consistent and addresses all the cases uniformly, and
remove the need to define try/catch blocks around the handle() method
invocations.

Now, there are two issues in the code pointed out in the start of this
thread by Jim:
 - the catch block doesn't set the response status to
Status.CONNECTOR_ERROR_INTERNAL
 - the exception described as "Only HTTP or HTTPS resource URIs are allowed
here" should be caught directly in the
com.noelios.restlet.ext.httpclient.HttpMethodCall constructor, by setting
the response status to the standard HTTP CLIENT_ERROR_BAD_REQUEST, with an
appropriate description message.

The offending code has been fixed in HttpClientHelper like this:

        try {
            HttpClientCall httpCall = getConverter().toSpecific(this,
request);
            getConverter().commit(httpCall, request, response);
        } catch (Exception e) {
            getLogger().log(Level.INFO,
                    "Error while handling an HTTP client call", e);
            response.setStatus(Status.CONNECTOR_ERROR_INTERNAL,
e.getMessage());
        }

Fix checked in SVN trunk and branch 1.0.

Best regards,
Jerome  

> -----Message d'origine-----
> De : Jim Alateras [mailto:[EMAIL PROTECTED] 
> Envoyé : mardi 29 mai 2007 00:39
> À : [email protected]
> Objet : Re: Problem with org.restlet.Client
> 
> Adam Taft wrote:
> > 
> > The biggest concern for me is that IOException is being 
> eaten in the 
> > client.  So, for example, an illegal url or a host not 
> found error is 
> > being trapped, logged and then no other error is being 
> thrown.  Yuck. 
> > There's no appropriate status code which can model a "host 
> not found" 
> > exception, because the status codes imply actual contact 
> with the server.
> > 
> i'm starting to agree that that its hard to get an appropriate status 
> code particularly since the request hasn't left the client side.
> 
> cheers
> </jima>

Reply via email to