HostConfig (Apache Tomcat 10.1.57 API Documentation)
Description: declaration: package: org.apache.catalina.startup, class: HostConfig

# Class HostConfig

java.lang.Object
org.apache.catalina.startup.HostConfig

All Implemented Interfaces:
  `LifecycleListener`

public class HostConfig extends Object implements LifecycleListener
Startup event listener for a `Host` that configures the properties of that Host, and the associated defined contexts.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected static class`
  `HostConfig.DeployedApplication`
  This class represents the state of a deployed application, as well as the monitored resources.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected String`
  `contextClass`
  The Java class name of the Context implementation we should use.
  `protected boolean`
  `copyXML`
  Should XML files be copied to $CATALINA_BASE/conf/<engine>/<host> by default when a web application is deployed?
  `protected final Map<String, HostConfig.DeployedApplication>`
  `deployed`
  Map of deployed applications.
  `protected boolean`
  `deployXML`
  Should we deploy XML Context config files packaged with WAR files and directories?
  `protected Digester`
  `digester`
  The `Digester` instance used to parse context descriptors.
  `protected static final long`
  `FILE_MODIFICATION_RESOLUTION_MS`
  The resolution, in milliseconds, of file modification times.
  `protected Host`
  `host`
  The Host we are associated with.
  `protected final Set<String>`
  `invalidDescriptors`
  The list of descriptors in the appBase to be ignored because they are invalid (e.g. contain /../ sequences).
  `protected final Set<String>`
  `invalidDirectories`
  The list of directories in the appBase to be ignored because they are invalid (e.g. contain /../ sequences).
  `protected final Set<String>`
  `invalidWars`
  The list of Wars in the appBase to be ignored because they are invalid (e.g. contain /../ sequences).
  `protected ObjectName`
  `oname`
  The JMX ObjectName of this component.
  `protected static final StringManager`
  `sm`
  The string resources for this package.
  `protected boolean`
  `unpackWARs`
  Should we unpack WAR files when auto-deploying applications in the `appBase` directory?

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `HostConfig()`
  Constructs a new HostConfig.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `addGlobalRedeployResources(HostConfig.DeployedApplication app)`
  Add global redeploy resources to the deployed application.
  `protected void`
  `addWatchedResources(HostConfig.DeployedApplication app, String docBase, Context context)`
  Add watched resources to the specified Context.
  `void`
  `beforeStart()`
  Perform actions before the Host starts, including creating required directories.
  `protected void`
  `check()`
  Check status of all webapps.
  `void`
  `check(String name)`
  Check status of a specific web application and reload, redeploy or deploy it as necessary.
  `protected void`
  `checkResources(HostConfig.DeployedApplication app, boolean skipFileModificationResolutionCheck)`
  Check resources for redeployment and reloading.
  `void`
  `checkUndeploy()`
  Check for old versions of applications using parallel deployment that are now unused (have no active sessions) and undeploy any that are found.
  `protected static Digester`
  `createDigester(String contextClassName)`
  Create the digester which will be used to parse context config files.
  `protected void`
  `deployApps()`
  Deploy applications for any directories or WAR files that are found in our "application root" directory.
  `protected void`
  `deployApps(String name)`
  Deploy applications for any directories or WAR files that are found in our "application root" directory.
  `protected void`
  `deployDescriptor(ContextName cn, File contextXml)`
  Deploy specified context descriptor.
  `protected void`
  `deployDescriptors(File configBase, String[] files)`
  Deploy XML context descriptors.
  `protected void`
  `deployDirectories(File appBase, String[] files)`
  Deploy exploded webapps.
  `protected void`
  `deployDirectory(ContextName cn, File dir)`
  Deploy exploded webapp.
  `protected boolean`
  `deploymentExists(String contextName)`
  Check if a webapp is already deployed in this host.
  `protected void`
  `deployWAR(ContextName cn, File war)`
  Deploy packed WAR.
  `protected void`
  `deployWARs(File appBase, String[] files)`
  Deploy WAR files.
  `protected String[]`
  `filterAppPaths(String[] unfilteredAppPaths)`
  Filter the list of application file paths to remove those that match the regular expression defined by `Host.getDeployIgnore()`.
  `String`
  `getConfigBaseName()`
  Get the name of the configBase.
  `String`
  `getContextClass()`
  Get the Context implementation class name.
  `long`
  `getDeploymentTime(String name)`
  Get the instant where an application was deployed.
  `boolean`
  `isCopyXML()`
  Get the copy XML config file flag for this component.
  `boolean`
  `isDeployed(String name)`
  Has the specified application been deployed?
  `boolean`
  `isDeployXML()`
  Get the deploy XML config file flag for this component.
  `boolean`
  `isUnpackWARs()`
  Get the unpack WARs flag.
  `void`
  `lifecycleEvent(LifecycleEvent event)`
  Process the START event for an associated Host.
  `void`
  `manageApp(Context context)`
  Add a new Context to be managed by us.
  `protected void`
  `migrateLegacyApp(File source, File destination)`
  Migrate a single legacy Java EE application from source to destination using the Migration utility.
  `protected void`
  `migrateLegacyApps()`
  Migrate legacy Java EE applications from the legacy appBase to the current appBase.
  `void`
  `removeServiced(String name)`
  Remove a serviced application from the list.
  `protected File`
  `returnCanonicalPath(String path)`
  Return the canonical file for the given path.
  `void`
  `setContextClass(String contextClass)`
  Set the Context implementation class name.
  `void`
  `setCopyXML(boolean copyXML)`
  Set the copy XML config file flag for this component.
  `void`
  `setDeployXML(boolean deployXML)`
  Set the deploy XML config file flag for this component.
  `void`
  `setUnpackWARs(boolean unpackWARs)`
  Set the unpack WARs flag.
  `void`
  `start()`
  Process a "start" event for this Host.
  `void`
  `stop()`
  Process a "stop" event for this Host.
  `boolean`
  `tryAddServiced(String name)`
  Add a serviced application to the list and indicates if the application was already present in the list.
  `void`
  `unmanageApp(String contextName)`
  Remove a webapp from our control.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### sm

    protected static final StringManager sm
    The string resources for this package.

  - ### FILE_MODIFICATION_RESOLUTION_MS

    protected static final long FILE_MODIFICATION_RESOLUTION_MS
    The resolution, in milliseconds, of file modification times.
    See Also:
      - Constant Field Values

  - ### contextClass

    protected String contextClass
    The Java class name of the Context implementation we should use.

  - ### host

    protected Host host
    The Host we are associated with.

  - ### oname

    protected ObjectName oname
    The JMX ObjectName of this component.

  - ### deployXML

    protected boolean deployXML
    Should we deploy XML Context config files packaged with WAR files and directories?

  - ### copyXML

    protected boolean copyXML
    Should XML files be copied to $CATALINA_BASE/conf/<engine>/<host> by default when a web application is deployed?

  - ### unpackWARs

    protected boolean unpackWARs
    Should we unpack WAR files when auto-deploying applications in the `appBase` directory?

  - ### deployed

    protected final Map<String, HostConfig.DeployedApplication> deployed
    Map of deployed applications.

  - ### digester

    protected Digester digester
    The `Digester` instance used to parse context descriptors.

  - ### invalidDescriptors

    protected final Set<String> invalidDescriptors
    The list of descriptors in the appBase to be ignored because they are invalid (e.g. contain /../ sequences).

  - ### invalidDirectories

    protected final Set<String> invalidDirectories
    The list of directories in the appBase to be ignored because they are invalid (e.g. contain /../ sequences).

  - ### invalidWars

    protected final Set<String> invalidWars
    The list of Wars in the appBase to be ignored because they are invalid (e.g. contain /../ sequences).

