Search in sources :

Example 46 with Application

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

the class WebContainer method loadWebModule.

/**
 * Creates and configures a web module and adds it to the specified
 * virtual server.
 */
private WebModule loadWebModule(VirtualServer vs, WebModuleConfig wmInfo, String j2eeApplication, Properties deploymentProperties) throws Exception {
    String wmName = wmInfo.getName();
    String wmContextPath = wmInfo.getContextPath();
    if (wmContextPath.indexOf('%') != -1) {
        try {
            RequestUtil.urlDecode(wmContextPath, "UTF-8");
        } catch (Exception e) {
            String msg = rb.getString(LogFacade.INVALID_ENCODED_CONTEXT_ROOT);
            msg = MessageFormat.format(msg, wmName, wmContextPath);
            throw new Exception(msg);
        }
    }
    if (wmContextPath.length() == 0 && vs.getDefaultWebModuleID() != null) {
        String msg = rb.getString(LogFacade.DEFAULT_WEB_MODULE_CONFLICT);
        msg = MessageFormat.format(msg, new Object[] { wmName, vs.getID() });
        throw new Exception(msg);
    }
    wmInfo.setWorkDirBase(_appsWorkRoot);
    // START S1AS 6178005
    wmInfo.setStubBaseDir(appsStubRoot);
    // END S1AS 6178005
    String displayContextPath = null;
    if (wmContextPath.length() == 0)
        displayContextPath = "/";
    else
        displayContextPath = wmContextPath;
    Map<String, AdHocServletInfo> adHocPaths = null;
    Map<String, AdHocServletInfo> adHocSubtrees = null;
    WebModule ctx = (WebModule) vs.findChild(wmContextPath);
    if (ctx != null) {
        if (ctx instanceof AdHocWebModule) {
            /*
                 * Found ad-hoc web module which has been created by web
                 * container in order to store mappings for ad-hoc paths
                 * and subtrees.
                 * All these mappings must be propagated to the context
                 * that is being deployed.
                 */
            if (ctx.hasAdHocPaths()) {
                adHocPaths = ctx.getAdHocPaths();
            }
            if (ctx.hasAdHocSubtrees()) {
                adHocSubtrees = ctx.getAdHocSubtrees();
            }
            vs.removeChild(ctx);
        } else if (Constants.DEFAULT_WEB_MODULE_NAME.equals(ctx.getModuleName())) {
            /*
                 * Dummy context that was created just off of a docroot,
                 * (see
                 * VirtualServer.createSystemDefaultWebModuleIfNecessary()).
                 * Unload it so it can be replaced with the web module to be
                 * loaded
                 */
            unloadWebModule(wmContextPath, ctx.getWebBundleDescriptor().getApplication().getRegistrationName(), vs.getName(), true, null);
        } else if (!ctx.getAvailable()) {
            /*
                 * Context has been marked unavailable by a previous
                 * call to disableWebModule. Mark the context as available and
                 * return
                 */
            ctx.setAvailable(true);
            return ctx;
        } else {
            String msg = rb.getString(LogFacade.DUPLICATE_CONTEXT_ROOT);
            throw new Exception(MessageFormat.format(msg, vs.getID(), ctx.getModuleName(), displayContextPath, wmName));
        }
    }
    if (logger.isLoggable(Level.FINEST)) {
        Object[] params = { wmName, vs.getID(), displayContextPath };
        logger.log(Level.FINEST, LogFacade.WEB_MODULE_LOADING, params);
    }
    File docBase = null;
    if (JWS_APPCLIENT_MODULE_NAME.equals(wmName)) {
        docBase = new File(System.getProperty("com.sun.aas.installRoot"));
    } else {
        docBase = wmInfo.getLocation();
    }
    ctx = (WebModule) _embedded.createContext(wmName, wmContextPath, docBase, vs.getDefaultContextXmlLocation(), vs.getDefaultWebXmlLocation(), useDOLforDeployment, wmInfo);
    // for now disable JNDI
    ctx.setUseNaming(false);
    // Set JSR 77 object name and attributes
    Engine engine = (Engine) vs.getParent();
    if (engine != null) {
        ctx.setEngineName(engine.getName());
        ctx.setJvmRoute(engine.getJvmRoute());
    }
    String j2eeServer = _serverContext.getInstanceName();
    String domain = _serverContext.getDefaultDomainName();
    // String[] javaVMs = J2EEModuleUtil.getjavaVMs();
    ctx.setDomain(domain);
    ctx.setJ2EEServer(j2eeServer);
    ctx.setJ2EEApplication(j2eeApplication);
    // turn on container internal cache by default as in v2
    // ctx.setCachingAllowed(false);
    ctx.setCacheControls(vs.getCacheControls());
    ctx.setBean(wmInfo.getBean());
    if (adHocPaths != null) {
        ctx.addAdHocPaths(adHocPaths);
    }
    if (adHocSubtrees != null) {
        ctx.addAdHocSubtrees(adHocSubtrees);
    }
    // Object containing web.xml information
    WebBundleDescriptor wbd = wmInfo.getDescriptor();
    // Set the context root
    if (wbd != null) {
        ctx.setContextRoot(wbd.getContextRoot());
    } else {
        // Should never happen.
        logger.log(Level.WARNING, LogFacade.UNABLE_TO_SET_CONTEXT_ROOT, wmInfo);
    }
    // 
    // Ensure that the generated directory for JSPs in the document root
    // (i.e. those that are serviced by a system default-web-module)
    // is different for each virtual server.
    String wmInfoWorkDir = wmInfo.getWorkDir();
    if (wmInfoWorkDir != null) {
        StringBuilder workDir = new StringBuilder(wmInfo.getWorkDir());
        if (wmName.equals(Constants.DEFAULT_WEB_MODULE_NAME)) {
            workDir.append("-");
            workDir.append(FileUtils.makeFriendlyFilename(vs.getID()));
        }
        ctx.setWorkDir(workDir.toString());
    }
    ClassLoader parentLoader = wmInfo.getParentLoader();
    if (parentLoader == null) {
        // Use the shared classloader as the parent for all
        // standalone web-modules
        parentLoader = _serverContext.getSharedClassLoader();
    }
    ctx.setParentClassLoader(parentLoader);
    if (wbd != null) {
        // Determine if an alternate DD is set for this web-module in
        // the application
        ctx.configureAlternateDD(wbd);
        ctx.configureWebServices(wbd);
    }
    // Object containing sun-web.xml information
    SunWebAppImpl iasBean = null;
    // The default context is the only case when wbd == null
    if (wbd != null) {
        iasBean = (SunWebAppImpl) wbd.getSunDescriptor();
    }
    // set the sun-web config bean
    ctx.setIasWebAppConfigBean(iasBean);
    // Configure SingleThreadedServletPools, work/tmp directory etc
    ctx.configureMiscSettings(iasBean, vs, displayContextPath);
    // Configure alternate docroots if dummy web module
    if (ctx.getID().startsWith(Constants.DEFAULT_WEB_MODULE_NAME)) {
        ctx.setAlternateDocBases(vs.getProperties());
    }
    // Configure the class loader delegation model, classpath etc
    Loader loader = ctx.configureLoader(iasBean);
    // Set the class loader on the DOL object
    if (wbd != null && wbd.hasWebServices()) {
        wbd.addExtraAttribute("WEBLOADER", loader);
    }
    for (LifecycleListener listener : ctx.findLifecycleListeners()) {
        if (listener instanceof ContextConfig) {
            ((ContextConfig) listener).setClassLoader(wmInfo.getAppClassLoader());
        }
    }
    // Configure the session manager and other related settings
    ctx.configureSessionSettings(wbd, wmInfo);
    // set i18n info from locale-charset-info tag in sun-web.xml
    ctx.setI18nInfo();
    if (wbd != null) {
        String resourceType = wmInfo.getObjectType();
        boolean isSystem = resourceType != null && resourceType.startsWith("system-");
        // security will generate policy for system default web module
        if (!wmName.startsWith(Constants.DEFAULT_WEB_MODULE_NAME)) {
            // TODO : v3 : dochez Need to remove dependency on security
            Realm realm = habitat.getService(Realm.class);
            if ("null".equals(j2eeApplication)) {
                /*
                     * Standalone webapps inherit the realm referenced by
                     * the virtual server on which they are being deployed,
                     * unless they specify their own
                     */
                if (realm != null && realm instanceof RealmInitializer) {
                    ((RealmInitializer) realm).initializeRealm(wbd, isSystem, vs.getAuthRealmName());
                    ctx.setRealm(realm);
                }
            } else {
                if (realm != null && realm instanceof RealmInitializer) {
                    ((RealmInitializer) realm).initializeRealm(wbd, isSystem, null);
                    ctx.setRealm(realm);
                }
            }
        }
        // post processing DOL object for standalone web module
        if (wbd.getApplication() != null && wbd.getApplication().isVirtual()) {
            wbd.visit(new WebValidatorWithoutCL());
        }
    }
    // Add virtual server mime mappings, if present
    addMimeMappings(ctx, vs.getMimeMap());
    String moduleName = Constants.DEFAULT_WEB_MODULE_NAME;
    String monitoringNodeName = moduleName;
    if (wbd != null && wbd.getApplication() != null) {
        // Not a dummy web module
        com.sun.enterprise.deployment.Application app = wbd.getApplication();
        ctx.setStandalone(app.isVirtual());
        // S1AS BEGIN WORKAROUND FOR 6174360
        if (app.isVirtual()) {
            // Standalone web module
            moduleName = app.getRegistrationName();
            monitoringNodeName = wbd.getModuleID();
        } else {
            // Nested (inside EAR) web module
            moduleName = wbd.getModuleDescriptor().getArchiveUri();
            StringBuilder sb = new StringBuilder();
            sb.append(app.getRegistrationName()).append(MONITORING_NODE_SEPARATOR).append(moduleName);
            monitoringNodeName = sb.toString().replaceAll("\\.", "\\\\.").replaceAll("_war", "\\\\.war");
        }
    // S1AS END WORKAROUND FOR 6174360
    }
    ctx.setModuleName(moduleName);
    ctx.setMonitoringNodeName(monitoringNodeName);
    List<String> servletNames = new ArrayList<String>();
    if (wbd != null) {
        for (WebComponentDescriptor webCompDesc : wbd.getWebComponentDescriptors()) {
            if (webCompDesc.isServlet()) {
                servletNames.add(webCompDesc.getCanonicalName());
            }
        }
    }
    webStatsProviderBootstrap.registerApplicationStatsProviders(monitoringNodeName, vs.getName(), servletNames);
    vs.addChild(ctx);
    ctx.loadSessions(deploymentProperties);
    return ctx;
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) WebValidatorWithoutCL(org.glassfish.web.deployment.util.WebValidatorWithoutCL) RealmInitializer(com.sun.enterprise.security.integration.RealmInitializer) ArrayList(java.util.ArrayList) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) Loader(org.apache.catalina.Loader) LifecycleListener(org.apache.catalina.LifecycleListener) ContextConfig(org.apache.catalina.startup.ContextConfig) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) Realm(org.apache.catalina.Realm) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine) LifecycleException(org.apache.catalina.LifecycleException) NamingException(javax.naming.NamingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException) WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) Application(com.sun.enterprise.deployment.Application) File(java.io.File)

