incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r685590 - in /incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp: JspScriptEngineFactory.java jasper/servlet/JspServletWrapper.java
Date Wed, 13 Aug 2008 15:49:09 GMT
Author: cziegeler
Date: Wed Aug 13 08:49:07 2008
New Revision: 685590

URL: http://svn.apache.org/viewvc?rev=685590&view=rev
Log:
SLING-571 ; Apply another patch from Alexander Klimetschek

Modified:
    incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
    incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java

Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java?rev=685590&r1=685589&r2=685590&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
(original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
Wed Aug 13 08:49:07 2008
@@ -27,6 +27,7 @@
 import javax.script.ScriptException;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
 
 import org.apache.sling.api.SlingException;
 import org.apache.sling.api.SlingIOException;
@@ -279,6 +280,25 @@
             if (scriptHelper != null) {
                 try {
                     callJsp(props, scriptHelper);
+                } catch (SlingServletException e) {
+                    // ServletExceptions use getRootCause() instead of getCause(),
+                    // so we have to extract the actual root cause and pass it as
+                    // cause in our new ScriptException
+                    if (e.getCause() != null) {
+                        // SlingServletException always wraps ServletExceptions
+                        ServletException se = (ServletException) e.getCause();
+                        if (se.getRootCause() != null) {
+                            // the ScriptException unfortunately does not accept a Throwable
as cause,
+                            // but only a Exception, so we have to wrap it with a dummy Exception
in Throwable cases
+                            if (se.getRootCause() instanceof Exception) {
+                                throw new BetterScriptException(se.getRootCause().getMessage(),
(Exception) se.getRootCause());
+                            } else {
+                                throw new BetterScriptException(se.getRootCause().getMessage(),
new Exception("Wrapping Throwable: " + se.getRootCause().toString(), se.getRootCause()));
+                            }
+                        }
+                    }
+                    // fallback to standard behaviour
+                    throw new BetterScriptException(e.getMessage(), e);
                 } catch (Exception e) {
                     throw new BetterScriptException(e.getMessage(), e);
                 }

Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java?rev=685590&r1=685589&r2=685590&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
(original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
Wed Aug 13 08:49:07 2008
@@ -482,16 +482,16 @@
      * @return a JasperException with more detailed information
      */
     protected JasperException handleJspException(Exception ex) {
-        try {
-            Throwable realException = ex;
-            if (ex instanceof ServletException) {
-                realException = ((ServletException) ex).getRootCause();
-                // root cause might be null (eg. for a JasperException ex)
-                if (realException == null) {
-                    realException = ex;
-                }
+        Throwable realException = ex;
+        if (ex instanceof ServletException) {
+            realException = ((ServletException) ex).getRootCause();
+            // root cause might be null (eg. for a JasperException ex)
+            if (realException == null) {
+                realException = ex;
             }
+        }
 
+        try {
             // First identify the stack frame in the trace that represents the JSP
             StackTraceElement[] frames = realException.getStackTrace();
             StackTraceElement jspFrame = null;
@@ -506,7 +506,7 @@
             if (jspFrame == null) {
                 // If we couldn't find a frame in the stack trace corresponding
                 // to the generated servlet class, we can't really add anything
-                return new JasperException(ex);
+                return new JasperException(realException);
             }
             else {
                 int javaLineNumber = jspFrame.getLineNumber();
@@ -521,7 +521,7 @@
                 // where in the JSP things went wrong
                 int jspLineNumber = detail.getJspBeginLineNumber();
                 if (jspLineNumber < 1) {
-                    throw new JasperException(ex);
+                    throw new JasperException(realException);
                 }
 
                 if (options.getDisplaySourceFragment()) {
@@ -529,20 +529,20 @@
                             ("jsp.exception", detail.getJspFileName(),
                                     "" + jspLineNumber) +
                                     "\n\n" + detail.getJspExtract() +
-                                    "\n\nStacktrace:", ex);
+                                    "\n\nStacktrace:", realException);
                     
                 } else {
                     return new JasperException(Localizer.getMessage
                             ("jsp.exception", detail.getJspFileName(),
-                                    "" + jspLineNumber), ex);
+                                    "" + jspLineNumber), realException);
                 }
             }
         } catch (Exception je) {
             // If anything goes wrong, just revert to the original behaviour
-            if (ex instanceof JasperException) {
-                return (JasperException) ex;
+            if (realException instanceof JasperException) {
+                return (JasperException) realException;
             } else {
-                return new JasperException(ex);
+                return new JasperException(realException);
             }
         }
     }



Mime
View raw message