Search in sources :

Example 16 with JasperException

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

the class JspRuntimeLibrary method handleSetProperty.

public static void handleSetProperty(Object bean, String prop, Object value) throws JasperException {
    try {
        Method method = getWriteMethod(bean.getClass(), prop);
        method.invoke(bean, new Object[] { value });
    } catch (Exception ex) {
        Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
        ExceptionUtils.handleThrowable(thr);
        throw new JasperException(ex);
    }
}
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 17 with JasperException

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

the class JspRuntimeLibrary method createTypedArray.

// __end toStringMethod
/**
     * Create a typed array.
     * This is a special case where params are passed through
     * the request and the property is indexed.
     * @param propertyName The property name
     * @param bean The bean
     * @param method The method
     * @param values Array values
     * @param t The class
     * @param propertyEditorClass The editor for the property
     * @throws JasperException An error occurred
     */
public static void createTypedArray(String propertyName, Object bean, Method method, String[] values, Class<?> t, Class<?> propertyEditorClass) throws JasperException {
    try {
        if (propertyEditorClass != null) {
            Object[] tmpval = new Integer[values.length];
            for (int i = 0; i < values.length; i++) {
                tmpval[i] = getValueFromBeanInfoPropertyEditor(t, propertyName, values[i], propertyEditorClass);
            }
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(Integer.class)) {
            Integer[] tmpval = new Integer[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Integer.valueOf(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(Byte.class)) {
            Byte[] tmpval = new Byte[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Byte.valueOf(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(Boolean.class)) {
            Boolean[] tmpval = new Boolean[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Boolean.valueOf(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(Short.class)) {
            Short[] tmpval = new Short[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Short.valueOf(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(Long.class)) {
            Long[] tmpval = new Long[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Long.valueOf(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(Double.class)) {
            Double[] tmpval = new Double[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Double.valueOf(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(Float.class)) {
            Float[] tmpval = new Float[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Float.valueOf(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(Character.class)) {
            Character[] tmpval = new Character[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Character.valueOf(values[i].charAt(0));
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(int.class)) {
            int[] tmpval = new int[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Integer.parseInt(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(byte.class)) {
            byte[] tmpval = new byte[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Byte.parseByte(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(boolean.class)) {
            boolean[] tmpval = new boolean[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Boolean.parseBoolean(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(short.class)) {
            short[] tmpval = new short[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Short.parseShort(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(long.class)) {
            long[] tmpval = new long[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Long.parseLong(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(double.class)) {
            double[] tmpval = new double[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Double.parseDouble(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(float.class)) {
            float[] tmpval = new float[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = Float.parseFloat(values[i]);
            method.invoke(bean, new Object[] { tmpval });
        } else if (t.equals(char.class)) {
            char[] tmpval = new char[values.length];
            for (int i = 0; i < values.length; i++) tmpval[i] = values[i].charAt(0);
            method.invoke(bean, new Object[] { tmpval });
        } else {
            Object[] tmpval = new Integer[values.length];
            for (int i = 0; i < values.length; i++) {
                tmpval[i] = getValueFromPropertyEditorManager(t, propertyName, values[i]);
            }
            method.invoke(bean, new Object[] { tmpval });
        }
    } catch (Exception ex) {
        Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
        ExceptionUtils.handleThrowable(thr);
        throw new JasperException("error in invoking method", ex);
    }
}
Also used : ServletException(javax.servlet.ServletException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) JasperException(org.apache.jasper.JasperException) JasperException(org.apache.jasper.JasperException)

Example 18 with JasperException

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

the class JspRuntimeLibrary method handleSetProperty.

public static void handleSetProperty(Object bean, String prop, int value) throws JasperException {
    try {
        Method method = getWriteMethod(bean.getClass(), prop);
        method.invoke(bean, new Object[] { Integer.valueOf(value) });
    } catch (Exception ex) {
        Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
        ExceptionUtils.handleThrowable(thr);
        throw new JasperException(ex);
    }
}
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 19 with JasperException

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

the class Parser method parseCustomTag.

/*
     * # '<' CustomAction CustomActionBody
     *
     * CustomAction ::= TagPrefix ':' CustomActionName
     *
     * TagPrefix ::= Name
     *
     * CustomActionName ::= Name
     *
     * CustomActionBody ::= ( Attributes CustomActionEnd ) | <TRANSLATION_ERROR>
     *
     * Attributes ::= ( S Attribute )* S?
     *
     * CustomActionEnd ::= CustomActionTagDependent | CustomActionJSPContent |
     * CustomActionScriptlessContent
     *
     * CustomActionTagDependent ::= TagDependentOptionalBody
     *
     * CustomActionJSPContent ::= OptionalBody
     *
     * CustomActionScriptlessContent ::= ScriptlessOptionalBody
     */
// tagFileInfo can't be null after initial test
@SuppressWarnings("null")
private boolean parseCustomTag(Node parent) throws JasperException {
    if (reader.peekChar() != '<') {
        return false;
    }
    // Parse 'CustomAction' production (tag prefix and custom action name)
    // skip '<'
    reader.nextChar();
    String tagName = reader.parseToken(false);
    int i = tagName.indexOf(':');
    if (i == -1) {
        reader.reset(start);
        return false;
    }
    String prefix = tagName.substring(0, i);
    String shortTagName = tagName.substring(i + 1);
    // Check if this is a user-defined tag.
    String uri = pageInfo.getURI(prefix);
    if (uri == null) {
        if (pageInfo.isErrorOnUndeclaredNamespace()) {
            err.jspError(start, "jsp.error.undeclared_namespace", prefix);
        } else {
            reader.reset(start);
            // Remember the prefix for later error checking
            pageInfo.putNonCustomTagPrefix(prefix, reader.mark());
            return false;
        }
    }
    TagLibraryInfo tagLibInfo = pageInfo.getTaglib(uri);
    TagInfo tagInfo = tagLibInfo.getTag(shortTagName);
    TagFileInfo tagFileInfo = tagLibInfo.getTagFile(shortTagName);
    if (tagInfo == null && tagFileInfo == null) {
        err.jspError(start, "jsp.error.bad_tag", shortTagName, prefix);
    }
    Class<?> tagHandlerClass = null;
    if (tagInfo != null) {
        // Must be a classic tag, load it here.
        // tag files will be loaded later, in TagFileProcessor
        String handlerClassName = tagInfo.getTagClassName();
        try {
            tagHandlerClass = ctxt.getClassLoader().loadClass(handlerClassName);
        } catch (Exception e) {
            err.jspError(start, "jsp.error.loadclass.taghandler", handlerClassName, tagName);
        }
    }
    // Parse 'CustomActionBody' production:
    // At this point we are committed - if anything fails, we produce
    // a translation error.
    // Parse 'Attributes' production:
    Attributes attrs = parseAttributes();
    reader.skipSpaces();
    // Parse 'CustomActionEnd' production:
    if (reader.matches("/>")) {
        if (tagInfo != null) {
            @SuppressWarnings("unused") Node unused = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagHandlerClass);
        } else {
            @SuppressWarnings("unused") Node unused = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagFileInfo);
        }
        return true;
    }
    // Now we parse one of 'CustomActionTagDependent',
    // 'CustomActionJSPContent', or 'CustomActionScriptlessContent'.
    // depending on body-content in TLD.
    // Looking for a body, it still can be empty; but if there is a
    // a tag body, its syntax would be dependent on the type of
    // body content declared in the TLD.
    String bc;
    if (tagInfo != null) {
        bc = tagInfo.getBodyContent();
    } else {
        bc = tagFileInfo.getTagInfo().getBodyContent();
    }
    Node tagNode = null;
    if (tagInfo != null) {
        tagNode = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagHandlerClass);
    } else {
        tagNode = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagFileInfo);
    }
    parseOptionalBody(tagNode, tagName, bc);
    return true;
}
Also used : TagFileInfo(javax.servlet.jsp.tagext.TagFileInfo) TagInfo(javax.servlet.jsp.tagext.TagInfo) Attributes(org.xml.sax.Attributes) TagLibraryInfo(javax.servlet.jsp.tagext.TagLibraryInfo) FileNotFoundException(java.io.FileNotFoundException) JasperException(org.apache.jasper.JasperException)

Example 20 with JasperException

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

the class JspServletWrapper method service.

public void service(HttpServletRequest request, HttpServletResponse response, boolean precompile) throws ServletException, IOException, FileNotFoundException {
    Servlet servlet;
    try {
        if (ctxt.isRemoved()) {
            throw new FileNotFoundException(jspUri);
        }
        if ((available > 0L) && (available < Long.MAX_VALUE)) {
            if (available > System.currentTimeMillis()) {
                response.setDateHeader("Retry-After", available);
                response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, Localizer.getMessage("jsp.error.unavailable"));
                return;
            }
            // Wait period has expired. Reset.
            available = 0;
        }
        /*
             * (1) Compile
             */
        if (options.getDevelopment() || firstTime) {
            synchronized (this) {
                firstTime = false;
                // The following sets reload to true, if necessary
                ctxt.compile();
            }
        } else {
            if (compileException != null) {
                // Throw cached compilation exception
                throw compileException;
            }
        }
        /*
             * (2) (Re)load servlet class file
             */
        servlet = getServlet();
        // If a page is to be precompiled only, return.
        if (precompile) {
            return;
        }
    } catch (ServletException ex) {
        if (options.getDevelopment()) {
            throw handleJspException(ex);
        }
        throw ex;
    } catch (FileNotFoundException fnfe) {
        // File has been removed. Let caller handle this.
        throw fnfe;
    } catch (IOException ex) {
        if (options.getDevelopment()) {
            throw handleJspException(ex);
        }
        throw ex;
    } catch (IllegalStateException ex) {
        if (options.getDevelopment()) {
            throw handleJspException(ex);
        }
        throw ex;
    } catch (Exception ex) {
        if (options.getDevelopment()) {
            throw handleJspException(ex);
        }
        throw new JasperException(ex);
    }
    try {
        /*
             * (3) Handle limitation of number of loaded Jsps
             */
        if (unloadAllowed) {
            synchronized (this) {
                if (unloadByCount) {
                    if (unloadHandle == null) {
                        unloadHandle = ctxt.getRuntimeContext().push(this);
                    } else if (lastUsageTime < ctxt.getRuntimeContext().getLastJspQueueUpdate()) {
                        ctxt.getRuntimeContext().makeYoungest(unloadHandle);
                        lastUsageTime = System.currentTimeMillis();
                    }
                } else {
                    if (lastUsageTime < ctxt.getRuntimeContext().getLastJspQueueUpdate()) {
                        lastUsageTime = System.currentTimeMillis();
                    }
                }
            }
        }
        /*
             * (4) Service request
             */
        if (servlet instanceof SingleThreadModel) {
            // of the page is determined right before servicing
            synchronized (this) {
                servlet.service(request, response);
            }
        } else {
            servlet.service(request, response);
        }
    } catch (UnavailableException ex) {
        String includeRequestUri = (String) request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);
        if (includeRequestUri != null) {
            // servlet engine.
            throw ex;
        }
        int unavailableSeconds = ex.getUnavailableSeconds();
        if (unavailableSeconds <= 0) {
            // Arbitrary default
            unavailableSeconds = 60;
        }
        available = System.currentTimeMillis() + (unavailableSeconds * 1000L);
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, ex.getMessage());
    } catch (ServletException ex) {
        if (options.getDevelopment()) {
            throw handleJspException(ex);
        }
        throw ex;
    } catch (IOException ex) {
        if (options.getDevelopment()) {
            throw new IOException(handleJspException(ex).getMessage(), ex);
        }
        throw ex;
    } catch (IllegalStateException ex) {
        if (options.getDevelopment()) {
            throw handleJspException(ex);
        }
        throw ex;
    } catch (Exception ex) {
        if (options.getDevelopment()) {
            throw handleJspException(ex);
        }
        throw new JasperException(ex);
    }
}
Also used : ServletException(javax.servlet.ServletException) JasperException(org.apache.jasper.JasperException) FileNotFoundException(java.io.FileNotFoundException) UnavailableException(javax.servlet.UnavailableException) Servlet(javax.servlet.Servlet) IOException(java.io.IOException) SingleThreadModel(javax.servlet.SingleThreadModel) ServletException(javax.servlet.ServletException) JasperException(org.apache.jasper.JasperException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnavailableException(javax.servlet.UnavailableException)

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