FileDocCategorySizeDatePackage
WebContainer.javaAPI DocGlassfish v2 API135519Wed Jul 18 08:33:30 BST 2007com.sun.enterprise.web

WebContainer

public class WebContainer extends Object implements com.sun.enterprise.admin.event.ModuleDeployEventListener, com.sun.enterprise.admin.event.ApplicationDeployEventListener, org.apache.catalina.Lifecycle, com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener
Web container implementation for the Sun ONE Application Server. This class is intended for use in versions of the application server that *do not* have web-core as well as in versions that do. NSAPI specific functionality is implemented the NSAPIWebContainer subclass in the j2ee-plugin component.

Fields Summary
public static final String
DISPATCHER_MAX_DEPTH
static final int
DEFAULT_REAP_INTERVAL
public static final String
JWS_APPCLIENT_EAR_NAME
public static final String
JWS_APPCLIENT_WAR_NAME
private static final String
JWS_APPCLIENT_MODULE_NAME
private static final String
DOC_BUILDER_FACTORY_PROPERTY
private static final String
DOC_BUILDER_FACTORY_IMPL
protected EmbeddedWebContainer
_embedded
The embedded Catalina object.
protected com.sun.enterprise.server.ServerContext
_serverContext
The server context under which this container was created.
protected com.sun.enterprise.config.ConfigContext
_configContext
The config context under which this container was created.
protected com.sun.enterprise.config.serverbeans.Domain
domain
protected com.sun.enterprise.instance.InstanceEnvironment
instance
protected com.sun.enterprise.instance.WebModulesManager
webModulesManager
protected com.sun.enterprise.instance.AppsManager
appsManager
private com.sun.enterprise.config.serverbeans.Server
_serverBean
The schema2beans object that represents the root node of server.xml.
private String
_id
The id of this web container object.
protected static final Logger
_logger
The logger to use for logging ALL web container related messages.
protected static final ResourceBundle
_rb
The resource bundle containing the message strings for _logger.
protected static com.sun.enterprise.admin.monitor.registry.MonitoringLevel
monitoringLevel
protected Level
_logLevel
The current level of logging verbosity for this object.
protected int
_debug
Controls the verbosity of the web container subsystem's debug messages. This value is non-zero only when the iAS level is one of FINE, FINER or FINEST.
private String
_modulesWorkRoot
Top-level directory for files generated (compiled JSPs) by standalone web modules.
private String
modulesStubRoot
Top-level directory where ejb stubs of standalone web modules are stored
protected String
_modulesRoot
Absolute path for location where all the deployed standalone modules are stored for this Server Instance.
private String
_appsWorkRoot
Top-level directory for files generated by application web modules.
private String
appsStubRoot
Top-level directory where ejb stubs for applications are stored.
private boolean
_reloadingEnabled
Indicates whether dynamic reloading is enabled (as specified by the dynamic-reload-enabled attribute of in server.xml)
private int
_pollInterval
The number of seconds between checks for modified classes (if dynamic reloading is enabled). This value is specified by the reload-poll-interval attribute of in server.xml.
private com.sun.enterprise.server.StandaloneWebModulesManager
_reloadManager
Adds/removes standalone web modules to the reload monitor thread (when dynamic reloading is enabled in server.xml).
private org.apache.catalina.util.LifecycleSupport
_lifecycle
The lifecycle event support for this component.
protected boolean
_started
Has this component been started yet?
protected boolean
globalSSOEnabled
The global (at the http-service level) ssoEnabled property.
private com.sun.web.security.WebSecurityManagerFactory
webSecurityManagerFactory
The WebSecurityManagerFactory used for generating web permission
private EjbWebServiceRegistryListener
ejbWebServiceRegistryListener
protected com.sun.enterprise.server.pluggable.WebContainerFeatureFactory
webFeatureFactory
private static final String
DOL_DEPLOYMENT
protected static boolean
useDOLforDeployment
Are we using Tomcat deployment backend or DOL?
private String
instanceClassPath
The instance classpath, which is composed of the pathnames of domain_root/lib/classes and domain_root/lib/[*.jar|*.zip] (in this order), separated by the path-separator character.
private boolean
instanceEnableCookies
The value of the instance-level session property named "enableCookies"
protected static WebContainer
webContainer
The current WebContainer instance used (single).
private static boolean
debugMonitoring
private static long
debugMonitoringPeriodMS
private static WebContainerTimer
_timer
protected boolean
catalinaCachingAllowed
false when the Grizzly File Cache is enabled. When disabled the Servlet Container temporary Naming cache is used when loading the resources.
private HealthChecker
_healthChecker
private ReplicationReceiver
_replicationReceiver
private WebContainerAdminEventProcessor
_adminEventProcessor
Constructors Summary
protected WebContainer(String id, com.sun.enterprise.server.ServerContext context)
This creates the embedded Catalina/Jasper container and sets the config properties on the container.


        _id = id;
        _serverContext = context;

        _configContext = _serverContext.getConfigContext();

        String rootDir = _serverContext.getInstallRoot();
        String name = _serverContext.getInstanceName();
        instance = new InstanceEnvironment(rootDir, name);
        _modulesWorkRoot = instance.getWebModuleCompileJspPath();
        _appsWorkRoot = instance.getApplicationCompileJspPath();
        _modulesRoot = instance.getModuleRepositoryPath();

        instanceClassPath = getInstanceClassPath(instance);

        ejbWebServiceRegistryListener = new EjbWebServiceRegistryListener(this);

        // START S1AS 6178005
        modulesStubRoot = instance.getModuleStubPath();
        appsStubRoot = instance.getApplicationStubPath();
        // END S1AS 6178005

        webFeatureFactory = _serverContext.getPluggableFeatureFactory().getWebContainerFeatureFactory();

        try {
            webModulesManager = new WebModulesManager(instance);
            appsManager = new AppsManager(instance);
        } catch (ConfigException cx) {
            _logger.log(Level.WARNING,
                "Error in creating web modules manager: ", cx);
        }

        setNoTldScan();

        LogService logService = null;

        try {
            domain = (Domain) _configContext.getRootConfigBean();

            _serverBean = ServerBeansFactory.getServerBean(_configContext);

            getDynamicReloadingSettings(ServerBeansFactory.getDasConfigBean(_configContext));

            Config cfg = ServerBeansFactory.getConfigBean(_configContext);
            logService = cfg.getLogService();
            initLogLevel(logService);
            initMonitoringLevel(cfg.getMonitoringService());

            ElementProperty maxDepth
                = ServerBeansFactory.getWebContainerBean(_configContext).getElementPropertyByName(DISPATCHER_MAX_DEPTH);
            if (maxDepth != null && maxDepth.getValue() != null) {

                int depth = -1;
                try {
                    depth = Integer.parseInt(maxDepth.getValue());
                } catch (Exception e) {}

                if (depth > 0) {
                    CoyoteRequest.setMaxDispatchDepth(depth);
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.fine("Maximum depth for nested request "
                                     + "dispatches set to "
                                     + maxDepth.getValue());
                    }
                }
            }

        } catch (ConfigException e) {
            _logger.log(Level.SEVERE, "webcontainer.configError", e);
        }

        String logServiceFile = null;
        if (logService != null) {
            logServiceFile = logService.getFile();
        }
        _embedded = new EmbeddedWebContainer(_logger, _serverContext, this,
                                             logServiceFile);
        _embedded.setUseNaming(false);
        if (_debug > 1)
            _embedded.setDebug(_debug);
        _embedded.setLogger(new IASLogger(_logger));

        DigesterFactory.setSchemaResourcePrefix("/schemas/");
        DigesterFactory.setDtdResourcePrefix("/dtds/");
        ParserUtils.setSchemaResourcePrefix("/schemas/");
        ParserUtils.setDtdResourcePrefix("/dtds/");

        /*
         * Set the server name and version.
         * Allow customers to override this information by specifying
         * product.name system property. For example, some customers prefer
         * not to disclose the product name and version for security
         * reasons, in which case they would set the value of the 
         * product.name system property to the empty string.
         */
        String serverInfo = System.getProperty("product.name");
        if (serverInfo != null) {
            ServerInfo.setServerInfo(serverInfo);
        } else {
            ServerInfo.setServerInfo(Version.getVersion());
            System.setProperty("product.name", Version.getVersion());            
        }
  
        //HERCULES:add
        //added for internal monitoring
        WebDebugMonitor debugMonitor = new WebDebugMonitor();
        HashMap monitorMap = debugMonitor.getDebugMonitoringDetails();
        debugMonitoring = ((Boolean) monitorMap.get("debugMonitoring")).booleanValue();
        debugMonitoringPeriodMS = ((Long) monitorMap.get(
                                    "debugMonitoringPeriodMS")).longValue();

        if (debugMonitoring) {
            _timer.schedule(new DebugMonitor(_embedded), 0L,
                                             debugMonitoringPeriodMS);
        }
        //added for internal monitoring
        //END HERCULES:add      
    
Methods Summary
private voidaddLibs(org.apache.catalina.Loader loader, WebModule ctx)
Adds all libraries specified via the --libraries deployment option to the given loader associated with the given web context.

param
loader The loader to configure
param
ctx The loader's associated web context

 
        String list = ASClassLoaderUtil.getLibrariesForWebModule(ctx.getID());
        if (list == null) {
            return;
        }
        String[] libs = list.split(",");
        if (libs == null) {
            return;
        }

        File libDir = new File(instance.getLibPath());
        String libDirPath = libDir.getAbsolutePath();
        String appLibsPrefix = libDirPath + File.separator + "applibs"
            + File.separator;

        for (int i=0; i<libs.length; i++) {
            try {
                URL url = new URL(libs[i]);
                loader.addRepository(libs[i]);
            } catch (MalformedURLException e) {
                // Not a URL, interpret as file
                File file = new File(libs[i]);
                if (file.isAbsolute()) {
                    loader.addRepository("file:" + file.getAbsolutePath());
                } else {
                    loader.addRepository("file:" + appLibsPrefix + libs[i]);
                }
            }
        }
    
public voidaddLifecycleListener(org.apache.catalina.LifecycleListener listener)
Add a lifecycle event listener to this component.

param
listener The listener to add

        _lifecycle.addLifecycleListener(listener);
    
private voidaddMimeMappings(org.apache.catalina.core.StandardContext ctx, MimeMap mimeMap)
Adds the given mime mappings to those of the specified context, unless they're already present in the context (that is, the mime mappings of the specified context, which correspond to those in default-web.xml, can't be overridden).

param
ctx The StandardContext to whose mime mappings to add
param
mimeMap The mime mappings to be added

        if (mimeMap == null) {
            return;
        }

        for (Iterator itr = mimeMap.getExtensions(); itr.hasNext(); ) {
            String extension = (String) itr.next();
            if (ctx.findMimeMapping(extension) == null) {
                ctx.addMimeMapping(extension, mimeMap.getType(extension));
            }
        }
    
public voidapplicationDeployed(com.sun.enterprise.admin.event.ApplicationDeployEvent deployEvent)

        _adminEventProcessor.applicationDeployed(deployEvent);
    
public voidapplicationDisabled(com.sun.enterprise.admin.event.ApplicationDeployEvent deployEvent)

    
public voidapplicationEnabled(com.sun.enterprise.admin.event.ApplicationDeployEvent deployEvent)

    
public voidapplicationRedeployed(com.sun.enterprise.admin.event.ApplicationDeployEvent deployEvent)

        _adminEventProcessor.applicationRedeployed(deployEvent);
    
public voidapplicationReferenceAdded(com.sun.enterprise.admin.event.ApplicationDeployEvent event)
Invoked when an application reference is created from a server instance (or cluster) to a particular application.

throws
AdminEventListenerException when the listener is unable to process the event.

