Search in sources :

Example 1 with ApplicationDeploymentDescriptorFile

use of com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile in project Payara by payara.

the class ApplicationFactory method getApplicationName.

/**
 * @param jarFile the .ear file
 * @return the application name from an application .ear file
 */
public String getApplicationName(File jarFile) throws IOException {
    if (!jarFile.exists()) {
        throw new IOException(localStrings.getLocalString("enterprise.deployment.exceptionjarfiledoesn'texist", "{0} does not exist", new Object[] { jarFile }));
    }
    /*
        *Add finally clause containing explicit close of jar file.
        */
    JarFile jar = null;
    try {
        jar = new JarFile(jarFile);
        ApplicationDeploymentDescriptorFile node = new ApplicationDeploymentDescriptorFile();
        node.setXMLValidation(false);
        ZipEntry deploymentEntry = jar.getEntry(node.getDeploymentDescriptorPath());
        if (deploymentEntry != null) {
            try {
                Application application = (Application) node.read(jar.getInputStream(deploymentEntry));
                return application.getDisplayName();
            } catch (Exception pe) {
                logger.log(Level.WARNING, "Error occurred", pe);
            }
        }
    } finally {
        if (jar != null) {
            jar.close();
        }
    }
    return null;
}
Also used : ApplicationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) Application(com.sun.enterprise.deployment.Application) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException)

Aggregations

Application (com.sun.enterprise.deployment.Application)1 ApplicationDeploymentDescriptorFile (com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile)1 IOException (java.io.IOException)1 JarFile (java.util.jar.JarFile)1 ZipEntry (java.util.zip.ZipEntry)1 SAXParseException (org.xml.sax.SAXParseException)1