Author: cziegeler
Date: Sun Feb 22 17:37:11 2009
New Revision: 746782
URL: http://svn.apache.org/viewvc?rev=746782&view=rev
Log:
SLING-571 : Apply patch from Alexander Klimetschek.
Modified:
incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/DefaultErrorHandler.java
incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
Modified:
incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java?rev=746782&r1=746781&r2=746782&view=diff
==============================================================================
---
incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
(original)
+++
incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
Sun Feb 22 17:37:11 2009
@@ -43,6 +43,7 @@
import org.apache.sling.scripting.jsp.jasper.Options;
import org.apache.sling.scripting.jsp.jasper.compiler.JspRuntimeContext;
import org.apache.sling.scripting.jsp.jasper.runtime.JspApplicationContextImpl;
+import org.apache.sling.scripting.jsp.util.TagUtil;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -354,15 +355,14 @@
// 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()));
- }
+ Throwable rootCause =
TagUtil.getRootCause((ServletException) e.getCause());
+ // 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 (rootCause instanceof Exception) {
+ throw new
BetterScriptException(rootCause.toString(), (Exception) rootCause);
+ } else {
+ throw new
BetterScriptException(rootCause.toString(),
+ new Exception("Wrapping Throwable: " +
rootCause.toString(), rootCause));
}
}
Modified:
incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/DefaultErrorHandler.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/DefaultErrorHandler.java?rev=746782&r1=746781&r2=746782&view=diff
==============================================================================
---
incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/DefaultErrorHandler.java
(original)
+++
incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/DefaultErrorHandler.java
Sun Feb 22 17:37:11 2009
@@ -88,7 +88,7 @@
buf.append(details[i].getErrorMessage());
}
}
- buf.append("\n\nStacktrace:");
+ //buf.append("\n\nStacktrace:");
throw new JasperException(
Localizer.getMessage("jsp.error.unable.compile") + ": " + buf);
}
Modified:
incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java?rev=746782&r1=746781&r2=746782&view=diff
==============================================================================
---
incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
(original)
+++
incubator/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
Sun Feb 22 17:37:11 2009
@@ -33,6 +33,7 @@
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
+import org.apache.sling.api.scripting.ScriptEvaluationException;
import org.apache.sling.scripting.jsp.jasper.JasperException;
import org.apache.sling.scripting.jsp.jasper.JspCompilationContext;
import org.apache.sling.scripting.jsp.jasper.Options;
@@ -483,13 +484,21 @@
*/
protected JasperException handleJspException(Exception ex) {
Throwable realException = ex;
+ String exMessage = "";
if (ex instanceof ServletException) {
realException = ((ServletException) ex).getRootCause();
// root cause might be null (eg. for a JasperException ex)
if (realException == null) {
realException = ex;
+ } else {
+ exMessage = ex.toString();
}
}
+
+ // avoid nested ScriptEvaluationExceptions (eg. in nested jsp includes)
+ while (realException instanceof ScriptEvaluationException) {
+ realException = realException.getCause();
+ }
try {
// First identify the stack frame in the trace that represents the
JSP
@@ -506,7 +515,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(realException);
+ return new JasperException(exMessage, realException);
}
else {
int javaLineNumber = jspFrame.getLineNumber();
@@ -521,7 +530,7 @@
// where in the JSP things went wrong
int jspLineNumber = detail.getJspBeginLineNumber();
if (jspLineNumber < 1) {
- throw new JasperException(realException);
+ return new JasperException(exMessage, realException);
}
if (options.getDisplaySourceFragment()) {
@@ -529,7 +538,7 @@
("jsp.exception", detail.getJspFileName(),
"" + jspLineNumber) +
"\n\n" + detail.getJspExtract() +
- "\n\nStacktrace:", realException);
+ "\n", realException);
} else {
return new JasperException(Localizer.getMessage
@@ -542,7 +551,7 @@
if (realException instanceof JasperException) {
return (JasperException) realException;
} else {
- return new JasperException(realException);
+ return new JasperException(exMessage, realException);
}
}
}