Author: johnh
Date: Thu Jun 24 01:06:38 2010
New Revision: 957398

URL: http://svn.apache.org/viewvc?rev=957398&view=rev
Log:
Add notion of recoverable error handling.


Modified:
    
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/AccelHandler.java

Modified: 
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/AccelHandler.java
URL: 
http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/AccelHandler.java?rev=957398&r1=957397&r2=957398&view=diff
==============================================================================
--- 
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/AccelHandler.java
 (original)
+++ 
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/AccelHandler.java
 Thu Jun 24 01:06:38 2010
@@ -93,8 +93,10 @@ public class AccelHandler extends ProxyB
     try {
       results = contentRewriterRegistry.rewriteHttpResponse(req, results);
     } catch (RewritingException e) {
-      throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e,
-                                e.getHttpStatusCode());
+      if (!isRecoverable(req, results, e)) {
+        throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, 
e,
+                                  e.getHttpStatusCode());
+      }
     }
 
     // Copy the response headers and status code to the final http servlet
@@ -136,6 +138,28 @@ public class AccelHandler extends ProxyB
   }
 
   /**
+   * Returns true in case the error encountered while rewriting the content
+   * is recoverable. The rationale behind it is that errors should be thrown
+   * only in case of serious grave errors (defined to be un recoverable).
+   * It should always be preferred to handle errors and return the original
+   * content at least.
+   *
+   * TODO: Think through all cases which are recoverable to enforce minimal
+   * possible set of constraints.
+   * TODO: Log the exception and context around it.
+   *
+   * @param req The http request for fetching the resource.
+   * @param results The result of rewriting.
+   * @param exception Exception caught.
+   * @return True if the error is recoverable, false otherwise.
+   */
+  protected boolean isRecoverable(HttpRequest req, HttpResponse results,
+                                  RewritingException exception) {
+    return !(StringUtils.isEmpty(results.getResponseAsString()) &&
+             results.getHeaders() == null);
+  }
+
+  /**
    * Generate a remote content request based on the parameters sent from the 
client.
    * @param request The http request.
    * @param uriToProxyOrRewrite The parsed uri to proxy or rewrite through


Reply via email to