FileDocCategorySizeDatePackage
StandardHost.javaAPI DocGlassfish v2 API38346Fri May 04 22:31:54 BST 2007org.apache.catalina.core

StandardHost

public class StandardHost extends ContainerBase implements org.apache.catalina.Host, org.apache.catalina.Deployer
Standard implementation of the Host interface. Each child container must be a Context implementation to process the requests directed to a particular web application.
author
Craig R. McClanahan
author
Remy Maucherat
version
$Revision: 1.14 $ $Date: 2007/05/05 05:31:54 $

Fields Summary
private static com.sun.org.apache.commons.logging.Log
log
protected String[]
aliases
The set of aliases for this Host.
private String
appBase
The application root for this Host.
private boolean
autoDeploy
The auto deploy flag for this Host.
private String
configClass
The Java class name of the default context configuration class for deployed web applications.
private String
contextClass
The Java class name of the default Context implementation class for deployed web applications.
private org.apache.catalina.Deployer
deployer
The Deployer to whom we delegate application deployment requests.
private boolean
deployOnStartup
The deploy on startup flag for this Host.
private boolean
deployXML
deploy Context XML config files property.
private String
errorReportValveClass
The Java class name of the default error reporter implementation class for deployed web applications.
private static final String
info
The descriptive information string for this implementation.
private boolean
liveDeploy
The live deploy flag for this Host.
private boolean
unpackWARs
Unpack WARs property.
private String
workDir
Work Directory base for applications.
private org.apache.catalina.DefaultContext
defaultContext
DefaultContext config
private boolean
xmlValidation
Attribute value used to turn on/off XML validation
private boolean
xmlNamespaceAware
Attribute value used to turn on/off XML namespace awarenes.
private HashMap
statusPages
The status code error pages for this StandardHost, keyed by HTTP status code.
private int[]
ports
The port numbers with which this StandardHost is associated
private boolean
securePagesWithPragma
With proxy caching disabled, setting this flag to true adds Pragma and Cache-Control headers with "No-cache" as value. Setting this flag to false does not add any Pragma header, but sets the Cache-Control header to "private".
private org.apache.catalina.authenticator.SingleSignOn
sso
static String
STANDARD_HOST_DEPLOYER
Constructors Summary
public StandardHost()
Create a new StandardHost component with the default basic Valve.

    
    // ----------------------------------------------------------- Constructors


                   
      

        super();
        pipeline.setBasic(new StandardHostValve());

    
Methods Summary
public voidaddAlias(java.lang.String alias)
Add an alias name that should be mapped to this same Host.

param
alias The alias to be added


        // START OF PE 4989789
        //alias = alias.toLowerCase();
        // START OF PE 4989789
        
        // Skip duplicate aliases
        for (int i = 0; i < aliases.length; i++) {
            if (aliases[i].equals(alias))
                return;
        }

        // Add this alias to the list
        String newAliases[] = new String[aliases.length + 1];
        for (int i = 0; i < aliases.length; i++)
            newAliases[i] = aliases[i];
        newAliases[aliases.length] = alias;

        aliases = newAliases;

        // Inform interested listeners
        fireContainerEvent(ADD_ALIAS_EVENT, alias);

    
public voidaddChild(org.apache.catalina.Container child)
Add a child Container, only if the proposed child is an implementation of Context.

param
child Child container to be added


        if (!(child instanceof Context))
            throw new IllegalArgumentException
                (sm.getString("standardHost.notContext"));
        super.addChild(child);

    
public voidaddDefaultContext(org.apache.catalina.DefaultContext defaultContext)
Set the DefaultContext for new web applications.

param
defaultContext The new DefaultContext


        DefaultContext oldDefaultContext = this.defaultContext;
        this.defaultContext = defaultContext;
        support.firePropertyChange("defaultContext",
                                   oldDefaultContext, this.defaultContext);

    
public voidaddErrorPage(org.apache.catalina.deploy.ErrorPage errorPage)
Adds the given error page to this StandardHost.

param
errorPage The error page definition to be added

        // Validate the input parameters
        if (errorPage == null) {
            throw new IllegalArgumentException
                (sm.getString("standardHost.errorPage.required"));
        }

        // Add the specified error page to our internal collections
        synchronized (statusPages) {
            statusPages.put(Integer.valueOf(errorPage.getErrorCode()),
                            errorPage);
        }

        fireContainerEvent("addErrorPage", errorPage);

    
