FileDocCategorySizeDatePackage
VirtualServer.javaAPI DocGlassfish v2 API59241Wed Jul 25 17:58:04 BST 2007com.sun.enterprise.web

VirtualServer

public class VirtualServer extends org.apache.catalina.core.StandardHost
Standard implementation of a virtual server (aka virtual host) in the iPlanet Application Server.

Fields Summary
public static final String
ADMIN_VS
static final String
STATE
static final String
SSO_MAX_IDLE
static final String
SSO_REAP_INTERVAL
static final String
DISABLED
static final String
OFF
static final String
ON
private VirtualServerPipeline
vsPipeline
private org.apache.catalina.Pipeline
origPipeline
private String
_id
The id of this virtual server as specified in the configuration.
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 boolean
_debug
Indicates whether the logger level is set to any one of FINE/FINER/FINEST. This flag is used to avoid incurring a perf penalty by making logging calls for debug messages when the logger level is INFO or higher.
private static final String
_info
The descriptive information about this implementation.
private com.sun.enterprise.config.serverbeans.VirtualServer
vsBean
The config bean associated with this VirtualServer
private MimeMap
mimeMap
The mime mapping associated with this VirtualServer
private boolean
allowLinking
private String
defaultContextXmlLocation
private String
defaultWebXmlLocation
private String[]
cacheControls
private boolean
isActive
private com.sun.enterprise.web.stats.PWCRequestStatsImpl
pwcRequestStatsImpl
The Stats holder used by this virtual-server.
private String
authRealmName
private PEAccessLogValve
accessLogValve
Constructors Summary
public VirtualServer()
Default constructor that simply gets a handle to the web container subsystem's logger.


    // ------------------------------------------------------------ Constructor

                       
      

        super();

        origPipeline = pipeline;
        vsPipeline = new VirtualServerPipeline(this);
        accessLogValve = new PEAccessLogValve();

        _debug = _logger.isLoggable(Level.FINE);
    
Methods Summary
protected voidaddListener(java.lang.String listenerName)
Adds the Catalina listener with the given class name to this VirtualServer.

param
listenerName The fully qualified class name of the listener.

        Object listener = loadInstance(listenerName);
        
        if ( listener == null ) return;

        if (listener instanceof ContainerListener) {
            addContainerListener((ContainerListener)listener);
        } else if (listener instanceof LifecycleListener){
            addLifecycleListener((LifecycleListener)listener);            
        } else {
            _logger.log(Level.SEVERE,"webcontainer.invalidListener"
                    + listenerName);
        }     
    
public synchronized voidaddValve(org.apache.catalina.Valve valve)
Adds the given valve to the currently active pipeline, keeping the valve that is not currently active in sync.

        super.addValve(valve);
        if (pipeline == vsPipeline) {
            origPipeline.addValve(valve);
        } else {
            vsPipeline.addValve(valve);
        }
    
protected voidaddValve(java.lang.String valveName)
Adds the Valve with the given class name to this VirtualServer.

param
valveName The valve's fully qualified class name

        Valve valve = (Valve)loadInstance(valveName);  
        
        if (valve == null) return;
        
        super.addValve(valve); 
    
public voidclearAliases()
Delete all aliases.

        aliases = new String[0];
    
voidconfigureAliases()
Configure virtual-server alias attribute.


        // Add each host name from the 'hosts' attribute as an alias
        List hosts = StringUtils.parseStringList(vsBean.getHosts(), ",");
        for (int i=0; i < hosts.size(); i++ ){
            String alias = hosts.get(i).toString();
            if ( !alias.equalsIgnoreCase("localhost.localdomain")){
                addAlias(alias);
            }
        }
    
voidconfigureAuthRealm(com.sun.enterprise.config.serverbeans.SecurityService securityService)
Configures this virtual server with its authentication realm. Checks if this virtual server specifies any authRealm property, and if so, ensures that its value identifies a valid realm.

param
securityService The security-service element from domain.xml

        ElementProperty prop = vsBean.getElementPropertyByName("authRealm");
        if (prop != null && prop.getValue() != null) {
            if (securityService.getAuthRealmByName(prop.getValue()) != null) {
                authRealmName = prop.getValue();
            } else {
                _logger.log(Level.SEVERE, "vs.invalidAuthRealm",
                            new Object[] { getID(), prop.getValue() });
            }
        }
    
voidconfigureCacheControl(java.lang.String cacheControl)
Configures the cache control of this VirtualServer

       
        if (cacheControl != null) {
            List values = StringUtils.parseStringList(cacheControl,
                                                      ",");
            if (values != null && !values.isEmpty()) {
                String[] cacheControls = new String[values.size()];
                setCacheControls((String[]) values.toArray(cacheControls));
            }
        }
    
protected voidconfigureCatalinaProperties()
Configures the valve_ and listener_ properties of this VirtualServer.


        ElementProperty[] props = vsBean.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) {
                _logger.log(Level.WARNING,
                            "webcontainer.nullWebModuleProperty",
                            getName());
            }

            if (propName.startsWith("valve_")) {
                addValve(propValue);            
            } else if (propName.startsWith("listener_")) {
                addListener(propValue);   
            } else if (propName.equals("securePagesWithPragma")){
                setSecurePagesWithPragma(Boolean.valueOf(propValue));
            }
        }
    
