Search in sources :

Example 1 with ArchiveFactory

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

the class SunDeploymentManager method deploy.

/**
 *Deploy the specified module to the list of targets.
 *The deployment plan archive can be null.
 *@param Target[] the targets to which to deploy the module
 *@param File the archive file to be deployed
 *@param File the (optional) deployment plan file
 *@param options set by the caller to override and augment any settings made here
 *@return ProgressObject to communicate progress and results of the deployment
 *@exception IllegalStateException if the DeploymentManager has disconnected
 *@exception IOException if there are problems opening the archive files
 */
private ProgressObject deploy(Target[] targetList, File moduleArchive, File deploymentPlan, Properties presetOptions) throws IllegalStateException {
    /*
         *Create archives for the module file and, if present, the deployment plan file, and
         *then delegate to the variant of deploy that accepts archives as arguments.
         */
    ReadableArchive appArchive = null;
    ReadableArchive planArchive = null;
    ArchiveFactory archiveFactory = getArchiveFactory();
    try {
        appArchive = archiveFactory.openArchive(moduleArchive);
        if (deploymentPlan != null && deploymentPlan.length() != 0) {
            planArchive = archiveFactory.openArchive(deploymentPlan);
            if (planArchive == null) {
                throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployapi.spi.noarchivisthandlesplan", "No archivist is able to handle the deployment plan {0}", new Object[] { deploymentPlan.getAbsolutePath() }));
            }
        }
        ProgressObject po = deploy(targetList, appArchive, planArchive, presetOptions);
        return po;
    } catch (Exception se) {
        String msg = localStrings.getLocalString("enterprise.deployapi.spi.errpreparearchfile", "Could not prepare archives for module and/or deployment plan files");
        IllegalArgumentException ex = new IllegalArgumentException(msg);
        ex.initCause(se);
        return prepareErrorProgressObject(CommandType.DISTRIBUTE, ex);
    } finally {
        closeArchives(CommandType.DISTRIBUTE, appArchive, moduleArchive.getAbsolutePath(), planArchive, (deploymentPlan != null) ? deploymentPlan.getAbsolutePath() : null);
    }
}
Also used : ArchiveFactory(com.sun.enterprise.deploy.shared.ArchiveFactory) DeployableObject(javax.enterprise.deploy.model.DeployableObject) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject) DConfigBeanVersionUnsupportedException(javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException) ConfigurationException(javax.enterprise.deploy.spi.exceptions.ConfigurationException) TargetException(javax.enterprise.deploy.spi.exceptions.TargetException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvalidModuleException(javax.enterprise.deploy.spi.exceptions.InvalidModuleException)

Example 2 with ArchiveFactory

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

the class GenericAnnotationDetector method hasAnnotationInArchive.

public boolean hasAnnotationInArchive(ReadableArchive archive) {
    scanArchive(archive);
    if (found) {
        return found;
    }
    ArchiveFactory archiveFactory = null;
    if (Globals.getDefaultHabitat() != null) {
        archiveFactory = Globals.getDefaultHabitat().getService(ArchiveFactory.class);
    }
    if (archiveFactory != null) {
        List<URI> externalLibs = DeploymentUtils.getExternalLibraries(archive);
        for (URI externalLib : externalLibs) {
            try {
                scanArchive(archiveFactory.openArchive(new File(externalLib.getPath())));
            } catch (FileNotFoundException fnfe) {
                Object[] args = { externalLib.getPath(), archive.getName() };
                deplLogger.log(Level.WARNING, ARCHIVE_NOT_FOUND, args);
            } catch (Exception e) {
                LogRecord lr = new LogRecord(Level.WARNING, EXCEPTION_CAUGHT);
                Object[] args = { e.getMessage() };
                lr.setParameters(args);
                lr.setThrown(e);
                deplLogger.log(lr);
            }
        }
    }
    return found;
}
Also used : ArchiveFactory(com.sun.enterprise.deploy.shared.ArchiveFactory) LogRecord(java.util.logging.LogRecord) FileNotFoundException(java.io.FileNotFoundException) URI(java.net.URI) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with ArchiveFactory

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

the class SunDeploymentManager method getArchive.

/**
 * Creates a new instance of Archive which can be used to
 * store application elements in a layout that can be directly used by
 * the application server. Implementation of this method should carefully
 * return the appropriate implementation of the interface that suits
 * the server needs and provide the fastest deployment time.
 * An archive may already exist at the location and elements may be
 * read but not changed or added depending on the underlying medium.
 * @param path the directory in which to create this archive if local
 * storage is a possibility.
 * @param name is the desired name for the archive
 * @return the writable archive instance
 */
public Archive getArchive(URI path, String name) throws IOException {
    if (path == null) {
        // no particular path was provided, using tmp jar file
        // NOI18N
        File root = File.createTempFile(name, ".jar");
        path = root.toURI();
    }
    ArchiveFactory factory = getArchiveFactory();
    boolean exists = false;
    if (// NOI18N
    (path.getScheme().equals("file")) || (path.getScheme().equals("jar"))) {
        // NOI18N
        File target = new File(path);
        exists = target.exists();
    } else {
        return null;
    }
    if (exists) {
        return factory.openArchive(path);
    } else {
        return factory.createArchive(path);
    }
}
Also used : ArchiveFactory(com.sun.enterprise.deploy.shared.ArchiveFactory) File(java.io.File)

Example 4 with ArchiveFactory

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

the class EJBContainerProviderImpl method createContainer.

private Locations createContainer(Map<?, ?> properties, Locations l) throws EJBException {
    synchronized (lock) {
        // if (container == null || !container.isOpen()) {
        try {
            if (runtime != null) {
                // dispose of the old one
                runtime.shutdown();
            }
            BootstrapProperties bootstrapProperties = new BootstrapProperties();
            // Propagate non EJB embeddable container properties into GlassFishProperties
            Properties newProps = new Properties();
            if (properties != null) {
                copyUserProperties(properties, newProps);
            }
            // Disable weaving if it is not spesified
            if (newProps.getProperty(WEAVING) == null) {
                newProps.setProperty(WEAVING, "false");
            }
            GlassFishProperties glassFishProperties = new GlassFishProperties(newProps);
            if (Boolean.getBoolean(KEEP_TEMPORARY_FILES)) {
                // set autodelete to false.
                glassFishProperties.setProperty("org.glassfish.embeddable.autoDelete", "false");
                // make sure the domain.xml is written back.
                glassFishProperties.setConfigFileReadOnly(false);
            }
            if (l.installed_root != null && l.instance_root != null) {
                // Real install
                _logger.info("[EJBContainerProviderImpl] Using installation location " + l.installed_root.getCanonicalPath());
                bootstrapProperties.setInstallRoot(l.installed_root.getCanonicalPath());
            }
            if (l.instance_root != null && l.reuse_instance_location) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("[EJBContainerProviderImpl] Reusing instance location at: " + l.instance_root);
                }
                _logger.info("[EJBContainerProviderImpl] Using instance location: " + l.instance_root.getCanonicalPath());
                glassFishProperties.setInstanceRoot(l.instance_root.getCanonicalPath());
            } else if (l.domain_file != null) {
                _logger.info("[EJBContainerProviderImpl] Using config file location: " + l.domain_file.toURI().toString());
                glassFishProperties.setConfigFileURI(l.domain_file.toURI().toString());
            }
            addWebContainerIfRequested(properties, glassFishProperties);
            runtime = GlassFishRuntime.bootstrap(bootstrapProperties);
            _logger.info("[EJBContainerProviderImpl] Using runtime class: " + runtime.getClass());
            GlassFish server = runtime.newGlassFish(glassFishProperties);
            if (l.instance_root != null && !l.reuse_instance_location) {
                // XXX Start the server to get the services
                server.start();
                EmbeddedSecurity es = server.getService(EmbeddedSecurity.class);
                ServiceLocator habitat = server.getService(ServiceLocator.class);
                server.stop();
                // If we are running from an existing install, copy over security files to the temp instance
                if (es != null) {
                    es.copyConfigFiles(habitat, l.instance_root, l.domain_file);
                }
            }
            // server is started in EJBContainerImpl constructor
            container = new EJBContainerImpl(server);
            validateInstanceDirectory();
            archiveFactory = server.getService(ArchiveFactory.class);
            Sniffer sniffer = server.getService(Sniffer.class, "Ejb");
            ejbAnnotations = sniffer.getAnnotationTypes();
        } catch (Exception e) {
            try {
                if (container != null) {
                    container.stop();
                }
            } catch (Exception e0) {
                _logger.log(Level.SEVERE, e0.getMessage(), e0);
            }
            container = null;
            throw new EJBException(e);
        }
    // }
    }
    return l;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ArchiveFactory(com.sun.enterprise.deploy.shared.ArchiveFactory) EmbeddedSecurity(com.sun.enterprise.security.EmbeddedSecurity) Sniffer(org.glassfish.api.container.Sniffer) EJBException(javax.ejb.EJBException) EJBException(javax.ejb.EJBException)