public voidaddValve(org.apache.catalina.Valve valve)

        super.addValve(valve);
        if (valve instanceof SingleSignOn) {
            sso = (SingleSignOn) valve;
        }
    
public voidbackgroundProcess()
Execute a periodic task, such as reloading, etc. This method will be invoked inside the classloading context of this container. Unexpected throwables will be caught and logged.

        lifecycle.fireLifecycleEvent("check", null);
    
public javax.management.ObjectNamecreateObjectName(java.lang.String domain, javax.management.ObjectName parent)

        if( log.isDebugEnabled())
            log.debug("Create ObjectName " + domain + " " + parent );
        return new ObjectName( domain + ":type=Host,host=" + getName());
    
public java.lang.String[]findAliases()
Return the set of alias names for this Host. If none are defined, a zero length array is returned.


        return (this.aliases);

    
public org.apache.catalina.ContainerfindChild(java.lang.String contextRoot)
Returns the context deployed at the given context root.

param
contextRoot The context root whose associated context to return
return
The context deployed at the given context root, or null

        return super.findChild(RequestUtil.URLDecode(contextRoot));
    
public org.apache.catalina.ContextfindDeployedApp(java.lang.String contextPath)
Return the Context for the deployed application that is associated with the specified context path (if any); otherwise return null.

param
contextPath The context path of the requested web application


        return (getDeployer().findDeployedApp(contextPath));

    
public java.lang.String[]findDeployedApps()
Return the context paths of all deployed web applications in this Container. If there are no deployed applications, a zero-length array is returned.


        return (getDeployer().findDeployedApps());

    
public org.apache.catalina.deploy.ErrorPagefindErrorPage(int errorCode)
Gets the error page for the specified HTTP error code.

param
errorCode Error code to look up
return
The error page that is mapped to the specified HTTP error code, or null if no error page exists for that HTTP error code

        return statusPages.get(Integer.valueOf(errorCode));
    
public org.apache.catalina.HostfindMappingObject()

        return (Host) getMappingObject();
    
public int[]findPorts()
Gets the port numbers with which this StandardHost is associated.

return
The port numbers with which this StandardHost is associated, or null if this StandardHost has not been associated with any port numbers

        return getPorts();
    
public java.lang.String[]getAliases()

        return aliases;
    
public java.lang.StringgetAppBase()
Return the application root for this Host. This can be an absolute pathname, a relative pathname, or a URL.


        return (this.appBase);

    
public booleangetAutoDeploy()
Return the value of the auto deploy flag. If true, it indicates that this host's child webapps will be dynamically deployed.


        return (this.autoDeploy);

    
public java.lang.StringgetConfigClass()
Return the Java class name of the context configuration class for new web applications.


        return (this.configClass);

    
public java.lang.StringgetContextClass()
Return the Java class name of the Context implementation class for new web applications.


        return (this.contextClass);

    
public org.apache.catalina.DefaultContextgetDefaultContext()
Retrieve the DefaultContext for new web applications.

        return (this.defaultContext);
    
public booleangetDeployOnStartup()
Return the value of the deploy on startup flag. If true, it indicates that this host's child webapps should be discovred and automatically deployed at startup time.


        return (this.deployOnStartup);

    
public org.apache.catalina.DeployergetDeployer()

    
       
        if( deployer!= null )
            return deployer;
        log.info( "Create Host deployer for direct deployment ( non-jmx ) ");
        try {
            Class c=Class.forName( STANDARD_HOST_DEPLOYER );
            deployer=(Deployer)c.newInstance();
            Method m=c.getMethod("setHost", new Class[] {Host.class} );
            m.invoke( deployer,  new Object[] { this } );
        } catch( Throwable t ) {
            log.error( "Error creating deployer ", t);
        }
        return deployer;
    
public java.lang.StringgetErrorReportValveClass()
Return the Java class name of the error report valve class for new web applications.


        return (this.errorReportValveClass);

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


        return (info);

    
