Top Description Fields Constructors Methods
org.apache.catalina.manager.host

public Class HostManagerServlet

extends HttpServlet
implements ContainerServlet
Class Inheritance
All Implemented Interfaces
org.apache.catalina.ContainerServlet
Known Direct Subclasses
org.apache.catalina.manager.host.HTMLHostManagerServlet
Imports
java.io.File, .IOException, .InputStream, .PrintWriter, java.lang.management.ManagementFactory, java.nio.file.Files, .Path, java.util.StringTokenizer, javax.management.InstanceNotFoundException, .MBeanServer, .ObjectName, jakarta.servlet.ServletException, .UnavailableException, jakarta.servlet.http.HttpServlet, .HttpServletRequest, .HttpServletResponse, org.apache.catalina.Container, .ContainerServlet, .Context, .Engine, .Host, .Wrapper, org.apache.catalina.core.ContainerBase, .StandardHost, org.apache.catalina.startup.HostConfig, org.apache.tomcat.util.ExceptionUtils, org.apache.tomcat.util.buf.StringUtils, org.apache.tomcat.util.res.StringManager

Servlet that enables remote management of the virtual hosts installed on the server. Normally, this functionality will be protected by a security constraint in the web application deployment descriptor. However, this requirement can be relaxed during testing.

This servlet examines the value returned by getPathInfo() and related query parameters to determine what action is being requested. The following actions and parameters (starting after the servlet path) are supported:

Note

- Attempting to stop or remove the host containing this servlet itself will not succeed. Therefore, this servlet should generally be deployed in a separate virtual host.

The following servlet initialization parameters are recognized:

Authors
Craig R. McClanahan, Remy Maucherat

Field Summary

Modifier and TypeField and Description
protected transient Context
context

The Context container associated with our web application.

protected int
debug

The debugging detail level for this servlet.

protected transient Engine
engine

The associated engine.

protected transient Host
installedHost

The associated host.

private static final long
protected static final StringManager
sm

The string manager for this package.

protected transient Wrapper
wrapper

The Wrapper container associated with this servlet.

Inherited from jakarta.servlet.http.HttpServlet:
LEGACY_DO_HEAD

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
add(HttpServletRequest
The request
request
,
PrintWriter
The output writer
writer
,
String
The host name
name
,
boolean
Flag value
htmlMode
,
StringManager
StringManager for the client's locale
smClient
)

Add host with the given parameters.

protected synchronized void
add(PrintWriter
Writer to render results to
writer
,
String
host name
name
,
String
comma separated alias list
aliases
,
String
application base for the host
appBase
,
boolean
should the manager webapp be deployed to the new host ?
manager
,
boolean
Flag value
autoDeploy
,
boolean
Flag value
deployOnStartup
,
boolean
Flag value
deployXML
,
boolean
Flag value
unpackWARs
,
boolean
Flag value
copyXML
,
StringManager
StringManager for the client's locale
smClient
)

Add a host using the specified parameters.

protected boolean

Returns:

the boolean value for the parameter
booleanParameter
(HttpServletRequest
The Servlet request
request
,
String
The parameter name
parameter
,
boolean
Default value
theDefault
,
boolean
Flag value
htmlMode
)

Extract boolean value from checkbox with default.

public void
public void
doGet(HttpServletRequest
The servlet request we are processing
request
,
HttpServletResponse
The servlet response we are creating
response
)

Overrides jakarta.servlet.http.HttpServlet.doGet.

Process a GET request for the specified resource.

protected File

Returns:

the config base for the host
getConfigBase
(String
The host name
hostName
)

Get config base.

public Wrapper
getWrapper()

Implements org.apache.catalina.ContainerServlet.getWrapper.

Return the Wrapper with which we are associated.

public void
init()

Overrides jakarta.servlet.GenericServlet.init.

A convenience method which can be overridden so that there's no need to call super.init(config).

protected void
list(PrintWriter
Writer to render to
writer
,
StringManager
StringManager for the client's locale
smClient
)

Render a list of the currently active Contexts in our virtual host.

protected void
persist(PrintWriter
Writer to render to
writer
,
StringManager
i18n resources localized for the client
smClient
)

Persist the current configuration to server.xml.

protected synchronized void
remove(PrintWriter
Writer to render results to
writer
,
String
host name
name
,
StringManager
StringManager for the client's locale
smClient
)

Remove the specified host.

public void
setWrapper(Wrapper
The new wrapper
wrapper
)

Implements org.apache.catalina.ContainerServlet.setWrapper.

Set the Wrapper with which we are associated.

protected void
start(PrintWriter
Writer to render to
writer
,
String
Host name
name
,
StringManager
StringManager for the client's locale
smClient
)

Start the host with the specified name.

protected void
stop(PrintWriter
Writer to render to
writer
,
String
Host name
name
,
StringManager
StringManager for the client's locale
smClient
)

Stop the host with the specified name.

Inherited from jakarta.servlet.http.HttpServlet:
doDeletedoHeaddoOptionsdoPostdoPutdoTracegetLastModifiedinitserviceservice

