Search in sources :

Example 26 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class JspRuntimeLibrary method getReadMethod.

public static Method getReadMethod(Class<?> beanClass, String prop) throws JasperException {
    Method method = null;
    Class<?> type = null;
    try {
        java.beans.BeanInfo info = java.beans.Introspector.getBeanInfo(beanClass);
        if (info != null) {
            java.beans.PropertyDescriptor[] pd = info.getPropertyDescriptors();
            for (int i = 0; i < pd.length; i++) {
                if (pd[i].getName().equals(prop)) {
                    method = pd[i].getReadMethod();
                    type = pd[i].getPropertyType();
                    break;
                }
            }
        } else {
            // just in case introspection silently fails.
            throw new JasperException(Localizer.getMessage("jsp.error.beans.nobeaninfo", beanClass.getName()));
        }
    } catch (Exception ex) {
        throw new JasperException(ex);
    }
    if (method == null) {
        if (type == null) {
            throw new JasperException(Localizer.getMessage("jsp.error.beans.noproperty", prop, beanClass.getName()));
        } else {
            throw new JasperException(Localizer.getMessage("jsp.error.beans.nomethod", prop, beanClass.getName()));
        }
    }
    return method;
}
Also used : JasperException(org.apache.jasper.JasperException) Method(java.lang.reflect.Method) ServletException(javax.servlet.ServletException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) JasperException(org.apache.jasper.JasperException)

Example 27 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class JspServletWrapper method getServlet.

public Servlet getServlet() throws ServletException {
    // new servlet object is read consistently)
    if (reload) {
        synchronized (this) {
            // of different pages, but not the same page.
            if (reload) {
                // This is to maintain the original protocol.
                destroy();
                final Servlet servlet;
                try {
                    InstanceManager instanceManager = InstanceManagerFactory.getInstanceManager(config);
                    servlet = (Servlet) instanceManager.newInstance(ctxt.getFQCN(), ctxt.getJspLoader());
                } catch (Exception e) {
                    Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
                    ExceptionUtils.handleThrowable(t);
                    throw new JasperException(t);
                }
                servlet.init(config);
                if (!firstTime) {
                    ctxt.getRuntimeContext().incrementJspReloadCount();
                }
                theServlet = servlet;
                reload = false;
            // Volatile 'reload' forces in order write of 'theServlet' and new servlet object
            }
        }
    }
    return theServlet;
}
Also used : JasperException(org.apache.jasper.JasperException) InstanceManager(org.apache.tomcat.InstanceManager) Servlet(javax.servlet.Servlet) ServletException(javax.servlet.ServletException) JasperException(org.apache.jasper.JasperException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnavailableException(javax.servlet.UnavailableException)

Example 28 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class JspServletWrapper method handleJspException.

/**
     * <p>Attempts to construct a JasperException that contains helpful information
     * about what went wrong. Uses the JSP compiler system to translate the line
     * number in the generated servlet that originated the exception to a line
     * number in the JSP.  Then constructs an exception containing that
     * information, and a snippet of the JSP to help debugging.
     * Please see http://bz.apache.org/bugzilla/show_bug.cgi?id=37062 and
     * http://www.tfenne.com/jasper/ for more details.
     *</p>
     *
     * @param ex the exception that was the cause of the problem.
     * @return a JasperException with more detailed information
     */
protected JasperException handleJspException(Exception ex) {
    try {
        Throwable realException = ex;
        if (ex instanceof ServletException) {
            realException = ((ServletException) ex).getRootCause();
        }
        // 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.getServlet().getClass().getName())) {
                jspFrame = frames[i];
                break;
            }
        }
        if (jspFrame == null || this.ctxt.getCompiler().getPageNodes() == null) {
            // parsed JSP to hand, we can't really add anything
            return new JasperException(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) {
            throw new JasperException(ex);
        }
        if (options.getDisplaySourceFragment()) {
            return new JasperException(Localizer.getMessage("jsp.exception", detail.getJspFileName(), "" + jspLineNumber) + System.lineSeparator() + System.lineSeparator() + detail.getJspExtract() + System.lineSeparator() + System.lineSeparator() + "Stacktrace:", ex);
        }
        return new JasperException(Localizer.getMessage("jsp.exception", detail.getJspFileName(), "" + jspLineNumber), ex);
    } catch (Exception je) {
        // If anything goes wrong, just revert to the original behaviour
        if (ex instanceof JasperException) {
            return (JasperException) ex;
        }
        return new JasperException(ex);
    }
}
Also used : ServletException(javax.servlet.ServletException) JavacErrorDetail(org.apache.jasper.compiler.JavacErrorDetail) JasperException(org.apache.jasper.JasperException) ServletException(javax.servlet.ServletException) JasperException(org.apache.jasper.JasperException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnavailableException(javax.servlet.UnavailableException)

Example 29 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class SmapUtil method generateSmap.

//*********************************************************************
// Public entry points
/**
     * Generates an appropriate SMAP representing the current compilation
     * context.  (JSR-045.)
     *
     * @param ctxt Current compilation context
     * @param pageNodes The current JSP page
     * @return a SMAP for the page
     * @throws IOException Error writing SMAP
     */
public static String[] generateSmap(JspCompilationContext ctxt, Node.Nodes pageNodes) throws IOException {
    // Scan the nodes for presence of Jasper generated inner classes
    PreScanVisitor psVisitor = new PreScanVisitor();
    try {
        pageNodes.visit(psVisitor);
    } catch (JasperException ex) {
    }
    HashMap<String, SmapStratum> map = psVisitor.getMap();
    // set up our SMAP generator
    SmapGenerator g = new SmapGenerator();
    /** Disable reading of input SMAP because:
            1. There is a bug here: getRealPath() is null if .jsp is in a jar
               Bugzilla 14660.
            2. Mappings from other sources into .jsp files are not supported.
            TODO: fix 1. if 2. is not true.
        // determine if we have an input SMAP
        String smapPath = inputSmapPath(ctxt.getRealPath(ctxt.getJspFile()));
            File inputSmap = new File(smapPath);
            if (inputSmap.exists()) {
                byte[] embeddedSmap = null;
            byte[] subSmap = SDEInstaller.readWhole(inputSmap);
            String subSmapString = new String(subSmap, SMAP_ENCODING);
            g.addSmap(subSmapString, "JSP");
        }
        **/
    // now, assemble info about our own stratum (JSP) using JspLineMap
    SmapStratum s = new SmapStratum("JSP");
    g.setOutputFileName(unqualify(ctxt.getServletJavaFileName()));
    // Map out Node.Nodes
    evaluateNodes(pageNodes, s, map, ctxt.getOptions().getMappedFile());
    s.optimizeLineSection();
    g.addStratum(s, true);
    if (ctxt.getOptions().isSmapDumped()) {
        File outSmap = new File(ctxt.getClassFileName() + ".smap");
        PrintWriter so = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outSmap), SMAP_ENCODING));
        so.print(g.getString());
        so.close();
    }
    String classFileName = ctxt.getClassFileName();
    int innerClassCount = map.size();
    String[] smapInfo = new String[2 + innerClassCount * 2];
    smapInfo[0] = classFileName;
    smapInfo[1] = g.getString();
    int count = 2;
    Iterator<Map.Entry<String, SmapStratum>> iter = map.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry<String, SmapStratum> entry = iter.next();
        String innerClass = entry.getKey();
        s = entry.getValue();
        s.optimizeLineSection();
        g = new SmapGenerator();
        g.setOutputFileName(unqualify(ctxt.getServletJavaFileName()));
        g.addStratum(s, true);
        String innerClassFileName = classFileName.substring(0, classFileName.indexOf(".class")) + '$' + innerClass + ".class";
        if (ctxt.getOptions().isSmapDumped()) {
            File outSmap = new File(innerClassFileName + ".smap");
            PrintWriter so = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outSmap), SMAP_ENCODING));
            so.print(g.getString());
            so.close();
        }
        smapInfo[count] = innerClassFileName;
        smapInfo[count + 1] = g.getString();
        count += 2;
    }
    return smapInfo;
}
Also used : JasperException(org.apache.jasper.JasperException) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 30 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class TagLibraryInfoImpl method createValidator.

