Search in sources :

Example 1 with WebArchivist

use of org.glassfish.web.deployment.archivist.WebArchivist in project Payara by payara.

the class WebContainer method updateHost.

/**
 * Updates a virtual-server element.
 *
 * @param vsBean the virtual-server config bean.
 */
public void updateHost(com.sun.enterprise.config.serverbeans.VirtualServer vsBean) throws LifecycleException {
    if (org.glassfish.api.web.Constants.ADMIN_VS.equals(vsBean.getId())) {
        return;
    }
    final VirtualServer vs = (VirtualServer) getEngine().findChild(vsBean.getId());
    if (vs == null) {
        logger.log(Level.WARNING, LogFacade.CANNOT_UPDATE_NON_EXISTENCE_VS, vsBean.getId());
        return;
    }
    boolean updateListeners = false;
    // Only update connectors if virtual-server.http-listeners is changed dynamically
    if (vs.getNetworkListeners() == null) {
        if (vsBean.getNetworkListeners() == null) {
            updateListeners = false;
        } else {
            updateListeners = true;
        }
    } else if (vs.getNetworkListeners().equals(vsBean.getNetworkListeners())) {
        updateListeners = false;
    } else {
        List<String> vsList = StringUtils.parseStringList(vs.getNetworkListeners(), ",");
        List<String> vsBeanList = StringUtils.parseStringList(vsBean.getNetworkListeners(), ",");
        for (String vsBeanName : vsBeanList) {
            if (!vsList.contains(vsBeanName)) {
                updateListeners = true;
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, LogFacade.UPDATE_LISTENER, new Object[] { vsBeanName, vs.getNetworkListeners() });
                }
                break;
            }
        }
    }
    // Must retrieve the old default-web-module before updating the
    // virtual server with the new vsBean, because default-web-module is
    // read from vsBean
    String oldDefaultWebModule = vs.getDefaultWebModuleID();
    vs.setBean(vsBean);
    String vsLogFile = vsBean.getLogFile();
    vs.setLogFile(vsLogFile, logLevel, logServiceFile);
    vs.configureState();
    vs.clearAliases();
    vs.configureAliases();
    // support both docroot property and attribute
    String docroot = vsBean.getPropertyValue("docroot");
    if (docroot == null) {
        docroot = vsBean.getDocroot();
    }
    if (docroot != null) {
        // Only update docroot if it is modified
        if (!vs.getDocRoot().getAbsolutePath().equals(docroot)) {
            updateDocroot(docroot, vs, vsBean);
        }
    }
    List<Property> props = vs.getProperties();
    for (Property prop : props) {
        updateHostProperties(vsBean, prop.getName(), prop.getValue(), securityService, vs);
    }
    vs.configureSingleSignOn(globalSSOEnabled, webContainerFeatureFactory, isSsoFailoverEnabled());
    vs.reconfigureAccessLog(globalAccessLogBufferSize, globalAccessLogWriteInterval, habitat, domain, globalAccessLoggingEnabled);
    // old listener names
    List<String> oldListenerList = StringUtils.parseStringList(vsBean.getNetworkListeners(), ",");
    String[] oldListeners = (oldListenerList != null) ? oldListenerList.toArray(new String[oldListenerList.size()]) : new String[0];
    // new listener config
    HashSet<NetworkListener> networkListeners = new HashSet<NetworkListener>();
    if (oldListenerList != null) {
        for (String listener : oldListeners) {
            boolean found = false;
            for (NetworkListener httpListener : serverConfig.getNetworkConfig().getNetworkListeners().getNetworkListener()) {
                if (httpListener.getName().equals(listener)) {
                    networkListeners.add(httpListener);
                    found = true;
                    break;
                }
            }
            if (!found) {
                String msg = rb.getString(LogFacade.LISTENER_REFERENCED_BY_HOST_NOT_EXIST);
                msg = MessageFormat.format(msg, listener, vs.getName());
                logger.log(Level.SEVERE, msg);
            }
        }
        // Update the port numbers with which the virtual server is
        // associated
        configureHostPortNumbers(vs, networkListeners);
    } else {
        // The virtual server is not associated with any http listeners
        vs.setNetworkListenerNames(new String[0]);
    }
    // have been removed from its http-listeners attribute
    for (String oldListener : oldListeners) {
        boolean found = false;
        for (NetworkListener httpListener : networkListeners) {
            if (httpListener.getName().equals(oldListener)) {
                found = true;
            }
        }
        if (!found) {
            // http listener was removed
            Connector[] connectors = _embedded.findConnectors();
            for (Connector connector : connectors) {
                WebConnector conn = (WebConnector) connector;
                if (oldListener.equals(conn.getName())) {
                    try {
                        conn.getMapperListener().unregisterHost(vs.getJmxName());
                    } catch (Exception e) {
                        throw new LifecycleException(e);
                    }
                }
            }
        }
    }
    // have been added to its http-listeners attribute
    for (NetworkListener httpListener : networkListeners) {
        boolean found = false;
        for (String oldListener : oldListeners) {
            if (httpListener.getName().equals(oldListener)) {
                found = true;
            }
        }
        if (!found) {
            // http listener was added
            Connector[] connectors = _embedded.findConnectors();
            for (Connector connector : connectors) {
                WebConnector conn = (WebConnector) connector;
                if (httpListener.getName().equals(conn.getName())) {
                    if (!conn.isAvailable()) {
                        conn.start();
                    }
                    try {
                        conn.getMapperListener().registerHost(vs);
                    } catch (Exception e) {
                        throw new LifecycleException(e);
                    }
                }
            }
        }
    }
    // passing in "null" as the default context path
    if (oldDefaultWebModule != null) {
        updateDefaultWebModule(vs, oldListeners, null);
    }
    /*
         * Add default web module if one has been configured for the
         * virtual server. If the module declared as the default web module
         * has already been deployed at the root context, we don't have
         * to do anything.
         */
    WebModuleConfig wmInfo = vs.getDefaultWebModule(domain, habitat.<WebArchivist>getService(WebArchivist.class), appRegistry);
    if ((wmInfo != null) && (wmInfo.getContextPath() != null) && !"".equals(wmInfo.getContextPath()) && !"/".equals(wmInfo.getContextPath())) {
        // Remove dummy context that was created off of docroot, if such
        // a context exists
        removeDummyModule(vs);
        updateDefaultWebModule(vs, vs.getNetworkListenerNames(), wmInfo);
    } else {
        WebModuleConfig wmc = vs.createSystemDefaultWebModuleIfNecessary(habitat.<WebArchivist>getService(WebArchivist.class));
        if (wmc != null) {
            loadStandaloneWebModule(vs, wmc);
        }
    }
    if (updateListeners) {
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, LogFacade.VS_UPDATED_NETWORK_LISTENERS, new Object[] { vs.getName(), vs.getNetworkListeners(), vsBean.getNetworkListeners() });
        }
        /*
             * Need to update connector and mapper restart is required
             * when virtual-server.http-listeners is changed dynamically
             */
        List<NetworkListener> httpListeners = serverConfig.getNetworkConfig().getNetworkListeners().getNetworkListener();
        if (httpListeners != null) {
            for (NetworkListener httpListener : httpListeners) {
                updateConnector(httpListener, habitat.<HttpService>getService(HttpService.class));
            }
        }
    }
}
Also used : PECoyoteConnector(com.sun.enterprise.web.connector.coyote.PECoyoteConnector) Connector(org.apache.catalina.Connector) LifecycleException(org.apache.catalina.LifecycleException) LifecycleException(org.apache.catalina.LifecycleException) NamingException(javax.naming.NamingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException) WebArchivist(org.glassfish.web.deployment.archivist.WebArchivist) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) HashSet(java.util.HashSet)