voidconfigureErrorPage()
Configures this VirtualServer with its send-error properties.


        ErrorPage errorPage = null;

        if (vsBean == null) {
            return;
        }

        ElementProperty[] props = vsBean.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) {
                _logger.log(Level.WARNING,
                            "webcontainer.nullVirtualServerProperty",
                            getID());
                continue;
            }

            if (!propName.startsWith("send-error_")) {
                continue;
            }

            /* 
             * Validate the prop value
             */
            String path = null;
            String reason = null;
            String status = null;

            String[] errorParams = propValue.split(" ");
            for (int j=0; j<errorParams.length; j++) {

                if (errorParams[j].startsWith("path=")) {
                    if (path != null) {
                        _logger.log(Level.WARNING,
                                    "webcontainer.sendErrorMultipleElement",
                                    new Object[] { propValue, "path" });
                    }
                    path = errorParams[j].substring("path=".length());
                }

                if (errorParams[j].startsWith("reason=")) {
                    if (reason != null) {
                        _logger.log(Level.WARNING,
                                    "webcontainer.sendErrorMultipleElement",
                                    new Object[] { propValue, "reason" });
                    }
                    reason = errorParams[j].substring("reason=".length());
                }

                if (errorParams[j].startsWith("code=")) {
                    if (status != null) {
                        _logger.log(Level.WARNING,
                                    "webcontainer.sendErrorMultipleElement",
                                    new Object[] { propValue, "code" });
                    }
                    status = errorParams[j].substring("code=".length());
                }
            }

            if (path == null || path.length() == 0) {
                _logger.log(Level.WARNING,
                            "webcontainer.sendErrorMissingPath",
                            propValue);
            }

            errorPage = new ErrorPage();
            errorPage.setLocation(path);
            errorPage.setErrorCode(status);
            errorPage.setReason(reason);

            addErrorPage(errorPage);
        }

    
voidconfigureRedirect()
Configures this VirtualServer with its redirect properties.


        vsPipeline.clearRedirects();

        if (vsBean == null) {
            return;
        }

        ElementProperty[] props = vsBean.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) {
                _logger.log(Level.WARNING,
                            "webcontainer.nullVirtualServerProperty",
                            getID());
                continue;
            }

            if (!propName.startsWith("redirect_")) {
                continue;
            }

            /* 
             * Validate the prop value
             */
            String from = null;
            String url = null;
            String urlPrefix = null;
            String escape = null;

            String[] redirectParams = propValue.split(" ");
            for (int j=0; j<redirectParams.length; j++) {

                if (redirectParams[j].startsWith("from=")) {
                    if (from != null) {
                        _logger.log(Level.WARNING,
                                    "webcontainer.redirectMultipleElement",
                                    new Object[] { propValue, "from" });
                    }
                    from = redirectParams[j].substring("from=".length());
                }

                if (redirectParams[j].startsWith("url=")) {
                    if (url != null) {
                        _logger.log(Level.WARNING,
                                    "webcontainer.redirectMultipleElement",
                                    new Object[] { propValue, "url" });
                    }
                    url = redirectParams[j].substring("url=".length());
                }

                if (redirectParams[j].startsWith("url-prefix=")) {
                    if (urlPrefix != null) {
                        _logger.log(Level.WARNING,
                                    "webcontainer.redirectMultipleElement",
                                    new Object[] { propValue, "url-prefix" });
                    }
                    urlPrefix = redirectParams[j].substring(
                                                    "url-prefix=".length());
                }

                if (redirectParams[j].startsWith("escape=")) {
                    if (escape != null) {
                        _logger.log(Level.WARNING,
                                    "webcontainer.redirectMultipleElement",
                                    new Object[] { propValue, "escape" });
                    }
                    escape = redirectParams[j].substring("escape=".length());
                }
            }

            if (from == null || from.length() == 0) {
                _logger.log(Level.WARNING,
                            "webcontainer.redirectMissingFrom",
                            propValue);
            }

            // Either url or url-prefix (but not both!) must be present
            if ((url == null || url.length() == 0)
                    && (urlPrefix == null || urlPrefix.length() == 0)) {
                _logger.log(Level.WARNING,
                            "webcontainer.redirectMissingUrlOrUrlPrefix",
                            propValue);
            }
            if (url != null && url.length() > 0
                    && urlPrefix != null && urlPrefix.length() > 0) {
                _logger.log(Level.WARNING,
                            "webcontainer.redirectBothUrlAndUrlPrefix",
                            propValue);
            }

            boolean escapeURI = true;
            if (escape != null) {
                if ("yes".equalsIgnoreCase(escape)) {
                    escapeURI = true;
                } else if ("no".equalsIgnoreCase(escape)) {
                    escapeURI = false;
                } else {
                    _logger.log(Level.WARNING,
                                "webcontainer.redirectInvalidEscape",
                                propValue);
                }
            }

            vsPipeline.addRedirect(from, url, urlPrefix, escapeURI);
        }

        if (vsPipeline.hasRedirects()) {
            if (pipeline != vsPipeline) {
                // Enable custom pipeline
                setPipeline(vsPipeline);
            }
        } else if (isActive && pipeline != origPipeline) {
            setPipeline(origPipeline);
        }
    
