Search in sources :

Example 6 with AppClientArchivist

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

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

the class UndeployedLaunchable method getDescriptor.

public ApplicationClientDescriptor getDescriptor(final URLClassLoader loader) throws IOException, SAXParseException {
    this.classLoader = loader;
    if (acDesc == null) {
        final AppClientArchivist _archivist = getArchivist(AccessController.doPrivileged(new PrivilegedAction<ACCClassLoader>() {

            @Override
            public ACCClassLoader run() {
                return new ACCClassLoader(loader.getURLs(), loader.getParent());
            }
        }));
        _archivist.setAnnotationProcessingRequested(true);
        acDesc = _archivist.open(clientRA);
        Application.createVirtualApplication(null, acDesc.getModuleDescriptor());
        acDesc.getApplication().setAppName(getDefaultApplicationName(clientRA));
    }
    return acDesc;
}
Also used : PrivilegedAction(java.security.PrivilegedAction) AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist)

Example 8 with AppClientArchivist

use of com.sun.enterprise.deployment.archivist.AppClientArchivist 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 9 with AppClientArchivist

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

the class AppClientDeployer method createAndSaveHelper.

private AppClientDeployerHelper createAndSaveHelper(final DeploymentContext dc, final ClassLoader clientModuleLoader) throws IOException {
    final AppClientArchivist archivist = habitat.getService(AppClientArchivist.class);
    final AppClientDeployerHelper h = AppClientDeployerHelper.newInstance(dc, archivist, clientModuleLoader, habitat, jarSigner);
    dc.addTransientAppMetaData(HELPER_KEY_NAME + moduleURI(dc), h.proxy());
    return h;
}
Also used : AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist)

Example 10 with AppClientArchivist

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

the class StandAloneAppClientInfo method postConstruct.

public void postConstruct() {
    Archivist archivist = archivistFactory.getArchivist(ModuleType.CAR.toString(), getClassLoader());
    if (!(archivist instanceof AppClientArchivist)) {
        throw new IllegalArgumentException("expected an app client module but " + appClientArchive.getURI().toASCIIString() + " was recognized by " + archivist.getClass().getName());
    }
    appClientArchivist = (AppClientArchivist) archivist;
    setDescriptor(appClientArchivist.getDescriptor());
}
Also used : AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) Archivist(com.sun.enterprise.deployment.archivist.Archivist) AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist)

Aggregations

AppClientArchivist (com.sun.enterprise.deployment.archivist.AppClientArchivist)10 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)3 ArchivistFactory (com.sun.enterprise.deployment.archivist.ArchivistFactory)3 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)3 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)2 Archivist (com.sun.enterprise.deployment.archivist.Archivist)2 File (java.io.File)2 Attributes (java.util.jar.Attributes)2 Manifest (java.util.jar.Manifest)2 ACCAppClientArchivist (org.glassfish.appclient.common.ACCAppClientArchivist)2 ArchiveFactory (com.sun.enterprise.deploy.shared.ArchiveFactory)1 Application (com.sun.enterprise.deployment.Application)1 MultiReadableArchive (com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive)1 URI (java.net.URI)1 PrivilegedAction (java.security.PrivilegedAction)1 ArrayList (java.util.ArrayList)1 ArchiveType (org.glassfish.api.deployment.archive.ArchiveType)1 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)1 RootDeploymentDescriptor (org.glassfish.deployment.common.RootDeploymentDescriptor)1