Search in sources :

Example 1 with ApplicationValidator

use of com.sun.enterprise.deployment.util.ApplicationValidator in project Payara by payara.

the class ApplicationFactory method openArchive.

/**
 * Open a jar file and return an application object for the modules contained
 * in the archive. If the archive is a standalone module, this API will
 * create an empty application and add the standalone module to it
 *
 * @param appName           the application moduleID
 * @param archivist         to use to open the archive file
 * @param in                the input archive
 * @param handleRuntimeInfo set to true to read configuration deployment descriptors
 * @return the application object
 */
public Application openArchive(String appName, Archivist archivist, ReadableArchive in, boolean handleRuntimeInfo) throws IOException, SAXParseException {
    // we are not reading the runtime deployment descriptor now...
    archivist.setHandleRuntimeInfo(false);
    BundleDescriptor descriptor = archivist.open(in);
    Application application;
    if (descriptor instanceof Application) {
        application = (Application) descriptor;
        application.setAppName(appName);
        application.setRegistrationName(appName);
    } else {
        if (descriptor == null) {
            logger.log(Level.SEVERE, localStrings.getLocalString("enterprise.deployment.cannotreadDDs", "Cannot read the Deployment Descriptors for module {0}", new Object[] { in.getURI() }));
            return null;
        }
        ModuleDescriptor newModule = archivist.createModuleDescriptor(descriptor);
        newModule.setArchiveUri(in.getURI().getSchemeSpecificPart());
        application = Application.createVirtualApplication(appName, newModule);
    }
    // now read the runtime deployment descriptor
    if (handleRuntimeInfo) {
        // now read the runtime deployment descriptors from the original jar file
        archivist.setHandleRuntimeInfo(true);
        archivist.readRuntimeDeploymentDescriptor(in, (BundleDescriptor) descriptor);
    }
    // validate
    if (application != null) {
        application.setClassLoader(archivist.getClassLoader());
        application.visit((ApplicationVisitor) new ApplicationValidator());
    }
    return application;
}
Also used : BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) ApplicationValidator(com.sun.enterprise.deployment.util.ApplicationValidator) Application(com.sun.enterprise.deployment.Application)

Example 2 with ApplicationValidator

use of com.sun.enterprise.deployment.util.ApplicationValidator in project Payara by payara.

the class DescriptorFactory method createApplicationDescriptor.

/**
 * Returns the parsed DOL object from archive
 *
 * @param archiveFile original archive file
 * @param destRootDir root destination directory where the application
 *        should be expanded under in case of archive deployment
 * @param parentCl parent classloader
 *
 * @return the parsed DOL object
 */
public ResultHolder createApplicationDescriptor(File archiveFile, File destRootDir, ClassLoader parentCl) throws IOException {
    ReadableArchive archive = null;
    Application application = null;
    try {
        Descriptor.setBoundsChecking(false);
        archive = archiveFactory.openArchive(archiveFile);
        ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
        ActionReport dummyReport = new HTMLActionReporter();
        String appName = DeploymentUtils.getDefaultEEName(archiveFile.getName());
        DeployCommandParameters params = new DeployCommandParameters();
        params.name = appName;
        ExtendedDeploymentContext context = new DeploymentContextImpl(dummyReport, archive, params, env);
        context.setArchiveHandler(archiveHandler);
        if (!archiveFile.isDirectory()) {
            // expand archive
            File destDir = new File(destRootDir, appName);
            if (destDir.exists()) {
                FileUtils.whack(destDir);
            }
            destDir.mkdirs();
            archiveHandler.expand(archive, archiveFactory.createArchive(destDir), context);
            archive.close();
            archive = archiveFactory.openArchive(destDir);
            context.setSource(archive);
        }
        // issue 14564
        context.addTransientAppMetaData(ExtendedDeploymentContext.IS_TEMP_CLASSLOADER, Boolean.TRUE);
        String archiveType = context.getArchiveHandler().getArchiveType();
        ClassLoader cl = archiveHandler.getClassLoader(parentCl, context);
        Archivist archivist = archivistFactory.getArchivist(archiveType, cl);
        if (archivist == null) {
            throw new IOException("Cannot determine the Java EE module type for " + archive.getURI());
        }
        archivist.setAnnotationProcessingRequested(true);
        String xmlValidationLevel = dasConfig.getDeployXmlValidation();
        archivist.setXMLValidationLevel(xmlValidationLevel);
        if (xmlValidationLevel.equals("none")) {
            archivist.setXMLValidation(false);
        }
        archivist.setRuntimeXMLValidation(false);
        try {
            application = applicationFactory.openArchive(appName, archivist, archive, true);
        } catch (SAXParseException e) {
            throw new IOException(e);
        }
        if (application != null) {
            application.setClassLoader(cl);
            application.visit((ApplicationVisitor) new ApplicationValidator());
        }
    } finally {
        if (archive != null) {
            archive.close();
        }
        // We need to reset it after descriptor building
        Descriptor.setBoundsChecking(true);
    }
    ResultHolder result = new ResultHolder();
    result.application = application;
    result.archive = archive;
    return result;
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) Archivist(com.sun.enterprise.deployment.archivist.Archivist) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ApplicationValidator(com.sun.enterprise.deployment.util.ApplicationValidator) SAXParseException(org.xml.sax.SAXParseException) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.deployment.Application) File(java.io.File)

Aggregations

Application (com.sun.enterprise.deployment.Application)2 ApplicationValidator (com.sun.enterprise.deployment.util.ApplicationValidator)2 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)1 Archivist (com.sun.enterprise.deployment.archivist.Archivist)1 HTMLActionReporter (com.sun.enterprise.v3.common.HTMLActionReporter)1 File (java.io.File)1 IOException (java.io.IOException)1 ActionReport (org.glassfish.api.ActionReport)1 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)1 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)1 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)1 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)1 SAXParseException (org.xml.sax.SAXParseException)1