Example 47 with Application

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

the class WeldDeployer method load.

/**
 * Processing in this method is performed for each module that is in the process of being loaded by
 * the container.
 *
 * <p>
 * This method will collect information from each archive (module) and produce
 * <code>BeanDeploymentArchive</code> information for each module.
 * </p>
 *
 * <p>
 * The
 * <code>BeanDeploymentArchive</code>s are stored in the <code>Deployment</code> (that will
 * eventually be handed off to <code>Weld</code>. Once this method is called for all modules (and
 * <code>BeanDeploymentArchive</code> information has been collected for all <code>Weld</code>
 * modules), a relationship structure is produced defining the accessiblity rules for the
 * <code>BeanDeploymentArchive</code>s.
 * </p>
 *
 * @param container
 * @param context
 * @return
 */
@Override
public WeldApplicationContainer load(WeldContainer container, DeploymentContext context) {
    DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
    ApplicationInfo applicationInfo = applicationRegistry.get(deployParams.name);
    ReadableArchive archive = context.getSource();
    boolean[] setTransientAppMetaData = { false };
    // See if a WeldBootsrap has already been created - only want one per app.
    WeldBootstrap bootstrap = getWeldBootstrap(context, applicationInfo, setTransientAppMetaData);
    EjbBundleDescriptor ejbBundle = getEjbBundleFromContext(context);
    EjbServices ejbServices = null;
    Set<EjbDescriptor> ejbs = new HashSet<>();
    if (ejbBundle != null) {
        ejbs.addAll(ejbBundle.getEjbs());
        ejbServices = new EjbServicesImpl(services);
    }
    // Create a deployment collecting information from the ReadableArchive (archive)
    // If the archive is a composite, or has version numbers per maven conventions, strip them out
    String archiveName = getArchiveName(context, applicationInfo, archive);
    DeploymentImpl deploymentImpl = context.getTransientAppMetaData(WELD_DEPLOYMENT, DeploymentImpl.class);
    if (deploymentImpl == null) {
        deploymentImpl = new DeploymentImpl(archive, ejbs, context, archiveFactory, archiveName, services.getService(InjectionManager.class));
        // Add services
        TransactionServices transactionServices = new TransactionServicesImpl(services);
        deploymentImpl.getServices().add(TransactionServices.class, transactionServices);
        SecurityServices securityServices = new SecurityServicesImpl();
        deploymentImpl.getServices().add(SecurityServices.class, securityServices);
        ProxyServices proxyServices = new ProxyServicesImpl(services);
        deploymentImpl.getServices().add(ProxyServices.class, proxyServices);
        BootstrapConfigurationImpl bootstrapConfiguration = new BootstrapConfigurationImpl();
        deploymentImpl.getServices().add(BootstrapConfiguration.class, bootstrapConfiguration);
        addWeldListenerToAllWars(context);
    } else {
        deploymentImpl.scanArchive(archive, ejbs, context, archiveName);
    }
    deploymentImpl.addDeployedEjbs(ejbs);
    if (ejbBundle != null && (!deploymentImpl.getServices().contains(EjbServices.class))) {
        // EJB Services is registered as a top-level service
        deploymentImpl.getServices().add(EjbServices.class, ejbServices);
    }
    DeployCommandParameters dc = context.getCommandParameters(DeployCommandParameters.class);
    ExternalConfigurationImpl externalConfiguration = new ExternalConfigurationImpl();
    externalConfiguration.setRollingUpgradesDelimiter(System.getProperty("fish.payara.rollingUpgradesDelimiter", ":"));
    externalConfiguration.setBeanIndexOptimization(dc != null ? !dc.isAvailabilityEnabled() : true);
    deploymentImpl.getServices().add(ExternalConfiguration.class, externalConfiguration);
    BeanDeploymentArchive beanDeploymentArchive = deploymentImpl.getBeanDeploymentArchiveForArchive(archiveName);
    if (beanDeploymentArchive != null && !beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(NONE)) {
        if (setTransientAppMetaData[0]) {
            // Do this only if we have a root BDA
            appToBootstrap.put(context.getModuleMetaData(Application.class), bootstrap);
            applicationInfo.addTransientAppMetaData(WELD_BOOTSTRAP, bootstrap);
        }
        WebBundleDescriptor webBundleDescriptor = context.getModuleMetaData(WebBundleDescriptor.class);
        boolean developmentMode = isDevelopmentMode(context);
        if (webBundleDescriptor != null) {
            webBundleDescriptor.setExtensionProperty(WELD_EXTENSION, "true");
            // Add the Weld Listener. We have to do it here too in case addWeldListenerToAllWars wasn't
            // able to do it.
            webBundleDescriptor.addAppListenerDescriptorToFirst(new AppListenerDescriptorImpl(WELD_LISTENER));
            // Add Weld Context Listener - this listener will ensure the WeldELContextListener is used
            // for JSP's..
            webBundleDescriptor.addAppListenerDescriptor(new AppListenerDescriptorImpl(WELD_CONTEXT_LISTENER));
            // Weld 2.2.1.Final. There is a tck test for this:
            // org.jboss.cdi.tck.tests.context.session.listener.SessionContextHttpSessionListenerTest
            // This WeldTerminationListener must come after all application-defined listeners
            webBundleDescriptor.addAppListenerDescriptor(new AppListenerDescriptorImpl(WeldTerminationListenerProxy.class.getName()));
            // Adding Weld ConverstationFilter if there is a filterMapping for it and it doesn't exist already.
            // However, it will be applied only if web.xml has a mapping for it.
            // Doing this here to make sure that its done only for CDI enabled web applications
            registerWeldConversationFilter(webBundleDescriptor);
            // every deployment
            if (developmentMode) {
                registerProbeFilter(webBundleDescriptor);
            }
        }
        if (developmentMode) {
            registerProbeExtension(externalConfiguration, deploymentImpl);
        }
        BundleDescriptor bundle = (webBundleDescriptor != null) ? webBundleDescriptor : ejbBundle;
        if (bundle != null) {
            if (!beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(NONE)) {
                // Register EE injection manager at the bean deployment archive level.
                // We use the generic InjectionService service to handle all EE-style
                // injection instead of the per-dependency-type InjectionPoint approach.
                // Each InjectionServicesImpl instance knows its associated GlassFish bundle.
                InjectionServices injectionServices = new InjectionServicesImpl(deploymentImpl.injectionManager, bundle, deploymentImpl);
                if (logger.isLoggable(FINE)) {
                    logger.log(FINE, ADDING_INJECTION_SERVICES, new Object[] { injectionServices, beanDeploymentArchive.getId() });
                }
                beanDeploymentArchive.getServices().add(InjectionServices.class, injectionServices);
                EEModuleDescriptor eeModuleDescriptor = getEEModuleDescriptor(beanDeploymentArchive);
                if (eeModuleDescriptor != null) {
                    beanDeploymentArchive.getServices().add(EEModuleDescriptor.class, eeModuleDescriptor);
                }
                // Relevant in WAR BDA - WEB-INF/lib BDA scenarios
                for (BeanDeploymentArchive subBda : beanDeploymentArchive.getBeanDeploymentArchives()) {
                    if (logger.isLoggable(FINE)) {
                        logger.log(FINE, ADDING_INJECTION_SERVICES, new Object[] { injectionServices, subBda.getId() });
                    }
                    subBda.getServices().add(InjectionServices.class, injectionServices);
                    // Should not be subBda?
                    eeModuleDescriptor = getEEModuleDescriptor(beanDeploymentArchive);
                    if (eeModuleDescriptor != null) {
                        beanDeploymentArchive.getServices().add(EEModuleDescriptor.class, eeModuleDescriptor);
                    }
                }
            }
            bundleToBeanDeploymentArchive.put(bundle, beanDeploymentArchive);
        }
    }
    context.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl);
    applicationInfo.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl);
    return new WeldApplicationContainer();
}
Also used : ProxyServices(org.jboss.weld.serialization.spi.ProxyServices) ExternalConfigurationImpl(org.glassfish.weld.services.ExternalConfigurationImpl) SecurityServices(org.jboss.weld.security.spi.SecurityServices) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) NonModuleInjectionServices(org.glassfish.weld.services.NonModuleInjectionServices) InjectionServices(org.jboss.weld.injection.spi.InjectionServices) EjbServicesImpl(org.glassfish.weld.services.EjbServicesImpl) ProxyServicesImpl(org.glassfish.weld.services.ProxyServicesImpl) TransactionServicesImpl(org.glassfish.weld.services.TransactionServicesImpl) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) HashSet(java.util.HashSet) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) EjbServices(org.jboss.weld.ejb.spi.EjbServices) TransactionServices(org.jboss.weld.transaction.spi.TransactionServices) BootstrapConfigurationImpl(org.glassfish.weld.services.BootstrapConfigurationImpl) AppListenerDescriptorImpl(org.glassfish.web.deployment.descriptor.AppListenerDescriptorImpl) SecurityServicesImpl(org.glassfish.weld.services.SecurityServicesImpl) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) InjectionServicesImpl(org.glassfish.weld.services.InjectionServicesImpl) Application(com.sun.enterprise.deployment.Application) EEModuleDescriptor(org.jboss.weld.bootstrap.spi.EEModuleDescriptor)

