Search in sources :

Example 21 with JasperException

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);
    }
}
Also used : JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) Method(java.lang.reflect.Method) PrivilegedActionException(java.security.PrivilegedActionException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Example 22 with JasperException

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
                }
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) InputStream(java.io.InputStream) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) MalformedURLException(java.net.MalformedURLException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Example 23 with JasperException

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()));
    }
}
Also used : JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) MalformedURLException(java.net.MalformedURLException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Example 24 with JasperException

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);
    }
}
Also used : JspCompilationContext(org.apache.sling.scripting.jsp.jasper.JspCompilationContext) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException)

Example 25 with JasperException

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) SlingServletException(org.apache.sling.api.SlingServletException) JavacErrorDetail(org.apache.sling.scripting.jsp.jasper.compiler.JavacErrorDetail) ScriptEvaluationException(org.apache.sling.api.scripting.ScriptEvaluationException) SlingException(org.apache.sling.api.SlingException) ServletException(javax.servlet.ServletException) SlingServletException(org.apache.sling.api.SlingServletException) SlingException(org.apache.sling.api.SlingException) IOException(java.io.IOException) SlingIOException(org.apache.sling.api.SlingIOException) UnavailableException(javax.servlet.UnavailableException) ScriptEvaluationException(org.apache.sling.api.scripting.ScriptEvaluationException) SlingPageException(org.apache.sling.scripting.jsp.SlingPageException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Aggregations

JasperException (org.apache.sling.scripting.jsp.jasper.JasperException)42 IOException (java.io.IOException)31 ServletException (javax.servlet.ServletException)19 PrivilegedActionException (java.security.PrivilegedActionException)17 Method (java.lang.reflect.Method)14 FileNotFoundException (java.io.FileNotFoundException)9 MalformedURLException (java.net.MalformedURLException)6 Iterator (java.util.Iterator)6 InputStream (java.io.InputStream)5 JarFile (java.util.jar.JarFile)5 TagInfo (javax.servlet.jsp.tagext.TagInfo)4 TreeNode (org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode)4 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 SAXException (org.xml.sax.SAXException)3 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 Enumeration (java.util.Enumeration)2 HashMap (java.util.HashMap)2