public booleangetLiveDeploy()
Return the value of the live deploy flag. If true, it indicates that a background thread should be started that looks for web application context files, WAR files, or unpacked directories being dropped in to the appBase directory, and deploys new ones as they are encountered.

        return (this.autoDeploy);
    
public java.lang.StringgetName()
Return the canonical, fully qualified, name of the virtual host this Container represents.


        return (name);

    
public int[]getPorts()
Gets the port numbers with which this StandardHost is associated.

return
The port numbers with which this StandardHost is associated, or null if this StandardHost has not been associated with any ports

        return (int[])this.ports.clone();
    
public org.apache.catalina.authenticator.SingleSignOngetSingleSignOn()

        return sso;
    
public java.lang.String[]getValveNames()
Return the MBean Names of the Valves assoicated with this Host

exception
Exception if an MBean cannot be created or registered

         Valve [] valves = this.getValves();
         String [] mbeanNames = new String[valves.length];
         for (int i = 0; i < valves.length; i++) {
             if( valves[i] == null ) continue;
             if( ((ValveBase)valves[i]).getObjectName() == null ) continue;
             mbeanNames[i] = ((ValveBase)valves[i]).getObjectName().toString();
         }

         return mbeanNames;

     
public java.lang.StringgetWorkDir()
Host work directory base.


        return (workDir);
    
public booleangetXmlNamespaceAware()
Get the server.xml attribute's xmlNamespaceAware.

return
true if namespace awarenes is enabled.

        return xmlNamespaceAware;
    
public booleangetXmlValidation()
Get the server.xml attribute's xmlValidation.

return
true if validation is enabled.

        return xmlValidation;
    
public voidimportDefaultContext(org.apache.catalina.Context context)
Import the DefaultContext config into a web application context.

param
context web application context to import default context


        if( this.defaultContext != null )
            this.defaultContext.importDefaultContext(context);

    
public voidinit()

        if( initialized ) return;
        /* CR 6368085
        initialized=true;
        */
        
        // already registered.
        if( getParent() == null ) {
            try {
                // Register with the Engine
                ObjectName serviceName=new ObjectName(domain + ":type=Engine");
                
                if( mserver.isRegistered( serviceName )) {
                    log.debug("Registering with the Engine");
                    mserver.invoke( serviceName, "addChild",
                            new Object[] { this },
                            new String[] { "org.apache.catalina.Container" } );
                }
            } catch( Exception ex ) {
                ex.printStackTrace();
            }
        }
        
        if( oname==null ) {
            // not registered in JMX yet - standalone mode
            try {
                StandardEngine engine=(StandardEngine)parent;
                domain=engine.getName();
                if (log.isDebugEnabled()) {
                    log.debug("Registering host " + getName()
                              + " with domain " + domain);
                }
                oname=new ObjectName(domain + ":type=Host,host=" +
                        this.getName());
                // START CR 6368091
                controller = oname;
                // END CR 6368091
                Registry.getRegistry().registerComponent(this, oname, null);
            } catch( Throwable t ) {
                log.info("Error registering ", t );
            }
        }
        // START CR 6368085
        initialized = true;
        // END CR 6368085
    
public voidinstall(java.lang.String contextPath, java.net.URL war)
Install a new web application, whose web application archive is at the specified URL, into this container with the specified context path. A context path of "" (the empty string) should be used for the root application for this container. Otherwise, the context path must start with a slash.

If this application is successfully installed, a ContainerEvent of type INSTALL_EVENT will be sent to all registered listeners, with the newly created Context as an argument.

param
contextPath The context path to which this application should be installed (must be unique)
param
war A URL of type "jar:" that points to a WAR file, or type "file:" that points to an unpacked directory structure containing the web application to be installed
exception
IllegalArgumentException if the specified context path is malformed (it must be "" or start with a slash)
exception
IllegalStateException if the specified context path is already attached to an existing web application
exception
IOException if an input/output error was encountered during install

        getDeployer().install(contextPath, war);

    
public synchronized voidinstall(java.net.URL config, java.net.URL war)

Install a new web application, whose context configuration file (consisting of a <Context> element) and web application archive are at the specified URLs.

If this application is successfully installed, a ContainerEvent of type INSTALL_EVENT will be sent to all registered listeners, with the newly created Context as an argument.