Example 48 with Application

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

the class WeldDeployer method processApplicationStopped.

private void processApplicationStopped(ApplicationInfo applicationInfo) {
    Application application = applicationInfo.getMetaData(Application.class);
    if (application != null) {
        removeBundleDescriptors(application);
        appToBootstrap.remove(application);
    }
    String shutdown = applicationInfo.getTransientAppMetaData(WELD_SHUTDOWN, String.class);
    if (Boolean.valueOf(shutdown).equals(TRUE)) {
        return;
    }
    ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(applicationInfo.getAppClassLoader());
    try {
        WeldBootstrap bootstrap = applicationInfo.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class);
        if (bootstrap != null) {
            invocationManager.pushAppEnvironment(() -> applicationInfo.getName());
            try {
                doBootstrapShutdown(applicationInfo);
            } catch (Exception e) {
                logger.log(WARNING, WELD_BOOTSTRAP_SHUTDOWN_EXCEPTION, new Object[] { e });
            } finally {
                invocationManager.popAppEnvironment();
            }
            applicationInfo.addTransientAppMetaData(WELD_SHUTDOWN, "true");
        }
    } finally {
        Thread.currentThread().setContextClassLoader(currentContextClassLoader);
    }
    DeploymentImpl deploymentImpl = applicationInfo.getTransientAppMetaData(WELD_DEPLOYMENT, DeploymentImpl.class);
    if (deploymentImpl != null) {
        deploymentImpl.cleanup();
    }
}
Also used : WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) Application(com.sun.enterprise.deployment.Application) DeploymentException(org.glassfish.deployment.common.DeploymentException) WeldException(org.jboss.weld.exceptions.WeldException)