Field Detail

contextback to summary
protected transient Context context

The Context container associated with our web application.

debugback to summary
protected int debug

The debugging detail level for this servlet.

engineback to summary
protected transient Engine engine

The associated engine.

installedHostback to summary
protected transient Host installedHost

The associated host.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides jakarta.servlet.http.HttpServlet.serialVersionUID.

smback to summary
protected static final StringManager sm

The string manager for this package.

wrapperback to summary
protected transient Wrapper wrapper

The Wrapper container associated with this servlet.

Constructor Detail

HostManagerServletback to summary
public HostManagerServlet()

Method Detail

addback to summary
protected void add(HttpServletRequest request, PrintWriter writer, String name, boolean htmlMode, StringManager smClient)

Add host with the given parameters.

Parameters
request:HttpServletRequest

The request

writer:PrintWriter

The output writer

name:String

The host name

htmlMode:boolean

Flag value

smClient:StringManager

StringManager for the client's locale

addback to summary
protected synchronized void add(PrintWriter writer, String name, String aliases, String appBase, boolean manager, boolean autoDeploy, boolean deployOnStartup, boolean deployXML, boolean unpackWARs, boolean copyXML, StringManager smClient)

Add a host using the specified parameters.

Parameters
writer:PrintWriter

Writer to render results to

name:String

host name

aliases:String

comma separated alias list

appBase:String

application base for the host

manager:boolean

should the manager webapp be deployed to the new host ?

autoDeploy:boolean

Flag value

deployOnStartup:boolean

Flag value

deployXML:boolean

Flag value

unpackWARs:boolean

Flag value

copyXML:boolean

Flag value

smClient:StringManager

StringManager for the client's locale

booleanParameterback to summary
protected boolean booleanParameter(HttpServletRequest request, String parameter, boolean theDefault, boolean htmlMode)

Extract boolean value from checkbox with default.

Parameters
request:HttpServletRequest

The Servlet request

parameter:String

The parameter name

theDefault:boolean

Default value

htmlMode:boolean

Flag value

Returns:boolean

the boolean value for the parameter

destroyback to summary
public void destroy()

Overrides jakarta.servlet.GenericServlet.destroy.

Implements jakarta.servlet.Servlet.destroy.

Finalize this servlet.

Annotations
@Override
doGetback to summary
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException

Overrides jakarta.servlet.http.HttpServlet.doGet.

Process a GET request for the specified resource.

Parameters
request:HttpServletRequest

The servlet request we are processing

response:HttpServletResponse

The servlet response we are creating

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
ServletException:
if a servlet-specified error occurs
getConfigBaseback to summary
protected File getConfigBase(String hostName)

Get config base.

Parameters
hostName:String

The host name

Returns:File

the config base for the host

getWrapperback to summary
public Wrapper getWrapper()

Implements org.apache.catalina.ContainerServlet.getWrapper.

Return the Wrapper with which we are associated.

Returns:Wrapper

Doc from org.apache.catalina.ContainerServlet.getWrapper.

The Wrapper with which this Servlet is associated.

Annotations
@Override
initback to summary
public void init() throws ServletException

Overrides jakarta.servlet.GenericServlet.init.

Doc from jakarta.servlet.GenericServlet.init.

A convenience method which can be overridden so that there's no need to call super.init(config).

Instead of overriding init(ServletConfig), simply override this method and it will be called by GenericServlet.init(ServletConfig config). The ServletConfig object can still be retrieved via getServletConfig.

Annotations
@Override
Exceptions
ServletException:
if an exception occurs that interrupts the servlet's normal operation
listback to summary
protected void list(PrintWriter writer, StringManager smClient)

Render a list of the currently active Contexts in our virtual host.

Parameters
writer:PrintWriter

Writer to render to

smClient:StringManager

StringManager for the client's locale

persistback to summary
protected void persist(PrintWriter writer, StringManager smClient)

Persist the current configuration to server.xml.

Parameters
writer:PrintWriter

Writer to render to

smClient:StringManager

i18n resources localized for the client

removeback to summary
protected synchronized void remove(PrintWriter writer, String name, StringManager smClient)

Remove the specified host.

Parameters
writer:PrintWriter

Writer to render results to

name:String

host name

smClient:StringManager

StringManager for the client's locale

setWrapperback to summary
public void setWrapper(Wrapper wrapper)

Implements org.apache.catalina.ContainerServlet.setWrapper.

Set the Wrapper with which we are associated.

Parameters
wrapper:Wrapper

The new wrapper

Annotations
@Override
startback to summary
protected void start(PrintWriter writer, String name, StringManager smClient)

Start the host with the specified name.

Parameters
writer:PrintWriter

Writer to render to

name:String

Host name

smClient:StringManager

StringManager for the client's locale

stopback to summary
protected void stop(PrintWriter writer, String name, StringManager smClient)

Stop the host with the specified name.

Parameters
writer:PrintWriter

Writer to render to

name:String

Host name

smClient:StringManager

StringManager for the client's locale