Search in sources :

Example 11 with ApplicationState

use of fish.payara.nucleus.hotdeploy.ApplicationState 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 virtualServer, WebModuleConfig webModuleConfig, String j2eeApplication, Properties deploymentProperties) throws Exception {
    DeploymentContext dc = webModuleConfig.getDeploymentContext();
    String webModuleName = webModuleConfig.getName();
    String webModuleContextPath = webModuleConfig.getContextPath();
    if (webModuleContextPath.indexOf('%') != -1) {
        try {
            RequestUtil.urlDecode(webModuleContextPath, "UTF-8");
        } catch (Exception e) {
            throw new Exception(format(rb.getString(INVALID_ENCODED_CONTEXT_ROOT), webModuleName, webModuleContextPath));
        }
    }
    if (webModuleContextPath.length() == 0 && virtualServer.getDefaultWebModuleID() != null) {
        throw new Exception(format(rb.getString(DEFAULT_WEB_MODULE_CONFLICT), new Object[] { webModuleName, virtualServer.getID() }));
    }
    webModuleConfig.setWorkDirBase(_appsWorkRoot);
    webModuleConfig.setStubBaseDir(appsStubRoot);
    final String displayContextPath;
    if (webModuleContextPath.isEmpty()) {
        displayContextPath = "/";
    } else {
        displayContextPath = webModuleContextPath;
    }
    final File docBase;
    if (JWS_APPCLIENT_MODULE_NAME.equals(webModuleName)) {
        docBase = new File(System.getProperty("com.sun.aas.installRoot"));
    } else {
        docBase = webModuleConfig.getLocation();
    }
    Map<String, AdHocServletInfo> adHocPaths = null;
    Map<String, AdHocServletInfo> adHocSubtrees = null;
    WebModule webModule = (WebModule) virtualServer.findChild(webModuleContextPath);
    if (webModule != null) {
        Optional<ApplicationState> appState = hotDeployService.getApplicationState(dc);
        if (webModule 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 (webModule.hasAdHocPaths()) {
                adHocPaths = webModule.getAdHocPaths();
            }
            if (webModule.hasAdHocSubtrees()) {
                adHocSubtrees = webModule.getAdHocSubtrees();
            }
            virtualServer.removeChild(webModule);
        } else if (DEFAULT_WEB_MODULE_NAME.equals(webModule.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(webModuleContextPath, webModule.getWebBundleDescriptor().getApplication().getRegistrationName(), virtualServer.getName(), true, null);
        } else if (!webModule.getAvailable()) {
            /*
                 * Context has been marked unavailable by a previous call to disableWebModule. Mark the context as available and return
                 */
            webModule.setAvailable(true);
            return webModule;
        } else if (appState.map(ApplicationState::isActive).orElse(false)) {
            webModule.stop();
            if (webModule.getWebModuleConfig() != webModuleConfig || webModule.getWebBundleDescriptor() != webModuleConfig.getDescriptor()) {
                _embedded.updateContext(webModule, virtualServer.getDefaultContextXmlLocation(), virtualServer.getDefaultWebXmlLocation(), useDOLforDeployment, webModuleConfig);
                processWebBundleDescriptor(virtualServer, webModule, webModuleConfig, displayContextPath);
            }
            processWebAppClassLoader(webModule, webModuleConfig);
            webModule.start();
            return webModule;
        } else {
            throw new Exception(format(rb.getString(DUPLICATE_CONTEXT_ROOT), virtualServer.getID(), webModule.getModuleName(), displayContextPath, webModuleName));
        }
    }
    if (logger.isLoggable(FINEST)) {
        logger.log(FINEST, WEB_MODULE_LOADING, new Object[] { webModuleName, virtualServer.getID(), displayContextPath });
    }
    webModule = (WebModule) _embedded.createContext(webModuleName, webModuleContextPath, docBase, virtualServer.getDefaultContextXmlLocation(), virtualServer.getDefaultWebXmlLocation(), useDOLforDeployment, webModuleConfig);
    // For now disable JNDI
    webModule.setUseNaming(false);
    // Set JSR 77 object name and attributes
    Engine vsContainer = (Engine) virtualServer.getParent();
    if (vsContainer != null) {
        webModule.setEngineName(vsContainer.getName());
        webModule.setJvmRoute(vsContainer.getJvmRoute());
    }
    webModule.setDomain(_serverContext.getDefaultDomainName());
    webModule.setJ2EEServer(_serverContext.getInstanceName());
    webModule.setJ2EEApplication(j2eeApplication);
    webModule.setCacheControls(virtualServer.getCacheControls());
    webModule.setBean(webModuleConfig.getBean());
    if (adHocPaths != null) {
        webModule.addAdHocPaths(adHocPaths);
    }
    if (adHocSubtrees != null) {
        webModule.addAdHocSubtrees(adHocSubtrees);
    }
    final WebBundleDescriptor webBundleDescriptor = webModuleConfig.getDescriptor();
    if (webBundleDescriptor == null) {
        logger.log(WARNING, UNABLE_TO_SET_CONTEXT_ROOT, webModuleConfig);
    } else {
        webModule.setContextRoot(webBundleDescriptor.getContextRoot());
    }
    // 
    // 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.
    final String webModuleWorkDir = webModuleConfig.getWorkDir();
    if (webModuleWorkDir != null) {
        StringBuilder workDir = new StringBuilder(webModuleConfig.getWorkDir());
        if (webModuleName.equals(DEFAULT_WEB_MODULE_NAME)) {
            workDir.append("-");
            workDir.append(makeFriendlyFilename(virtualServer.getID()));
        }
        webModule.setWorkDir(workDir.toString());
    }
    ClassLoader parentLoader = webModuleConfig.getParentLoader();
    if (parentLoader == null) {
        // Use the shared classloader as the parent for all
        // standalone web-modules
        parentLoader = _serverContext.getSharedClassLoader();
    }
    webModule.setParentClassLoader(parentLoader);
    processWebBundleDescriptor(virtualServer, webModule, webModuleConfig, displayContextPath);
    processWebAppClassLoader(webModule, webModuleConfig);
    // set i18n info from locale-charset-info tag in sun-web.xml
    webModule.setI18nInfo();
    if (webBundleDescriptor != null) {
        final boolean isSystem = webModuleConfig.isSystemObjectType();
        final Realm realm = serviceLocator.getService(Realm.class);
        logger.finest(() -> "Realm provided by the service locator: " + realm);
        if (realm instanceof RealmInitializer) {
            ((RealmInitializer) realm).initializeRealm(webBundleDescriptor, isSystem, virtualServer.getAuthRealmName());
        }
        webModule.setRealm(realm);
        // post processing DOL object for standalone web module
        if (webBundleDescriptor.getApplication() != null && webBundleDescriptor.getApplication().isVirtual()) {
            webBundleDescriptor.visit(new WebValidatorWithoutCL());
        }
    }
    // Add virtual server mime mappings, if present
    addMimeMappings(webModule, virtualServer.getMimeMap());
    String moduleName = Constants.DEFAULT_WEB_MODULE_NAME;
    String monitoringNodeName = moduleName;
    if (webBundleDescriptor != null && webBundleDescriptor.getApplication() != null) {
        // Not a dummy web module
        com.sun.enterprise.deployment.Application app = webBundleDescriptor.getApplication();
        webModule.setStandalone(app.isVirtual());
        if (app.isVirtual()) {
            // Standalone web module
            moduleName = app.getRegistrationName();
            monitoringNodeName = webBundleDescriptor.getModuleID();
        } else {
            // Nested (inside EAR) web module
            moduleName = webBundleDescriptor.getModuleDescriptor().getArchiveUri();
            StringBuilder sb = new StringBuilder();
            sb.append(app.getRegistrationName()).append(MONITORING_NODE_SEPARATOR).append(moduleName);
            monitoringNodeName = sb.toString().replaceAll("\\.", "\\\\.").replaceAll("_war", "\\\\.war");
        }
    }
    webModule.setModuleName(moduleName);
    webModule.setMonitoringNodeName(monitoringNodeName);
    webStatsProviderBootstrap.registerApplicationStatsProviders(monitoringNodeName, virtualServer.getName(), getServletNames(webBundleDescriptor));
    virtualServer.addChild(webModule);
    webModule.loadSessions(deploymentProperties);
    return webModule;
}
Also used : WebValidatorWithoutCL(org.glassfish.web.deployment.util.WebValidatorWithoutCL) ApplicationState(fish.payara.nucleus.hotdeploy.ApplicationState) RealmInitializer(com.sun.enterprise.security.integration.RealmInitializer) LifecycleException(org.apache.catalina.LifecycleException) NamingException(javax.naming.NamingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) Application(com.sun.enterprise.deployment.Application) File(java.io.File) Realm(org.apache.catalina.Realm) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine)

