Search in sources :

Example 26 with FileArchive

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

the class CheckMgr method check.

/**
 * <p/>
 * Entry point for executing all tests pertinent to this architecture
 * </p>
 *
 * @param descriptor <code>ConnectorDescritor</code> the deployment descriptor
 */
protected void check(Descriptor descriptor) throws Exception {
    logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.CheckMgr.check", new Object[] { getClass().getName(), descriptor.getName() });
    setRuntimeDDPresent(getAbstractArchiveUri(descriptor));
    // Load the list of tests from the property file for this manager
    loadTestInformationFromPropsFile();
    // These temporary placeholder will keep the results of the tests
    logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.CheckMgr.RunAllTests", new Object[] { descriptor.getName() });
    String schemaVersion = getSchemaVersion(descriptor);
    context.setSchemaVersion(schemaVersion);
    context.setJavaEEVersion(verifierFrameworkContext.getJavaEEVersion());
    context.setComponentNameConstructor(getComponentNameConstructor(descriptor));
    FileArchive moduleArchive = new FileArchive();
    moduleArchive.open(getAbstractArchiveUri(descriptor));
    context.setModuleArchive(moduleArchive);
    ResultManager resultManager = verifierFrameworkContext.getResultManager();
    for (int i = 0; i < test.size(); i++) {
        TestInformation ti = (TestInformation) test.elementAt(i);
        String minVersion = ti.getMinimumVersion();
        String maxVersion = ti.getMaximumVersion();
        // this component's descriptor
        if (schemaVersion != null && minVersion != null && schemaVersion.compareTo(minVersion) < 0) {
            logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.CheckMgr.version.NOT_APPLICABLE", new Object[] { ti.getClassName() });
            continue;
        }
        if (schemaVersion != null && maxVersion != null && schemaVersion.compareTo(maxVersion) > 0) {
            logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.CheckMgr.version.NOT_APPLICABLE", new Object[] { ti.getClassName() });
            continue;
        }
        if (!isApplicable(ti, descriptor)) {
            logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.CheckMgr.version.NOT_APPLICABLE", new Object[] { ti.getClassName() });
            continue;
        }
        try {
            Class c = Class.forName(ti.getClassName());
            VerifierCheck t = (VerifierCheck) c.newInstance();
            t.setVerifierContext(context);
            Result r = t.check(descriptor);
            // no need to setComponentName as it is already set in
            // VerifierTest.getInitialisedResult(). By Sahoo
            // r.setComponentName(getArchiveUri(descriptor));
            setModuleName(r);
            resultManager.add(r);
            // notify listeners of test completion
            fireTestFinishedEvent(r);
        } catch (Throwable e) {
            LogRecord logRecord = new LogRecord(Level.SEVERE, ti.getClassName());
            logRecord.setThrown(e);
            resultManager.log(logRecord);
        }
    }
    fireAllTestsFinishedEvent();
// done adding it to hastable vector.
}
Also used : LogRecord(java.util.logging.LogRecord) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) VerifierCheck(com.sun.enterprise.tools.verifier.tests.VerifierCheck)

Example 27 with FileArchive

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

the class AppAltDDEjb method check.