param
config A URL that points to the context configuration file to be used for configuring the new Context
param
war A URL of type "jar:" that points to a WAR file, or type "file:" that points to an unpacked directory structure containing the web application to be installed
exception
IllegalArgumentException if one of the specified URLs is null
exception
IllegalStateException if the context path specified in the context configuration file is already attached to an existing web application
exception
IOException if an input/output error was encountered during installation


        getDeployer().install(config, war);

    
public voidinstallDefaultContext(org.apache.catalina.Context context)
Install the StandardContext portion of the DefaultContext configuration into current Context.

param
context current web application context


        if (defaultContext != null &&
            defaultContext instanceof StandardDefaultContext) {

            ((StandardDefaultContext)defaultContext).installDefaultContext(context);
        }

    
public booleanisDeployXML()
Deploy XML Context config files flag accessor.


        return (deployXML);

    
public booleanisSecurePagesWithPragma()
Returns the value of the securePagesWithPragma property.


        return (this.securePagesWithPragma);
    
public booleanisUnpackWARs()
Unpack WARs flag accessor.


        return (unpackWARs);

    
public org.apache.catalina.Contextmap(java.lang.String uri)
Return the Context that would be used to process the specified host-relative request URI, if any; otherwise return null.

param
uri Request URI to be mapped


        if (log.isDebugEnabled())
            log.debug("Mapping request URI '" + uri + "'");
        if (uri == null)
            return (null);

        // Match on the longest possible context path prefix
        if (log.isTraceEnabled())
            log.trace("  Trying the longest context path prefix");
        Context context = null;
        String mapuri = uri;
        while (true) {
            context = (Context) findChild(mapuri);
            if (context != null)
                break;
            int slash = mapuri.lastIndexOf('/");
            if (slash < 0)
                break;
            mapuri = mapuri.substring(0, slash);
        }

        // If no Context matches, select the default Context
        if (context == null) {
            if (log.isTraceEnabled())
                log.trace("  Trying the default context");
            context = (Context) findChild("");
        }

        // Complain if no Context has been selected
        if (context == null) {
            log.error(sm.getString("standardHost.mappingError", uri));
            return (null);
        }

        // Return the mapped Context (if any)
        if (log.isDebugEnabled())
            log.debug(" Mapped to context '" + context.getPath() + "'");
        return (context);

    
public javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName oname)

        ObjectName res=super.preRegister(server, oname);
        String name=oname.getKeyProperty("host");
        if( name != null )
            setName( name );
        return res;        
    
public voidremove(java.lang.String contextPath)
Remove an existing web application, attached to the specified context path. If this application is successfully removed, a ContainerEvent of type REMOVE_EVENT will be sent to all registered listeners, with the removed Context as an argument.

param
contextPath The context path of the application to be removed
exception
IllegalArgumentException if the specified context path is malformed (it must be "" or start with a slash)
exception
IllegalArgumentException if the specified context path does not identify a currently installed web application
exception
IOException if an input/output error occurs during removal


        getDeployer().remove(contextPath);

    
public voidremove(java.lang.String contextPath, boolean undeploy)
Remove an existing web application, attached to the specified context path. If this application is successfully removed, a ContainerEvent of type REMOVE_EVENT will be sent to all registered listeners, with the removed Context as an argument. Deletes the web application war file and/or directory if they exist in the Host's appBase.

param
contextPath The context path of the application to be removed
param
undeploy boolean flag to remove web application from server
exception
IllegalArgumentException if the specified context path is malformed (it must be "" or start with a slash)
exception
IllegalArgumentException if the specified context path does not identify a currently installed web application
exception
IOException if an input/output error occurs during removal


        getDeployer().remove(contextPath,undeploy);

    
public voidremoveAlias(java.lang.String alias)
Remove the specified alias name from the aliases for this Host.

param
alias Alias name to be removed


        // START OF PE 4989789
        //alias = alias.toLowerCase();
        // START OF PE 4989789
        
        synchronized (aliases) {

            // Make sure this alias is currently present
            int n = -1;
            for (int i = 0; i < aliases.length; i++) {
                if (aliases[i].equals(alias)) {
                    n = i;
                    break;
                }
            }
            if (n < 0)
                return;

            // Remove the specified alias
            int j = 0;
            String results[] = new String[aliases.length - 1];
            for (int i = 0; i < aliases.length; i++) {
                if (i != n)
                    results[j++] = aliases[i];
            }
            aliases = results;

        }

        // Inform interested listeners
        fireContainerEvent(REMOVE_ALIAS_EVENT, alias);

    
