Search in sources :

Example 21 with FileArchive

use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.

the class WSXMLLocCheck method check.

/**
 * @param descriptor the WebServices  descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebServiceEndpoint descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // boolean pass = true;
    // File f = Verifier.getArchiveFile(descriptor.getBundleDescriptor().
    // getModuleDescriptor().getArchiveUri());
    // JarFile jarFile = null;
    InputStream deploymentEntry = null;
    try {
        // if (f == null) {
        String uri = getAbstractArchiveUri(descriptor);
        // try {
        FileArchive arch = new FileArchive();
        arch.open(uri);
        if (descriptor.implementedByEjbComponent()) {
            deploymentEntry = arch.getEntry(ejbWSXmlLoc);
        } else if (descriptor.implementedByWebComponent()) {
            deploymentEntry = arch.getEntry(jaxrpcWSXmlLoc);
        } else {
            throw new Exception("Niether implemented by EJB nor by WEB Component");
        }
        // }
        if (deploymentEntry != null) {
            // webservices XML exists
            // result.pass
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed", "The webservices.xml file for [{0}] is located at the correct place.", new Object[] { compName.toString() }));
        } else {
            // ws xml is does not exist
            // result.fail
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "The webservices.xml file for [{0}] is not located in WEB-INF/META-INF directory as applicable.", new Object[] { compName.toString() }));
        // pass = false;
        }
    } catch (Exception e) {
        // result.fail
        result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.webservices.Error", "Error: Unexpected error occurred [ {0} ]", new Object[] { e.getMessage() }));
    // pass = false;
    } finally {
        try {
            if (deploymentEntry != null)
                deploymentEntry.close();
        } catch (IOException e) {
        }
    }
    return result;
}
Also used : FileArchive(com.sun.enterprise.deploy.shared.FileArchive)

Example 22 with FileArchive

use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.

the class FormErrorPage method check.

/**
 * The Web form-error-page value defines the location in the web application
 * where the page can be used for error page can be found within web
 * application test
 *
 * @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 (descriptor.getLoginConfiguration() != null) {
        boolean foundIt = false;
        // ZipEntry ze=null;
        // JarFile jar=null;
        FileArchive arch = null;
        String formErrorPage = descriptor.getLoginConfiguration().getFormErrorPage();
        if (formErrorPage.length() > 0) {
            try {
                // File f = Verifier.getArchiveFile(descriptor.getModuleDescriptor().getArchiveUri());
                // if(f==null){
                String uri = getAbstractArchiveUri(descriptor);
                try {
                    arch = new FileArchive();
                    arch.open(uri);
                } catch (IOException e) {
                    throw e;
                }
                // }
                if (formErrorPage.startsWith("/"))
                    formErrorPage = formErrorPage.substring(1);
                // if (f!=null){
                // ze = jar.getEntry(formErrorPage);
                // foundIt = (ze != null);
                // }
                // else{
                File fep = new File(new File(arch.getURI()), formErrorPage);
                if (fep.exists())
                    foundIt = true;
                fep = null;
            // }
            // if (jar!=null)
            // jar.close();
            } catch (Exception ex) {
                // should be aldready set?
                foundIt = false;
            }
            if (foundIt) {
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.passed(smh.getLocalString(getClass().getName() + ".passed", "The form-error-page [ {0} ] value defines the location in the web application where the error page that is displayed when login is not successful can be found within web application [ {1} ]", new Object[] { formErrorPage, descriptor.getName() }));
            } else {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: The form-error-page [ {0} ] value does not define the location in the web application where the error page that is displayed when login is not successful can be found within web application [ {1} ]", new Object[] { formErrorPage, descriptor.getName() }));
            }
        } else {
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no form-error-page elements within this web archive [ {0} ]", new Object[] { descriptor.getName() }));
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no form-error-page elements within this web archive [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : FileArchive(com.sun.enterprise.deploy.shared.FileArchive)

Example 23 with FileArchive

use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.

the class JarContainsXMLFile method check.

/**
 * An web-war file must contain the XML-based deployment descriptor.  The
 * deployment descriptor must be name META-INF/web.xml in the WAR file.
 *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    // hence we must exclude this test based on platform version.
    if (getVerifierContext().getJavaEEVersion().compareTo(SpecVersionMapper.JavaEEVersion_5) >= 0) {
        result.setStatus(Result.NOT_APPLICABLE);
        return result;
    }
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // JarFile jarFile = null;
    InputStream deploymentEntry = null;
    try {
        // File applicationJarFile = Verifier.getArchiveFile(descriptor.getModuleDescriptor().getArchiveUri());
        // if (applicationJarFile == null) {
        String uri = getAbstractArchiveUri(descriptor);
        try {
            FileArchive arch = new FileArchive();
            arch.open(uri);
            deploymentEntry = arch.getEntry("WEB-INF/web.xml");
        } catch (IOException e) {
            throw e;
        }
        if (deploymentEntry != null) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed", "Found deployment descriptor xml file [ {0} ]", new Object[] { "WEB-INF/web.xml" }));
        } else {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: No deployment descriptor xml file found, looking for [ {0} ]", new Object[] { "WEB-INF/web.xml" }));
        }
    } catch (FileNotFoundException ex) {
        Verifier.debug(ex);
        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: File not found trying to read deployment descriptor file [ {0} ]", new Object[] { "WEB-INF/web.xml" }));
    } catch (IOException ex) {
        Verifier.debug(ex);
        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: IO Error trying to read deployment descriptor file [ {0} ]", new Object[] { "WEB-INF/web.xml" }));
    } finally {
        try {
            // jarFile.close();
            if (deploymentEntry != null)
                deploymentEntry.close();
        } catch (Exception x) {
        }
    }
    return result;
}
Also used : FileArchive(com.sun.enterprise.deploy.shared.FileArchive)

Example 24 with FileArchive

use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.

the class ServletClassDeclared method check.

/**
 *  All Servlet class of an war bundle should be declared in the deployment
 *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    // See bug #6332745
    if (getVerifierContext().getJavaEEVersion().compareTo(SpecVersionMapper.JavaEEVersion_5) >= 0) {
        result.setStatus(Result.NOT_APPLICABLE);
        return result;
    }
    // ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean oneWarning = false;
    boolean foundOne = false;
    // File f =  Verifier.getArchiveFile(descriptor.getModuleDescriptor().getArchiveUri());
    result = loadWarFile(descriptor);
    // ZipFile zip = null;
    FileArchive arch = null;
    Enumeration entries = null;
    // ZipEntry entry;
    Object entry;
    try {
        // if (f == null) {
        String uri = getAbstractArchiveUri(descriptor);
        try {
            arch = new FileArchive();
            arch.open(uri);
            entries = arch.entries();
        } catch (Exception e) {
            throw e;
        }
    // }
    // else {
    // zip = new ZipFile(f);
    // entries = zip.entries();
    // }
    } catch (Exception e) {
        e.printStackTrace();
        result.failed(smh.getLocalString(getClass().getName() + ".exception", "IOException while loading the war file [ {0} ]", new Object[] { descriptor.getName() }));
        return result;
    }
    while (entries.hasMoreElements()) {
        entry = entries.nextElement();
        // if (f == null) {
        String name = (String) entry;
        // }
        if (name.startsWith(servletClassPath)) {
            if (name.endsWith(".class")) {
                String classEntryName = name.substring(0, name.length() - ".class".length());
                classEntryName = classEntryName.substring(servletClassPath.length() + 1, classEntryName.length());
                String className = classEntryName.replace('/', '.');
                Class servletClass = loadClass(result, className);
                if (!Modifier.isAbstract(servletClass.getModifiers()) && isImplementorOf(servletClass, "javax.servlet.Servlet")) {
                    foundOne = true;
                    // let's find out if this servlet has associated deployment descriptors...
                    Set servlets = descriptor.getServletDescriptors();
                    boolean foundDD = false;
                    for (Iterator itr = servlets.iterator(); itr.hasNext(); ) {
                        WebComponentDescriptor servlet = (WebComponentDescriptor) itr.next();
                        String servletClassName = servlet.getWebComponentImplementation();
                        if (servletClassName.equals(className)) {
                            foundDD = true;
                            break;
                        }
                    }
                    if (foundDD) {
                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Servlet class [ {0} ] found in war file is defined in the Deployement Descriptors", new Object[] { className }));
                    } else {
                        oneWarning = true;
                        result.addWarningDetails(smh.getLocalString(getClass().getName() + ".warning", "Servlet class [ {0} ] found in war file is not defined in the Deployement Descriptors", new Object[] { className }));
                    }
                }
            }
        }
    }
    if (!foundOne) {
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no servlet implementation within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
    } else {
        if (oneWarning) {
            result.setStatus(Result.WARNING);
        } else {
            result.setStatus(Result.PASSED);
        }
    }
    return result;
}
Also used : FileArchive(com.sun.enterprise.deploy.shared.FileArchive)

Example 25 with FileArchive

use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.

the class BaseVerifier method getInputStreamFromAbstractArchive.

protected InputStream getInputStreamFromAbstractArchive(String uri, String ddName) throws IOException {
    FileArchive arch = new FileArchive();
    arch.open(new File(uri).toURI());
    InputStream deploymentEntry = arch.getEntry(ddName);
    return deploymentEntry;
}
Also used : InputStream(java.io.InputStream) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) File(java.io.File)

Aggregations

FileArchive (com.sun.enterprise.deploy.shared.FileArchive)46 File (java.io.File)11 IOException (java.io.IOException)7 InputStream (java.io.InputStream)6 URI (java.net.URI)5 JarFile (java.util.jar.JarFile)5 Result (com.sun.enterprise.tools.verifier.Result)4 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)4 Enumeration (java.util.Enumeration)4 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)3 URISyntaxException (java.net.URISyntaxException)3 Manifest (java.util.jar.Manifest)3 SAXParseException (org.xml.sax.SAXParseException)3 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)2 AppClientArchivist (com.sun.enterprise.deployment.archivist.AppClientArchivist)2 InputJarArchive (com.sun.enterprise.deployment.deploy.shared.InputJarArchive)2 MultiReadableArchive (com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive)2 ClosureCompiler (com.sun.enterprise.tools.verifier.apiscan.classfile.ClosureCompiler)2 URL (java.net.URL)2 Attributes (java.util.jar.Attributes)2