//       throws AdminEventListenerException {
                
    
public voidapplicationReferenceRemoved(com.sun.enterprise.admin.event.ApplicationDeployEvent event)
Invoked when a reference is removed from a server instance (or cluster) to a particular application.

throws
AdminEventListenerException when the listener is unable to process the event.

 // throws AdminEventListenerException {
    
public voidapplicationUndeployed(com.sun.enterprise.admin.event.ApplicationDeployEvent deployEvent)

        _adminEventProcessor.applicationUndeployed(deployEvent);
    
public voidchangeLevel(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to, javax.management.j2ee.statistics.Stats handback)

        // deprecated, ignore
    
public voidchangeLevel(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to, com.sun.enterprise.admin.monitor.registry.MonitoredObjectType type)

        if (MonitoredObjectType.SERVLET.equals(type)) {
            monitoringLevel = to;
            if(MonitoringLevel.OFF.equals(to)) {
                this.resetMonitorStatistics();
            }
        }
    
private voidcleanSecurityContext(java.lang.String appName)
Clean security policy generated at deployment time. NOTE: This routine calls destroy on the WebSecurityManagers, but that does not cause deletion of the underlying policy (files). The underlying policy is deleted when removePolicy (in AppDeployerBase and WebModuleDeployer) is called.

param
appName the app name

	String cIDs[] = webSecurityManagerFactory.getContextIdsOfApp(appName);

	for (int i=0; cIDs != null && i <cIDs.length; i++) {
	    WebSecurityManager wsm
		= webSecurityManagerFactory.getWebSecurityManager(cIDs[i]);

	    _logger.log(Level.FINE,"[JACC]: Removing WebSecurityManager: "
                + cIDs[i]);

	    if (wsm != null) {
		try {
		    wsm.destroy();
		} catch (javax.security.jacc.PolicyContextException pce){
		    // log it and continue
		    _logger.log(Level.WARNING,
                            "Unable to destroy WebSecurityManager",
                            pce);
		}
		webSecurityManagerFactory.removeWebSecurityManager(cIDs[i]);
	    }
	}
    
private voidconfigureCookieProperties(WebModule ctx, com.sun.enterprise.deployment.runtime.web.CookieProperties bean)
Configure the settings for the session cookie using the values in sun-web.xml's cookie-property

        if (bean != null) {
            WebProperty[] props = bean.getWebProperty();
            if (props != null) {
                SessionCookieConfig cookieConfig = new SessionCookieConfig();
                for (int i = 0; i < props.length; i++) {

                    String name = props[i].getAttributeValue(WebProperty.NAME);
                    String value = props[i].getAttributeValue(WebProperty.VALUE);
                    if (name == null || value == null) {
                        throw new IllegalArgumentException(
                            _rb.getString("webcontainer.nullWebProperty"));
                    }

                    if (name.equalsIgnoreCase("cookieName")) {
                        cookieConfig.setName(value);
                    } else if (name.equalsIgnoreCase("cookiePath")) {
                        cookieConfig.setPath(value);
                    } else if (name.equalsIgnoreCase("cookieMaxAgeSeconds")) {
                        try {
                            cookieConfig.setMaxAge(Integer.parseInt(value));
                        } catch (NumberFormatException e) {
                            // XXX need error message
                        }
                    } else if (name.equalsIgnoreCase("cookieDomain")) {
                        cookieConfig.setDomain(value);
                    } else if (name.equalsIgnoreCase("cookieComment")) {
                        cookieConfig.setComment(value);
                    } else {
                        Object[] params = { name, value };
                        _logger.log(Level.WARNING,
                                    "webcontainer.invalidProperty",
                                    params);
                    }
                }
                if (props.length > 0) {
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.fine("WebModule[" + ctx.getPath() + "]: "
                                     + cookieConfig);
                    }
                    ctx.setSessionCookieConfig(cookieConfig);
                }
            }
        }
    
private org.apache.catalina.LoaderconfigureLoader(WebModule ctx, com.sun.enterprise.deployment.runtime.web.SunWebApp bean, WebModuleConfig wmInfo)
Configure the class loader for the web module based on the settings in sun-web.xml's class-loader element (if any).


        com.sun.enterprise.deployment.runtime.web.ClassLoader clBean = null;

        WebappLoader loader = (WebappLoader)
            _embedded.createLoader(ctx.getParentClassLoader());

        loader.setUseMyFaces(ctx.isUseMyFaces());

        if (bean != null) {            
            clBean = bean.getClassLoader();
        }
        if (clBean != null) {
            configureLoaderAttributes(loader, clBean, ctx);
            configureLoaderProperties(loader, clBean);
        } else {
            loader.setDelegate(true);
        }

        // START S1AS 6178005
        String stubPath = wmInfo.getStubPath();
        if (stubPath != null) {
            loader.addRepository("file:" + stubPath + File.separator);
        }
        // END S1AS 6178005

        addLibs(loader, ctx);

        // START PE 4985680
        /**
         * Adds the given package name to the list of packages that may 
         * always be overriden, regardless of whether they belong to a 
         * protected namespace
         */
        String packagesName = 
            System.getProperty("com.sun.enterprise.overrideablejavaxpackages");

        if (packagesName != null) {
            List overridablePackages = 
                    StringUtils.parseStringList(packagesName, " ,");        
            for( int i=0; i < overridablePackages.size(); i++){ 
                loader.addOverridablePackage((String)overridablePackages.get(i));
            }
        }
        // END PE 4985680

        ctx.setLoader(loader);
        
        return loader;
    
private voidconfigureLoaderAttributes(org.apache.catalina.Loader loader, com.sun.enterprise.deployment.runtime.web.ClassLoader clBean, WebModule ctx)
Configures the given classloader with its attributes specified in sun-web.xml.

param
loader The classloader to configure
param
clBean The class-loader info from sun-web.xml
param
ctx The classloader's associated web module


        String value = clBean.getAttributeValue(
            com.sun.enterprise.deployment.runtime.web.ClassLoader.DELEGATE);

        /*
         * The DOL will *always* return a value: If 'delegate' has not been
         * configured in sun-web.xml, its default value will be returned,
         * which is FALSE in the case of sun-web-app_2_2-0.dtd and
         * sun-web-app_2_3-0.dtd, and TRUE in the case of
         * sun-web-app_2_4-0.dtd.
         */
        boolean delegate = ConfigBean.toBoolean(value);
        loader.setDelegate(delegate);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("WebModule[" + ctx.getPath()
                         + "]: Setting delegate to " + delegate);
        }

        // Get any extra paths to be added to the class path of this
        // class loader
        value = clBean.getAttributeValue(
            com.sun.enterprise.deployment.runtime.web.ClassLoader.EXTRA_CLASS_PATH);
        if (value != null) {
            // Parse the extra classpath into its ':' and ';' separated 
            // components. Ignore ':' as a separator if it is preceded by
            // '\'
            String[] pathElements = value.split(";|((?<!\\\\):)");
            if (pathElements != null) {
                for (String path : pathElements) {
                    path = path.replace("\\:", ":");
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.fine("WebModule[" + ctx.getPath()
                                     + "]: Adding " + path
                                     + " to the classpath");
                    }

                    try {
                        URL url = new URL(path);
                        loader.addRepository(path);
                    } catch (MalformedURLException mue1) {
                        // Not a URL, interpret as file
                        File file = new File(path);
                        // START GlassFish 904
                        if (!file.isAbsolute()) {
                            // Resolve relative extra class path to the
                            // context's docroot
                            file = new File(ctx.getDocBase(), path);
                        }
                        // END GlassFish 904

                        try {
                            URL url = file.toURI().toURL();
                            loader.addRepository(url.toString());
                        } catch (MalformedURLException mue2) {
                            String msg = _rb.getString(
                                "webcontainer.classpathError");
                            Object[] params = { path };
                            msg = MessageFormat.format(msg, params);
                            _logger.log(Level.SEVERE, msg, mue2);
                        }
                    }
                }
            }
        }

        value = clBean.getAttributeValue(
            com.sun.enterprise.deployment.runtime.web.ClassLoader.DYNAMIC_RELOAD_INTERVAL);
        if (value != null) {
            // Log warning if dynamic-reload-interval is specified
            // in sun-web.xml since it is not supported
            _logger.log(Level.WARNING,
                        "webcontainer.dynamicReloadInterval");
        }
    
private voidconfigureLoaderProperties(org.apache.catalina.Loader loader, com.sun.enterprise.deployment.runtime.web.ClassLoader clBean)
Configures the given classloader with its properties specified in sun-web.xml.

param
loader The classloader to configure
param
clBean The class-loader info from sun-web.xml


        String name = null;
        String value = null;

        WebProperty[] props = clBean.getWebProperty();
        if (props == null || props.length == 0) {
            return;
        }

        for (int i = 0; i < props.length; i++) {

            name = props[i].getAttributeValue(WebProperty.NAME);
            value = props[i].getAttributeValue(WebProperty.VALUE);

            if (name == null || value == null) {
                throw new IllegalArgumentException(
                    _rb.getString("webcontainer.nullWebProperty"));
            }

            if (name.equalsIgnoreCase("ignoreHiddenJarFiles")) {
                loader.setIgnoreHiddenJarFiles(ConfigBean.toBoolean(value));
            } else {
                Object[] params = { name, value };
                _logger.log(Level.WARNING,
                            "webcontainer.invalidProperty",
                            params);
            }
        }
    
private voidconfigureMiscSettings(WebModule ctx, com.sun.enterprise.deployment.runtime.web.SunWebApp bean, VirtualServer vs, java.lang.String contextPath)
Configure miscellaneous settings such as the pool size for single threaded servlets, specifying a temporary directory other than the default etc. Since the work directory is used when configuring the session manager persistence settings, this method must be invoked prior to configureSessionSettings.


        /*
         * Web app inherits setting of allowLinking property from vs on which
         * it is being deployed, but may override it using allowLinking
         * property in its sun-web.xml
         */
        boolean allowLinking = vs.getAllowLinking();

        if ((bean != null) && (bean.sizeWebProperty() > 0)) {
            WebProperty[] props = bean.getWebProperty();
            for (int i = 0; i < props.length; i++) {

                String name = props[i].getAttributeValue("name");
                String value = props[i].getAttributeValue("value");
                if (name == null || value == null) {
                    throw new IllegalArgumentException(
                        _rb.getString("webcontainer.nullWebProperty"));
                }

                if (name.equalsIgnoreCase("singleThreadedServletPoolSize")) {
                    int poolSize = ctx.getSTMPoolSize();
                    try {
                        poolSize = Integer.parseInt(value);
                    } catch (NumberFormatException e) {
                        Object[] params =
                            { value, contextPath, Integer.toString(poolSize) };
                        _logger.log(Level.WARNING,
                                    "webcontainer.invalidServletPoolSize",
                                    params);
                    }
                    if (poolSize > 0) {
                        ctx.setSTMPoolSize(poolSize);
                    }

                } else if (name.equalsIgnoreCase("tempdir")) {
                    ctx.setWorkDir(value);
                } else if (name.equalsIgnoreCase("crossContextAllowed")) {
                    boolean crossContext = ConfigBean.toBoolean(value);
                    ctx.setCrossContext(crossContext);
		} else if (name.equalsIgnoreCase("allowLinking")) {
                    allowLinking = ConfigBean.toBoolean(value);
                // START S1AS8PE 4817642
                } else if (name.equalsIgnoreCase("reuseSessionID")) {
                    boolean reuse = ConfigBean.toBoolean(value);
                    ctx.setReuseSessionID(reuse);
                    if (reuse) {
                        Object[] params = { contextPath,
                                            vs.getID() };
                        _logger.log(Level.WARNING,
                                    "webcontainer.sessionIDsReused",
                                    params);
                    }
                // END S1AS8PE 4817642
                } else if(name.equalsIgnoreCase("useResponseCTForHeaders")) {
                    if(value.equalsIgnoreCase("true")) {
                        ctx.setResponseCTForHeaders();   
                    }
                } else if(name.equalsIgnoreCase("encodeCookies")) {
                    boolean flag = ConfigBean.toBoolean(value);
                    ctx.setEncodeCookies(flag);
                // START RIMOD 4642650 
                } else if (name.equalsIgnoreCase("relativeRedirectAllowed")) {
                    boolean relativeRedirect = ConfigBean.toBoolean(value);
                    ctx.setAllowRelativeRedirect(relativeRedirect);
                // END RIMOD 4642650 
                } else if (name.equalsIgnoreCase("fileEncoding")) {
                    ctx.setFileEncoding(value);
                } else if (name.equalsIgnoreCase("enableTldValidation")
                        &&  ConfigBean.toBoolean(value)) {
                    ctx.setTldValidation(true);
                } else if (name.equalsIgnoreCase("enableTldNamespaceAware")
                        &&  ConfigBean.toBoolean(value)) {
                    ctx.setTldNamespaceAware(true);
                } else if (name.equalsIgnoreCase("securePagesWithPragma")){
                    boolean securePagesWithPragma = ConfigBean.toBoolean(value);
                    ctx.setSecurePagesWithPragma(securePagesWithPragma); 
                } else if (name.equalsIgnoreCase("useMyFaces")){
                    ctx.setUseMyFaces(ConfigBean.toBoolean(value));
                } else if (name.startsWith("alternatedocroot_")) {
                    ctx.parseAlternateDocBase(name, value);
                } else {
                    Object[] params = { name, value };
                    _logger.log(Level.WARNING, "webcontainer.invalidProperty",
                                params);
                }
            }
        }

        ctx.setAllowLinking(allowLinking);
    
