use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.
the class JspRuntimeLibrary method handleSetProperty.
public static void handleSetProperty(Object bean, String prop, byte value) throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { new Byte(value) });
} catch (Exception ex) {
throw new JasperException(ex);
}
}
use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.
the class JspCTldLocationsCache method scanJar.
/**
* Scans the given JarURLConnection for TLD files located in META-INF
* (or a subdirectory of it), adding an implicit map entry to the taglib
* map for any TLD that has a <uri> element.
*
* @param conn The JarURLConnection to the JAR file to scan
* @param ignore true if any exceptions raised when processing the given
* JAR should be ignored, false otherwise
*/
private void scanJar(JarURLConnection conn, boolean ignore) throws JasperException {
JarFile jarFile = null;
String resourcePath = conn.getJarFileURL().toString();
try {
if (redeployMode) {
conn.setUseCaches(false);
}
jarFile = conn.getJarFile();
Enumeration entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = (JarEntry) entries.nextElement();
String name = entry.getName();
if (!name.startsWith("META-INF/"))
continue;
if (!name.endsWith(".tld"))
continue;
InputStream stream = jarFile.getInputStream(entry);
try {
String uri = getUriFromTld(resourcePath, stream);
// present in the map
if (uri != null && mappings.get(uri) == null) {
mappings.put(uri, new String[] { resourcePath, name });
}
} finally {
if (stream != null) {
try {
stream.close();
} catch (Throwable t) {
// do nothing
}
}
}
}
} catch (Exception ex) {
if (!redeployMode) {
// if not in redeploy mode, close the jar in case of an error
if (jarFile != null) {
try {
jarFile.close();
} catch (Throwable t) {
// ignore
}
}
}
if (!ignore) {
throw new JasperException(ex);
}
} finally {
if (redeployMode) {
// if in redeploy mode, always close the jar
if (jarFile != null) {
try {
jarFile.close();
} catch (Throwable t) {
// ignore
}
}
}
}
}
use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.
the class JspCTldLocationsCache method init.
private void init() throws JasperException {
if (initialized)
return;
try {
processWebDotXml();
scanJars();
processTldsInFileSystem("/WEB-INF/");
initialized = true;
} catch (Exception ex) {
throw new JasperException(Localizer.getMessage("jsp.error.internal.tldinit", ex.getMessage()));
}
}
use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.
the class JspcMojo method processFile.
private void processFile(final String file) throws JasperException {
try {
final String jspUri = file.replace('\\', '/');
final JspCompilationContext clctxt = new JspCompilationContext(jspUri, false, this, context, rctxt, false);
JasperException error = clctxt.compile();
if (error != null) {
throw error;
}
if (showSuccess) {
getLog().info("Built File: " + file);
}
} catch (final JasperException je) {
Throwable rootCause = je;
while (rootCause instanceof JasperException && ((JasperException) rootCause).getRootCause() != null) {
rootCause = ((JasperException) rootCause).getRootCause();
}
if (rootCause != je) {
getLog().error("General problem compiling " + file, rootCause);
}
// Bugzilla 35114.
if (failOnError) {
throw je;
}
// just log otherwise
getLog().error(je.getMessage());
} catch (Exception e) {
throw new JasperException(e);
}
}
use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.
the class JspServletWrapper method handleJspExceptionInternal.
/**
* Returns only a ServletException or a SlingException
*/
private Exception handleJspExceptionInternal(final Exception ex) throws ServletException {
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
StackTraceElement[] frames = realException.getStackTrace();
StackTraceElement jspFrame = null;
for (int i = 0; i < frames.length; ++i) {
if (frames[i].getClassName().equals(this.theServlet.getClass().getName())) {
jspFrame = frames[i];
break;
}
}
if (jspFrame == null) {
// to the generated servlet class, we can't really add anything
if (ex instanceof ServletException) {
return ex;
}
return new SlingException(ex) {
};
}
int javaLineNumber = jspFrame.getLineNumber();
JavacErrorDetail detail = ErrorDispatcher.createJavacError(jspFrame.getMethodName(), this.ctxt.getCompiler().getPageNodes(), null, javaLineNumber, ctxt);
// If the line number is less than one we couldn't find out
// where in the JSP things went wrong
int jspLineNumber = detail.getJspBeginLineNumber();
if (jspLineNumber < 1) {
if (realException instanceof ServletException) {
return (ServletException) realException;
}
return new SlingException(exMessage, realException);
}
if (options.getDisplaySourceFragment() && detail.getJspExtract() != null) {
return new SlingException(Localizer.getMessage("jsp.exception", detail.getJspFileName(), "" + jspLineNumber) + "\n\n" + detail.getJspExtract() + "\n", realException);
}
return new SlingException(Localizer.getMessage("jsp.exception", detail.getJspFileName(), "" + jspLineNumber), realException);
} catch (final Exception je) {
// If anything goes wrong, just revert to the original behaviour
if (realException instanceof ServletException) {
return (ServletException) realException;
}
return new SlingException(exMessage, realException);
}
}
Aggregations