- ## Constructor Details

  - ### HostConfig

    public HostConfig()
    Constructs a new HostConfig.

- ## Method Details

  - ### getContextClass

    public String getContextClass()
    Get the Context implementation class name.
    Returns:
      the Context implementation class name

  - ### setContextClass

    public void setContextClass(String contextClass)
    Set the Context implementation class name.
    Parameters:
      `contextClass` - The new Context implementation class name.

  - ### isDeployXML

    public boolean isDeployXML()
    Get the deploy XML config file flag for this component.
    Returns:
      the deploy XML flag

  - ### setDeployXML

    public void setDeployXML(boolean deployXML)
    Set the deploy XML config file flag for this component.
    Parameters:
      `deployXML` - The new deploy XML flag

  - ### isCopyXML

    public boolean isCopyXML()
    Get the copy XML config file flag for this component.
    Returns:
      the copy XML flag

  - ### setCopyXML

    public void setCopyXML(boolean copyXML)
    Set the copy XML config file flag for this component.
    Parameters:
      `copyXML` - The new copy XML flag

  - ### isUnpackWARs

    public boolean isUnpackWARs()
    Get the unpack WARs flag.
    Returns:
      the unpack WARs flag

  - ### setUnpackWARs

    public void setUnpackWARs(boolean unpackWARs)
    Set the unpack WARs flag.
    Parameters:
      `unpackWARs` - The new unpack WARs flag

  - ### lifecycleEvent

    public void lifecycleEvent(LifecycleEvent event)
    Process the START event for an associated Host.
    Specified by:
      `lifecycleEvent` in interface `LifecycleListener`
    Parameters:
      `event` - The lifecycle event that has occurred

  - ### tryAddServiced

    public boolean tryAddServiced(String name)
    Add a serviced application to the list and indicates if the application was already present in the list.
    Parameters:
      `name` - the context name
    Returns:
      `true` if the application was not already in the list

  - ### removeServiced

    public void removeServiced(String name)
    Remove a serviced application from the list.
    Parameters:
      `name` - the context name

  - ### getDeploymentTime

    public long getDeploymentTime(String name)
    Get the instant where an application was deployed.
    Parameters:
      `name` - the context name
    Returns:
      0L if no application with that name is deployed, or the instant on which the application was deployed

  - ### isDeployed

    public boolean isDeployed(String name)
    Has the specified application been deployed? Note applications defined in server.xml will not have been deployed.
    Parameters:
      `name` - the context name
    Returns:
      `true` if the application has been deployed and `false` if the application has not been deployed or does not exist

  - ### createDigester

    protected static Digester createDigester(String contextClassName)
    Create the digester which will be used to parse context config files.
    Parameters:
      `contextClassName` - The class which will be used to create the context instance
    Returns:
      the digester

  - ### returnCanonicalPath

    protected File returnCanonicalPath(String path)
    Return the canonical file for the given path. If the path is relative, it is resolved against the Catalina base directory.
    Parameters:
      `path` - the path to canonicalize
    Returns:
      the canonical file

  - ### getConfigBaseName

    public String getConfigBaseName()
    Get the name of the configBase. For use with JMX management.
    Returns:
      the config base

  - ### deployApps

    protected void deployApps()
    Deploy applications for any directories or WAR files that are found in our "application root" directory.

  - ### filterAppPaths

    protected String[] filterAppPaths(String[] unfilteredAppPaths)
    Filter the list of application file paths to remove those that match the regular expression defined by `Host.getDeployIgnore()`.
    Parameters:
      `unfilteredAppPaths` - The list of application paths to filter
    Returns:
      The filtered list of application paths

  - ### deployApps

    protected void deployApps(String name)
    Deploy applications for any directories or WAR files that are found in our "application root" directory.

    Note: It is expected that the caller has successfully added the app to servicedSet before calling this method.

    Parameters:
      `name` - The context name which should be deployed

  - ### deployDescriptors

    protected void deployDescriptors(File configBase, String[] files)
    Deploy XML context descriptors.
    Parameters:
      `configBase` - The config base
      `files` - The XML descriptors which should be deployed

  - ### deployDescriptor

    protected void deployDescriptor(ContextName cn, File contextXml)
    Deploy specified context descriptor.

    Note: It is expected that the caller has successfully added the app to servicedSet before calling this method.

    Parameters:
      `cn` - The context name
      `contextXml` - The descriptor

  - ### deployWARs

    protected void deployWARs(File appBase, String[] files)
    Deploy WAR files.
    Parameters:
      `appBase` - The base path for applications
      `files` - The WARs to deploy

  - ### deployWAR

    protected void deployWAR(ContextName cn, File war)
    Deploy packed WAR.

    Note: It is expected that the caller has successfully added the app to servicedSet before calling this method.

    Parameters:
      `cn` - The context name
      `war` - The WAR file

  - ### deployDirectories

    protected void deployDirectories(File appBase, String[] files)
    Deploy exploded webapps.
    Parameters:
      `appBase` - The base path for applications
      `files` - The exploded webapps that should be deployed

  - ### deployDirectory

    protected void deployDirectory(ContextName cn, File dir)
    Deploy exploded webapp.

    Note: It is expected that the caller has successfully added the app to servicedSet before calling this method.

    Parameters:
      `cn` - The context name
      `dir` - The path to the root folder of the webapp

  - ### migrateLegacyApps

    protected void migrateLegacyApps()
    Migrate legacy Java EE applications from the legacy appBase to the current appBase.

  - ### migrateLegacyApp

    protected void migrateLegacyApp(File source, File destination)
    Migrate a single legacy Java EE application from source to destination using the Migration utility.
    Parameters:
      `source` - the source file
      `destination` - the destination file

  - ### deploymentExists

    protected boolean deploymentExists(String contextName)
    Check if a webapp is already deployed in this host.
    Parameters:
      `contextName` - of the context which will be checked
    Returns:
      `true` if the specified deployment exists

  - ### addWatchedResources

    protected void addWatchedResources(HostConfig.DeployedApplication app, String docBase, Context context)
    Add watched resources to the specified Context.
    Parameters:
      `app` - HostConfig deployed app
      `docBase` - web app docBase
      `context` - web application context

  - ### addGlobalRedeployResources

    protected void addGlobalRedeployResources(HostConfig.DeployedApplication app)
    Add global redeploy resources to the deployed application. These include the host-level context.xml and the default context.xml files that trigger redeployment when modified.
    Parameters:
      `app` - the deployed application

  - ### checkResources

    protected void checkResources(HostConfig.DeployedApplication app, boolean skipFileModificationResolutionCheck)
    Check resources for redeployment and reloading.
    Parameters:
      `app` - The web application to check
      `skipFileModificationResolutionCheck` - When checking files for modification should the check that requires that any file modification must have occurred at least as long ago as the resolution of the file time stamp be skipped

  - ### beforeStart

    public void beforeStart()
    Perform actions before the Host starts, including creating required directories.

  - ### start

    public void start()
    Process a "start" event for this Host.

  - ### stop

    public void stop()
    Process a "stop" event for this Host.

  - ### check

    protected void check()
    Check status of all webapps.

  - ### check

    public void check(String name)
    Check status of a specific web application and reload, redeploy or deploy it as necessary. This method is for use with functionality such as management web applications that upload new/updated web applications and need to trigger the appropriate action to deploy them. This method assumes that any uploading/updating has been completed before this method is called. Any action taken as a result of the checks will complete before this method returns.
    Parameters:
      `name` - The name of the web application to check

  - ### checkUndeploy

    public void checkUndeploy()
    Check for old versions of applications using parallel deployment that are now unused (have no active sessions) and undeploy any that are found.

  - ### manageApp

    public void manageApp(Context context)
    Add a new Context to be managed by us. Entry point for the admin webapp, and other JMX Context controllers.
    Parameters:
      `context` - The context instance

  - ### unmanageApp

    public void unmanageApp(String contextName)
    Remove a webapp from our control. Entry point for the admin webapp, and other JMX Context controllers.

    Note: It is expected that the caller has successfully added the app to servicedSet before calling this method.

    Parameters:
      `contextName` - The context name