protected voidconfigureSecurity(com.sun.enterprise.deployment.WebBundleDescriptor wbd, boolean isSystem)
Generate the JSR 115 policy file for a web application, bundled within a ear or deployed as a standalone war file. Implementation note: If the generated file doesn't contains all the permission, the role mapper is probably broken.

        try{
            webSecurityManagerFactory.newWebSecurityManager(wbd);
	    String context = WebSecurityManager.getContextID(wbd);
	    SecurityUtil.generatePolicyFile(context);
        }catch(Exception ce){
            _logger.log(Level.SEVERE, "webcontainer.configureSecurity", ce);
            throw new RuntimeException(ce);
        }
    
private voidconfigureSession(WebModule ctx, com.sun.enterprise.deployment.runtime.web.SessionProperties spBean, com.sun.enterprise.deployment.WebBundleDescriptor wbd)
Configure the properties of the session, such as the timeout, whether to force URL rewriting etc. HERCULES:mod passing in new param wbd


        boolean timeoutConfigured = false;
        int timeoutSeconds = 1800; // tomcat default (see StandardContext)

        ctx.setCookies(instanceEnableCookies);

        if ((spBean != null) && (spBean.sizeWebProperty() > 0)) {
            WebProperty[] props = spBean.getWebProperty();
            for (int i = 0; i < props.length; i++) {

                String name = props[i].getAttributeValue(WebProperty.NAME);
                String value = props[i].getAttributeValue(WebProperty.VALUE);
                if (name == null || value == null) {
                    throw new IllegalArgumentException(
                        _rb.getString("webcontainer.nullWebProperty"));
                }

                if (name.equalsIgnoreCase("timeoutSeconds")) {
                    try {
                        timeoutSeconds = Integer.parseInt(value);
                        timeoutConfigured = true;
                    } catch (NumberFormatException e) {
                        // XXX need error message
                    }
                } else if (name.equalsIgnoreCase("enableCookies")) {
                    ctx.setCookies(ConfigBean.toBoolean(value));
                } else {
                    Object[] params = { name };
                    _logger.log(Level.INFO, "webcontainer.notYet", params);
                }
            }
        }
        
        //HERCULES:added/modified
        int webXmlTimeoutSeconds = -1; 
        if(wbd != null) {
            webXmlTimeoutSeconds = wbd.getSessionTimeout() * 60;
        }

        //web.xml setting has precedence if it exists
        //ignore if the value is the 30 min default
        if (webXmlTimeoutSeconds != -1 && webXmlTimeoutSeconds != 1800) {
            ctx.getManager().setMaxInactiveIntervalSeconds(webXmlTimeoutSeconds);
        } else {
            /*
             * Do not override Tomcat default, unless 'timeoutSeconds' was
             * specified in sun-web.xml
             */
            if (timeoutConfigured) {
                ctx.getManager().setMaxInactiveIntervalSeconds(timeoutSeconds);
            }
            
        }
        //end HERCULES:added/modified
    
private voidconfigureSessionManager(WebModule ctx, com.sun.enterprise.deployment.runtime.web.SessionManager smBean, com.sun.enterprise.deployment.WebBundleDescriptor wbd, WebModuleConfig wmInfo)
Configure the session manager according to the persistence-type specified in the element and the related settings in the and elements in sun-web.xml. HERCULES:modified

        
        PersistenceType persistence = PersistenceType.MEMORY;
        String frequency = null;
        String scope = null;
        
        SessionManagerConfigurationHelper configHelper = 
            new SessionManagerConfigurationHelper(ctx, smBean, wbd, wmInfo);
        
        persistence = configHelper.getPersistenceType();
        frequency = configHelper.getPersistenceFrequency();
        scope = configHelper.getPersistenceScope();

        if (_logger.isLoggable(Level.FINEST)) {        
            _logger.finest("IN WebContainer>>ConfigureSessionManager before builder factory");
            _logger.finest("FINAL_PERSISTENCE-TYPE IS = "
                           + persistence.getType());
            _logger.finest("FINAL_PERSISTENCE_FREQUENCY IS = " + frequency);
            _logger.finest("FINAL_PERSISTENCE_SCOPE IS = " + scope);          
        }

	PersistenceStrategyBuilderFactory factory = 
            new PersistenceStrategyBuilderFactory();
        PersistenceStrategyBuilder builder = 
            factory.createPersistenceStrategyBuilder(persistence.getType(),
                                                     frequency, scope, ctx);
        if (_logger.isLoggable(Level.FINEST)) {
            _logger.finest("PersistenceStrategyBuilder class = "
                           + builder.getClass().getName());
        }

        builder.setLogger(_logger);
        builder.initializePersistenceStrategy(ctx, smBean);
    
private voidconfigureSessionSettings(WebModule ctx, com.sun.enterprise.deployment.runtime.web.SunWebApp bean, com.sun.enterprise.deployment.WebBundleDescriptor wbd, WebModuleConfig wmInfo)
Create and configure the session manager for this web application according to the persistence type specified. Also configure the other aspects of session management for this web application according to the values specified in the session-config element of sun-web.xml (and whether app is distributable) HERCULES:mod method signature added wbd


        SessionConfig cfg = null;
        SessionManager smBean = null;
        SessionProperties sessionPropsBean = null;
        CookieProperties cookieBean = null;

        if (bean != null) {
            cfg = bean.getSessionConfig();
            if (cfg != null) {
                smBean = cfg.getSessionManager();
                sessionPropsBean = cfg.getSessionProperties();
                cookieBean = cfg.getCookieProperties();
            }
        }
        
        //Hercules: mod  - passing wbd and wmInfo into these methods
        configureSessionManager(ctx, smBean, wbd, wmInfo);
        //configureSessionManager(ctx, smBean, wbd);
        configureSession(ctx, sessionPropsBean, wbd);
        //end HERCULES:mod
        configureCookieProperties(ctx, cookieBean);        
    
private WebModulecreateAdHocWebModule(VirtualServer vs, java.lang.String ctxtRoot, java.lang.String appName)


        AdHocWebModule wm = new AdHocWebModule(this);

        wm.restrictedSetPipeline(new WebPipeline(wm));

        // The Parent ClassLoader of the AdhocWebModule was null
        // [System ClassLoader]. With the new hierarchy, the thread context
        // classloader needs to be set.
        if (Boolean.getBoolean(com.sun.enterprise.server.PELaunch.USE_NEW_CLASSLOADER_PROPERTY)) {
            wm.setParentClassLoader(
                Thread.currentThread().getContextClassLoader());
        }

        wm.setContextRoot(ctxtRoot);
        wm.setJ2EEApplication(appName);  
        wm.setName(ctxtRoot);
        wm.setDocBase(vs.getAppBase());
        wm.setEngineName(vs.getParent().getName());

        String domain = _serverContext.getDefaultDomainName();
        wm.setDomain(domain);
  
        String j2eeServer = _serverContext.getInstanceName();
        wm.setJ2EEServer(j2eeServer);

        String server = domain + ":j2eeType=J2EEServer,name=" + j2eeServer;
        wm.setServer(server);

        wm.setCrossContext(true);
        wm.setJavaVMs(J2EEModuleUtil.getjavaVMs());

        vs.addChild(wm);

        return wm;
    
public VirtualServercreateVS(java.lang.String vsID, com.sun.enterprise.config.serverbeans.VirtualServer vsBean, java.lang.String docroot, java.lang.String logFile, MimeMap mimeMap, com.sun.enterprise.config.serverbeans.HttpProtocol httpProtocol)
Create a virtual server/host.


        // Initialize the docroot
        VirtualServer vs = (VirtualServer) _embedded.createHost(vsID,
                                                                vsBean,
								docroot,
								logFile,
                                                                mimeMap);
                    
        vs.configureVirtualServerState();
        vs.configureRemoteAddressFilterValve();
        vs.configureRemoteHostFilterValve(httpProtocol);
        vs.configureSSOValve(globalSSOEnabled, webFeatureFactory);
        vs.configureRedirect();
        vs.configureErrorPage();

        return vs;
    
protected voiddisableMonitoring(WebModule ctx, java.lang.String vsId)
Disables monitoring on the given web module.


        if (!ctx.hasWebXml()) {
            // Ad-hoc module
            return;
        }

        /*
         * Standalone webmodules are loaded with the application name set to
         * the string "null"
         */
        String appName = ctx.getJ2EEApplication();
        if ("null".equalsIgnoreCase(appName)) {
            appName = null;
        }

        // Unregister stats for each of the web module's servlets
        Container[] children = ctx.findChildren();
        if (children != null) {
            for (int k = 0; k < children.length; k++) {
                unregisterServletStats(appName, ctx.getModuleName(),
                                       ctx.getEncodedPath(), vsId,
                                       children[k].getName());
            }
        }
        // Unregister web module stats
        unregisterWebModuleStats(appName, ctx.getModuleName(),
                                 ctx.getEncodedPath(), vsId);

    
private booleandisableWSMonitoring(com.sun.enterprise.deployment.WebBundleDescriptor wbd)
Disables monitoring of web service endpoints in a webmodule.