public voidremoveValve(org.apache.catalina.Valve valve)

        super.removeValve(valve);
        if (valve instanceof SingleSignOn) {
            sso = null;
        }
    
public voidsetAppBase(java.lang.String appBase)
Set the application root for this Host. This can be an absolute pathname, a relative pathname, or a URL.

param
appBase The new application root


        String oldAppBase = this.appBase;
        this.appBase = appBase;
        support.firePropertyChange("appBase", oldAppBase, this.appBase);

    
public voidsetAutoDeploy(boolean autoDeploy)
Set the auto deploy flag value for this host.

param
autoDeploy The new auto deploy flag


        boolean oldAutoDeploy = this.autoDeploy;
        this.autoDeploy = autoDeploy;
        support.firePropertyChange("autoDeploy", oldAutoDeploy, 
                                   this.autoDeploy);

    
public voidsetConfigClass(java.lang.String configClass)
Set the Java class name of the context configuration class for new web applications.

param
configClass The new context configuration class


        String oldConfigClass = this.configClass;
        this.configClass = configClass;
        support.firePropertyChange("configClass",
                                   oldConfigClass, this.configClass);

    
public voidsetContextClass(java.lang.String contextClass)
Set the Java class name of the Context implementation class for new web applications.

param
contextClass The new context implementation class


        String oldContextClass = this.contextClass;
        this.contextClass = contextClass;
        support.firePropertyChange("contextClass",
                                   oldContextClass, this.contextClass);

    
public voidsetDeployOnStartup(boolean deployOnStartup)
Set the deploy on startup flag value for this host.

param
autoDeploy The new deploy on startup flag


        boolean oldDeployOnStartup = this.deployOnStartup;
        this.deployOnStartup = deployOnStartup;
        support.firePropertyChange("deployOnStartup", oldDeployOnStartup, 
                                   this.deployOnStartup);

    
public voidsetDeployXML(boolean deployXML)
Deploy XML Context config files flag mutator.


        this.deployXML = deployXML;

    
public voidsetDeployer(org.apache.catalina.Deployer d)

        this.deployer=d;
    
public voidsetErrorReportValveClass(java.lang.String errorReportValveClass)
Set the Java class name of the error report valve class for new web applications.

param
errorReportValveClass The new error report valve class


        String oldErrorReportValveClassClass = this.errorReportValveClass;
        this.errorReportValveClass = errorReportValveClass;
        support.firePropertyChange("errorReportValveClass",
                                   oldErrorReportValveClassClass, 
                                   this.errorReportValveClass);

    
public voidsetLiveDeploy(boolean liveDeploy)
Set the live deploy flag value for this host.

param
liveDeploy The new live deploy flag

        setAutoDeploy(liveDeploy);
    
public voidsetName(java.lang.String name)
Set the canonical, fully qualified, name of the virtual host this Container represents.

param
name Virtual host name
exception
IllegalArgumentException if name is null


        if (name == null)
            throw new IllegalArgumentException
                (sm.getString("standardHost.nullName"));

        // START OF PE 4989789
        // name = name.toLowerCase();      // Internally all names are lower case
        // END OF PE 4989789

        String oldName = this.name;
        this.name = name;
        support.firePropertyChange("name", oldName, this.name);

    
public voidsetPipeline(org.apache.catalina.Pipeline pl)


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


    // START SJSAS 6331392
        
        pl.setBasic(new StandardHostValve());
        pipeline = pl;
    
public voidsetPorts(int[] ports)
Associates this StandardHost with the given port numbers.

param
ports The port numbers with which to associate this StandardHost

        int[] oldPorts = this.ports;
        this.ports = (int[])ports.clone();
        support.firePropertyChange("ports", oldPorts, this.ports);
    
public voidsetSecurePagesWithPragma(boolean securePagesWithPragma)
Sets the securePagesWithPragma property of this Context. Setting this property to true will result in Pragma and Cache-Control headers with a value of "No-cache" if proxy caching has been disabled. Setting this property to false will not add any Pragma header, but will set the Cache-Control header to "private".