Example 5 with ArchiveFactory

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

the class UndeployedLaunchable method newUndeployedLaunchable.

static UndeployedLaunchable newUndeployedLaunchable(final ServiceLocator habitat, final ReadableArchive ra, final String callerSuppliedMainClassName, final String callerSuppliedAppName, final ClassLoader classLoader) throws IOException, SAXParseException, UserError {
    ArchivistFactory af = Util.getArchivistFactory();
    /*
         * Try letting the factory decide what type of archive this is.  That
         * will often allow an app client or an EAR archive to be detected
         * automatically.
         */
    Archivist archivist = af.getArchivist(ModuleType.CAR.toString(), classLoader);
    if (archivist == null) {
        throw new UserError(localStrings.get("appclient.invalidArchive", ra.getURI().toASCIIString()));
    }
    final ArchiveType moduleType = archivist.getModuleType();
    if (moduleType != null && moduleType.equals(DOLUtils.carType())) {
        return new UndeployedLaunchable(habitat, ra, (AppClientArchivist) archivist, callerSuppliedMainClassName);
    } else if (moduleType != null && moduleType.equals(DOLUtils.earType())) {
        /*
             * Locate the app client submodule that matches the main class name
             * or the app client name.
             */
        Application app = (Application) archivist.open(ra);
        for (ModuleDescriptor<BundleDescriptor> md : app.getModules()) {
            if (!md.getModuleType().equals(DOLUtils.carType())) {
                continue;
            }
            ApplicationClientDescriptor acd = (ApplicationClientDescriptor) md.getDescriptor();
            final String displayName = acd.getDisplayName();
            final String appName = acd.getModuleID();
            ArchiveFactory archiveFactory = Util.getArchiveFactory();
            ReadableArchive clientRA = archiveFactory.openArchive(ra.getURI().resolve(md.getArchiveUri()));
            /*
                 * Choose this nested app client if the caller-supplied name
                 * matches, or if the caller-supplied main class matches, or
                 * if neither was provided.  
                 */
            final boolean useThisClient = (displayName != null && displayName.equals(callerSuppliedAppName)) || (appName != null && appName.equals(callerSuppliedAppName)) || (callerSuppliedMainClassName != null && clientRA.exists(classToResource(callerSuppliedMainClassName)) || (callerSuppliedAppName == null && callerSuppliedMainClassName == null));
            if (useThisClient) {
                return new UndeployedLaunchable(habitat, clientRA, acd, callerSuppliedMainClassName);
            }
            clientRA.close();
        }
        throw new UserError(localStrings.get("appclient.noMatchingClientInEAR", ra.getURI(), callerSuppliedMainClassName, callerSuppliedAppName));
    } else {
        /*
             * There is a possibility that the user is trying to launch an
             * archive that is more than one type of archive: such as an EJB
             * but also an app client (because the manifest identifies a main
             * class, for example).
             *
             * Earlier the archivist factory might have returned the other type
             * of archivist - such as the EJB archivist.  Now see if the app
             * client archivist will work when selected directly.
             */
        archivist = af.getArchivist(DOLUtils.carType());
        /*
             * Try to open the archive as an app client archive just to see
             * if it works.
             */
        RootDeploymentDescriptor tempACD = archivist.open(ra);
        if (tempACD != null && tempACD instanceof ApplicationClientDescriptor) {
            /*
                 * Start with a fresh archivist - unopened - so we can request
                 * anno processing, etc. before opening it for real.
                 */
            archivist = af.getArchivist(DOLUtils.carType());
            return new UndeployedLaunchable(habitat, ra, (AppClientArchivist) archivist, callerSuppliedMainClassName);
        }
        throw new UserError(localStrings.get("appclient.unexpectedArchive", ra.getURI()));
    }
}
Also used : ArchiveFactory(com.sun.enterprise.deploy.shared.ArchiveFactory) AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) Archivist(com.sun.enterprise.deployment.archivist.Archivist) ArchiveType(org.glassfish.api.deployment.archive.ArchiveType) ApplicationClientDescriptor(com.sun.enterprise.deployment.ApplicationClientDescriptor) AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) ArchivistFactory(com.sun.enterprise.deployment.archivist.ArchivistFactory) ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) RootDeploymentDescriptor(org.glassfish.deployment.common.RootDeploymentDescriptor) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.deployment.Application)

Aggregations

ArchiveFactory (com.sun.enterprise.deploy.shared.ArchiveFactory)5 File (java.io.File)2 IOException (java.io.IOException)2 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)2 Application (com.sun.enterprise.deployment.Application)1 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)1 AppClientArchivist (com.sun.enterprise.deployment.archivist.AppClientArchivist)1 Archivist (com.sun.enterprise.deployment.archivist.Archivist)1 ArchivistFactory (com.sun.enterprise.deployment.archivist.ArchivistFactory)1 EmbeddedSecurity (com.sun.enterprise.security.EmbeddedSecurity)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 LogRecord (java.util.logging.LogRecord)1 EJBException (javax.ejb.EJBException)1 DeployableObject (javax.enterprise.deploy.model.DeployableObject)1 ConfigurationException (javax.enterprise.deploy.spi.exceptions.ConfigurationException)1 DConfigBeanVersionUnsupportedException (javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException)1 InvalidModuleException (javax.enterprise.deploy.spi.exceptions.InvalidModuleException)1 TargetException (javax.enterprise.deploy.spi.exceptions.TargetException)1