voidconfigureRemoteAddressFilterValve()
Configures the Remote Address Filter valve of this VirtualServer. This valve enforces request accpetance/denial based on the string representation of the remote client's IP address.


        RemoteAddrValve remoteAddrValve = null;

        if (vsBean == null) {
            return;
        }

        ElementProperty allow = vsBean.getElementPropertyByName(
            "allowRemoteAddress");
        ElementProperty deny = vsBean.getElementPropertyByName(
            "denyRemoteAddress");
        if ((allow != null && allow.getValue() != null)
                || (deny != null && deny.getValue() != null))  {
            remoteAddrValve = new RemoteAddrValve();
        }

        if (allow != null && allow.getValue() != null) {
            _logger.fine("Allowing access to " + getID()+ " from " +
                         allow.getValue());
            remoteAddrValve.setAllow(allow.getValue());
        }

        if (deny != null && deny.getValue() != null) {
            _logger.fine("Denying access to " + getID()+ " from " +
                         deny.getValue());
            remoteAddrValve.setDeny(deny.getValue());
        }

        if (remoteAddrValve != null) {
            // Remove existing RemoteAddrValve (if any), in case of a reconfig
            Valve[] valves = getValves();
            for (int i=0; valves!=null && i<valves.length; i++) {
                if (valves[i] instanceof RemoteAddrValve) {
                    removeValve(valves[i]);
                    break;
                }
            }
            addValve(remoteAddrValve);
        }
    
voidconfigureRemoteHostFilterValve(com.sun.enterprise.config.serverbeans.HttpProtocol httpProtocol)
Configures the Remote Host Filter valve of this VirtualServer. This valve enforces request acceptance/denial based on the name of the remote host from where the request originated.


        RemoteHostValve remoteHostValve = null;

        if (vsBean == null) {
            return;
        }

        ElementProperty allow = vsBean.getElementPropertyByName(
            "allowRemoteHost");
        ElementProperty deny = vsBean.getElementPropertyByName(
            "denyRemoteHost");
        if ((allow != null && allow.getValue() != null)
                || (deny != null && deny.getValue() != null))  {
            remoteHostValve = new RemoteHostValve();
        }

        if (allow != null && allow.getValue() != null) {
            _logger.fine("Allowing access to " + getID()+ " from " +
                         allow.getValue());
            if (httpProtocol == null || !httpProtocol.isDnsLookupEnabled()) {
                _logger.log(Level.WARNING,
                            "webcontainer.allowRemoteHost.dnsLookupDisabled",
                            getID());
            }
            remoteHostValve.setAllow(allow.getValue());
        }

        if (deny != null && deny.getValue() != null) {
            _logger.fine("Denying access to " + getID()+ " from " +
                         deny.getValue());
            if (httpProtocol == null || !httpProtocol.isDnsLookupEnabled()) {
                _logger.log(Level.WARNING,
                            "webcontainer.denyRemoteHost.dnsLookupDisabled",
                            getID());
            }
            remoteHostValve.setDeny(deny.getValue());
        }

        if (remoteHostValve != null) {
            // Remove existing RemoteHostValve (if any), in case of a reconfig
            Valve[] valves = getValves();
            for (int i=0; valves!=null && i<valves.length; i++) {
                if (valves[i] instanceof RemoteHostValve) {
                    removeValve(valves[i]);
                    break;
                }
            }
            addValve(remoteHostValve);
        }
    
voidconfigureSSOValve(boolean globalSSOEnabled, com.sun.enterprise.server.pluggable.WebContainerFeatureFactory webContainerFeatureFactory)
Configures the SSO valve of this VirtualServer.


        if (vsBean == null) {
            return;
        }

        if (!isSSOEnabled(globalSSOEnabled)) {
            /*
             * Disable SSO
             */
            Object[] params = {  getID() };
            _logger.log(Level.INFO, "webcontainer.ssodisabled", params);

            // Remove existing SSO valve (if any)
            Valve[] valves = getValves();
            for (int i=0; valves!=null && i<valves.length; i++) {
                if (valves[i] instanceof SingleSignOn) {
                    removeValve(valves[i]);
                    break;
                }
            }

        } else {
            /*
             * Enable SSO
             */
            try {
                SSOFactory ssoFactory = webContainerFeatureFactory.getSSOFactory();
                //SingleSignOn sso = ssoFactory.createSingleSignOnValve();
                String vsName = this.getName();
                SingleSignOn sso = ssoFactory.createSingleSignOnValve(vsName);
                
                // set max idle time if given
                ElementProperty idle =
                    vsBean.getElementPropertyByName(SSO_MAX_IDLE);
                if (idle != null && idle.getValue() != null) {
                    _logger.fine("SSO entry max idle time set to: " +
                                 idle.getValue());
                    int i = Integer.parseInt(idle.getValue());
                    sso.setMaxInactive(i);
                }

                // set expirer thread sleep time if given
                ElementProperty expireTime =
                    vsBean.getElementPropertyByName(SSO_REAP_INTERVAL);
                if (expireTime !=null && expireTime.getValue() != null) {
                    _logger.fine("SSO expire thread interval set to : " +
                                 expireTime.getValue());
                    int i = Integer.parseInt(expireTime.getValue());
                    sso.setReapInterval(i);
                }

                // Remove existing SSO valve (if any), in case of a reconfig
                Valve[] valves = getValves();
                for (int i=0; valves!=null && i<valves.length; i++) {
                    if (valves[i] instanceof SingleSignOn) {
                        removeValve(valves[i]);
                        break;
                    }
                }

                addValve(sso);

            } catch (Exception e) {
                _logger.log(Level.WARNING, "webcontainer.ssobadconfig", e);
                _logger.log(Level.WARNING, "webcontainer.ssodisabled",
                            getID());
            }
        }
    
