diff --git a/projects/samskivert/src/java/com/samskivert/velocity/Application.java b/projects/samskivert/src/java/com/samskivert/velocity/Application.java index 97f4ea19..25901a55 100644 --- a/projects/samskivert/src/java/com/samskivert/velocity/Application.java +++ b/projects/samskivert/src/java/com/samskivert/velocity/Application.java @@ -24,6 +24,7 @@ import java.util.Properties; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; import org.apache.velocity.app.Velocity; @@ -34,6 +35,7 @@ import com.samskivert.servlet.MessageManager; import com.samskivert.servlet.RedirectException; import com.samskivert.servlet.SiteIdentifier; import com.samskivert.servlet.SiteResourceLoader; +import com.samskivert.servlet.util.ExceptionMap; import com.samskivert.util.StringUtil; /** @@ -43,6 +45,16 @@ import com.samskivert.util.StringUtil; * represents the web application. The application class is responsible * for initializing services that will be used by the application's logic * objects as well as cleaning them up when the application is shut down. + * + *
Error handling
+ * The application provides a common error handling mechanism. The design is to
+ * catch any exceptions thrown by the logic and to convert them into friendly
+ * error messages that are inserted into the invocation context with the key
+ * "error" for easy display in the resulting web page.
+ *
+ *
The default process of mapping exceptions to friendly error messages is + * done using the {@link ExceptionMap} class. This can be replaced by + * overriding {@link #handleException}. */ public class Application { @@ -198,6 +210,22 @@ public class Application return error; } + /** + * If a generic exception propagates up from {@link Logic#invoke} and is + * not otherwise converted into a friendly or redirect exception, the + * application will be required to provide a generic error message to be + * inserted into the context and should take this opportunity to log the + * exception. + */ + protected String handleException ( + HttpServletRequest req, Logic logic, Exception error) + { + Log.warning("Choked on request [logic=" + logic + + ", req=" + req.getRequestURI() + "]."); + Log.logStackTrace(error); + return ExceptionMap.getMessage(error); + } + /** * This should be overridden by the application implementation to * perform any necessary cleanup. diff --git a/projects/samskivert/src/java/com/samskivert/velocity/DispatcherServlet.java b/projects/samskivert/src/java/com/samskivert/velocity/DispatcherServlet.java index c7395377..f0993f5d 100644 --- a/projects/samskivert/src/java/com/samskivert/velocity/DispatcherServlet.java +++ b/projects/samskivert/src/java/com/samskivert/velocity/DispatcherServlet.java @@ -46,7 +46,6 @@ import com.samskivert.servlet.MessageManager; import com.samskivert.servlet.RedirectException; import com.samskivert.servlet.SiteIdentifier; import com.samskivert.servlet.SiteResourceLoader; -import com.samskivert.servlet.util.ExceptionMap; import com.samskivert.servlet.util.FriendlyException; import com.samskivert.util.ConfigUtil; @@ -136,19 +135,7 @@ import com.samskivert.util.StringUtil; * inserted in the future (ie. if I ever want to use this to develop a * cobranded web site). * - *
Error handling
- * The dispatcher servlet provides a common error handling mechanism. The
- * design is to catch any exceptions thrown by the logic and to convert
- * them into friendly error messages that are inserted into the invocation
- * context with the key "error" for easy display in the
- * resulting web page.
- *
- *
The process of mapping exceptions to friendly error messages is - * done using the {@link ExceptionMap} class. Consult its documentation - * for an explanation of how it works. - * * @see Logic - * @see ExceptionMap */ public class DispatcherServlet extends VelocityServlet implements MethodExceptionEventHandler @@ -382,10 +369,7 @@ public class DispatcherServlet extends VelocityServlet errmsg = fe.getMessage(); } catch (Exception e) { - errmsg = ExceptionMap.getMessage(e); - Log.warning("Choked on request [logic=" + logic + - ", req=" + req.getRequestURI() + "]."); - Log.logStackTrace(e); + errmsg = _app.handleException(req, logic, e); } // if we have an error message, insert it into the template