RE: Handling Ajax requests when decorating the RequestExceptionHandler
>> Is this method invoking super.handleRequestException()? If yes, you don't >> have to do anything. Actually no, the method is not invoking super.handleRequestException() . I coded it along the lines of "Version 3: Decorating the RequestExceptionHandler" at http://tapestry.apache.org/overriding-exception-reporting.html and that example does not invoke the super method, but that's because the class does not extend anything, it just implements the interface: > public class RequestExceptionHandlerImpl implements RequestExceptionHandler So it sounds like I should not implement RequestExceptionHandler directly, but rather extend DefaultRequestExceptionHandler - which already implements RequestExceptionHandler - and then call super.handleRequestException() at the top of my handleRequestException() ... I'm going to try that, thanks for the pointer :)
Re: Handling Ajax requests when decorating the RequestExceptionHandler
On Thu, 26 Jun 2014 04:35:52 -0300, Davide Vecchi wrote: I believe I'm actually decorating; this is a trimmed version of the code: --- In AppModule.java : @Match("RequestExceptionHandler") public static RequestExceptionHandler decorateRequestExceptionHandler(final Logger logger, final ResponseRenderer renderer, final ComponentSource componentSource, @Symbol(SymbolConstants.PRODUCTION_MODE) boolean productionMode, Object service) { return new RequestExceptionHandlerImpl(componentSource); } That's Tapestry-IoC service decoration for sure! :) public class RequestExceptionHandlerImpl implements RequestExceptionHandler { public RequestExceptionHandlerImpl(ComponentSource componentSource) { this.componentSource = componentSource; } @Override public void handleRequestException(Throwable exception) throws IOException { // Log the exception : // Redirect to previous page : Component previousPage = getPreviousPage(request, this.componentEventLinkEncoder, this.componentSource); Link redirectTo = this.pageRenderLinkSource.createPageRenderLink(previousPage.getClass()); response.sendRedirect(redirectTo); } Is this method invoking super.handleRequestException()? If yes, you don't have to do anything. -- Thiago H. de Paula Figueiredo Tapestry, Java and Hibernate consultant and developer http://machina.com.br - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
RE: Handling Ajax requests when decorating the RequestExceptionHandler
I believe I'm actually decorating; this is a trimmed version of the code: --- In AppModule.java : @Match("RequestExceptionHandler") public static RequestExceptionHandler decorateRequestExceptionHandler(final Logger logger, final ResponseRenderer renderer, final ComponentSource componentSource, @Symbol(SymbolConstants.PRODUCTION_MODE) boolean productionMode, Object service) { return new RequestExceptionHandlerImpl(componentSource); } --- In RequestExceptionHandlerImpl.java : public class RequestExceptionHandlerImpl implements RequestExceptionHandler { public RequestExceptionHandlerImpl(ComponentSource componentSource) { this.componentSource = componentSource; } @Override public void handleRequestException(Throwable exception) throws IOException { // Log the exception : // Redirect to previous page : Component previousPage = getPreviousPage(request, this.componentEventLinkEncoder, this.componentSource); Link redirectTo = this.pageRenderLinkSource.createPageRenderLink(previousPage.getClass()); response.sendRedirect(redirectTo); } } --- Thanks for the info, that's what I was looking for.
Re: Handling Ajax requests when decorating the RequestExceptionHandler
On Tue, 24 Jun 2014 09:39:42 -0300, Davide Vecchi wrote: Hi, Hi! I'm decorating the RequestExceptionHandler in order to handle exceptions and then redirecting to the previous page (the one I find in the "Referer" HTTP header). This works fine for normal page requests but I would like to handle also the case of Ajax requests. The JavaDoc of RequestExceptionHandler.handleRequestException (http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/services/RequestExceptionHandler.html) says: "The handler is also responsible for setting the response status and the X-Tapestry-ErrorMessage response header. These are very important in Ajax requests to allow the client-side logic to detect the error and present it to the user." I couldn't find documentation to figure out to what values I should set the response status and the X-Tapestry-ErrorMessage response header. Does anyone have suggestions ? If you're actually decorating, not overriding, and calling the handleRequestException() method from the object you're decorating, this is already being done. If not, here's the summary of what the default one does: response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); // HTTP status code 500 (internal error) response.setHeader("X-Tapestry-ErrorMessage", exception.getMessage()); where response is a org.apache.tapestry5.services.Response object. -- Thiago H. de Paula Figueiredo Tapestry, Java and Hibernate consultant and developer http://machina.com.br - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Handling Ajax requests when decorating the RequestExceptionHandler
Hi, I'm decorating the RequestExceptionHandler in order to handle exceptions and then redirecting to the previous page (the one I find in the "Referer" HTTP header). This works fine for normal page requests but I would like to handle also the case of Ajax requests. The JavaDoc of RequestExceptionHandler.handleRequestException (http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/services/RequestExceptionHandler.html) says: "The handler is also responsible for setting the response status and the X-Tapestry-ErrorMessage response header. These are very important in Ajax requests to allow the client-side logic to detect the error and present it to the user." I couldn't find documentation to figure out to what values I should set the response status and the X-Tapestry-ErrorMessage response header. Does anyone have suggestions ? Thanks in advance.