param
wbd WebBundleDescriptor of the web module
return
boolean true, if web service mbeans were unloaded successfully


       boolean result = true;

            try {
            Switch.getSwitch().getManagementObjectManager().
                deleteWSEndpointMBeans(wbd, instance.getName());
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
            return true;
    
public voiddisableWebModule(java.lang.String contextRoot, java.lang.String appName, java.lang.String virtualServers)
Disable a web application.

param
contextRoot the context's name to undeploy
param
appName the J2EE appname used at deployment time
param
virtualServers the list of current virtual-server object.

                                    
        // tomcat contextRoot starts with "/"
        if (!contextRoot.equals("") && !contextRoot.startsWith("/") ) {
            contextRoot = "/" + contextRoot;
        }
        
        Engine[] engines = _embedded.getEngines();
        List hostList = StringUtils.parseStringList(virtualServers, " ,");
        boolean disableToAll = (hostList == null) || (hostList.size() == 0);
        boolean hasBeenDisabled = false;
        Container[] hostArray = null;
        VirtualServer host = null;
        Context context = null;
        
        for (int j = 0; j < engines.length; j++) {
            hostArray = engines[j].findChildren();
            for (int i = 0; i < hostArray.length; i++) {
                host = (VirtualServer) hostArray[i];

                /**
                 * Related to Bug: 4904290
                 * Do not unloadload module on ADMIN_VS
                 */
                if ( disableToAll 
                        && host.getName().equalsIgnoreCase(VirtualServer.ADMIN_VS)){
                    continue;
                }

                if (disableToAll 
                        || hostList.contains(host.getName())
                        || verifyAlias(hostList,host)){

                    context = (Context) host.findChild(contextRoot);
                    if (context != null) {
                        context.setAvailable(false);
                        if (_logger.isLoggable(Level.FINEST)) {
                            _logger.log(Level.FINEST,
                                        "[WebContainer] Context "
                                        + contextRoot + " disabled from "
                                        + host);
                        }
                        hasBeenDisabled = true;
                    }
                }
            }
        }   
        
        if (!hasBeenDisabled){
            _logger.log(Level.WARNING,
                        "[WebContainer] moduleDisabled fail for context "
                        + contextRoot);
        }        
        
    
private voiddoSchemaCheck()

        SchemaUpdater schemaUpdater = null;
        try {
            schemaUpdater =
                _serverContext.getPluggableFeatureFactory().getSchemaUpdater();
        } catch (NoClassDefFoundError ex) {
            //one warning already logged so this one is level fine
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("HADB Warning - client jars missing - ok if not running with HADB");
            }            
        }; 
        if(schemaUpdater != null) {
            try {
                schemaUpdater.doSchemaCheck();
            } catch (Exception ex) {
                _logger.log(Level.SEVERE, "schemaupdater.error", ex);
            }
        }
    
private voidenableAllWSEndpoints()
Enables monitoring of web service endpoints in for all webmodules.


        Applications appsBean = null;
        try {
            appsBean = ServerBeansFactory.getApplicationsBean(_configContext);
        } catch (ConfigException e) {
            String msg = _rb.getString("webcontainer.appsConfigError");
            _logger.log(Level.SEVERE, msg, e);
        }

        if (appsBean != null) {
            J2eeApplication[] j2eeAppBeans = appsBean.getJ2eeApplication();
            if (j2eeAppBeans != null) {
                for (int i = 0; i < j2eeAppBeans.length; i++) {
                    //Begin EE: 4927099 - load only associated applications
                    if ( isReferenced(j2eeAppBeans[i].getName()) ) {
                        enableWSMonitoring(j2eeAppBeans[i].getName());
                    }
                    //End EE: 4927099 - load only associated applications
                }
            }
        }
    
voidenableMonitoring(WebModule ctx, java.lang.String vsId)
Enables monitoring on the Servlets in a webmodule.

param
ctx Web module to be monitored
param
vsId The engine that is currently loading the webmodule


        if (!ctx.hasWebXml()) {
            // Ad-hoc module
            return;
        }

        String j2eeServer = _serverContext.getInstanceName();

        // Register web module stats
        registerWebModuleStats(ctx.getJ2EEApplication(), j2eeServer, vsId,
                               ctx, null);

        // Register stats for each of the web module's servlets
        Container[] children = ctx.findChildren();
        if (children != null) {
            for (int i = 0; i < children.length; i++) {
                registerServletStats(ctx.getJ2EEApplication(), j2eeServer,
                                     ctx.getModuleName(), vsId,
                                     ctx.getEncodedPath(),
                                     children[i].getName(), null);
            }
        }
    
private booleanenableWSMonitoring(java.lang.String id)
Enables monitoring of web service endpoints in a webmodule.

param
id ID of the application
return
boolean true, if web service mbeans were intialized successfully


       boolean result = true;

       ApplicationRegistry registry = ApplicationRegistry.getInstance();
            ClassLoader appLoader = registry.getClassLoaderForApplication(id);
            if (appLoader != null) {
                Application appDesc = registry.getApplication(appLoader); 
             
                // Check to see if this app had deployed successfully (4663247)
                if(appDesc == null){ 
                    Object[] params = { id };
                    _logger.log(Level.SEVERE, "webcontainer.notLoaded",
                                params);
                } else {
                    //end Hercules: add                     
                    String j2eeApplication = appDesc.getRegistrationName();
                    Set wbds = appDesc.getWebBundleDescriptors();
                    WebBundleDescriptor wbd = null;
                    for (Iterator itr = wbds.iterator(); itr.hasNext(); ) {
                        wbd = (WebBundleDescriptor) itr.next();

                        try {
                            Switch.getSwitch().getManagementObjectManager().
                            createWSEndpointMBeans(wbd, instance.getName());
                        } catch (Exception e) {
                            e.printStackTrace();
                            return false;
                        }
                    }
                }
            }
        return true;
    
voidenableWSMonitoring(com.sun.enterprise.deployment.WebBundleDescriptor wbd, java.lang.String serverName)

         try {
             Switch.getSwitch().getManagementObjectManager().
             createWSEndpointMBeans(wbd, serverName);
         } catch (Exception e) {
             e.printStackTrace();
         }
     
