Hi Leon,
How to override server error pages depends on what server you're
using. As far as I'm aware it's unfortunately not possible to use
Tapestry pages as server error pages - if I'm wrong here, I'd really
like to know how to do it. :)
What I mean by turning the RequestExceptionHandler into a pipeline is
that I've overridden the original service with my own that uses a
pipeline.
http://tapestry.apache.org/tapestry5/tapestry-ioc/pipeline.html
So I define my filter:
public interface RequestExceptionFilter {
void handleRequestException(Throwable exception,
RequestExceptionHandler handler)
throws IOException;
}
Then I create a new RequestExceptionHandler as a pipeline:
public static RequestExceptionHandler
buildImprovedRequestExceptionHandler(
List<RequestExceptionFilter> configuration,
@InjectService("RequestExceptionHandler")
RequestExceptionHandler requestExceptionHandler,
PipelineBuilder builder,
Logger logger
) {
return builder.build(
logger,
RequestExceptionHandler.class,
RequestExceptionFilter.class,
configuration,
requestExceptionHandler
);
}
I then contribute this to AliasOverrides to replace the default
RequestExceptionHandler:
public static void contributeAliasOverrides(
Configuration<AliasContribution> configuration,
@InjectService("ImprovedRequestExceptionHandler")
RequestExceptionHandler requestExceptionHandler
) {
configuration.add(AliasContribution.create(RequestExceptionHandler.class,
requestExceptionHandler));
}
I can then contribute filters to the pipeline like this:
public static void contributeImprovedRequestExceptionHandler(
OrderedConfiguration<RequestExceptionFilter> configuration,
RequestExceptionErrorFilter requestExceptionErrorFilter
) {
configuration.add("Error", requestExceptionErrorFilter);
}
Where RequestExceptionErrorFilter looks like this:
public class RequestExceptionErrorFilter
implements RequestExceptionFilter {
private final RedirectService redirectService;
private final SecurityService securityService;
private final Logger logger;
public RequestExceptionErrorFilter(RedirectService
redirectService, SecurityService securityService, Logger logger) {
this.redirectService = redirectService;
this.securityService = securityService;
this.logger = logger;
}
public void handleRequestException(Throwable exception,
RequestExceptionHandler handler)
throws IOException {
if (securityService.isProductionModeEnabled()) {
logger.error("Exception during request", exception);
redirectService.sendRedirect(ErrorIndex.class, false);
}
else {
handler.handleRequestException(exception);
}
}
}
RedirectService and SecurityService are my own classes. They just make
some things easier for me. As you can see I show an error page when
I'm in production but invoke the next filter in the pipeline if I'm
not. You could contribute more filters if needed.
I've been wanting to contribute a strategy filter before this one
allowing to do different things depending on the type of exception
thrown, but haven't had the time nor need to do so yet.
http://tapestry.apache.org/tapestry5/tapestry-ioc/strategy.html
Anyhow, hope this helps - if not, you know where to ask. :)
-Filip
On 2008-05-16 17:37, Leon Derks wrote:
Thanks Peter,
Your original question in the post is also what I would like to know.
Do you now know how to override server error pages(404, 505 etc)?
And I don't understand what Flip means with :I've turned the
RequestExceptionHandler service into a pipeline.
Can you show me some code of how to do this?
Leon
Peter Stavrinides wrote:
Hi Leon
I posted a number of questions to the list about this topic, but got
only a few perls. One of them was this post, particularly Filip's
answer:
http://www.mail-archive.com/users@tapestry.apache.org/msg21914.html
Also see this page, for how to override Tapestry's error page with
your own friendly error page:
http://wiki.apache.org/tapestry/Tapestry5ExceptionPage
I am not sure what you are trying to do, but would suggest you
familiarize yourself a bit more with Tapestry's error reporting
mechanisms, which imho are incredibly powerful and easy to use.
Hope this helps,
Peter
----- Original Message -----
From: "Leon Derks" <[EMAIL PROTECTED]>
To: "Tapestry users" <users@tapestry.apache.org>
Sent: Friday, 16 May, 2008 1:35:19 PM GMT +02:00 Athens, Beirut,
Bucharest, Istanbul
Subject: T5: Exception Handling
Hello
What is the best way to handle exceptions in Tapestry 5?
I want to show some kind of general error page, when an exception
occurs.
At the moment I have a onException method in my BasePage class. But
for some reason the Error page is not returned.
What is the way in T5 to handle exceptions?
Object onException(Throwable cause) {
return new Error();
}
Leon
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]