Example 2 with WebArchivist

use of org.glassfish.web.deployment.archivist.WebArchivist in project Payara by payara.

the class WebContainer method loadSystemDefaultWebModules.

// ------------------------------------------------------ Private Methods
/**
 * Configures a default web module for each virtual server based on the
 * virtual server's docroot if a virtual server does not specify
 * any default-web-module, and none of its web modules are loaded at "/"
 * <p/>
 * Needed in postConstruct before Deployment.ALL_APPLICATIONS_PROCESSED
 * for "jsp from docroot before web container start" scenario
 */
public void loadSystemDefaultWebModules() {
    WebModuleConfig wmInfo = null;
    String defaultPath = null;
    Container[] vsArray = getEngine().findChildren();
    for (Container aVsArray : vsArray) {
        if (aVsArray instanceof VirtualServer) {
            VirtualServer vs = (VirtualServer) aVsArray;
            /*
                * Let AdminConsoleAdapter handle any requests for
                * the root context of the '__asadmin' virtual-server, see
                * https://glassfish.dev.java.net/issues/show_bug.cgi?id=5664
                */
            if (org.glassfish.api.web.Constants.ADMIN_VS.equals(vs.getName())) {
                continue;
            }
            // Create default web module off of virtual
            // server's docroot if necessary
            wmInfo = vs.createSystemDefaultWebModuleIfNecessary(habitat.<WebArchivist>getService(WebArchivist.class));
            if (wmInfo != null) {
                defaultPath = wmInfo.getContextPath();
                loadStandaloneWebModule(vs, wmInfo);
            }
            if (logger.isLoggable(Level.INFO)) {
                logger.log(Level.INFO, LogFacade.VIRTUAL_SERVER_LOADED_DEFAULT_WEB_MODULE, new Object[] { vs.getName(), defaultPath });
            }
        }
    }
}
Also used : Container(org.apache.catalina.Container) WebArchivist(org.glassfish.web.deployment.archivist.WebArchivist)

