Search in sources :

Example 1 with FileArchive

use of com.sun.enterprise.deploy.shared.FileArchive 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 FileArchive

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

the class WebPublicID method check.

/**
 * Web PUBLIC identifier test
 * The Web deployment descriptor has PUBLIC identifier with a PubidLiteral
 * of "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
 *
 * @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();
    String[] acceptablePubidLiterals = { "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" };
    String[] acceptableURLs = { "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd", "http://java.sun.com/dtd/web-app_2_3.dtd" };
    // open the jar and read the XML deployment descriptor
    if (descriptor.getSpecVersion().compareTo("2.4") < 0) {
        InputStream deploymentEntry = null;
        try {
            String uri = getAbstractArchiveUri(descriptor);
            FileArchive arch = new FileArchive();
            arch.open(uri);
            deploymentEntry = arch.getEntry("WEB-INF/web.xml");
            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] }));
                            }
                            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[] { getAbstractArchiveUri(descriptor) }));
        } 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 3 with FileArchive

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

the class MappingFileCheck 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();
    String mappingFile = descriptor.getWebService().getMappingFileUri();
    if (getVerifierContext().getSchemaVersion().compareTo("1.1") > 0) {
        if (mappingFile != null) {
            addWarningDetails(result, compName);
            result.warning(smh.getLocalString(getClass().getName() + ".warning", "The mapping file as specified in location [ {0} ] is not required.", new Object[] { mappingFile }));
            return result;
        }
    } else {
        InputStream deploymentEntry = null;
        try {
            String uri = getAbstractArchiveUri(descriptor);
            try {
                FileArchive arch = new FileArchive();
                arch.open(uri);
                deploymentEntry = arch.getEntry(mappingFile);
            } catch (IOException e) {
                throw e;
            }
            if (deploymentEntry == null) {
                // result.fail, mapping file does not exist at that location
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "The mapping file does not exist at the specified location [{0}] in the archive.", new Object[] { mappingFile }));
            }
        } catch (Exception e) {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "The mapping file does not exist at the specified location [{0}] in the archive.", new Object[] { mappingFile }));
        } finally {
            try {
                if (deploymentEntry != null)
                    deploymentEntry.close();
            } catch (IOException e) {
            }
        }
    }
    if (result.getStatus() != Result.FAILED || result.getStatus() != Result.WARNING) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "mapping file requirements are satisfied"));
    }
    return result;
}
Also used : FileArchive(com.sun.enterprise.deploy.shared.FileArchive)

Example 4 with FileArchive

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

the class WSDLFileCheck method check.

/**
 * @param descriptor the WebServices  descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(ServiceReferenceDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    InputStream deploymentEntry = null;
    // wsdl file
    if (descriptor.hasWsdlFile()) {
        String wsdlUri = descriptor.getWsdlFileUri();
        URL url = null;
        try {
            url = new URL(wsdlUri);
        } catch (java.net.MalformedURLException e) {
        // don't care, will eventuall fail below
        }
        if (url != null) {
            if ("http".equals(url.getProtocol()) || "https".equals(url.getProtocol())) {
                return result;
            }
        }
        try {
            String uri = getAbstractArchiveUri(descriptor);
            FileArchive arch = new FileArchive();
            arch.open(uri);
            deploymentEntry = arch.getEntry(wsdlUri);
            if (deploymentEntry == null) {
                // result.fail,
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "WSDL file does not exist in the archive at uri [{0}].", new Object[] { wsdlUri }));
            } else {
                // result.pass
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.passed(smh.getLocalString(getClass().getName() + ".passed", "WSDL file exists in the archive at uri [{0}].", new Object[] { wsdlUri }));
            }
        } 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() }));
        } finally {
            try {
                if (deploymentEntry != null)
                    deploymentEntry.close();
            } catch (IOException e) {
            }
        }
    } else {
        // result.notapplicable since no wsdl specified
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notapp", "Not applicable since Service Client does not have a WSDL file specified."));
    }
    return result;
}
Also used : FileArchive(com.sun.enterprise.deploy.shared.FileArchive) URL(java.net.URL)

Example 5 with FileArchive

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

the class MappingFileCheck method check.

/**
 * @param descriptor the WebServices  descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(ServiceReferenceDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor.hasWsdlFile()) {
        if (descriptor.hasMappingFile()) {
            // result.pass
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed1", "Mapping file specified because WSDL file is also specified."));
        } else {
            // result.fail, has wsdl but no mapping
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed1", "The webservice client [{0}] has a WSDL file specified but no Mapping File.", new Object[] { compName.toString() }));
        }
    } else {
        if (descriptor.hasMappingFile()) {
            // result.fail, mapping without WSDL
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed1", "The webservice client [{0}] has a Mapping file specified but no WSDL File.", new Object[] { compName.toString() }));
        } else {
            // result.pass, neither WSDL nor Mapping
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed2", "Mapping file found at location [{0}] in archive.", new Object[] { descriptor.getMappingFileUri() }));
        }
    }
    if (descriptor.hasMappingFile()) {
        // maybe we should not depend on DOL to get the location of Mapping file
        String mappingFile = descriptor.getMappingFileUri();
        // 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);
            deploymentEntry = arch.getEntry(mappingFile);
            // }
            if (deploymentEntry == null) {
                // result.fail, mapping file does not exist at that location
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "The mapping file does not exist at the specified location [{0}] in the archive.", new Object[] { mappingFile }));
            } else {
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.passed(smh.getLocalString(getClass().getName() + ".passed", "Mapping file found at location [{0}] in archive.", new Object[] { mappingFile }));
            }
        } catch (Exception e) {
            // result.fail, mapping file does not exist at that location
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "The mapping file does not exist at the specified location [{0}] in the archive.", new Object[] { mappingFile }));
        } finally {
            try {
                if (deploymentEntry != null)
                    deploymentEntry.close();
            } catch (IOException e) {
            }
        }
    } else {
        // result.notapplicable. Mapping file exists check not applicable
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notapp", "This webservice client does not have a Mapping File."));
    }
    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