Search in sources :

Example 31 with FileArchive

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

the class JarContainsXML method check.

/**
 * An AppClient jar file must contain the XML-based deployment descriptor.  The
 * deployment descriptor must be name META-INF/application-client-jar.xml in the
 * JAR file.
 *
 * @param descriptor the app-client deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(ApplicationClientDescriptor 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.getAppClientJarFile(descriptor.getModuleDescriptor().getArchiveUri());
        // should try to validate against SAX XML parser before
        // continuing, report syntax errors and drop out, otherwise
        // continue...
        // if (applicationJarFile == null) {
        String uri = getAbstractArchiveUri(descriptor);
        try {
            FileArchive arch = new FileArchive();
            arch.open(uri);
            deploymentEntry = arch.getEntry(DescriptorConstants.APP_CLIENT_DD_ENTRY);
        } 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[] { DescriptorConstants.APP_CLIENT_DD_ENTRY }));
        } 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[] { DescriptorConstants.APP_CLIENT_DD_ENTRY }));
        }
    } 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[] { DescriptorConstants.APP_CLIENT_DD_ENTRY }));
    } 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[] { DescriptorConstants.APP_CLIENT_DD_ENTRY }));
    } finally {
        try {
            if (jarFile != null)
                jarFile.close();
            if (deploymentEntry != null)
                deploymentEntry.close();
        } catch (Exception x) {
        }
    }
    return result;
}
Also used : FileArchive(com.sun.enterprise.deploy.shared.FileArchive)

Example 32 with FileArchive

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

the class EjbPublicID method check.

/**
 * Ejb PUBLIC identifier test
 * The ejb deployment descriptor has PUBLIC identifier with a PubidLiteral
 * of "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"
 *
 * @param descriptor the Ejb deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    String[] acceptablePubidLiterals = { "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN", "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" };
    String[] acceptableURLs = { "http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd", "http://java.sun.com/dtd/ejb-jar_2_0.dtd" };
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // open the jar and read the XML deployment descriptor
    if (descriptor.getEjbBundleDescriptor().getSpecVersion().compareTo("2.1") < 0) {
        InputStream deploymentEntry = null;
        String uri = null;
        try {
            uri = getAbstractArchiveUri(descriptor);
            FileArchive arch = new FileArchive();
            arch.open(uri);
            deploymentEntry = arch.getEntry(DescriptorConstants.EJB_DD_ENTRY);
            if (deploymentEntry != null) {
                BufferedReader in = new BufferedReader(new InputStreamReader(deploymentEntry));
                String s = in.readLine();
                boolean foundDOCTYPE = false, foundPubid = false, foundURL = false;
                while (s != null) {
                    // did we find the DOCTYPE entry?
                    if (s.indexOf("DOCTYPE") > -1)
                        foundDOCTYPE = true;
                    if (foundDOCTYPE) {
                        for (int i = 0; i < acceptablePubidLiterals.length; i++) {
                            if (s.indexOf(acceptablePubidLiterals[i]) > -1) {
                                foundPubid = true;
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "The deployment descriptor has the proper PubidLiteral: {0}", new Object[] { acceptablePubidLiterals[i] }));
                            }
                            // check if the URLs match as well
                            if (s.indexOf(acceptableURLs[i]) > -1) {
                                foundURL = true;
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed1", "The deployment descriptor has the proper URL corresponding the the PubIdLiteral: {0}", new Object[] { acceptableURLs[i] }));
                            }
                        }
                    }
                    if (foundPubid && foundURL) {
                        result.setStatus(Result.PASSED);
                        break;
                    } else // DOCTYPE doesn't have any more lines to check
                    if (foundDOCTYPE && s.endsWith(">"))
                        break;
                    s = in.readLine();
                }
                if (!foundDOCTYPE) {
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Error: No document type declaration found in the deployment descriptor for {0}", new Object[] { descriptor.getName() }));
                } else if (!foundPubid) {
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.failed(smh.getLocalString(getClass().getName() + ".failed2", "Error: The deployment descriptor for {0} does not have an expected PubidLiteral ", new Object[] { descriptor.getName() }));
                } else if (!foundURL) {
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.failed(smh.getLocalString(getClass().getName() + ".failed", "The deployment descriptor {0} doesnot have the right URL corresponding to the PubIdLiteral", new Object[] { descriptor.getName() }));
                }
            }
        } catch (IOException e) {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".IOException", "Error: I/O error trying to open {0}", new Object[] { uri }));
        } finally {
            try {
                if (deploymentEntry != null)
                    deploymentEntry.close();
            } catch (Exception x) {
            }
        }
    } else {
        // NOT APPLICABLE
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT-APPLICABLE: No DOCTYPE found for [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException) Result(com.sun.enterprise.tools.verifier.Result) BufferedReader(java.io.BufferedReader) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 33 with FileArchive

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

the class JarContainsXMLFile method check.

/**
 * An ejb-jar file must contain the XML-based deployment descriptor.  The
 * deployment descriptor must be name META-INF/ejb-jar.xml in the
 * JAR file.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor 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.getJarFile(descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri());
        // if (applicationJarFile == null) {
        String uri = getAbstractArchiveUri(descriptor);
        try {
            FileArchive arch = new FileArchive();
            arch.open(uri);
            deploymentEntry = arch.getEntry(DescriptorConstants.EJB_DD_ENTRY);
        } 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[] { DescriptorConstants.EJB_DD_ENTRY }));
        } 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[] { DescriptorConstants.EJB_DD_ENTRY }));
        }
    } 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[] { DescriptorConstants.EJB_DD_ENTRY }));
    } 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[] { DescriptorConstants.EJB_DD_ENTRY }));
    } finally {
        try {
            if (jarFile != null)
                jarFile.close();
            if (deploymentEntry != null)
                deploymentEntry.close();
        } catch (Exception x) {
        }
    }
    return result;
}
Also used : InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Result(com.sun.enterprise.tools.verifier.Result)

Example 34 with FileArchive

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

the class ConnectorArchiveClassesLoadable method check.

public Result check(ConnectorDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    String archiveUri = getAbstractArchiveUri(descriptor);
    boolean allPassed = true;
    Enumeration entries = null;
    ClosureCompiler closureCompiler = getVerifierContext().getClosureCompiler();
    ;
    try {
        String uri = getAbstractArchiveUri(descriptor);
        FileArchive arch = new FileArchive();
        arch.open(uri);
        entries = arch.entries();
        arch.close();
    } catch (Exception e) {
        e.printStackTrace();
        result.failed(smh.getLocalString(getClass().getName() + ".exception", "Error: [ {0} ] exception while loading the archive [ {1} ].", new Object[] { e, descriptor.getName() }));
        return result;
    }
    Object entry;
    while (entries.hasMoreElements()) {
        String name = null;
        entry = entries.nextElement();
        name = (String) entry;
        if (name.endsWith(".class")) {
            String classEntryName = name.substring(0, name.length() - ".class".length()).replace('/', '.');
            boolean status = closureCompiler.buildClosure(classEntryName);
            allPassed = status && allPassed;
        }
    }
    if (allPassed) {
        result.setStatus(Result.PASSED);
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "All the classes are loadable within [ {0} ] without any linkage error.", new Object[] { archiveUri }));
    // result.addGoodDetails(closureCompiler.toString());
    } else {
        result.setStatus(Result.FAILED);
        addErrorDetails(result, compName);
        result.addErrorDetails(ArchiveClassesLoadableHelper.getFailedResult(closureCompiler));
        result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.loadableError", "Please either bundle the above mentioned classes in the application " + "or use optional packaging support for them."));
    }
    return result;
}
Also used : Enumeration(java.util.Enumeration) ClosureCompiler(com.sun.enterprise.tools.verifier.apiscan.classfile.ClosureCompiler) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 35 with FileArchive

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

the class ConnectorTest method findImplementorOf.

/**
 * <p>
 * Find a class implementating the interface in the jar files contained
 * in the connector rar file.
 * </p>
 * @param interfaceName the interface the class should implement
 * @return class implementing the interface or null if not present in the
 * jar files
 */