voidconfigureVirtualServerState()
Configures this VirtualServer with its state (on | off | disabled).


        String stateValue = ON;
        if (vsBean != null){
            stateValue = vsBean.getState();
        }

        if ( ( !stateValue.equalsIgnoreCase(ON) )
            && (getName().equalsIgnoreCase(ADMIN_VS) ) ){
            throw new java.lang.IllegalArgumentException(
                "virtual-server " 
                + ADMIN_VS + " state property cannot be modified");
        }
        
        if ( stateValue.equalsIgnoreCase(DISABLED) ) {
            // state="disabled"
            setIsDisabled(true);
        } else if ( !ConfigBean.toBoolean( stateValue ) ) {
            // state="off"
            setIsOff(true);
        } else {
            setIsActive(true);
        }
    
protected WebModuleConfigcreateSystemDefaultWebModuleIfNecessary()
If a default web module has not yet been configured and added to this virtual server's list of web modules then return the configuration information needed in order to create a default web module for this virtual server. This method should be invoked only after all the standalone modules and the modules within j2ee-application elements have been added to this virtual server's list of modules (only then will one know whether the user has already configured a default web module or not).


        WebModuleConfig wmInfo = null;
        //
        // Add a default context only if one hasn't already been loaded
        // and then too only if docroot is not null
        //
        String docroot = getAppBase();
        if (getDefaultWebModuleID() == null && (findChild("") == null)
                && (docroot != null)) {
            wmInfo = new WebModuleConfig();
            WebModule wm = new WebModule();
            wm.setName(Constants.DEFAULT_WEB_MODULE_NAME);
            wm.setContextRoot("");
            wm.setLocation(docroot);
            wmInfo.setBean(wm);
            
            wmInfo.setDescriptor(DOLLoadingContextFactory.getDefaultWebBundleDescriptor());
 
            WebBundleDescriptor wbd = wmInfo.getDescriptor();
            if ( wbd.getApplication() == null ) {
                Application application = new Application();
                application.setVirtual(true);
                application.setName(Constants.DEFAULT_WEB_MODULE_NAME);
                wbd.setApplication(application);
            }
        }

        return wmInfo;
    
voiddisableAccessLogging()
Disables access logging for this virtual server, by removing its accesslog valve from its pipeline.

        removeValve(accessLogValve);
    
voidenableAccessLogging()
Enables access logging for this virtual server, by adding its accesslog valve to its pipeline, or starting its accesslog valve if it is already present in the pipeline.

        if (!isAccessLogValveActivated()) {
            addValve(accessLogValve);
        } else {
            try {
                if (accessLogValve.isStarted()) {
                    accessLogValve.stop();
                }
                accessLogValve.start();
            } catch (LifecycleException le) {
                _logger.log(Level.SEVERE,
                            "pewebcontainer.accesslog.reconfigure",
                            le);
            }
        }
    
protected WebModuleConfigfindWebModuleInJ2eeApp(com.sun.enterprise.config.serverbeans.Applications appsBean, java.lang.String id)
Finds and returns information about a web module embedded within a J2EE application, which is identified by a string of the form a:b or a#b, where a is the name of the J2EE application and b is the name of the embedded web module.

