Search in sources :

Example 1 with ErrorPageDescriptor

use of org.glassfish.web.deployment.descriptor.ErrorPageDescriptor in project Payara by payara.

the class WebArchiveClassesLoadable method getClassNames.

/**
 * Looks for Servlet classes, ServletFilter classes, Listener classes and
 * Exception classes in the webBundleDescriptor. The closure is computed
 * starting from these classes.
 * @param descriptor
 * @return returns a list of class names in the form that can be used in
 * classloader.load()
 * @throws Exception
 */
private List getClassNames(WebBundleDescriptor descriptor) throws Exception {
    final List<String> results = new LinkedList<String>();
    for (Object obj : descriptor.getServletDescriptors()) {
        String servletClassName = (WebComponentDescriptor.class.cast(obj)).getWebComponentImplementation();
        results.add(servletClassName);
    }
    for (Object obj : descriptor.getServletFilterDescriptors()) {
        String filterClassName = (ServletFilter.class.cast(obj)).getClassName();
        results.add(filterClassName);
    }
    for (Object obj : descriptor.getAppListenerDescriptors()) {
        String listenerClassName = (AppListenerDescriptor.class.cast(obj)).getListener();
        results.add(listenerClassName);
    }
    results.addAll(getVerifierContext().getFacesConfigDescriptor().getManagedBeanClasses());
    Enumeration en = ((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors();
    while (en.hasMoreElements()) {
        ErrorPageDescriptor errorPageDescriptor = (ErrorPageDescriptor) en.nextElement();
        String exceptionType = errorPageDescriptor.getExceptionType();
        if (exceptionType != null && !exceptionType.equals(""))
            results.add(exceptionType);
    }
    File file = getVerifierContext().getOutDir();
    if (!file.exists())
        return results;
    FileArchive arch = new FileArchive();
    arch.open(file.toURI());
    Enumeration entries = arch.entries();
    while (entries.hasMoreElements()) {
        String name = (String) entries.nextElement();
        if (name.startsWith("org/apache/jsp") && name.endsWith(".class"))
            results.add(name.substring(0, name.lastIndexOf(".")).replace('/', '.'));
    }
    return results;
}
Also used : WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) ErrorPageDescriptor(org.glassfish.web.deployment.descriptor.ErrorPageDescriptor) File(java.io.File)

Example 2 with ErrorPageDescriptor

use of org.glassfish.web.deployment.descriptor.ErrorPageDescriptor in project Payara by payara.

the class Location method check.

/**
 * Location element contains the location of the resource in the web
 * application
 *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors().hasMoreElements()) {
        boolean oneFailed = false;
        boolean foundIt = false;
        // ZipEntry ze = null;
        // JarFile jar =null;
        FileArchive arch = null;
        // get the errorpage's in this .war
        for (Enumeration e = ((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors(); e.hasMoreElements(); ) {
            foundIt = false;
            ErrorPageDescriptor errorpage = (ErrorPageDescriptor) e.nextElement();
            String location = errorpage.getLocation();
            String uri = null;
            try {
                // File f = Verifier.getArchiveFile(descriptor.getModuleDescriptor().getArchiveUri());
                // if(f==null){
                uri = getAbstractArchiveUri(descriptor);
                try {
                    arch = new FileArchive();
                    arch.open(uri);
                } catch (IOException ioe) {
                    throw ioe;
                }
                // }
                if (location.startsWith("/"))
                    location = location.substring(1);
                // if (f!=null){
                // ze = jar.getEntry(location);
                // foundIt = (ze != null);
                // }
                // else{
                File loc = new File(new File(arch.getURI()), location);
                if (loc.exists())
                    foundIt = true;
                loc = null;
            // }
            // if (jar!=null)
            // jar.close();
            } catch (Exception ex) {
                if (!oneFailed) {
                    oneFailed = true;
                }
            }
            if (foundIt) {
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Location [ {0} ] contains the location of the resource within web application [ {1} ]", new Object[] { location, descriptor.getName() }));
            } else {
                if (!oneFailed) {
                    oneFailed = true;
                }
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Location [ {0} ] is not found within [ {1} ] or does not contain the location of the resource within web application [ {2} ]", new Object[] { location, uri, descriptor.getName() }));
            }
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else {
            result.setStatus(Result.PASSED);
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no location elements within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) ErrorPageDescriptor(org.glassfish.web.deployment.descriptor.ErrorPageDescriptor)

Example 3 with ErrorPageDescriptor

use of org.glassfish.web.deployment.descriptor.ErrorPageDescriptor in project Payara by payara.

the class ErrorCode method check.

/**
 * Error code element contains an HTTP error code within web application test.
 *  i.e. 404
 *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors().hasMoreElements()) {
        boolean oneFailed = false;
        boolean foundIt = false;
        int oneErrorCode = 0;
        int oneNA = 0;
        // get the errorpage's in this .war
        for (Enumeration e = ((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors(); e.hasMoreElements(); ) {
            foundIt = false;
            oneErrorCode++;
            ErrorPageDescriptor errorpage = (ErrorPageDescriptor) e.nextElement();
            String exceptionType = errorpage.getExceptionType();
            if (!((exceptionType != null) && (exceptionType.length() > 0))) {
                Integer errorCode = new Integer(errorpage.getErrorCode());
                if (isValidErrorCode(errorCode)) {
                    foundIt = true;
                } else {
                    foundIt = false;
                }
                if (foundIt) {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Error code [ {0} ] contains valid HTTP error code within web application [ {1} ]", new Object[] { errorCode.toString(), descriptor.getName() }));
                } else {
                    if (!oneFailed) {
                        oneFailed = true;
                    }
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: error-code [ {0} ] does not contain valid HTTP error code within web application [ {1} ]", new Object[] { errorCode.toString(), descriptor.getName() }));
                }
            } else {
                // maybe ErrorCode is not used 'cause we are using Exception
                // if that is the case, then test is N/A,
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addNaDetails(smh.getLocalString(getClass().getName() + ".notApplicable1", "Not Applicable: Error-code is [ {0} ], using [ {1} ] instead within web application [ {2} ]", new Object[] { new Integer(errorpage.getErrorCode()), exceptionType, descriptor.getName() }));
                oneNA++;
            }
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (oneNA == oneErrorCode) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no error-code elements within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) ErrorPageDescriptor(org.glassfish.web.deployment.descriptor.ErrorPageDescriptor)

Example 4 with ErrorPageDescriptor

use of org.glassfish.web.deployment.descriptor.ErrorPageDescriptor in project Payara by payara.

the class ExceptionType method check.

/**
 * Exception-type element contains a fully qualified class name of a Java
 * exception type.
 *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Result result = loadWarFile(descriptor);
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors().hasMoreElements()) {
        boolean oneFailed = false;
        int oneExceptionType = 0;
        int oneNA = 0;
        boolean foundIt = false;
        // get the errorpage's in this .war
        for (Enumeration e = ((WebBundleDescriptorImpl) descriptor).getErrorPageDescriptors(); e.hasMoreElements(); ) {
            foundIt = false;
            oneExceptionType++;
            ErrorPageDescriptor errorpage = (ErrorPageDescriptor) e.nextElement();
            if (errorpage.getErrorCode() == 0) {
                String exceptionType = errorpage.getExceptionType();
                if ((exceptionType != null) && (exceptionType.length() > 0)) {
                    boolean isValidExceptionType = false;
                    try {
                        Class c = loadClass(result, exceptionType);
                        if (isSubclassOf(c, "java.lang.Exception")) {
                            isValidExceptionType = true;
                        }
                    } catch (Exception ex) {
                        // should already be set
                        isValidExceptionType = false;
                    }
                    if (isValidExceptionType) {
                        foundIt = true;
                    } else {
                        foundIt = false;
                    }
                    if (foundIt) {
                        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Exception type [ {0} ] contains a fully qualified class name of a Java exception type within web application [ {1} ]", new Object[] { exceptionType, descriptor.getName() }));
                    } else {
                        if (!oneFailed) {
                            oneFailed = true;
                        }
                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Exception type [ {0} ] does not contain a fully qualified class name of a Java exception type within web application [ {1} ]", new Object[] { exceptionType, descriptor.getName() }));
                    }
                } else {
                    if (!oneFailed) {
                        oneFailed = true;
                    }
                    Integer errorCode = new Integer(errorpage.getErrorCode());
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Exception type [ {0} ] does not contain a fully qualified class name of a Java exception type within web application [ {1} ]", new Object[] { errorCode.toString(), descriptor.getName() }));
                    oneNA++;
                }
            } else {
                // maybe Exception is null 'cause we are using ErrorCode
                // if that is the case, then test is N/A,
                Integer errorCode = new Integer(errorpage.getErrorCode());
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addNaDetails(smh.getLocalString(getClass().getName() + ".notApplicable1", "Exception type is null, using error-code [ {0} ] instead within web application [ {1} ]", new Object[] { errorCode.toString(), descriptor.getName() }));
                oneNA++;
            }
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (oneNA == oneExceptionType) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no exception-type elements within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) ErrorPageDescriptor(org.glassfish.web.deployment.descriptor.ErrorPageDescriptor)

Aggregations

ErrorPageDescriptor (org.glassfish.web.deployment.descriptor.ErrorPageDescriptor)4 WebBundleDescriptorImpl (org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl)4 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)2 File (java.io.File)1