protected Class findImplementorOf(ConnectorDescriptor desc, String interfaceName) {
    // let's get the rar file
    try {
        String uri = getAbstractArchiveUri(desc);
        FileArchive arch = new FileArchive();
        arch.open(uri);
        for (Enumeration en = arch.entries(); en.hasMoreElements(); ) {
            String entry = (String) en.nextElement();
            if (entry.endsWith(".jar")) {
                // we found a jar file, let's load it
                JarInputStream jis = new JarInputStream(arch.getEntry(entry));
                try {
                    // Now we are going to iterate over the element of the jar file
                    ZipEntry ze = jis.getNextEntry();
                    while (ze != null) {
                        String elementName = (String) ze.getName();
                        // Is this jar entry a java class file ?
                        if (elementName.endsWith(".class")) {
                            // we found a .class file let's load it and see if it does implement the interface
                            String className = elementName.substring(0, elementName.length() - ".class".length()).replace('/', '.');
                            // try {
                            ClassLoader jcl = getVerifierContext().getRarClassLoader();
                            Class c = Class.forName(className, false, jcl);
                            if (isImplementorOf(c, interfaceName))
                                if (c.getSuperclass() != null)
                                    return c;
                        }
                        ze = jis.getNextEntry();
                    }
                } catch (ClassNotFoundException cnfe) {
                // We ignore this for now
                } catch (NoClassDefFoundError cdnf) {
                // continue to search other classes
                } finally {
                    try {
                        if (jis != null)
                            jis.close();
                    } catch (IOException e) {
                    }
                }
            }
        }
    } catch (java.io.IOException ioe) {
        Verifier.debug(ioe);
    }
    return null;
}
Also used : Enumeration(java.util.Enumeration) JarInputStream(java.util.jar.JarInputStream) ZipEntry(java.util.zip.ZipEntry) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) IOException(java.io.IOException) IOException(java.io.IOException)

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