Hi Davide, Good suggestion, I've just updated the StatusService Javadocs in SVN.
* Service to handle error statuses. If an exception is thrown within your * application or Restlet code, it will be intercepted by this service if it is * enabled. * * When an exception or an error is caught, the * [EMAIL PROTECTED] #getStatus(Throwable, Request, Response)} method is first invoked to * obtain the status that you want to set on the response. If this method isn't * overridden or returns null, the [EMAIL PROTECTED] Status.SERVER_ERROR_INTERNAL} constant * will be set by default. * * Also, when the status of a response returned is an error status (see * [EMAIL PROTECTED] Status#isError()}, the * [EMAIL PROTECTED] #getRepresentation(Status, Request, Response)} method is then invoked * to give your service a chance to override the default error page. * * If you want to customize the default behavior, you need to create a subclass * of StatusService that overrides some or all of the methods mentioned above. * Then, just create a instance of your class and set it on your Component or * Application via the setStatusService() methods. Best regards, Jerome > -----Message d'origine----- > De : Davide Angelocola [mailto:[EMAIL PROTECTED] > Envoyé : vendredi 12 octobre 2007 20:50 > À : discuss@restlet.tigris.org > Objet : Re: Issue using StatusService > > Hi Jerome, > > On Thursday 11 October 2007 21:57:02 Jerome Louvel wrote: > > When an exception or error is thrown, is it ultimately caught by the > > Application's StatusFilter: > > > > public void doHandle(Request request, Response response) { > > try { > > super.doHandle(request, response); > > } catch (Throwable t) { > > response.setStatus(getStatus(t, request, response)); > > } > > } > > > > The ApplicationStatusFilter, subclass of StatusFilter has this > > implementation which calls your StatusService instance: > > > > public Status getStatus(Throwable throwable, Request request, > > Response response) { > > Status result = > getApplication().getStatusService().getStatus( > > throwable, request, response); > > if (result == null) > > result = super.getStatus(throwable, request, response); > > return result; > > } > > > > Your getRepresentation(Status,Req,Resp) method is called > later, but only > > if your status is an error status. See this StatusFilter code: > > > > public void afterHandle(Request request, Response response) { > > // If no status is set, then the "success ok" > status is assumed. > > if (response.getStatus() == null) { > > response.setStatus(Status.SUCCESS_OK); > > } > > > > // Do we need to get a representation for the > current status? > > if (response.getStatus().isError() > > && ((response.getEntity() == null) || overwrite)) { > > > response.setEntity(getRepresentation(response.getStatus(), > > request, > > response)); > > } > > } > > > > This implementation looks fine to me (I've just tested it). > I hope it > > helped clarifying the expected behavior on your side. Let > me know if it > > still doesn't work. > Yeah.. now it works. Thanks very much... moreover can this > behavior better > documented in the API or in the tutorial? > > But I've got another issue with the representation. Here is the code: > > @Override > public Status getStatus(Throwable throwable, Request > request, Response > response) { > final Writer result = new StringWriter(); > final PrintWriter printWriter = new PrintWriter(result); > throwable.printStackTrace(printWriter); > return new Status(Status.SERVER_ERROR_INTERNAL, > result.toString()); > } > > @Override > public Representation getRepresentation(Status status, > Request request, > Response response) { > StringBuilder buffer = new StringBuilder(); > > buffer.append("<html><head><title>").append(status.getName()). > append("</title></head><body>"); > buffer.append(status.getCode()).append("<br/>"); > buffer.append(status.getName()).append("<br/>"); > buffer.append(status.getUri()).append("<br/>"); > buffer.append(status.getDescription()).append("<br/>"); > buffer.append("</body></html>"); > return new StringRepresentation(buffer.toString(), > MediaType.TEXT_HTML); > } > > in the browser I see the HTTP response, something like: > > Date: Fri, 12 Oct 2007 00:03:07 GMT > Server: Noelios-Restlet-Engine/1.0.5 > Content-Type: text/html; charset=ISO-8859-1 > Content-Length: 4498 > > <html> > <head> > [...] > > I'm wrong? > > -- > Best Regards, > Davide Angelocola > -- > -- Davide Angelocola