Example 3 with WebArchivist

use of org.glassfish.web.deployment.archivist.WebArchivist in project Payara by payara.

the class WebContainer method unloadWebModule.

/**
 * Undeploy a web application.
 *
 * @param contextRoot    the context's name to undeploy
 * @param appName        the J2EE appname used at deployment time
 * @param virtualServers List of current virtual-server object.
 * @param dummy          true if the web module to be undeployed is a dummy web
 *                       module, that is, a web module created off of a virtual server's
 *                       docroot
 * @param props
 */
public void unloadWebModule(String contextRoot, String appName, String virtualServers, boolean dummy, Properties props) {
    if (logger.isLoggable(Level.FINEST)) {
        logger.log(Level.FINEST, LogFacade.LOADING_WEB_MODULE, new Object[] { contextRoot, virtualServers });
    }
    // tomcat contextRoot starts with "/"
    if (contextRoot.length() != 0 && !contextRoot.startsWith("/")) {
        contextRoot = "/" + contextRoot;
    } else if ("/".equals(contextRoot)) {
        // Make corresponding change as in WebModuleConfig.getContextPath()
        contextRoot = "";
    }
    List<String> hostList = StringUtils.parseStringList(virtualServers, " ,");
    boolean unloadFromAll = hostList == null || hostList.isEmpty();
    boolean hasBeenUndeployed = false;
    VirtualServer host = null;
    WebModule context = null;
    Container[] hostArray = getEngine().findChildren();
    for (Container aHostArray : hostArray) {
        host = (VirtualServer) aHostArray;
        if (unloadFromAll || hostList.contains(host.getName()) || verifyAlias(hostList, host)) {
            context = (WebModule) host.findChild(contextRoot);
            if (context != null && context.getWebBundleDescriptor().getApplication().getRegistrationName().equals(appName)) {
                context.saveSessions(props);
                host.removeChild(context);
                webStatsProviderBootstrap.unregisterApplicationStatsProviders(context.getMonitoringNodeName(), host.getName());
                try {
                    /*
                         * If the webapp is being undeployed as part of a
                         * domain shutdown, we don't want to destroy it,
                         * as that would remove any sessions persisted to
                         * file. Any active sessions need to survive the
                         * domain shutdown, so that they may be resumed
                         * after the domain has been restarted.
                         */
                    if (!isShutdown) {
                        context.destroy();
                    }
                } catch (Exception ex) {
                    String msg = rb.getString(LogFacade.EXCEPTION_DURING_DESTROY);
                    msg = MessageFormat.format(msg, contextRoot, host.getName());
                    logger.log(Level.WARNING, msg, ex);
                }
                if (logger.isLoggable(Level.FINEST)) {
                    logger.log(Level.FINEST, LogFacade.CONTEXT_UNDEPLOYED, new Object[] { contextRoot, host });
                }
                hasBeenUndeployed = true;
                host.fireContainerEvent(Deployer.REMOVE_EVENT, context);
                /*
                     * If the web module that has been unloaded
                     * contained any mappings for ad-hoc paths,
                     * those mappings must be preserved by registering an
                     * ad-hoc web module at the same context root
                     */
                if (context.hasAdHocPaths() || context.hasAdHocSubtrees()) {
                    WebModule wm = createAdHocWebModule(context.getID(), host, contextRoot, context.getJ2EEApplication());
                    wm.addAdHocPaths(context.getAdHocPaths());
                    wm.addAdHocSubtrees(context.getAdHocSubtrees());
                }
                // START GlassFish 141
                if (!dummy && !isShutdown) {
                    WebModuleConfig wmInfo = host.createSystemDefaultWebModuleIfNecessary(habitat.<WebArchivist>getService(WebArchivist.class));
                    if (wmInfo != null) {
                        loadStandaloneWebModule(host, wmInfo);
                    }
                }
            // END GlassFish 141
            }
        }
    }
    if (!hasBeenUndeployed) {
        logger.log(Level.SEVERE, LogFacade.UNDEPLOY_ERROR, contextRoot);
    }
}
Also used : Container(org.apache.catalina.Container) LifecycleException(org.apache.catalina.LifecycleException) NamingException(javax.naming.NamingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException) WebArchivist(org.glassfish.web.deployment.archivist.WebArchivist)

