I think there's a bug. Here is a resource:

public class MyResource  extends ServerResource {
  @Get
  public String getData() throws Exception {
    throw new Exception();
  }
}

If I add a StatusService to handle the exception, the getStatus() method is 
never called. This is due to the following code from ServerResource (line 458):

  } catch (InvocationTargetException e) {
    if (e.getTargetException() instanceof ResourceException) {
      throw (ResourceException) e.getTargetException();
    }
    throw new ResourceException(e.getTargetException());
  }

My exception is encapsulated into a InvocationTargetException. This code 
transforms the InvocationTargetException to a ResourceException so that 
StatusService.getStatus() is never called. Only 
StatusService.getRepresentation() is.

I think the best solution is to create a RuntimeException and transform the 
InvocationTargetException to this exception. Then, the 
UniformResource.doCatch() must process this exception by calling 
StatusService.getStatus() with the cause of this new exception.

I've implemented it by adding a UnhandledException, adding the following code 
in UniformResource, line 144:
  else if (throwable instanceof UnhandledException) {
    status = getStatusService().getStatus(throwable.getCause(), this);
  }
and replacing line 530 of ServerResource with:
  throw new UnhandledException(e.getTargetException());

Am I wrong?

Regards,

Olivier

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

Reply via email to