roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r354903 - in /incubator/roller/trunk/src/org/roller/presentation/velocity: BasePageServlet.java FlavorServlet.java LanguageServlet.java PreviewServlet.java
Date Wed, 07 Dec 2005 23:27:55 GMT
Author: agilliland
Date: Wed Dec  7 15:27:45 2005
New Revision: 354903

URL: http://svn.apache.org/viewcvs?rev=354903&view=rev
Log:
taking another stab at some better exception handling and error reporting.

- switched uses of response.setStatus() to response.sendError()
- handleRequest() method now throws IOException because of the call to response.sendError()
- RollerRequest objects are constructed at beginning of servlet and cause a 404 if there is
an exception during construction.


Modified:
    incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/FlavorServlet.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=354903&r1=354902&r2=354903&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java Wed Dec
 7 15:27:45 2005
@@ -58,16 +58,30 @@
      */
     public Template handleRequest(HttpServletRequest request,
                                 HttpServletResponse response, 
-                                Context ctx) {
+                                Context ctx) 
+            throws IOException {
         
         Template outty = null;
+        RollerRequest rreq = null;
         
+        // first off lets parse the incoming request and validate it
         try {
             PageContext pageContext =
                     JspFactory.getDefaultFactory().getPageContext(
                     this, request, response,"", true, 8192, true);
-            // Needed to init request attributes, etc.
-            RollerRequest rreq = RollerRequest.getRollerRequest(pageContext);
+            rreq = RollerRequest.getRollerRequest(pageContext);
+        } catch (RollerException e) {
+            
+            // An error initializing the request is considered to be a 404
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            request.setAttribute("DisplayException", e);
+            
+            return null;
+        }
+        
+        
+        // request appears to be valid, lets render
+        try {
             UserManager userMgr = RollerFactory.getRoller().getUserManager();
             
             WebsiteData website = null;
@@ -128,16 +142,16 @@
             }
             
         } catch(ResourceNotFoundException rnfe ) {
-            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
-            request.setAttribute("DisplayException", rnfe);
             
-            mLogger.error("ResourceNotFound: "+ request.getRequestURL());
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            request.setAttribute("DisplayException", rnfe);
+            mLogger.warn("ResourceNotFound: "+ request.getRequestURL());
             mLogger.debug(rnfe);
-            
         } catch(Exception e) {
-            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            
+            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
             request.setAttribute("DisplayException", e);
-            mLogger.error("EXCEPTION: in RollerServlet", e);
+            mLogger.error("Unexpected exception", e);
         }
         
         return outty;

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/FlavorServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/FlavorServlet.java?rev=354903&r1=354902&r2=354903&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/FlavorServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/FlavorServlet.java Wed Dec
 7 15:27:45 2005
@@ -47,9 +47,11 @@
  * @web.servlet-mapping url-pattern="/flavor/*"
  */
 public class FlavorServlet extends VelocityServlet {
+    
     static final long serialVersionUID = -2720532269434186051L;
     
     private static Log mLogger = LogFactory.getLog(FlavorServlet.class);
+    
     
     public Template handleRequest(HttpServletRequest request,
                                 HttpServletResponse response, 

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=354903&r1=354902&r2=354903&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/LanguageServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/LanguageServlet.java Wed Dec
 7 15:27:45 2005
@@ -5,6 +5,7 @@
  */
 package org.roller.presentation.velocity;
 
+import java.io.IOException;
 import java.util.Locale;
 
 import javax.servlet.ServletConfig;
@@ -65,13 +66,14 @@
         }
     }
     
+    
     /**
      * @see org.roller.presentation.velocity.BasePageServlet#handleRequest(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse, org.apache.velocity.context.Context)
      */
-    public Template handleRequest(
-            HttpServletRequest request,
-            HttpServletResponse response,
-            Context ctx) {
+    public Template handleRequest(HttpServletRequest request,
+                                HttpServletResponse response,
+                                Context ctx) 
+            throws IOException {
         
         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=354903&r1=354902&r2=354903&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/PreviewServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/PreviewServlet.java Wed Dec
 7 15:27:45 2005
@@ -1,4 +1,6 @@
 package org.roller.presentation.velocity;
+
+import java.io.IOException;
 import java.io.StringWriter;
 import org.apache.velocity.Template;
 import org.apache.velocity.context.Context;
@@ -19,6 +21,8 @@
 import org.roller.pojos.UserData;
 import org.roller.pojos.WebsiteData;
 import org.roller.presentation.RollerRequest;
+
+
 /**
  * Allow users to preview what their blog would look like in a given theme.
  *
@@ -28,8 +32,7 @@
  */
 public class PreviewServlet extends BasePageServlet {
     
-    private static Log mLogger =
-            LogFactory.getFactory().getInstance(PreviewServlet.class);
+    private static Log mLogger = LogFactory.getLog(PreviewServlet.class);
     
     
     /**
@@ -38,7 +41,8 @@
      */
     public Template handleRequest( HttpServletRequest request,
                                 HttpServletResponse response,
-                                Context ctx ) {
+                                Context ctx ) 
+            throws IOException {
         
         Theme previewTheme = null;
         
@@ -55,7 +59,7 @@
                 // possibly "custom", but we'll handle that below
             } catch(RollerException re) {
                 
-                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                 request.setAttribute("DisplayException", re);
                 mLogger.error("EXCEPTION: in RollerServlet", re);
             }
@@ -71,13 +75,26 @@
         }
         
         Template outty = null;
+        RollerRequest rreq = null;
         
+        // first off lets parse the incoming request and validate it
         try {
             PageContext pageContext =
                     JspFactory.getDefaultFactory().getPageContext(
                     this, request, response,"", true, 8192, true);
-            // Needed to init request attributes, etc.
-            RollerRequest rreq = RollerRequest.getRollerRequest(pageContext);
+            rreq = RollerRequest.getRollerRequest(pageContext);
+        } catch (RollerException e) {
+            
+            // An error initializing the request is considered to be a 404
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            request.setAttribute("DisplayException", e);
+            
+            return null;
+        }
+        
+        
+        // request appears to be valid, lets render
+        try {
             UserManager userMgr = RollerFactory.getRoller().getUserManager();
             
             WebsiteData website = null;
@@ -108,7 +125,7 @@
             // trying to preview a "custom" theme
             if ( page == null ) {
                 // lets just call it a 404 and return
-                response.sendError(404);
+                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                 return null;
             }
             
@@ -131,16 +148,16 @@
             }
             
         } catch(ResourceNotFoundException rnfe ) {
-            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
-            request.setAttribute("DisplayException", rnfe);
             
-            mLogger.error("ResourceNotFound: "+ request.getRequestURL());
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            request.setAttribute("DisplayException", rnfe);
+            mLogger.warn("ResourceNotFound: "+ request.getRequestURL());
             mLogger.debug(rnfe);
-            
         } catch(Exception e) {
-            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            
+            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
             request.setAttribute("DisplayException", e);
-            mLogger.error("EXCEPTION: in RollerServlet", e);
+            mLogger.error("Unexpected exception", e);
         }
         
         return outty;



Mime
View raw message