return
null if id does not identify a web module embedded within a J2EE application.

        WebModuleConfig wmInfo = null;

        int length = id.length();
        // Check for ':' separator
        int separatorIndex = id.indexOf(Constants.NAME_SEPARATOR);
        if (separatorIndex == -1) {
            // Check for '#' separator
            separatorIndex = id.indexOf('#");
        }
        if (separatorIndex != -1) {
            String appID = id.substring(0, separatorIndex);
            String moduleID = id.substring(separatorIndex + 1);
            J2eeApplication j2eeApp = appsBean.getJ2eeApplicationByName(appID);
            if ((j2eeApp != null) && j2eeApp.isEnabled()) {
                String location = j2eeApp.getLocation();
                String moduleDir = 
                    DeploymentUtils.getRelativeEmbeddedModulePath(
                        location, moduleID);
              
                ApplicationRegistry registry =
                    ApplicationRegistry.getInstance();
                ClassLoader appLoader =
                    registry.getClassLoaderForApplication(appID);
                if (appLoader != null) {
                    Application appDesc = registry.getApplication(appLoader);
                    if (appDesc != null) {
                        Set wbds = appDesc.getWebBundleDescriptors();
                        WebBundleDescriptor wbd = null;
                        for (Iterator itr = wbds.iterator(); itr.hasNext(); ) {
                            wbd = (WebBundleDescriptor) itr.next();
                            String webUri = wbd.getModuleDescriptor().getArchiveUri();
                            if (moduleID.equals(webUri)) {
                                StringBuffer dir = new StringBuffer(location);
                                dir.append(File.separator);
                                dir.append(moduleDir);
                                WebModule wm = new WebModule();
                                wm.setName(moduleID);
                                wm.setContextRoot(wbd.getContextRoot());
                                wm.setLocation(dir.toString());
                                wm.setEnabled(true);
                                String vsList = getVirtualServers(j2eeApp.getName());
                                wmInfo = new WebModuleConfig();
                                wmInfo.setBean(wm);
                                wmInfo.setDescriptor(wbd);
                                wmInfo.setParentLoader(appLoader);
                                wmInfo.setVirtualServers(vsList);
                                break;
                            }
                        }
                    }
                }
            } else {
                Object[] params = { id, getID() };
                _logger.log(Level.SEVERE, "vs.defaultWebModuleDisabled",
                            params);
            }
        }
        return wmInfo;
    
PEAccessLogValvegetAccessLogValve()

return
the accesslog valve of this virtual server

        return accessLogValve;
    
public booleangetAllowLinking()
Gets the value of the allowLinking property of this virtual server.

return
true if symbolic links from this virtual server's docroot (as well as symbolic links from archives of web modules deployed on this virtual server) are followed, false otherwise

        return allowLinking;
    
java.lang.StringgetAuthRealmName()
Gets the value of the authRealm property of this virtual server.

return
The value of the authRealm property of this virtual server, or null of this virtual server does not have any such property

        return authRealmName;
    
public com.sun.enterprise.config.serverbeans.VirtualServergetBean()
Gets the config bean associated with this VirtualServer.

        return vsBean;
    
public java.lang.String[]getCacheControls()
Gets the Cache-Control configuration of this VirtualServer.

return
Cache-Control configuration of this VirtualServer, or null if no such configuration exists for this VirtualServer

        return cacheControls;
    
protected java.lang.StringgetDefaultContextPath(com.sun.enterprise.config.serverbeans.Server serverBean)
Gets the context root of the web module that the user/configuration has designated as the default-web-module for this virtual server. The default-web-module for a virtual server is specified via the 'default-web-module' attribute of the 'virtual-server' element in server.xml. This is an optional attribute and if the configuration does not specify another web module (standalone or part of a j2ee-application) that is configured at a context-root="", then a default web module will be created and loaded. The value for this attribute is either "${standalone-web-module-name}" or "${j2ee-app-name}:${web-module-uri}".

return
null if the default-web-module has not been specified or if the web module specified either could not be found or is disabled or does not specify this virtual server (if it specifies a value for the virtual-servers attribute) or if there was an error loading its deployment descriptors.


        String contextRoot = null;
        Applications appsBean = null;

        try{
            appsBean = ServerBeansFactory.getApplicationsBean(
                serverBean.getConfigContext());
        } catch (ConfigException e) {
            String msg = _rb.getString("vs.appsConfigError");
            Object[] params = { getID() };
            msg = MessageFormat.format(msg, params);
            _logger.log(Level.SEVERE, msg, e);
        }

        String wmID = getDefaultWebModuleID();
        if (wmID != null) {
            // Check if the default-web-module is part of a
            // j2ee-application
            WebModuleConfig wmInfo = findWebModuleInJ2eeApp(appsBean, wmID);

            // Look up the list of standalone web modules
            if (wmInfo == null) {
                WebModule wm = appsBean.getWebModuleByName(wmID);
                if (wm != null) {
                    if (isActive(wm, false)) {
                        // Create a copy as we need to change the name
                        // and context root to indicate that this web module
                        // is to be loaded as the 'default' web module for
                        // the virtual server
                        // WebModule wmCopy = (WebModule) wm.clone();
                        contextRoot = wm.getContextRoot();
                    } else {
                        Object[] params = { wmID, getID() };
                        _logger.log(Level.SEVERE, "vs.defaultWebModuleDisabled",
                                    params);
                    }
                }
            } else {
                WebModule wm = wmInfo.getBean();
                contextRoot = wm.getContextRoot();
            }

            if (contextRoot == null) {
                Object[] params = { wmID, getID() };
                _logger.log(Level.SEVERE, "vs.defaultWebModuleNotFound",
                            params);
            }
        }

        return contextRoot;
    
public java.lang.StringgetDefaultContextXmlLocation()
Gets the default-context.xml location of web modules deployed on this virtual server.

return
default-context.xml location of web modules deployed on this virtual server

        return defaultContextXmlLocation;
    
protected java.lang.StringgetDefaultWebModuleID()
Returns the id of the default web module for this virtual server as specified in the 'default-web-module' attribute of the 'virtual-server' element. This is an optional attribute.

        String wmID = null;
        
        if (vsBean != null) {
            wmID = vsBean.getDefaultWebModule();
            if (wmID != null && _debug) {
                Object[] params = { wmID, _id };
                _logger.log(Level.FINE, "vs.defaultWebModule", params);
            }
        } else {
            _logger.log(Level.SEVERE, "vs.configError", _id);
        }

        return wmID;
    
public java.lang.StringgetDefaultWebXmlLocation()
Gets the default-web.xml location of web modules deployed on this virtual server.

return
default-web.xml location of web modules deployed on this virtual server

        return defaultWebXmlLocation;
    
public java.lang.StringgetID()
Return the virtual server identifier.



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

              
       
        return _id;
    
public java.lang.StringgetInfo()
Return descriptive information about this Container implementation and the corresponding version number, in the format <description>/<version>.

        return _info;
    
public MimeMapgetMimeMap()
Gets the mime map associated with this VirtualServer.

        return mimeMap;
    
public com.sun.enterprise.web.stats.PWCRequestStatsImplgetPWCRequestStatsImpl()
Get the Stat holder.

        return pwcRequestStatsImpl;
    
com.sun.enterprise.config.serverbeans.ElementProperty[]getProperties()

return
The properties of this virtual server, or null

        if (vsBean != null) {
            return vsBean.getElementProperty();
        } else {
            return null;
        }
    
private java.lang.StringgetVirtualServers(java.lang.String appName)
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
return
virtual servers as a string (separated by space or comma)

        String ret = null;
        try {
            ConfigContext ctx = 
                ApplicationServer.getServerContext().getConfigContext();
            ret = ServerBeansFactory
                    .getVirtualServersByAppName(ctx, appName);
        } catch (ConfigException ce) {
            _logger.log(Level.FINE, "Cannot get virtual server for " + appName, ce);
        }
        
        return ret;
    
protected java.util.ListgetWebModules(com.sun.enterprise.config.serverbeans.Server serverBean, java.lang.String modulesRoot)
Return the list of enabled web-modules configured for this virtual server.

return
The list of WebModuleConfig objects for all enabled web-modules hosted under the specified virtual server.


        List modules = new Vector();
        
        //ROB: config changes
        //Applications appsBean = serverBean.getApplications();
        Applications appsBean = null;
        try {
            appsBean = ServerBeansFactory.getApplicationsBean(serverBean.getConfigContext());
        } catch (ConfigException e) {
            String msg = _rb.getString("vs.appsConfigError");
            Object[] params = { getID() };
            msg = MessageFormat.format(msg, params);
            _logger.log(Level.SEVERE, msg, e);
        }

        if (appsBean != null) {
            WebModule[] wmBeans = appsBean.getWebModule();
            if (wmBeans != null && wmBeans.length > 0) {
                for (int i = 0; i < wmBeans.length; i++) {
                    WebModule wm = wmBeans[i];
                    if (isActive(wm)) {                      
                        // skips if the web module is not referenced by 
                        // this server
                        ApplicationRef ref = 
                            serverBean.getApplicationRefByRef(wm.getName());
                        if (ref == null) {
                            continue;
                        }                       

                        String location = wm.getLocation();
                        // If module root is relative then prefix it with the 
                        // location of where all the standalone modules for 
                        // this server instance are deployed
                        File moduleBase = new File(location);
                        if (!moduleBase.isAbsolute()) {
                            location = modulesRoot+File.separator+location;
                            wm.setLocation(location);
                        }
                        WebModuleConfig wmInfo = loadWebModuleConfig(wm);
                        if (wmInfo != null)
                            modules.add(wmInfo);
                    } else {
                        if (_debug) {
                            _logger.finer("Web Module [" + wm.getName() + 
                                          "] is not applicable for virtual " +
                                          " server [" + getID() + "]");
                        }
                    }
                }
            }
        }
        return modules;
    
private booleanisAccessLogValveActivated()

return
true if the accesslog valve of this virtual server has been activated, that is, added to this virtual server's pipeline; false otherwise


        Pipeline p = getPipeline();
        if (p != null) {
            Valve[] valves = p.getValves();
            if (valves != null) {
                for (int i=0; i<valves.length; i++) {
                    if (valves[i] instanceof PEAccessLogValve) {
                        return true;
                    }
                }
            }
        }

        return false;
    
booleanisAccessLoggingEnabled(boolean globalAccessLoggingEnabled)
Determines whether access logging is enabled for this virtual server.

param
globalAccessLoggingEnabled The value of the accessLoggingEnabled property of the http-service element
return
true if access logging is enabled for this virtual server, false otherwise.

        ElementProperty prop  = 
            vsBean.getElementPropertyByName(Constants.ACCESS_LOGGING_ENABLED);

        if (prop == null || prop.getValue() == null) {
            return globalAccessLoggingEnabled;
        } else {
            return ConfigBean.toBoolean(prop.getValue());
        }
    
private booleanisActive(com.sun.enterprise.config.serverbeans.WebModule wm)
Determines whether the specified web module is "active" under this virtual server.

        return isActive(wm, true);
    
protected booleanisActive(com.sun.enterprise.config.serverbeans.WebModule wm, boolean matchVSID)
Determines whether the specified web module is "active" under this virtual server. A web module is active if it meets ALL of the following conditions: - wm is not null - the enabled attribute of the web-module element is true If matchVSID is true then the following additional condition must be satisfied. - the virtual-servers attribute of the web-module element is either empty/not-specified or if specified then this virtual server's name/ID is one of the virtual servers specified in the list

param
wm The bean containing the web module configuration information as specified in server.xml
param
matchVSID This is set to false when testing to see if a web module that has been configured to be the default-web-module for a VS is active or not. In this case the only test is to check if the web module is enabled or not. When set to true, the virtual server list is examined to ensure that the web module has been configured to run on this virtual server.
return
true if all the criteria are satisfied and false otherwise.


        String vsID = getID();

        boolean active = ((vsID != null) && (vsID.length() > 0));
        active &= (wm != null);

        if (active) {
            // Check if the web module is enabled
            active &= wm.isEnabled();

            //
            // Check if vsID is one of the virtual servers specified
            // in the list of virtual servers that the web module is to
            // be loaded on. If the virtual-servers attribute of the
            // <web-module> element is missing or empty then the implied
            // behaviour is that the web module is active on every virtual
            // server.
            //
            String vsIDs = getVirtualServers(wm.getName());

            //
            // fix for bug# 4913636
            // so that for PE if the vsList is null and the virtual server is
            // admin-vs then return false because we don't want to load user apps
            // on admin-vs
            //
            if (getID().equals(ADMIN_VS) && matchVSID
                    && ((vsIDs == null) || (vsIDs.length() == 0 ))) {
                return false;
            } 


            if (matchVSID && (vsIDs != null) && (vsIDs.length() > 0)) {
                List vsList = StringUtils.parseStringList(vsIDs, " ,");
                if (vsList != null)
                    active &= vsList.contains(vsID.trim());
                else
                    active &= true;
            } else
                active &= true;
        }
        return active;
    
public booleanisActive()

return
true if this virtual server is active, false otherwise

        return isActive;
    
private booleanisSSOEnabled(boolean globalSSOEnabled)
Checks if SSO is enabled for this VirtualServer.

return
The value of the sso-enabled property for this VirtualServer

        ElementProperty ssoProperty  = 
            vsBean.getElementPropertyByName(Constants.SSO_ENABLED);

        if (ssoProperty == null || ssoProperty.getValue() == null) {
            return globalSSOEnabled;
        } else {
            return ConfigBean.toBoolean(ssoProperty.getValue());
        }
    
private java.lang.ObjectloadInstance(java.lang.String className)

        try{
            Class clazz = Class.forName(className);
            return clazz.newInstance();
        } catch (Throwable ex){
            _logger.log(Level.SEVERE,"webcontainer.unableToLoadExtension",ex);        
        }
        return null;
    
protected WebModuleConfigloadWebModuleConfig(com.sun.enterprise.config.serverbeans.WebModule wm)
Creates and returns an object that contains information about the web module's configuration such as the information specified in server.xml, the deployment descriptor objects etc.

return
null if an error occured while reading/parsing the deployment descriptors.


        WebModuleConfig wmInfo = new WebModuleConfig();
        wmInfo.setBean(wm);
        String wmID = wm.getName();
        String location = wm.getLocation();
        try {
            WebModulesManager webModulesManager = new WebModulesManager(
                ApplicationServer.getServerContext().getInstanceEnvironment());
	    Application app = webModulesManager.getDescriptor(wmID, location);	    
            WebBundleDescriptor wbd = (WebBundleDescriptor) app.getStandaloneBundleDescriptor();
            wmInfo.setDescriptor(wbd);
        } catch (ConfigException ce) {
            wmInfo = null;
            String msg = _rb.getString("vs.moduleConfigError");
            Object[] params = { wmID, getID() };
            msg = MessageFormat.format(msg, params);
            _logger.log(Level.SEVERE, msg, ce);
        }
        return wmInfo;
    
voidreconfigureAccessLog(java.lang.String globalAccessLogBufferSize, java.lang.String globalAccessLogWriteInterval, com.sun.enterprise.instance.InstanceEnvironment instance, com.sun.enterprise.config.serverbeans.Domain domain, boolean globalAccessLoggingEnabled)
Reconfigures the access log of this VirtualServer with its updated access log related properties.

        try {
            if (accessLogValve.isStarted()) {
                accessLogValve.stop();
            }
            boolean start = accessLogValve.updateVirtualServerProperties(
                vsBean.getId(), vsBean, domain, instance,
                globalAccessLogBufferSize, globalAccessLogWriteInterval);
            if (start && isAccessLoggingEnabled(globalAccessLoggingEnabled)) {
                enableAccessLogging();
            } else {
                disableAccessLogging();
            }
        } catch (LifecycleException le) {
            _logger.log(Level.SEVERE,
                        "pewebcontainer.accesslog.reconfigure",
                        le);
        }
    
voidreconfigureAccessLog(com.sun.enterprise.config.serverbeans.HttpService httpService, com.sun.enterprise.server.pluggable.WebContainerFeatureFactory webcontainerFeatureFactory)
Reconfigures the access log of this VirtualServer with the updated attributes of the access-log element from domain.xml.


        try {
            boolean restart = false;
            if (accessLogValve.isStarted()) {
                accessLogValve.stop();
                restart = true;
            }
            accessLogValve.updateAccessLogAttributes(
                httpService,
                webcontainerFeatureFactory);
            if (restart) {
                accessLogValve.start();
            }
        } catch (LifecycleException le) {
            _logger.log(Level.SEVERE,
                        "pewebcontainer.accesslog.reconfigure",
                        le);
        }
    
public synchronized voidremoveValve(org.apache.catalina.Valve valve)
Removes the given valve from the currently active pipeline, keeping the valve that is not currently active in sync.

        super.removeValve(valve);
        if (pipeline == vsPipeline) {
            origPipeline.removeValve(valve);
        } else {
            vsPipeline.removeValve(valve);
        }
    
public voidsetAllowLinking(boolean allowLinking)
Sets the allowLinking property of this virtual server, which determines whether symblic links from this virtual server's docroot are followed. This property is inherited by all web modules deployed on this virtual server, unless overridden by the allowLinking property in a web module's sun-web.xml.

param
allowLinking Value of allowLinking property

        this.allowLinking = allowLinking;
    
public voidsetBean(com.sun.enterprise.config.serverbeans.VirtualServer vsBean)
Sets the config bean for this VirtualServer

        this.vsBean = vsBean;
     
public voidsetCacheControls(java.lang.String[] cacheControls)
Sets the Cache-Control configuration for this VirtualServer

param
cacheControls Cache-Control configuration settings for this VirtualServer

        this.cacheControls = cacheControls;
    
public voidsetDefaultContextXmlLocation(java.lang.String defaultContextXmlLocation)
Sets the default-context.xml location for web modules deployed on this virtual server.

param
defaultWebXmlLocation default-context.xml location for web modules deployed on this virtual server

        this.defaultContextXmlLocation = defaultContextXmlLocation;
    
public voidsetDefaultWebXmlLocation(java.lang.String defaultWebXmlLocation)
Sets the default-web.xml location for web modules deployed on this virtual server.

param
defaultWebXmlLocation default-web.xml location for web modules deployed on this virtual server

        this.defaultWebXmlLocation = defaultWebXmlLocation;
    
public voidsetID(java.lang.String id)
Set the virtual server identifier string.

param
id New identifier for this virtual server

        _id = id;
    
public voidsetIsActive(boolean isActive)
Sets the state of this virtual server.

param
isActive true if this virtual server is active, false otherwise

        this.isActive = isActive;
        if (isActive) {
            vsPipeline.setIsDisabled(false);
            vsPipeline.setIsOff(false);
            if (pipeline == vsPipeline && !vsPipeline.hasRedirects()) {
                // Restore original pipeline
                setPipeline(origPipeline);
            }
        }
    
private voidsetIsDisabled(boolean isDisabled)

        vsPipeline.setIsDisabled(isDisabled);
        vsPipeline.setIsOff(false);
        if (isDisabled && pipeline != vsPipeline) {
            // Enable custom pipeline
            setPipeline(vsPipeline);
        } 
    
private voidsetIsOff(boolean isOff)

        vsPipeline.setIsOff(isOff);
        vsPipeline.setIsDisabled(false);
        if (isOff && pipeline != vsPipeline) {
            // Enable custom pipeline
            setPipeline(vsPipeline);
        } 
    
public voidsetMimeMap(MimeMap mimeMap)
Sets the mime map for this VirtualServer

        this.mimeMap = mimeMap;
    
public voidsetPWCRequestStatsImpl(com.sun.enterprise.web.stats.PWCRequestStatsImpl pwcRequestStatsImpl)
Set the Stat holder.

        this.pwcRequestStatsImpl = pwcRequestStatsImpl;
    
protected voidstartChildren()
Starts the children (web contexts) of this virtual server concurrently.


        ArrayList<LifecycleStarter> starters
            = new ArrayList<LifecycleStarter>();

        Container children[] = findChildren();
        for (int i = 0; i < children.length; i++) {
            if (children[i] instanceof Lifecycle) {
                LifecycleStarter starter =
                    new LifecycleStarter(((Lifecycle) children[i]));
                starters.add(starter);
                starter.submit();
            }
        }

        for (LifecycleStarter starter : starters) {
            Throwable t = starter.waitDone();
            if (t != null) {
                Lifecycle container = starter.getContainer();
                ((Context) container).setAvailable(false);
                String msg = _rb.getString("vs.startContextError");
                msg = MessageFormat.format(msg,
                                           new Object[] { container,
                                                          getID() });
                _logger.log(Level.SEVERE, msg, t);
            }
        }
    
public synchronized voidstop()
Gracefully shut down active use of the public methods 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


        super.stop();

        // Remove the descriptor bindings for all the web applications
        // in this virtual server
        Switch sw = Switch.getSwitch();
        Container children[] = findChildren();
        if (children != null) {
            for (int i = 0; i < children.length; i++) {
                sw.removeDescriptorFor(children[i]);
            }
        }