roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r354232 - in /incubator/roller/trunk/src/org/roller/presentation/velocity: BasePageServlet.java LanguageServlet.java PreviewServlet.java
Date Tue, 06 Dec 2005 00:02:46 GMT
Author: agilliland
Date: Mon Dec  5 16:02:37 2005
New Revision: 354232

URL: http://svn.apache.org/viewcvs?rev=354232&view=rev
Log:
more detailed exception handling and error reporting for page servlets.


Modified:
    incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/LanguageServlet.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/PreviewServlet.java

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java?rev=354232&r1=354231&r2=354232&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java Mon Dec
 5 16:02:37 2005
@@ -17,8 +17,10 @@
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.context.Context;
+import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
 import org.apache.velocity.servlet.VelocityServlet;
+import org.roller.RollerException;
 import org.roller.model.RollerFactory;
 import org.roller.model.UserManager;
 import org.roller.pojos.WeblogTemplate;
@@ -55,11 +57,10 @@
      * Process a request for a Weblog page.
      */
     public Template handleRequest(HttpServletRequest request,
-                            HttpServletResponse response, Context ctx)
-        throws Exception {
+                                HttpServletResponse response, 
+                                Context ctx) {
         
         Template outty = null;
-        Exception pageException = null;
         
         try {
             PageContext pageContext =
@@ -126,16 +127,19 @@
                 outty = findDecorator(website, (String) ctx.get("decorator"));
             }
             
-        } catch( Exception e ) {
-            pageException = e;
-            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-        }
-        
-        if (pageException != null) {
-            mLogger.error(pageException.getClass() 
+        } catch(ResourceNotFoundException rnfe ) {
+            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+            request.setAttribute("DisplayException", rnfe);
+            
+            mLogger.error(rnfe.getClass().getName() 
                 + " processing URL: " + request.getRequestURL());
-            mLogger.debug(pageException);
-            request.setAttribute("DisplayException", pageException);
+            mLogger.debug(rnfe);
+            
+        } catch(Exception e) {
+            
+            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            request.setAttribute("DisplayException", e);
+            mLogger.error("EXCEPTION: in RollerServlet", e);
         }
         
         return outty;
@@ -147,9 +151,11 @@
      * and populating velocity context.
      */
     protected Template prepareForPageExecution(Context ctx,
-            RollerRequest rreq,
-            HttpServletResponse response,
-            org.roller.pojos.Template page) throws Exception {
+                                            RollerRequest rreq,
+                                            HttpServletResponse response,
+                                            org.roller.pojos.Template page) 
+            
+            throws ResourceNotFoundException, RollerException {
         
         Template outty = null;
         
@@ -164,7 +170,17 @@
         // Made it this far, populate the Context
         ContextLoader.setupContext( ctx, rreq, response );
         
-        return getTemplate( page.getId(), "UTF-8" );
+        try {
+            outty = getTemplate( page.getId(), "UTF-8" );
+        } catch (ResourceNotFoundException ex) {
+            // just rethrow
+            throw ex;
+        } catch (Exception ex) {
+            // wrap this as a roller exception
+            throw new RollerException("Error getting velocity template", ex);
+        }
+        
+        return outty;
     }
     
     
@@ -173,7 +189,7 @@
      * decorator then the default decorator is applied.
      */
     protected Template findDecorator(WebsiteData website, String decorator_name)
-        throws Exception {
+            throws ResourceNotFoundException, RollerException {
         
         Template decorator = null;
         org.roller.pojos.Template decorator_template = null;
@@ -199,7 +215,15 @@
         
         // couldn't find Template, load default "no-op" decorator
         if (decorator == null) {
-            decorator = getTemplate("/themes/noop_decorator.vm", "UTF-8");
+            try {
+                decorator = getTemplate("/themes/noop_decorator.vm", "UTF-8");
+            } catch (ResourceNotFoundException ex) {
+                // just rethrow
+                throw ex;
+            } catch (Exception ex) {
+                // wrap as a RollerException
+                throw new RollerException("error getting no-op decorator", ex);
+            }
         }
         
         return decorator;

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/LanguageServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/LanguageServlet.java?rev=354232&r1=354231&r2=354232&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/LanguageServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/LanguageServlet.java Mon Dec
 5 16:02:37 2005
@@ -74,7 +74,7 @@
 	public Template handleRequest(
 		HttpServletRequest request,
 		HttpServletResponse response,
-		Context ctx) throws Exception
+		Context ctx)
 	{
 		mLogger.debug("Processing language change...");
         ServletContext servletContext = RollerContext.getServletContext();

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/PreviewServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/PreviewServlet.java?rev=354232&r1=354231&r2=354232&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/PreviewServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/PreviewServlet.java Mon Dec
 5 16:02:37 2005
@@ -1,7 +1,4 @@
 package org.roller.presentation.velocity;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 import java.io.StringWriter;
 import org.apache.velocity.Template;
 import org.apache.velocity.context.Context;
@@ -11,6 +8,8 @@
 import javax.servlet.jsp.PageContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.roller.RollerException;
 import org.roller.ThemeNotFoundException;
 import org.roller.model.Roller;
 import org.roller.model.RollerFactory;
@@ -18,10 +17,8 @@
 import org.roller.model.UserManager;
 import org.roller.pojos.Theme;
 import org.roller.pojos.UserData;
-import org.roller.pojos.WeblogTemplate;
 import org.roller.pojos.WebsiteData;
 import org.roller.presentation.RollerRequest;
-
 /**
  * Allow users to preview what their blog would look like in a given theme.
  *
@@ -40,8 +37,8 @@
      * modify the users theme for this request.
      */
     public Template handleRequest( HttpServletRequest request,
-            HttpServletResponse response,
-            Context ctx ) throws Exception {
+                                HttpServletResponse response,
+                                Context ctx ) {
         
         Theme previewTheme = null;
         
@@ -56,6 +53,11 @@
             } catch(ThemeNotFoundException tnfe) {
                 // bogus theme specified ... don't worry about it
                 // possibly "custom", but we'll handle that below
+            } catch(RollerException re) {
+                
+                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+                request.setAttribute("DisplayException", re);
+                mLogger.error("EXCEPTION: in RollerServlet", re);
             }
         }
         
@@ -69,7 +71,6 @@
         }
         
         Template outty = null;
-        Exception pageException = null;
         
         try {
             PageContext pageContext =
@@ -129,14 +130,19 @@
                 outty = findDecorator(tmpWebsite, (String) ctx.get("decorator"));
             }
             
-        } catch( Exception e ) {
-            pageException = e;
-            response.setStatus( HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-        }
-        
-        if (pageException != null) {
-            mLogger.error("EXCEPTION: in RollerServlet", pageException);
-            request.setAttribute("DisplayException", pageException);
+        } catch(ResourceNotFoundException rnfe ) {
+            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+            request.setAttribute("DisplayException", rnfe);
+            
+            mLogger.error(rnfe.getClass().getName() 
+                + " processing URL: " + request.getRequestURL());
+            mLogger.debug(rnfe);
+            
+        } catch(Exception e) {
+            
+            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            request.setAttribute("DisplayException", e);
+            mLogger.error("EXCEPTION: in RollerServlet", e);
         }
         
         return outty;



Mime
View raw message