Example 12 with ApplicationState

use of fish.payara.nucleus.hotdeploy.ApplicationState in project Payara by payara.

the class WebServletHandler method findWebComponentDescriptor.

private WebComponentDescriptor findWebComponentDescriptor(String servletName, Class servletClass, WebBundleDescriptor descriptor, ProcessingContext context) {
    WebComponentDescriptor webCompDesc = descriptor.getWebComponentByCanonicalName(servletName);
    ApplicationState state = context.getArchive().getExtraData(ApplicationState.class);
    if (state != null) {
        if (webCompDesc == null) {
            WebComponentDescriptor[] webCompDescs = descriptor.getWebComponentByImplName(servletClass.getName());
            if (webCompDescs.length > 0) {
                webCompDesc = webCompDescs[0];
            }
        }
        if (webCompDesc != null) {
            descriptor.removeWebComponentDescriptor(webCompDesc);
            webCompDesc = null;
        }
    }
    return webCompDesc;
}
Also used : WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) ApplicationState(fish.payara.nucleus.hotdeploy.ApplicationState)

Aggregations

ApplicationState (fish.payara.nucleus.hotdeploy.ApplicationState)12 File (java.io.File)4 IOException (java.io.IOException)4 ActionReport (org.glassfish.api.ActionReport)4 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)4 Parser (org.glassfish.hk2.classmodel.reflect.Parser)4 Types (org.glassfish.hk2.classmodel.reflect.Types)4 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)3 Application (com.sun.enterprise.deployment.Application)3 Level (java.util.logging.Level)3 ArchiveFactory (com.sun.enterprise.deploy.shared.ArchiveFactory)2 LocalStringManagerImpl (com.sun.enterprise.util.LocalStringManagerImpl)2 FileUtils (com.sun.enterprise.util.io.FileUtils)2 HotDeployService (fish.payara.nucleus.hotdeploy.HotDeployService)2 Annotation (java.lang.annotation.Annotation)2 List (java.util.List)2 Optional (java.util.Optional)2 Logger (java.util.logging.Logger)2 AnnotatedElementHandler (org.glassfish.apf.AnnotatedElementHandler)2 HandlerProcessingResult (org.glassfish.apf.HandlerProcessingResult)2