Search in sources :

Example 1 with ArchivistFactory

use of com.sun.enterprise.deployment.archivist.ArchivistFactory in project Payara by payara.

the class MainClassLaunchable method getArchivist.

private AppClientArchivist getArchivist(final ReadableArchive clientRA, final ClassLoader classLoader) throws IOException {
    if (archivist == null) {
        ArchivistFactory af = Util.getArchivistFactory();
        /*
             * Get the archivist by type rather than by archive to avoid
             * having to set the URI to some fake URI that the archivist
             * factory would understand.
             */
        archivist = completeInit((AppClientArchivist) af.getArchivist(DOLUtils.carType()));
    }
    return archivist;
}
Also used : AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) ArchivistFactory(com.sun.enterprise.deployment.archivist.ArchivistFactory)

Example 2 with ArchivistFactory

use of com.sun.enterprise.deployment.archivist.ArchivistFactory 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)

Example 3 with ArchivistFactory

use of com.sun.enterprise.deployment.archivist.ArchivistFactory in project Payara by payara.

the class UndeployedLaunchable method getArchivist.

private AppClientArchivist getArchivist(final ClassLoader classLoader) throws IOException {
    if (archivist == null) {
        ArchivistFactory af = Util.getArchivistFactory();
        archivist = completeInit((AppClientArchivist) af.getArchivist(ModuleType.CAR.toString()));
    }
    archivist.setClassLoader(classLoader);
    return archivist;
}
Also used : AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) ArchivistFactory(com.sun.enterprise.deployment.archivist.ArchivistFactory)

Example 4 with ArchivistFactory

use of com.sun.enterprise.deployment.archivist.ArchivistFactory in project Payara by payara.

the class RegistrationSupport method getDeploymentDescriptor.

private String getDeploymentDescriptor(final BundleDescriptor bundleDesc) {
    final ArchivistFactory archivistFactory = J2EEInjectedValues.getInstance().getArchivistFactory();
    String dd = "unavailable";
    ByteArrayOutputStream out = null;
    try {
        final Archivist moduleArchivist = archivistFactory.getArchivist(bundleDesc.getModuleDescriptor().getModuleType());
        final DeploymentDescriptorFile ddFile = moduleArchivist.getStandardDDFile();
        out = new ByteArrayOutputStream();
        ddFile.write(bundleDesc, out);
        final String charsetName = "UTF-8";
        dd = out.toString(charsetName);
    } catch (final Exception e) {
        dd = null;
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (Exception ee) {
            }
        }
    }
    return dd;
}
Also used : Archivist(com.sun.enterprise.deployment.archivist.Archivist) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DeploymentDescriptorFile(com.sun.enterprise.deployment.io.DeploymentDescriptorFile) ArchivistFactory(com.sun.enterprise.deployment.archivist.ArchivistFactory)

Example 5 with ArchivistFactory

use of com.sun.enterprise.deployment.archivist.ArchivistFactory in project Payara by payara.

the class DOLUtils method setExtensionArchivistForSubArchivist.

/**
 * Sets the class for processing an archive on a subarchive
 * <p>
 * If there an exception occurs in this method it will be caught and logged as a warning
 * @param habitat
 * @param archive
 * @param md
 * @param app
 * @param subArchivist
 */
public static void setExtensionArchivistForSubArchivist(ServiceLocator habitat, ReadableArchive archive, ModuleDescriptor md, Application app, Archivist subArchivist) {
    try {
        Collection<Sniffer> sniffers = getSniffersForModule(habitat, archive, md, app);
        ArchivistFactory archivistFactory = habitat.getService(ArchivistFactory.class);
        subArchivist.setExtensionArchivists(archivistFactory.getExtensionsArchivists(sniffers, subArchivist.getModuleType()));
    } catch (Exception e) {
        deplLogger.log(Level.WARNING, EXCEPTION_CAUGHT, new Object[] { e.getMessage(), e });
    }
}
Also used : Sniffer(org.glassfish.api.container.Sniffer) ArchivistFactory(com.sun.enterprise.deployment.archivist.ArchivistFactory) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException)

Aggregations

ArchivistFactory (com.sun.enterprise.deployment.archivist.ArchivistFactory)5 AppClientArchivist (com.sun.enterprise.deployment.archivist.AppClientArchivist)3 Archivist (com.sun.enterprise.deployment.archivist.Archivist)2 ArchiveFactory (com.sun.enterprise.deploy.shared.ArchiveFactory)1 Application (com.sun.enterprise.deployment.Application)1 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)1 DeploymentDescriptorFile (com.sun.enterprise.deployment.io.DeploymentDescriptorFile)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Sniffer (org.glassfish.api.container.Sniffer)1 ArchiveType (org.glassfish.api.deployment.archive.ArchiveType)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)1 RootDeploymentDescriptor (org.glassfish.deployment.common.RootDeploymentDescriptor)1 SAXParseException (org.xml.sax.SAXParseException)1