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

Reply via email to