param
securePagesWithPragma true if Pragma and Cache-Control headers are to be set to "No-cache" if proxy caching has been disabled, false otherwise


        boolean oldSecurePagesWithPragma = this.securePagesWithPragma;
        this.securePagesWithPragma = securePagesWithPragma;
        support.firePropertyChange("securePagesWithPragma",
                                   Boolean.valueOf(oldSecurePagesWithPragma),
                                   Boolean.valueOf(this.securePagesWithPragma));
    
public voidsetUnpackWARs(boolean unpackWARs)
Unpack WARs flag mutator.


        this.unpackWARs = unpackWARs;

    
public voidsetWorkDir(java.lang.String workDir)
Host work directory base.


        this.workDir = workDir;
    
public voidsetXmlNamespaceAware(boolean xmlNamespaceAware)
Set the namespace aware feature of the XML parser used when parsing xml instances.

param
xmlNamespaceAware true to enable namespace awareness

        this.xmlNamespaceAware=xmlNamespaceAware;
    
public voidsetXmlValidation(boolean xmlValidation)
Set the validation feature of the XML parser used when parsing xml instances.

param
xmlValidation true to enable xml instance validation

        this.xmlValidation = xmlValidation;
    
public synchronized voidstart()
Start this host.

exception
LifecycleException if this component detects a fatal error that prevents it from being started

        if( started ) {
            return;
        }
        if( ! initialized )
            init();

        // Look for a realm - that may have been configured earlier. 
        // If the realm is added after context - it'll set itself.
        if( realm == null ) {
            ObjectName realmName=null;
            try {
                realmName=new ObjectName( domain + ":type=Host,host=" + getName());
                if( mserver.isRegistered(realmName ) ) {
                    mserver.invoke(realmName, "setContext", 
                            new Object[] {this},
                            new String[] { "org.apache.catalina.Container" }
                    );            
                }
            } catch( Throwable t ) {
                if (log.isDebugEnabled()) {
                    log.debug("No realm for this host " + realmName);
                }
            }
        }

        // Set error report valve
        if ((errorReportValveClass != null)
            && (!errorReportValveClass.equals(""))) {
            try {
                Valve valve = (Valve) Class.forName(errorReportValveClass)
                    .newInstance();
                /* START SJSAS 6374691
                addValve(valve);
                */
                // START SJSAS 6374691
                ((StandardHostValve) pipeline.getBasic()).setErrorReportValve(valve);
                // END SJSAS 6374691
            } catch (Throwable t) {
                log.error(sm.getString
                    ("standardHost.invalidErrorReportValveClass", 
                     errorReportValveClass));
            }
        }

        // START SJSAS_PE 8.1 5034793
        if (log.isDebugEnabled()) {
            if (xmlValidation) {
                log.debug( sm.getString("standardHost.validationEnabled"));
            } else {
                log.debug( sm.getString("standardHost.validationDisabled"));
            }
        }
        // END SJSAS_PE 8.1 5034793 

        super.start();

    
public voidstart(java.lang.String contextPath)
Start an existing web application, attached to the specified context path. Only starts a web application if it is not running.

param
contextPath The context path of the application to be started
exception
IllegalArgumentException if the specified context path is malformed (it must be "" or start with a slash)
exception
IllegalArgumentException if the specified context path does not identify a currently installed web application
exception
IOException if an input/output error occurs during startup


        getDeployer().start(contextPath);

    
public voidstop(java.lang.String contextPath)
Stop an existing web application, attached to the specified context path. Only stops a web application if it is running.

param
contextPath The context path of the application to be stopped
exception
IllegalArgumentException if the specified context path is malformed (it must be "" or start with a slash)
exception
IllegalArgumentException if the specified context path does not identify a currently installed web application
exception
IOException if an input/output error occurs while stopping the web application


        getDeployer().stop(contextPath);

    
public java.lang.StringtoString()
Return a String representation of this component.


        StringBuffer sb = new StringBuffer();
        if (getParent() != null) {
            sb.append(getParent().toString());
            sb.append(".");
        }
        sb.append("StandardHost[");
        sb.append(getName());
        sb.append("]");
        return (sb.toString());