public voidenableWebModule(WebModuleConfig wmInfo, java.lang.String j2eeApplication)
Creates and configures a web module for each virtual server that the web module is hosted under. If the web module has been disabled by a call to disableWebModule, enable the module instead of re-crearing new one. If no virtual servers are specified, then the web module is enabled` on EVERY virtual server.

 
        String vsIDs = wmInfo.getVirtualServers();
        List vsList = StringUtils.parseStringList(vsIDs, " ,");
        boolean enabledToAll = (vsList == null) || (vsList.size() == 0);

        Engine[] engines =  _embedded.getEngines();

        for (int j=0; j<engines.length; j++) {
            Container[] vsArray = engines[j].findChildren();
            for (int i = 0; i < vsArray.length; i++) {
                if (vsArray[i] instanceof VirtualServer) {
                    VirtualServer vs = (VirtualServer) vsArray[i];

                    /*
                     * Fix for 4913636: If vsList is null and virtual server is
                     * equal to __asadmin, continue with next iteration
		     * because we don't want to load user apps on __asadmin
                     */
                    if (vs.getID().equals(VirtualServer.ADMIN_VS) && enabledToAll) {
                        continue;
                    }

                    if ( enabledToAll 
                            || vsList.contains(vs.getID()) 
                            || verifyAlias(vsList,vs)){

                        loadWebModule(vs, wmInfo, j2eeApplication);
                    }
                }
            }
        }
    
public org.apache.catalina.LifecycleListener[]findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.

       return new LifecycleListener[0];
    
public java.lang.StringgetApplicationId(WebModule wm)
The application id for this web module HERCULES:add

        return wm.getID();
    
java.lang.StringgetAppsWorkRoot()

return
The work root directory of all webapps bundled in EAR Files

        return _appsWorkRoot;
    
private voidgetDynamicReloadingSettings(com.sun.enterprise.config.serverbeans.DasConfig appsBean)
Save the server-wide dynamic reloading settings for use when configuring each web module.

        if (appsBean != null) {
            _reloadingEnabled = appsBean.isDynamicReloadEnabled();
            String seconds = appsBean.getDynamicReloadPollIntervalInSeconds();
            if (seconds != null) {
                try {
                    _pollInterval = Integer.parseInt(seconds);
                } catch (NumberFormatException e) {
                }
            }
        }
    
public org.apache.catalina.Engine[]getEngines()
Return the parent/top-level container in _embedded for virtual servers.

        return _embedded.getEngines();
    
public HealthCheckergetHealthChecker()

       
        return _healthChecker;
    
public java.lang.StringgetID()
Return the web container identifier.

    

    // ------------------------------------------------------------ Properties

              
       
        return _id;
    
public static com.sun.enterprise.web.WebContainergetInstance()
Return the current WebContainer child instance.

        return webContainer;
    
private java.lang.StringgetInstanceClassPath(com.sun.enterprise.instance.InstanceEnvironment instanceEnv)


        if (instanceEnv == null) {
            return null;
        }

        StringBuffer sb = new StringBuffer();

        File libDir = new File(instanceEnv.getLibPath());
        String libDirPath = libDir.getAbsolutePath();

        // Append domain_root/lib/classes
        sb.append(libDirPath + File.separator + "classes");
        sb.append(File.pathSeparator);

        // Append domain_root/lib/[*.jar|*.zip]
        String[] files = libDir.list();
        if (files != null) {
            for (int i=0; i<files.length; i++) {
                if (files[i].endsWith(".jar") || files[i].endsWith(".zip")) {
                    sb.append(libDirPath + File.separator + files[i]);
                    sb.append(File.pathSeparator);
                }
            }
        }

        return sb.toString();
    
java.lang.StringgetInstanceClassPath()

        return this.instanceClassPath;
    
public java.lang.StringgetModulesRoot()
Return the Absolute path for location where all the deployed standalone modules are stored for this Server Instance.

        return _modulesRoot;
    
java.lang.StringgetModulesWorkRoot()

return
The work root directory of all standalone webapps

        return _modulesWorkRoot;
    
public static com.sun.enterprise.admin.monitor.registry.MonitoringLevelgetMonitoringLevel()
Returns the current monitoring level.

return
The current monitoring level

        return monitoringLevel;
    
private java.lang.StringgetPersistenceFrequency(com.sun.enterprise.deployment.runtime.web.SessionManager smBean)
Get the persistence frequency for this web module (this is the value from sun-web.xml if defined

param
the session manager config bean HERCULES:add

        String persistenceFrequency = null;        
        ManagerProperties mgrBean = smBean.getManagerProperties();
        if ((mgrBean != null) && (mgrBean.sizeWebProperty() > 0)) {
            WebProperty[] props = mgrBean.getWebProperty();
            for (int i = 0; i < props.length; i++) {

                String name = props[i].getAttributeValue(WebProperty.NAME);
                String value = props[i].getAttributeValue(WebProperty.VALUE);
                if (name == null || value == null) {
                    throw new IllegalArgumentException(
                        _rb.getString("webcontainer.nullWebProperty"));
                }

                if (name.equalsIgnoreCase("persistenceFrequency")) {
                    persistenceFrequency = value;
                    break;
                }
            }
        }
        return persistenceFrequency;
    
private java.lang.StringgetPersistenceScope(com.sun.enterprise.deployment.runtime.web.SessionManager smBean)
Get the persistence scope for this web module (this is the value from sun-web.xml if defined

param
the session manager config bean HERCULES:add

        String persistenceScope = null;
        StoreProperties storeBean = smBean.getStoreProperties();
        if ((storeBean != null) && (storeBean.sizeWebProperty() > 0)) {
            WebProperty[] props = storeBean.getWebProperty();
            for (int i = 0; i < props.length; i++) {

                String name = props[i].getAttributeValue(WebProperty.NAME);
                String value = props[i].getAttributeValue(WebProperty.VALUE);
                if (name == null || value == null) {
                    throw new IllegalArgumentException(
                        _rb.getString("webcontainer.nullWebProperty"));
                }

                if (name.equalsIgnoreCase("persistenceScope")) {
                    persistenceScope = value;
                    break;
                }
            }
        }
        return persistenceScope;
    
public ReplicationReceivergetReplicationReceiver()

       
        return _replicationReceiver;
    
public com.sun.enterprise.server.ServerContextgetServerContext()
Utility Method to access the ServerContext

        return _serverContext;
    
private java.lang.StringgetVirtualServers(java.lang.String appName, com.sun.enterprise.config.ConfigContext configCtx)
Virtual servers are maintained in the reference contained in Server element. First, we need to find the server and then get the virtual server from the correct reference

param
appName Name of the app to get vs
param
configCtx config context to use to obtain virtual servers. If this parameter is null, config context cached at startup time will be used.
return
virtual servers as a string (separated by space or comma)

        if (configCtx == null) {
            configCtx = _configContext;
        }
        String ret = null;
        try {
            ret = ServerBeansFactory.getVirtualServersByAppName(configCtx,
                                                                appName);
        } catch (ConfigException ce) {
            _logger.log(Level.WARNING,
                        "No virtual servers defined for " + appName,
                        ce);
        }
        return ret;
    
public WebContainerStartStopOperationgetWebContainerStartStopOperation()
Get the webContainerStartStopOperation used for doing shutdown cleanup work

        
        WebContainerStartStopOperation startStopOperation =
            webFeatureFactory.getWebContainerStartStopOperation();
        
        startStopOperation.init(_embedded);
        return startStopOperation;
    
private voidinitHealthChecker()

        HealthChecker healthChecker = null;
        try {
            healthChecker = webFeatureFactory.getHADBHealthChecker(this);
        } catch (NoClassDefFoundError ex) {
            _logger.log(Level.WARNING,
                        "hadbhealthchecker.hadbClientJarsMissing");            
        }
        if(_logger.isLoggable(Level.FINEST)) {
            _logger.finest("WebContainer>>initHealthChecker - healthChecker = " + healthChecker);
        }
        if(healthChecker != null) {
            _healthChecker = healthChecker;
            try {
                _healthChecker.start();
            } catch (LifecycleException ex) {}                
        }
     
private voidinitInstanceSessionProperties()
Initializes the instance-level session properties (read from config.web-container.session-config.session-properties in domain.xml).


        ServerConfigLookup lookup = new ServerConfigLookup();
        com.sun.enterprise.config.serverbeans.SessionProperties spBean =
            lookup.getInstanceSessionProperties();
        if (spBean == null || spBean.sizeElementProperty() == 0) {
            return;
        }

        ElementProperty[] props = spBean.getElementProperty();
        if (props == null) {
            return;
        }

        for (int i=0; i<props.length; i++) {
            String propName = props[i].getName();
            String propValue = props[i].getValue();
            if (propName == null || propValue == null) {
                throw new IllegalArgumentException(
                    _rb.getString("webcontainer.nullWebProperty"));
            }

            if (propName.equalsIgnoreCase("enableCookies")) {
                instanceEnableCookies = ConfigBean.toBoolean(propValue);
            } else {
                Object[] params = { propName };
                _logger.log(Level.INFO, "webcontainer.notYet", params);
            }
        }
    
private voidinitLogLevel(com.sun.enterprise.config.serverbeans.LogService logserviceBean)


        Level level = Level.SEVERE;
        setLogLevel(level);

        if (logserviceBean != null) {
            try {
                level = Level.parse(logserviceBean.getModuleLogLevels().getRoot());
                setLogLevel(level);
            } catch (NullPointerException e) {
            } catch (IllegalArgumentException e) { }
        }

        // If the <web-container> element in server.xml contains a 
        // log-level setting then use that
        try {
            level = Level.parse(ServerBeansFactory.getWebContainerLogLevel(
                                                            _configContext));
            setLogLevel(level);
        } catch (NullPointerException e) {
            if (_debug > 0)
                _logger.finest("Defaulting <web-container> log-level");
        } catch (IllegalArgumentException e) {
        }
        if (_debug > 0) {
            _logger.fine("Web container log level: " + _logLevel);
        }
    
private voidinitMonitoringLevel(com.sun.enterprise.config.serverbeans.MonitoringService monitoringBean)


        monitoringLevel = MonitoringLevel.OFF; // default per DTD

        if (monitoringBean != null) {
            ModuleMonitoringLevels levels =
                monitoringBean.getModuleMonitoringLevels();
            if (levels != null) {
                monitoringLevel = MonitoringLevel.instance(
                                                levels.getWebContainer());
            }
        }
    
private voidinitReplicationReceiver()

        ReplicationReceiver replicationReceiver = 
            webFeatureFactory.getReplicationReceiver(_embedded);
        if(_logger.isLoggable(Level.FINEST)) {
            _logger.finest("WebContainer>>initReplicationReceiver - replicationReceiver = " + replicationReceiver);
        }
        if(replicationReceiver != null) {
            _replicationReceiver = replicationReceiver; 
            if (_logger.isLoggable(Level.FINEST)) {
                _logger.finest("WebContainer:about to call replicationReceiver>>init()" + _replicationReceiver); 
            }
            _replicationReceiver.init();
        }
     
protected booleanisEnabled(com.sun.enterprise.config.ConfigContext config, java.lang.String moduleName)
Whether or not a component (either an application or a module) should be enabled is defined by the "enable" attribute on both the application/module element and the application-ref element.

param
config The dynamic ConfigContext
param
moduleName The name of the component (application or module)
return
boolean

        try {
            if (config == null) {
                config = _configContext;
            }
 
            ConfigBean app = ApplicationHelper.findApplication(config, 
                moduleName);
            Server server = ServerBeansFactory.getServerBean(config);
            ApplicationRef appRef = server.getApplicationRefByRef(moduleName);

            return ((app != null && app.isEnabled()) &&
                        (appRef != null && appRef.isEnabled()));
        } catch (ConfigException e) {
            _logger.log(Level.WARNING, "Error finding " + moduleName, e);

            //If there is anything wrong, do not enable the module
            return false;
        }
    
public static booleanisMonitoringEnabled()
Returns true if monitoring is enabled, false otherwise.

return
true if monitoring is enabled, false otherwise

        return (!MonitoringLevel.OFF.equals(monitoringLevel));
    
private booleanisNativeReplicationEnabled()

         ServerConfigLookup lookup = new ServerConfigLookup();
         if (_logger.isLoggable(Level.FINEST)) {
            _logger.finest("GMS ENABLED:" + lookup.isGMSEnabled());
            _logger.finest("NATIVE REPLICATION ENABLED:" + lookup.isNativeReplicationEnabledFromConfig());
         }
         return lookup.isGMSEnabled() && lookup.isNativeReplicationEnabledFromConfig();
     
private booleanisReferenced(java.lang.String appName)
Returns true if the names application is referenced by this server.

param
appName name of the application id
return
true if the names application is referenced by this server


        Servers servers = domain.getServers();
        Server server = servers.getServerByName(
                                _serverContext.getInstanceName());

        ApplicationRef ref = server.getApplicationRefByRef(appName);
        return (ref == null) ? false : true;
    
protected voidloadAllJ2EEApplicationWebModules()
Loads all the web modules that are configured for every j2ee-application specified in server.xml.

        loadAllJ2EEApplicationWebModules(false);
    
private voidloadAllJ2EEApplicationWebModules(boolean isStartUp)
Loads all the web modules that are configured for every j2ee-application specified in server.xml.

param
isStartUp true, if this is called during server startup


        Applications appsBean = null;
        try {
            appsBean = ServerBeansFactory.getApplicationsBean(_configContext);
        } catch (ConfigException e) {
            String msg = _rb.getString("webcontainer.appsConfigError");
            _logger.log(Level.SEVERE, msg, e);
        }

        if (appsBean != null) {
            J2eeApplication[] j2eeAppBeans = appsBean.getJ2eeApplication();
            if (j2eeAppBeans != null) {
                for (int i = 0; i < j2eeAppBeans.length; i++) {
                    //Begin EE: 4927099 - load only associated applications
                    if ( isReferenced(j2eeAppBeans[i].getName()) ) {
                        loadJ2EEApplicationWebModules(j2eeAppBeans[i]);
                    }
                    //End EE: 4927099 - load only associated applications
                }
            }
        }
    
protected voidloadDefaultWebModules()
Configures a default web module for each virtual server. If a virtual server does not specify any default-web-module, and none of its web modules are loaded at "/", this method will create and load a default context for the virtual server, based on the virtual server's docroot.


        Engine[] engines =  _embedded.getEngines();

        for (int j=0; j<engines.length; j++) {
            Container[] vsArray = engines[j].findChildren();
            for (int i = 0; i < vsArray.length; i++) {
                if (vsArray[i] instanceof VirtualServer) {

                    VirtualServer vs = (VirtualServer) vsArray[i];

                    String defaultPath = vs.getDefaultContextPath(_serverBean);
                    if (defaultPath != null) {
                        // Virtual server declares default-web-module
                        try {
                            updateDefaultWebModule(vs, vs.getPorts(),
                                                   defaultPath);
                        } catch (LifecycleException le) {
                            String msg = _rb.getString(
                                "webcontainer.defaultWebModuleError");
                            msg = MessageFormat.format(
                                msg, 
                                new Object[] { defaultPath,
                                               vs.getName() });
                            _logger.log(Level.SEVERE, msg, le);
                        }

                    } else {
                        // Create default web module off of virtual
                        // server's docroot if necessary
                        WebModuleConfig wmInfo = 
                            vs.createSystemDefaultWebModuleIfNecessary();
                        if (wmInfo != null) {
                            loadStandaloneWebModule(vs, wmInfo);
                        }
                    }
                }
            }
        }
    
public voidloadJ2EEApplicationWebModules(com.sun.enterprise.config.serverbeans.J2eeApplication j2eeAppBean)
Loads all the web modules that are configured for the specified j2ee-application.

        if ((j2eeAppBean != null) && 
            isEnabled(j2eeAppBean.getConfigContext(), j2eeAppBean.getName())) {
            String id = j2eeAppBean.getName();
            String location = j2eeAppBean.getLocation();
            String resourceType = j2eeAppBean.getObjectType();

            ApplicationRegistry registry = ApplicationRegistry.getInstance();
            ClassLoader appLoader = registry.getClassLoaderForApplication(id);
            if (appLoader != null) {
                Application appDesc = registry.getApplication(appLoader); 
             
                // Check to see if this app had deployed successfully (4663247)
                if(appDesc == null){ 
                    Object[] params = { id };
                    _logger.log(Level.SEVERE, "webcontainer.notLoaded",
                                params);
                } else {
                    //Hercules: add 
                    ConfigContext eventConfigContext = j2eeAppBean.getConfigContext();
                    //end Hercules: add                     
                    String j2eeApplication = appDesc.getRegistrationName();
                    Set wbds = appDesc.getWebBundleDescriptors();
                    WebBundleDescriptor wbd = null;
                    com.sun.enterprise.config.serverbeans.WebModule wm = null;
                    WebModuleConfig wmInfo = null;
                    for (Iterator itr = wbds.iterator(); itr.hasNext(); ) {
                        StringBuffer dir = new StringBuffer(location);
                        wbd = (WebBundleDescriptor) itr.next();
                        String moduleName = wbd.getModuleDescriptor().getArchiveUri();
                        dir.append(File.separator);
                        dir.append(DeploymentUtils.getRelativeEmbeddedModulePath(location, moduleName));

                        wm = new com.sun.enterprise.config.serverbeans.WebModule();
                        //Hercules add
                        wm.setConfigContext(eventConfigContext);
                        //end Hercules add                        
                        wm.setName(moduleName);
                        wm.setContextRoot(wbd.getContextRoot());
                        wm.setLocation(dir.toString());
                        wm.setEnabled(true);
                        wm.setObjectType(resourceType);

                        wmInfo = new WebModuleConfig();
                        wmInfo.setBean(wm);
                        wmInfo.setDescriptor(wbd);
                        wmInfo.setParentLoader(appLoader);
                        wmInfo.setVirtualServers(
                                getVirtualServers(id,
                                        j2eeAppBean.getConfigContext()));
                        loadWebModule(wmInfo, j2eeApplication);
                    }
                }//end if(appDesc != null)
            }
        }
    
protected voidloadStandaloneWebModule(VirtualServer vs, WebModuleConfig wmInfo)
Load the specified web module as a standalone module on the specified virtual server.

        loadWebModule(vs, wmInfo, "null");
    
public java.util.ListloadWebModule(WebModuleConfig wmInfo, java.lang.String j2eeApplication)
Creates and configures a web module for each virtual server that the web module is hosted under. If no virtual servers are specified, then the web module is loaded on EVERY virtual server.


        String vsIDs = wmInfo.getVirtualServers();
        List vsList = StringUtils.parseStringList(vsIDs, " ,");
        boolean loadToAll = (vsList == null) || (vsList.size() == 0);
        boolean loadAtLeastToOne = false;

        Engine[] engines =  _embedded.getEngines();

        List<Throwable> throwables = new ArrayList();
        for (int j=0; j<engines.length; j++) {
            Container[] vsArray = engines[j].findChildren();
            for (int i = 0; i < vsArray.length; i++) {
                if (vsArray[i] instanceof VirtualServer) {
                    VirtualServer vs = (VirtualServer) vsArray[i];

                    /*
                     * Fix for bug# 4913636:
                     * If the vsList is null and the virtual server is
                     * __asadmin, continue with next iteration
                     * because we don't want to load user apps on __asadmin
                     */
                    if (vs.getID().equals(VirtualServer.ADMIN_VS) && loadToAll) {
                        continue;
                    }

                    if ( loadToAll 
                            || vsList.contains(vs.getID()) 
                            || verifyAlias(vsList,vs)){

                        Throwable t = loadWebModule(vs, wmInfo, j2eeApplication);
                        if (t != null) {
                            throwables.add(t);
                        }
                        loadAtLeastToOne = true;
                    }
                }
            }
        }
        if (!loadAtLeastToOne) {
            Object[] params = {wmInfo.getName(), vsIDs};
            _logger.log(Level.SEVERE, "webcontainer.moduleNotLoadedToVS",
                            params);
        }
        return throwables;
    
protected java.lang.ThrowableloadWebModule(VirtualServer vs, WebModuleConfig wmInfo, java.lang.String j2eeApplication)
Creates and configures a web module and adds it to the specified virtual server.


        String wmName = wmInfo.getName();
        String wmContextPath = wmInfo.getContextPath();

        if (wmContextPath.equals("") && vs.getDefaultWebModuleID() != null) {
            _logger.log(Level.WARNING, "webcontainer.defaultWebModuleConflict",
                        new Object[] { wmName, wmContextPath, vs.getID() });
            return null;
        }

        if (wmName.indexOf(Constants.NAME_SEPARATOR) != -1) {
            wmInfo.setWorkDirBase(_appsWorkRoot);
            // START S1AS 6178005
            wmInfo.setStubBaseDir(appsStubRoot);
            // END S1AS 6178005
        } else {
            wmInfo.setWorkDirBase(_modulesWorkRoot);
            // START S1AS 6178005
            wmInfo.setStubBaseDir(modulesStubRoot);
            // END S1AS 6178005
        }

        String displayContextPath = null;
        if (wmContextPath.equals(""))
            displayContextPath = "/";
        else
            displayContextPath = wmContextPath;

        HashMap adHocPaths = null;
        HashMap 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.getJ2EEApplication(),
                                vs.getName(),
                                null,
                                true);
            } 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 null;
            } else {
                Object[] params = { vs.getID(), displayContextPath, wmName };
                _logger.log(Level.WARNING, "webcontainer.duplicateContextRoot",
                            params);
                return null;
            }
        }

        if (_logger.isLoggable(Level.FINEST)) {
            Object[] params = { wmName, vs.getID(), displayContextPath };
            _logger.log(Level.FINEST, "webcontainer.loadModule", params);
        }

        String docBase = null;
        if (JWS_APPCLIENT_MODULE_NAME.equals(wmName)) {
            File installRootFile = new File(System.getProperty("com.sun.aas.installRoot"));
            String path = installRootFile.toURI().getPath();
            if (OS.isWindows()) {
                path = path.substring(1); // On Windows, skip the slash before the device
            }
            docBase = path;
        } else {
            docBase = wmInfo.getLocation();
        }
        ctx = (WebModule) _embedded.createContext(wmContextPath,
                                                  docBase,
                                                  vs.getDefaultContextXmlLocation(),
                                                  vs.getDefaultWebXmlLocation(),
                                                  useDOLforDeployment,
                                                  wmInfo.getDescriptor());

        // Set JSR 77 object name and attributes
        String engineName = vs.getParent().getName();
        String j2eeServer = _serverContext.getInstanceName();
        String domain = _serverContext.getDefaultDomainName();
        String server = domain + ":j2eeType=J2EEServer,name=" + j2eeServer;
        String[] javaVMs = J2EEModuleUtil.getjavaVMs();
        ctx.setDomain(domain);

        ctx.setJ2EEServer(j2eeServer);
        ctx.setJ2EEApplication(j2eeApplication);   
        ctx.setEngineName(engineName);
        ctx.setServer(server);
        ctx.setJavaVMs(javaVMs);
        ctx.setCachingAllowed(catalinaCachingAllowed);
        ctx.setCacheControls(vs.getCacheControls());
        ctx.setBean(wmInfo.getBean());
        ctx.setSecurePagesWithPragma(vs.isSecurePagesWithPragma());

        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 (wmInfo.getBean() != null) {
            String contextRoot = wmInfo.getBean().getContextRoot();
            ctx.setContextRoot(contextRoot);
            if (wbd != null) {
                wbd.setContextRoot(contextRoot);
            }
        } else {
            // Should never happen.
            _logger.log(Level.WARNING, "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) {
            StringBuffer workDir = new StringBuffer(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);

        Throwable exception = null; 
        Switch sw = Switch.getSwitch();
        try{
            // Determine if an alternate DD is set for this web-module in 
            // the application
            if (wbd != null) {
                String altDDName = wbd.getModuleDescriptor().
                                        getAlternateDescriptor();
                if (altDDName != null) {
                    // we should load the alt dd from generated/xml directory
                    // first, then fall back to original app location.

                    // if we have alt dd, it must be an embedded web module
                    String appName =  wmName.substring(0, 
                        wmName.indexOf(Constants.NAME_SEPARATOR));
                    String appLoc = 
                        appsManager.getGeneratedXMLLocation(appName);
                    if (! FileUtils.safeIsDirectory(appLoc)) {
                        appLoc = wmInfo.getLocation()+"/..";
                    }

                    if (altDDName.startsWith("/")) {
                        altDDName = appLoc+altDDName.trim();
                    }
                    else {
                        altDDName = appLoc+"/"+altDDName.trim();
                    }
                    Object[] objs = {altDDName, wmName};
                    _logger.log(Level.INFO, "webcontainer.altDDName", objs);
                    ctx.setAltDDName(altDDName);

                }
                // time to update the Web Services related information in 
                // our runtime jsr77 mbeans. We publish two extra properties
                // hasWebServices and endpointAddresses for webservices
                // enable web applications.
                if (wbd.hasWebServices()) {
                    ctx.setHasWebServices(true);
                    
                    // creates the list of endpoint addresses
                    String[] endpointAddresses;
                    WebServicesDescriptor webService = wbd.getWebServices();
                    Vector endpointList = new Vector();
                    for (Iterator endpoints = webService.getEndpoints().iterator();
                    endpoints.hasNext();) {
                        WebServiceEndpoint wse = (WebServiceEndpoint) endpoints.next();
                        if (wbd.getContextRoot()!=null) {
                            endpointList.add(wbd.getContextRoot() + "/"
                                             + wse.getEndpointAddressUri());
                        } else {
                            endpointList.add(wse.getEndpointAddressUri());
                        }
                    }
                    endpointAddresses = new String[endpointList.size()];
                    endpointList.copyInto(endpointAddresses);
                    
                    ctx.setEndpointAddresses(endpointAddresses);
                    
                } else {
                    ctx.setHasWebServices(false);
                }
            }

            // Object containing sun-web.xml information
            SunWebApp iasBean = null;

            // The default context is the only case when wbd == null
            if (wbd != null) 
                iasBean = wbd.getSunDescriptor();

            // set the sun-web config bean
            ctx.setIasWebAppConfigBean(iasBean);
            ctx.setID(wmName);

            // Configure SingleThreadedServletPools, work/tmp directory etc
            configureMiscSettings(ctx, iasBean, vs, displayContextPath);
           
            // Configure alternate docroots if dummy web module
            if (Constants.DEFAULT_WEB_MODULE_NAME.equals(ctx.getID())) {
                ctx.setAlternateDocBases(vs.getProperties());
            }
          
            // Configure the class loader delegation model, classpath etc
            Loader loader = configureLoader(ctx, iasBean, wmInfo);
            
            // Set the class loader on the DOL object 
            if (wbd != null && wbd.hasWebServices())
                wbd.addExtraAttribute("WEBLOADER", loader);

            // Enable dynamic reloading
            if (_reloadingEnabled) {
                if (_reloadManager == null) {
                    _reloadManager = new StandaloneWebModulesManager(
                                                            _id,
                                                            _modulesRoot,
                                                            _pollInterval);
                }
                _reloadManager.addWebModule(wmInfo.getBean());
            }

            // Configure the session manager and other related settings
            // HERCULES:mod - take into account if app is distributable
            // passing in WebBundleDescriptor which has info about whether
            // app is distributable
            configureSessionSettings(ctx, iasBean, wbd, wmInfo);
            // END HERCULES:mod

            // set i18n info from locale-charset-info tag in sun-web.xml
            ctx.setI18nInfo();

            if (wbd != null) {
                String resourceType = wmInfo.getBean().getObjectType();
                boolean isSystem = (resourceType != null &&
                    resourceType.startsWith("system-"));
                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
                     */  
                    ctx.setRealm(new RealmAdapter(wbd, isSystem,
                                                  vs.getAuthRealmName()));
                } else {
                    ctx.setRealm(new RealmAdapter(wbd, isSystem));
                }
                configureSecurity(wbd, isSystem);
                sw.setDescriptorFor(ctx, wbd);

                // post processing DOL object for standalone web module
                if (wbd.getApplication() != null &&
                    wbd.getApplication().isVirtual()) {
                    wbd.visit((WebBundleVisitor) new WebValidatorWithoutCL());
                }

            }

            // Add virtual server mime mappings, if present
            addMimeMappings(ctx, vs.getMimeMap());

        } catch (Throwable ex){
            exception = ex;
        }

        if (wbd != null && wbd.getApplication() != null) {
            // no dummy web module
            String moduleName;
            // S1AS BEGIN WORKAROUND FOR 6174360
            if (wbd.getApplication().isVirtual()) {
                // this is a standalone module
                moduleName = wbd.getApplication().getRegistrationName();
            } else {
                moduleName = wbd.getModuleDescriptor().getArchiveUri();
            }
            // S1AS END WORKAROUND FOR 6174360
            ctx.setModuleName(moduleName);
        } else {
            ctx.setModuleName(Constants.DEFAULT_WEB_MODULE_NAME);
        }

        try {
            vs.addChild(ctx);
        } catch (Throwable ex){
            exception = ex;
        }
        
        if (exception != null){
            ctx.setAvailable(false);

            String msg = _rb.getString("webcontainer.webModuleDisabled");
            msg = MessageFormat.format(msg, 
                                       new Object[] { wmName });
            _logger.log(Level.SEVERE, msg, exception);
            
        }

        enableWSMonitoring(wbd, j2eeServer);
        return exception;
    
protected voidloadWebModules(VirtualServer vs)
Loads all the standalone web-modules that are hosted (as specified by the server configuration) under the specified virtual server.

        WebModuleConfig wmInfo = null;
        
        String defaultWebModuleId = vs.getDefaultWebModuleID();
        
        // Get a list of the web modules to be loaded on this virtual server
        List modules = vs.getWebModules(_serverBean, _modulesRoot);
        if ((modules != null) && (modules.size() > 0)) {
            ListIterator iterator = modules.listIterator();
            while (iterator.hasNext()) {
                wmInfo = (WebModuleConfig) iterator.next();
                if (defaultWebModuleId != null && "".equals(wmInfo.getContextPath())) {
                    _logger.log(Level.SEVERE, "webcontainer.defaultWebModuleConflict",
                                new Object[] { wmInfo.getName(),
                                               wmInfo.getContextPath(),
                                               vs.getID() });
                }
                com.sun.enterprise.config.serverbeans.WebModule webBean =
                     wmInfo.getBean();
                 // load the stand alone web module if it is enabled
                 if (webBean != null && 
                     isEnabled(webBean.getConfigContext(), webBean.getName())) {
                     loadStandaloneWebModule(vs, wmInfo);
                 }
            }
        }
    
public voidmoduleDeployed(com.sun.enterprise.admin.event.ModuleDeployEvent deployEvent)

        _adminEventProcessor.moduleDeployed(deployEvent);
    
public voidmoduleDisabled(com.sun.enterprise.admin.event.ModuleDeployEvent deployEvent)

    
public voidmoduleEnabled(com.sun.enterprise.admin.event.ModuleDeployEvent deployEvent)

    
public voidmoduleRedeployed(com.sun.enterprise.admin.event.ModuleDeployEvent deployEvent)

        _adminEventProcessor.moduleRedeployed(deployEvent);	
    
public voidmoduleReferenceAdded(com.sun.enterprise.admin.event.ModuleDeployEvent event)
Invoked when a reference is created from a server instance (or cluster) to a particular module.

throws
AdminEventListenerException when the listener is unable to process the event.

 //    throws AdminEventListenerException {
                
    
public voidmoduleReferenceRemoved(com.sun.enterprise.admin.event.ModuleDeployEvent event)
Invoked when a reference is removed from a server instance (or cluster) to a particular module.

throws
AdminEventListenerException when the listener is unable to process the event.

 //     throws AdminEventListenerException {
                
    
public voidmoduleUndeployed(com.sun.enterprise.admin.event.ModuleDeployEvent deployEvent)

        _adminEventProcessor.moduleUndeployed(deployEvent);
    
public voidregisterAdHocPath(java.lang.String path, java.lang.String ctxtRoot, java.lang.String appName, AdHocServletInfo servletInfo)
Registers the given ad-hoc path at the given context root.

param
path The ad-hoc path to register
param
ctxtRoot The context root at which to register
param
appName The name of the application with which the ad-hoc path is associated
param
servletInfo Info about the ad-hoc servlet that will service requests on the given path


        registerAdHocPathAndSubtree(path, null, ctxtRoot, appName, servletInfo);
    
public voidregisterAdHocPathAndSubtree(java.lang.String path, java.lang.String subtree, java.lang.String ctxtRoot, java.lang.String appName, AdHocServletInfo servletInfo)
Registers the given ad-hoc path and subtree at the given context root.

param
path The ad-hoc path to register
param
subtree The ad-hoc subtree path to register
param
ctxtRoot The context root at which to register
param
appName The name of the application with which the ad-hoc path and subtree are associated
param
servletInfo Info about the ad-hoc servlet that will service requests on the given ad-hoc path and subtree

        WebModule wm = null;

        Engine[] engines =  _embedded.getEngines();
        for (int j=0; j<engines.length; j++) {

            Container[] vsList = engines[j].findChildren();
            for (int i = 0; i < vsList.length; i++) {

                VirtualServer vs = (VirtualServer)vsList[i];
                if (vs.getName().equalsIgnoreCase(VirtualServer.ADMIN_VS)) {
                    // Do not deploy on admin vs
                    continue;
                }

                wm = (WebModule) vs.findChild(ctxtRoot);
                if (wm == null) {
                    wm = createAdHocWebModule(vs, ctxtRoot, appName);
                } 
                wm.addAdHocPathAndSubtree(path, subtree, servletInfo);
            }
        }
    
public voidregisterAdminEvents()

    
    //HERCULES:add
           

        AdminEventListenerRegistry.addApplicationDeployEventListener(this);
        AdminEventListenerRegistry.addModuleDeployEventListener(this);
	_adminEventProcessor = 
            webFeatureFactory.getWebContainerAdminEventProcessor();
        _adminEventProcessor.init(_embedded);
    
public voidregisterMonitoringLevelEvents()

        MonitoringRegistry monitoringRegistry =
                _serverContext.getMonitoringRegistry();
        monitoringRegistry.registerMonitoringLevelListener(
                                        this, MonitoredObjectType.SERVLET);
    
private voidregisterServletStats(java.lang.String j2eeApplication, java.lang.String j2eeServer, java.lang.String webModuleName, java.lang.String vsId, java.lang.String contextRoot, java.lang.String servletName, com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener listener)


        PwcServletStats pwcServletStats = new PwcServletStatsImpl(
                                    _serverContext.getDefaultDomainName(), 
                                    vsId, contextRoot, servletName,
                                    j2eeApplication, j2eeServer);
        ServletStats servletStats = new ServletStatsImpl(pwcServletStats);


        MonitoringRegistry monitoringRegistry =
                _serverContext.getMonitoringRegistry();

        /*
         * Standalone webmodules are loaded with the application name set to
         * the string "null"
         */
        String app = ("null".equalsIgnoreCase(j2eeApplication) ?
                        null : j2eeApplication);
        try {
            monitoringRegistry.registerServletStats(servletStats,
                                                    app,
                                                    webModuleName,
                                                    contextRoot,
                                                    vsId,
                                                    servletName,
                                                    listener);
        } catch(Exception e) {
            _logger.log(Level.WARNING,
                        "Exception during registration of servletstats",
                        e);
        }
    
private com.sun.enterprise.admin.monitor.stats.WebModuleStatsregisterWebModuleStats(java.lang.String j2eeApplication, java.lang.String j2eeServer, java.lang.String vsId, WebModule ctx, com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener listener)


        WebModuleStatsImpl webStats = (WebModuleStatsImpl)
            webFeatureFactory.getWebModuleStats();
        PwcWebModuleStatsImpl pwcWebStats = new PwcWebModuleStatsImpl(
                                        ctx.getObjectName(),
                                        ctx.getEncodedPath(),
                                        _serverContext.getDefaultDomainName(), 
                                        vsId,
                                        j2eeApplication,
                                        j2eeServer);
        webStats.setPwcWebModuleStats(pwcWebStats);
        webStats.setSessionManager(ctx.getManager());

        MonitoringRegistry monitoringRegistry =
                _serverContext.getMonitoringRegistry();

        /*
         * Standalone webmodules are loaded with the application name set to
         * the string "null"
         */
        String app = ("null".equalsIgnoreCase(j2eeApplication) ?
                        null : j2eeApplication);
        try {
            monitoringRegistry.registerWebModuleStats(webStats,
                                                      app,
                                                      ctx.getModuleName(),
                                                      ctx.getEncodedPath(),
                                                      vsId,
                                                      listener);
        } catch (Exception e) {
            _logger.log(Level.WARNING,
                        "Fail to register WebModuleStats for "
                        + ctx.getModuleName() + " deployed on " + vsId, e);
        }

        return webStats;
    
voidremoveDummyModule(VirtualServer vs)
Removes the dummy module (the module created off of a virtual server's docroot) from the given virtual server if such a module exists.

param
vs The virtual server whose dummy module is to be removed

        WebModule ctx = (WebModule)vs.findChild("");
        if (ctx != null
                && Constants.DEFAULT_WEB_MODULE_NAME.equals(
                    ctx.getModuleName())) {
            unloadWebModule("", ctx.getJ2EEApplication(),
                            vs.getName(), null, true);
        }
    
public voidremoveLifecycleListener(org.apache.catalina.LifecycleListener listener)
Remove a lifecycle event listener from this component.

param
listener The listener to remove

        _lifecycle.removeLifecycleListener(listener);
    
private voidresetMonitorStatistics()

        MonitorUtil.resetMonitorStats(_embedded, _serverContext);
    
public voidsetLevel(com.sun.enterprise.admin.monitor.registry.MonitoringLevel level)

        // deprecated, ignore
    
private voidsetLogLevel(java.util.logging.Level level)
Set the level for the web container logger and determine the debug setting for Catalina's containers based on the iAS log level.

        _logLevel = level;
        _logger.setLevel(_logLevel);

        // Determine the appropriate value for Catalina's debug level
        if (level.equals(Level.FINE))
            _debug = 1;
        else if (level.equals(Level.FINER))
            _debug = 2;
        else if (level.equals(Level.FINEST))
            _debug = 5;
        else
            _debug = 0;
    
private voidsetNoTldScan()


        List tldJars = null;
        List tldListeners = null;
        HashSet<String> noTldJars = new HashSet<String>();
        HashSet<String> noTldListeners = new HashSet<String>();

        String prop = System.getProperty("com.sun.enterprise.taglibs");
        if (prop != null) {
            tldJars = StringUtils.parseStringList(prop, ",");
        }
        
        prop = System.getProperty("com.sun.enterprise.taglisteners");
        if (prop != null) {
            tldListeners = StringUtils.parseStringList(prop, ",");
        }  
        
        // Check to see if we need to scan the parent classloader when
        // searching for TLD listener. JSF application mandate the search, as
        // well as shared TLD added to the 
        // property com.sun.enterprise.taglisteners
        if ( tldListeners != null ){
            int size = tldListeners.size();
            if ( size > 0 ){
                // By default, domain.xml contains 1 elements.
                if ( !tldListeners.contains("jsf-impl.jar") || (size > 1))
                    TldConfig.setScanParentTldListener(true);
            }
        }

        ClassLoader loader = getClass().getClassLoader();
        while (loader != null) {
            if (loader instanceof URLClassLoader) {
                URL[] urls = ((URLClassLoader) loader).getURLs();
                for (int i=0; i<urls.length; i++) {
                    String url = urls[i].toString();
                    int index = url.lastIndexOf('/");
                    if (index != -1) {
                        url = url.substring(index+1);
                    }
                    if (url != null && url.endsWith(".jar")) {
                        if (tldJars == null || !tldJars.contains(url)) {
                            noTldJars.add(url);
                        }
                        if (tldListeners == null
                                || !tldListeners.contains(url)) {
                            noTldListeners.add(url);
                        }
                    }
                }
            }
            loader = loader.getParent();
        }

        TldConfig.setNoTldListeners(noTldListeners);
        TldLocationsCache.setNoTldJars(noTldJars);
    
public voidstart()
Prepare for the beginning of active use of the public methods of this component. This method should be called before any of the public methods of the component are utilized.

exception
IllegalStateException if this component has already been started
exception
LifecycleException if this component detects a fatal error that prevents this component from being used

        if (_started) {
            String msg = _rb.getString("webcontainer.alreadyStarted");
            throw new LifecycleException(msg);
        }

        if (System.getProperty(DOC_BUILDER_FACTORY_PROPERTY) == null) {
            System.setProperty(DOC_BUILDER_FACTORY_PROPERTY,
                               DOC_BUILDER_FACTORY_IMPL);
        }

        initInstanceSessionProperties();

        //HERCULES:mod
        registerAdminEvents();
        registerMonitoringLevelEvents();
        initHealthChecker();
        if(isNativeReplicationEnabled()) {
            initReplicationReceiver();
        }
        long btime = 0L;
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("before schema check");
            btime = System.currentTimeMillis();
        }
        doSchemaCheck();
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("after schema check time: " + (System.currentTimeMillis() - btime));
        }        
        //end HERCULES:mod

        ejbWebServiceRegistryListener.register();

        Engine[] engines =  _embedded.getEngines();

        for (int j=0; j<engines.length; j++) {
            Container[] vsList = engines[j].findChildren();
            for (int i = 0; i < vsList.length; i++) {
                // Load all the standalone web modules for each VS
                loadWebModules((VirtualServer)vsList[i]);
            }
        }

        // Load the web modules specified in each j2ee-application
        loadAllJ2EEApplicationWebModules(true);

        loadDefaultWebModules();

        _lifecycle.fireLifecycleEvent(START_EVENT, null);
        _started = true;
         // start the embedded container
        _embedded.start();

        if (_reloadingEnabled) {
            // Enable dynamic reloading (via the .reload file) for all
            // standalone web-modules that are marked as enabled
 
            Applications appsBean = null;
            try {
            	appsBean = ServerBeansFactory.getApplicationsBean(_configContext);
            } catch (ConfigException e) {
               String msg = _rb.getString("webcontainer.appsConfigError");
               _logger.log(Level.SEVERE, msg, e);
            }

            _reloadManager = new StandaloneWebModulesManager(_id,
                                                             _modulesRoot,
                                                             _pollInterval);
            if (appsBean != null) {
                com.sun.enterprise.config.serverbeans.WebModule[] wmBeans = appsBean.getWebModule();
                if (wmBeans != null && wmBeans.length > 0) {
                    _reloadManager.addWebModules(wmBeans);
                }
            }
        }
        enableAllWSEndpoints();
    
public voidstop()
Gracefully terminate the active use of the public methods of this component. This method should be the last one called on a given instance of this component.

exception
IllegalStateException if this component has not been started
exception
LifecycleException if this component detects a fatal error that needs to be reported

        // Validate and update our current component state
        if (!_started) {
            String msg = _rb.getString("webcontainer.notStarted");
            throw new LifecycleException(msg);
        }
          
        ejbWebServiceRegistryListener.unregister();

        //HERCULES:mod
        unregisterAdminEvents();
	unregisterMonitoringLevelEvents();
        stopHealthChecker();
        WebContainerStartStopOperation startStopOperation = 
            this.getWebContainerStartStopOperation();
        ArrayList shutdownCleanupCapablesList = startStopOperation.doPreStop();
        //end HERCULES:mod
         
        _started = false;

        // stop the embedded container         
        try{
            _embedded.stop();
        } catch (LifecycleException ex){
            if (ex.getMessage().indexOf("has not been started") == -1){
                throw ex;
            }
        }

        if (_reloadManager != null) {
            // Remove the entries from the reload monitor thread corresponding
            // to this web container object that is being stopped
            _reloadManager.stop();
            _reloadManager = null;
        }
         
        //HERCULES:mod 
        startStopOperation.doPostStop(shutdownCleanupCapablesList);
        //end HERCULES:mod
     
private voidstopHealthChecker()

         if(_healthChecker != null) {
             try {
                 _healthChecker.stop();
             } catch (LifecycleException ex) {}
             _healthChecker = null;
         }
     
private voidstopReplicationReceiver()

         if (_logger.isLoggable(Level.FINEST)) {
            _logger.finest("WebContainer:about to call replicationReceiver>>stop()" + _replicationReceiver);
         }
         try {
             _replicationReceiver.stop();
         } catch(Exception ex) {
             if (_logger.isLoggable(Level.FINEST)) {
                _logger.finest("WebContainer:error during replicationReceiver>>stop(): can be ignored" + _replicationReceiver);
             }             
         };
         _replicationReceiver = null;
     
public voidunloadWebModule(java.lang.String contextRoot, java.lang.String appName, java.lang.String virtualServers, com.sun.enterprise.deployment.WebBundleDescriptor wbd)
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
wbd Web bundle descriptor, or null if dummy context (see loadWebModule())

        unloadWebModule(contextRoot, appName, virtualServers, wbd, false);
    
public voidunloadWebModule(java.lang.String contextRoot, java.lang.String appName, java.lang.String virtualServers, com.sun.enterprise.deployment.WebBundleDescriptor wbd, boolean dummy)
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
wbd Web bundle descriptor, or null if dummy context (see loadWebModule())
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

        disableWSMonitoring(wbd);

        if (_logger.isLoggable(Level.FINEST)) {
            _logger.finest("WebContainer.unloadWebModule(): contextRoot: "
                           + contextRoot + " appName:" + appName);
        }

        cleanSecurityContext(appName);

        // unregister WebBundleDescriptor from the WebModulesManager
        if (webModulesManager != null) {
            webModulesManager.unregisterDescriptor(appName);
        }
        
        // tomcat contextRoot starts with "/"
        if (!contextRoot.equals("") && !contextRoot.startsWith("/") ) {
            contextRoot = "/" + contextRoot;
        } else if ("/".equals(contextRoot)) {
            // Make corresponding change as in WebModuleConfig.getContextPath()
            contextRoot = "";
        }
        
        Engine[] engines = _embedded.getEngines();
        List hostList = StringUtils.parseStringList(virtualServers, " ,");
        boolean unloadToAll = (hostList == null) || (hostList.size() == 0);
        boolean hasBeenUndeployed = false;
        Container[] hostArray = null;
        VirtualServer host = null;
        WebModule context = null;
        
        for (int j = 0; j < engines.length; j++) {
            hostArray = engines[j].findChildren();
            for (int i = 0; i < hostArray.length; i++) {
                host = (VirtualServer) hostArray[i];

                /**
                 * Related to Bug: 4904290
                 * Do not unloadload module on ADMIN_VS
                 */
                if ( unloadToAll && host.getName().equalsIgnoreCase(
                        VirtualServer.ADMIN_VS)){
                    continue;
                }

                if (unloadToAll 
                        || hostList.contains(host.getName())
                        || verifyAlias(hostList,host)){

                    context = (WebModule) host.findChild(contextRoot);
                    if (context != null) {
                        host.removeChild(context);
                        try {
                            ((StandardContext)context).destroy();
                        } catch (Exception ex) {
                            _logger.log(Level.WARNING,
                                "[WebContainer] Context " + contextRoot
                                + " threw exception in destroy()", ex);
                        }
                        // START SJSAS 6330332
                        Switch sw = Switch.getSwitch();
                        sw.removeDescriptorFor(context);
                        // END SJSAS 6330332
                        if (_logger.isLoggable(Level.FINEST)) {
                            _logger.log(Level.FINEST,
                                "[WebContainer] Context " + contextRoot
                                + " undeployed from " + host);
                        }
                        hasBeenUndeployed = true;
                        ((StandardHost)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(
                                            host,
                                            contextRoot,
                                            context.getJ2EEApplication());
                            wm.addAdHocPaths(context.getAdHocPaths());
                            wm.addAdHocSubtrees(context.getAdHocSubtrees());
                        }

                        // START GlassFish 141
                        if (!dummy) {
                            WebModuleConfig wmInfo = 
                                host.createSystemDefaultWebModuleIfNecessary();
                            if (wmInfo != null) {
                                loadStandaloneWebModule(host, wmInfo);
                            }
                        }
                        // END GlassFish 141
                    }
                }
            }
        }   
        
        if (!hasBeenUndeployed) {
            _logger.log(Level.SEVERE,
                "[WebContainer] Undeployment failed for context "
                + contextRoot);
        }        
    
public voidunregisterAdHocPath(java.lang.String path, java.lang.String ctxtRoot)
Unregisters the given ad-hoc path from the given context root.

param
path The ad-hoc path to unregister
param
ctxtRoot The context root from which to unregister

        unregisterAdHocPathAndSubtree(path, null, ctxtRoot);
    
public voidunregisterAdHocPathAndSubtree(java.lang.String path, java.lang.String subtree, java.lang.String ctxtRoot)
Unregisters the given ad-hoc path and subtree from the given context root.

param
path The ad-hoc path to unregister
param
subtree The ad-hoc subtree to unregister
param
ctxtRoot The context root from which to unregister


        WebModule wm = null;

        Engine[] engines =  _embedded.getEngines();
        for (int j=0; j<engines.length; j++) {

            Container[] vsList = engines[j].findChildren();
            for (int i = 0; i < vsList.length; i++) {

                VirtualServer vs = (VirtualServer) vsList[i];
                if (vs.getName().equalsIgnoreCase(VirtualServer.ADMIN_VS)) {
                    // Do not undeploy from admin vs, because we never 
                    // deployed onto it
                    continue;
                }

                wm = (WebModule) vs.findChild(ctxtRoot);
                if (wm == null) {
                    continue;
                }

                /*
                 * If the web module was created by the container for the
                 * sole purpose of mapping ad-hoc paths and subtrees,
                 * and does no longer contain any ad-hoc paths or subtrees,
                 * remove the web module.
                 */
                wm.removeAdHocPath(path);
                wm.removeAdHocSubtree(subtree);
                if ((wm instanceof AdHocWebModule)
                        && !wm.hasAdHocPaths()
                        && !wm.hasAdHocSubtrees()) {
                    vs.removeChild(wm);
                    try {
                        wm.destroy();
                    } catch (Exception ex) {
                        _logger.log(Level.WARNING,
                            "[WebContainer] Context " + wm.getPath()
                            + " threw exception in destroy()", ex);
                    }
                }
            }
        }
    
public voidunregisterAdminEvents()

        AdminEventListenerRegistry.removeEventListener(this);
        _adminEventProcessor = null;
    
public voidunregisterMonitoringLevelEvents()

        MonitoringRegistry monitoringRegistry =
                _serverContext.getMonitoringRegistry();
        monitoringRegistry.unregisterMonitoringLevelListener(this);
    
private voidunregisterServletStats(java.lang.String j2eeApplication, java.lang.String webModuleName, java.lang.String contextRoot, java.lang.String vsId, java.lang.String servletName)


        MonitoringRegistry monitoringRegistry =
                _serverContext.getMonitoringRegistry();

        try {
            monitoringRegistry.unregisterServletStats(j2eeApplication,
                                                      webModuleName,
                                                      contextRoot,
                                                      vsId,
                                                      servletName);
        } catch (Exception e) {
            _logger.log(Level.WARNING,
                        "Exception during unregistration of servletstats",
                        e);
        }
    
private voidunregisterWebModuleStats(java.lang.String j2eeApplication, java.lang.String webModuleName, java.lang.String contextRoot, java.lang.String vsId)

 

        MonitoringRegistry monitoringRegistry =
                _serverContext.getMonitoringRegistry();

        try {
            monitoringRegistry.unregisterWebModuleStats(j2eeApplication,
                                                        webModuleName,
                                                        contextRoot,
                                                        vsId);
        } catch (Exception e) {
            _logger.log(Level.WARNING,
                        "Fail to unregister WebModuleStats for "
                        + webModuleName + " deployed on " + vsId, e);
        }
    
protected voidupdateDefaultWebModule(VirtualServer virtualServer, int[] ports, java.lang.String defaultContextPath)


        if (defaultContextPath != null
                && !defaultContextPath.startsWith("/")) {
            defaultContextPath = "/" + defaultContextPath;
        }

        Connector[] connectors = _embedded.findConnectors();
        for (int i=0; i<connectors.length; i++) {
            PECoyoteConnector conn = (PECoyoteConnector) connectors[i];
            int port = conn.getPort();
            for (int j=0; j<ports.length; j++) {
                if (port == ports[j]) {
                    Mapper mapper = conn.getMapper();
                    try {
                        mapper.setDefaultContextPath(virtualServer.getName(),
                                                     defaultContextPath);

                    } catch (Exception e) {
                        throw new LifecycleException(e);
                    }
                }
            }
        }
    
private booleanverifyAlias(java.util.List vsList, VirtualServer vs)
Deploy on aliases as well as host.

        for(int i=0; i < vs.getAliases().length; i++){
            if (vsList.contains(vs.getAliases()[i]) ){
                return true;
            }
        }
        return false;