Hi Davide,

>   I've an Application that sets it's StatusService. Here the 
> code (imports omitted):
 
[...]
 
> The status service is then connected to the Application via 
> setStatusService() instance method.
> my intent is to return the complete exception as html page. 
> I'm expecting getStatus() 
> to be called before getRerpresentation() but actually is never called.
> It's a bug?

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.

Best regards,
Jerome  

Reply via email to