Example 49 with Application

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

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

the class AppClientDeployerHelper method newInstance.

/**
 * Returns the correct concrete implementation of Helper.
 * @param dc the DeploymentContext for this deployment
 * @return an instance of the correct type of Helper
 * @throws java.io.IOException
 */
static AppClientDeployerHelper newInstance(final DeploymentContext dc, final AppClientArchivist archivist, final ClassLoader gfClientModuleLoader, final ServiceLocator habitat, final ASJarSigner jarSigner) throws IOException {
    ApplicationClientDescriptor bundleDesc = dc.getModuleMetaData(ApplicationClientDescriptor.class);
    Application application = bundleDesc.getApplication();
    boolean insideEar = !application.isVirtual();
    final AppClientDeployerHelper helper = (insideEar ? new NestedAppClientDeployerHelper(dc, bundleDesc, archivist, gfClientModuleLoader, application, habitat, jarSigner) : new StandaloneAppClientDeployerHelper(dc, bundleDesc, archivist, gfClientModuleLoader, application, habitat));
    return helper;
}
Also used : ApplicationClientDescriptor(com.sun.enterprise.deployment.ApplicationClientDescriptor) Application(com.sun.enterprise.deployment.Application)

Aggregations

Application (com.sun.enterprise.deployment.Application)66 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)17 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)10 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)10 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)10 IOException (java.io.IOException)9 File (java.io.File)8 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)8 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)7 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)7 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)5 DeploymentException (org.glassfish.deployment.common.DeploymentException)5 SAXParseException (org.xml.sax.SAXParseException)5 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)4 ArrayList (java.util.ArrayList)4 WebappClassLoader (org.glassfish.web.loader.WebappClassLoader)4 OpsParams (org.glassfish.api.deployment.OpsParams)3 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)3 Applications (com.sun.enterprise.config.serverbeans.Applications)2 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)2