/**
 * The alt-dd element specifies a URI to the post-assembly deployment descriptor
 * relative to the root of the application
 *
 * @param descriptor the Application deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(Application descriptor) {
    Result result = getInitializedResult();
    if (descriptor.getBundleDescriptors(EjbBundleDescriptor.class).size() > 0) {
        boolean oneFailed = false;
        int na = 0;
        for (Iterator itr = descriptor.getBundleDescriptors(EjbBundleDescriptor.class).iterator(); itr.hasNext(); ) {
            EjbBundleDescriptor ejbd = (EjbBundleDescriptor) itr.next();
            if (ejbd.getModuleDescriptor().getAlternateDescriptor() != null) {
                if (!(ejbd.getModuleDescriptor().getAlternateDescriptor().equals(""))) {
                    JarFile jarFile = null;
                    InputStream deploymentEntry = null;
                    try {
                        // if (f==null){
                        String uri = getAbstractArchiveUri(descriptor);
                        // try {
                        FileArchive arch = new FileArchive();
                        arch.open(uri);
                        deploymentEntry = arch.getEntry(ejbd.getModuleDescriptor().getAlternateDescriptor());
                        if (deploymentEntry != null) {
                            result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Found alternate EJB deployment descriptor URI file [ {0} ] within [ {1} ]", new Object[] { ejbd.getModuleDescriptor().getAlternateDescriptor(), ejbd.getName() }));
                        } else {
                            if (!oneFailed) {
                                oneFailed = true;
                            }
                            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: No alternate EJB deployment descriptor URI file found, looking for [ {0} ] within [ {1} ]", new Object[] { ejbd.getModuleDescriptor().getAlternateDescriptor(), ejbd.getName() }));
                        }
                    // jarFile.close();
                    } catch (FileNotFoundException ex) {
                        Verifier.debug(ex);
                        if (!oneFailed) {
                            oneFailed = true;
                        }
                        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: File not found trying to read deployment descriptor file [ {0} ] within [ {1} ]", new Object[] { ejbd.getModuleDescriptor().getAlternateDescriptor(), ejbd.getName() }));
                    } catch (IOException ex) {
                        Verifier.debug(ex);
                        if (!oneFailed) {
                            oneFailed = true;
                        }
                        result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: IO Error trying to read deployment descriptor file [ {0} ] within [ {1} ]", new Object[] { ejbd.getModuleDescriptor().getAlternateDescriptor(), ejbd.getName() }));
                    } finally {
                        try {
                            if (deploymentEntry != null)
                                deploymentEntry.close();
                        } catch (Exception x) {
                        }
                    }
                }
            } else {
                na++;
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "There is no java EJB alternative deployment descriptor in [ {0} ]", new Object[] { ejbd.getName() }));
            }
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (na == descriptor.getBundleDescriptors(EjbBundleDescriptor.class).size()) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
    } else {
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no EJB components in application [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : FileArchive(com.sun.enterprise.deploy.shared.FileArchive)

Example 28 with FileArchive

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

the class AppAltDDAppClient method check.

/**
 * The alt-dd element specifies a URI to the post-assembly deployment descriptor
 * relative to the root of the application
 *
 * @param descriptor the Application deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(Application descriptor) {
    Result result = getInitializedResult();
    if (descriptor.getBundleDescriptors(ApplicationClientDescriptor.class).size() > 0) {
        boolean oneFailed = false;
        int na = 0;
        for (Iterator itr = descriptor.getBundleDescriptors(ApplicationClientDescriptor.class).iterator(); itr.hasNext(); ) {
            ApplicationClientDescriptor acd = (ApplicationClientDescriptor) itr.next();
            if (acd.getModuleDescriptor().getAlternateDescriptor() != null) {
                if (!(acd.getModuleDescriptor().getAlternateDescriptor().equals(""))) {
                    InputStream deploymentEntry = null;
                    try {
                        // if (f==null){
                        String uri = getAbstractArchiveUri(descriptor);
                        // try {
                        FileArchive arch = new FileArchive();
                        arch.open(uri);
                        deploymentEntry = arch.getEntry(acd.getModuleDescriptor().getAlternateDescriptor());
                        if (deploymentEntry != null) {
                            result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Found alternate application client deployment descriptor URI file [ {0} ] within [ {1} ]", new Object[] { acd.getModuleDescriptor().getAlternateDescriptor(), acd.getName() }));
                        } else {
                            if (!oneFailed) {
                                oneFailed = true;
                            }
                            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: No alternate application client deployment descriptor URI file found, looking for [ {0} ] within [ {1} ]", new Object[] { acd.getModuleDescriptor().getAlternateDescriptor(), acd.getName() }));
                        }
                    // jarFile.close();
                    } catch (FileNotFoundException ex) {
                        Verifier.debug(ex);
                        if (!oneFailed) {
                            oneFailed = true;
                        }
                        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: File not found trying to read deployment descriptor file [ {0} ] within [ {1} ]", new Object[] { acd.getModuleDescriptor().getAlternateDescriptor(), acd.getName() }));
                    } catch (IOException ex) {
                        Verifier.debug(ex);
                        if (!oneFailed) {
                            oneFailed = true;
                        }
                        result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: IO Error trying to read deployment descriptor file [ {0} ] within [ {1} ]", new Object[] { acd.getModuleDescriptor().getAlternateDescriptor(), acd.getName() }));
                    } finally {
                        try {
                            if (deploymentEntry != null)
                                deploymentEntry.close();
                        } catch (Exception x) {
                        }
                    }
                }
            } else {
                na++;
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "There is no java application client alternative deployment descriptor in [ {0} ]", new Object[] { acd.getName() }));
            }
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (na == descriptor.getBundleDescriptors(ApplicationClientDescriptor.class).size()) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
    } else {
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no java application clients in application [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : FileArchive(com.sun.enterprise.deploy.shared.FileArchive)

Example 29 with FileArchive

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

the class AppPublicID method check.

/**
 * Application PUBLIC identifier test
 * The application deployment descriptor has PUBLIC identifier with
 * a PubidLiteral of "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN"
 *
 * @param descriptor the Application deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(Application descriptor) {
    Result result = getInitializedResult();
    // open the jar and read the XML deployment descriptor
    if (descriptor.getSpecVersion().compareTo("1.4") < 0) {
        InputStream deploymentEntry = null;
        String uri = null;
        try {
            uri = getAbstractArchiveUri(descriptor);
            FileArchive arch = new FileArchive();
            arch.open(uri);
            deploymentEntry = arch.getEntry(ApplicationDeploymentDescriptorFile.DESC_PATH);
            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(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(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.failed(smh.getLocalString(getClass().getName() + ".failed1", "No document type declaration found in the deployment descriptor for {0}", new Object[] { descriptor.getName() }));
                } else if (!foundPubid) {
                    result.failed(smh.getLocalString(getClass().getName() + ".failed2", "The deployment descriptor for {0} does not have the expected PubidLiteral ", new Object[] { descriptor.getName() }));
                } else if (!foundURL) {
                    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.failed(smh.getLocalString(getClass().getName() + ".IOException", "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 : FileArchive(com.sun.enterprise.deploy.shared.FileArchive)

Example 30 with FileArchive

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

the class AppClientPublicID method check.

/**
 * Application Client PUBLIC identifier test
 * The application client deployment descriptor has PUBLIC identifier with
 * a PubidLiteral of
 * "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.2//EN"
 *
 * @param descriptor the app-client deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(ApplicationClientDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // open the jar and read the XML deployment descriptor
    if (descriptor.getSpecVersion().compareTo("1.4") < 0) {
        InputStream deploymentEntry = null;
        BufferedReader in = null;
        String uri = null;
        try {
            uri = getAbstractArchiveUri(descriptor);
            FileArchive arch = new FileArchive();
            arch.open(uri);
            deploymentEntry = arch.getEntry(DescriptorConstants.APP_CLIENT_DD_ENTRY);
            if (deploymentEntry != null) {
                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", "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", "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", "I/O error trying to open {0}", new Object[] { uri }));
        } finally {
            try {
                if (in != null)
                    in.close();
                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 : FileArchive(com.sun.enterprise.deploy.shared.FileArchive)

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