private TagLibraryValidator createValidator(ValidatorXml validatorXml) throws JasperException {
    if (validatorXml == null) {
        return null;
    }
    String validatorClass = validatorXml.getValidatorClass();
    if (validatorClass == null || validatorClass.isEmpty()) {
        return null;
    }
    Map<String, Object> initParams = new Hashtable<>();
    initParams.putAll(validatorXml.getInitParams());
    try {
        Class<?> tlvClass = ctxt.getClassLoader().loadClass(validatorClass);
        TagLibraryValidator tlv = (TagLibraryValidator) tlvClass.newInstance();
        tlv.setInitParameters(initParams);
        return tlv;
    } catch (Exception e) {
        err.jspError(e, "jsp.error.tlvclass.instantiation", validatorClass);
        return null;
    }
}
Also used : Hashtable(java.util.Hashtable) TagLibraryValidator(javax.servlet.jsp.tagext.TagLibraryValidator) URISyntaxException(java.net.URISyntaxException) JasperException(org.apache.jasper.JasperException) IOException(java.io.IOException)

Aggregations

JasperException (org.apache.jasper.JasperException)37 IOException (java.io.IOException)29 ServletException (javax.servlet.ServletException)20 JspException (javax.servlet.jsp.JspException)17 Method (java.lang.reflect.Method)14 FileNotFoundException (java.io.FileNotFoundException)7 File (java.io.File)3 HashMap (java.util.HashMap)3 UnavailableException (javax.servlet.UnavailableException)3 TagInfo (javax.servlet.jsp.tagext.TagInfo)3 SAXException (org.xml.sax.SAXException)3 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 Map (java.util.Map)2 Servlet (javax.servlet.Servlet)2 TagFileInfo (javax.servlet.jsp.tagext.TagFileInfo)2 Result (com.sun.enterprise.tools.verifier.Result)1 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)1