Updated Branches:
  refs/heads/master 9e40372c1 -> fb3fca8d0

FIXED - TAP5-1833: Merge functionality of Tynamo.org's
tapestry-exceptionpage module with the built-in ExceptionHandler 
- add javadoc


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/fb3fca8d
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/fb3fca8d
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/fb3fca8d

Branch: refs/heads/master
Commit: fb3fca8d0835843bcbb25613ceafd393485fe4d2
Parents: 9e40372
Author: Kalle Korhonen <[email protected]>
Authored: Mon Jan 14 12:14:59 2013 -0800
Committer: Kalle Korhonen <[email protected]>
Committed: Mon Jan 14 12:14:59 2013 -0800

----------------------------------------------------------------------
 .../services/DefaultRequestExceptionHandler.java   |   46 ++++++++++++++-
 1 files changed, 43 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/fb3fca8d/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.java
 
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.java
index 969c756..c40c6a0 100644
--- 
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.java
+++ 
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.java
@@ -40,8 +40,18 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 /**
- * Default implementation of {@link RequestExceptionHandler} that displays the 
standard ExceptionReport page. The page
- * must implement the {@link ExceptionReporter} interface.
+ * Default implementation of {@link RequestExceptionHandler} that displays the 
standard ExceptionReport page. Similarly to the
+ * servlet spec's standard error handling, the default exception handler 
allows configuring handlers for specific types of
+ * exceptions. The error-page/exception-type configuration in web.xml does not 
work in Tapestry application as errors are
+ * wrapped in Tapestry's exception types (see {@link OperationException} and 
{@link ComponentEventException} ).
+ *
+ * Configurations are flexible. You can either contribute a {@link 
ExceptionHandlerAssistant} to use arbitrary complex logic
+ * for error handling or a page class to render for the specific exception. 
Additionally, exceptions can carry context for the
+ * error page. Exception context is formed either from the name of Exception 
(e.g. SmtpNotRespondingException -> ServiceFailure mapping
+ * would render a page with URL /servicefailure/smtpnotresponding) or they can 
implement {@link ContextAwareException} interface.
+ *
+ * If no configured exception type is found, the default exception page {@link 
SymbolConstants.EXCEPTION_REPORT_PAGE} is rendered.
+ * This fallback exception page must implement the {@link ExceptionReporter} 
interface.
  */
 public class DefaultRequestExceptionHandler implements RequestExceptionHandler
 {
@@ -64,6 +74,19 @@ public class DefaultRequestExceptionHandler implements 
RequestExceptionHandler
     // should be Class<? extends Throwable>, Object but it's not allowed to 
configure subtypes
     private final Map<Class, Object> configuration;
 
+    /**
+     * @param pageCache
+     * @param renderer
+     * @param logger
+     * @param pageName
+     * @param request
+     * @param response
+     * @param componentClassResolver
+     * @param linkSource
+     * @param serviceResources
+     * @param configuration A map of Exception class and handler values. A 
handler is either a page class or an ExceptionHandlerAssistant. 
ExceptionHandlerAssistant can be a class
+     * in which case the instance is autobuilt.
+     */
     @SuppressWarnings("rawtypes")
     public DefaultRequestExceptionHandler(RequestPageCache pageCache, 
PageResponseRenderer renderer, Logger logger,
 
@@ -105,9 +128,19 @@ public class DefaultRequestExceptionHandler implements 
RequestExceptionHandler
         this.configuration = configuration;
     }
 
+    /**
+     * Handles the exception thrown at some point the request was being 
processed
+     *
+     * First checks if there was a specific exception handler/page configured 
for this exception type, it's super class or super-super class.
+     * Renders the default exception page if none was configured.
+     *
+     * @param exception The exception that was thrown
+     *
+     */
+    @SuppressWarnings({ "rawtypes", "unchecked" })
     public void handleRequestException(Throwable exception) throws IOException
     {
-        // skip handling of known exceptions if there are none configured 
+        // skip handling of known exceptions if there are none configured
         if (configuration.isEmpty())
         {
             renderException(exception);
@@ -224,6 +257,13 @@ public class DefaultRequestExceptionHandler implements 
RequestExceptionHandler
         renderer.renderPageResponse(page);
     }
 
+    /**
+     * Form exception context either from the name of the exception, or the 
context the exception contains if it's of type
+     * {@link ContextAwareException}
+     *
+     * @param exception The exception that the context is formed for
+     * @return Returns an array of objects to be used as the exception context
+     */
     @SuppressWarnings({"unchecked", "rawtypes"})
     protected Object[] formExceptionContext(Throwable exception)
     {

Reply via email to