Example 4 with WebArchivist

use of org.glassfish.web.deployment.archivist.WebArchivist in project Payara by payara.

the class WebContainer method loadDefaultWebModulesAfterAllAppsProcessed.

/**
 * Configures a default web module for each virtual server
 * if default-web-module is defined.
 */
public void loadDefaultWebModulesAfterAllAppsProcessed() {
    String defaultPath = null;
    Container[] vsArray = getEngine().findChildren();
    for (Container aVsArray : vsArray) {
        if (aVsArray instanceof VirtualServer) {
            VirtualServer vs = (VirtualServer) aVsArray;
            /*
                * Let AdminConsoleAdapter handle any requests for
                * the root context of the '__asadmin' virtual-server, see
                * https://glassfish.dev.java.net/issues/show_bug.cgi?id=5664
                */
            if (org.glassfish.api.web.Constants.ADMIN_VS.equals(vs.getName())) {
                continue;
            }
            WebModuleConfig wmInfo = vs.getDefaultWebModule(domain, habitat.<WebArchivist>getService(WebArchivist.class), appRegistry);
            if (wmInfo != null) {
                defaultPath = wmInfo.getContextPath();
                // Virtual server declares default-web-module
                try {
                    updateDefaultWebModule(vs, vs.getNetworkListenerNames(), wmInfo);
                } catch (LifecycleException le) {
                    String msg = rb.getString(LogFacade.DEFAULT_WEB_MODULE_ERROR);
                    msg = MessageFormat.format(msg, defaultPath, vs.getName());
                    logger.log(Level.SEVERE, msg, le);
                }
                if (logger.isLoggable(Level.INFO)) {
                    logger.log(Level.INFO, LogFacade.VIRTUAL_SERVER_LOADED_DEFAULT_WEB_MODULE, new Object[] { vs.getName(), defaultPath });
                }
            } else {
            // No need to create default web module off of virtual
            // server's docroot since system web modules are already
            // created in WebContainer.postConstruct
            }
        }
    }
}
Also used : Container(org.apache.catalina.Container) LifecycleException(org.apache.catalina.LifecycleException) WebArchivist(org.glassfish.web.deployment.archivist.WebArchivist)

Aggregations

WebArchivist (org.glassfish.web.deployment.archivist.WebArchivist)4 Container (org.apache.catalina.Container)3 LifecycleException (org.apache.catalina.LifecycleException)3 BindException (java.net.BindException)2 MalformedURLException (java.net.MalformedURLException)2 NamingException (javax.naming.NamingException)2 HttpService (com.sun.enterprise.config.serverbeans.HttpService)1 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)1 PECoyoteConnector (com.sun.enterprise.web.connector.coyote.PECoyoteConnector)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Connector (org.apache.catalina.Connector)1 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)1 Property (org.jvnet.hk2.config.types.Property)1