Apache Tomcat 7.0.28

org.apache.catalina.manager
Class ManagerServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.apache.catalina.manager.ManagerServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig, ContainerServlet
Direct Known Subclasses:
HTMLManagerServlet

public class ManagerServlet
extends HttpServlet
implements ContainerServlet

Servlet that enables remote management of the web applications installed within the same virtual host as this web application is. 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:

Use path=/ for the ROOT context.

The syntax of the URL for a web application archive must conform to one of the following patterns to be successfully deployed:

NOTE - Attempting to reload or remove the application containing this servlet itself will not succeed. Therefore, this servlet should generally be deployed as a separate web application within the virtual host to be managed.

The following servlet initialization parameters are recognized:

Version:
$Id: ManagerServlet.java 1162172 2011-08-26 17:12:33Z markt $
Author:
Craig R. McClanahan, Remy Maucherat
See Also:
Serialized Form

Field Summary
protected  File appBase
          The host appBase.
protected  File configBase
          Path where context descriptors should be deployed.
protected  Context context
          The Context container associated with our web application.
protected  File contextDescriptors
          Path used to store context descriptors.
protected  int debug
          The debugging detail level for this servlet.
protected  File deployed
          File object representing the directory into which the deploy() command will store the WAR and context configuration files that have been uploaded.
protected  Context global
          The global JNDI NamingContext for this server, if available.
protected  Host host
          The associated host.
protected  MBeanServer mBeanServer
          MBean server.
protected  ObjectName oname
          The associated deployer ObjectName.
protected static StringManager sm
          The string manager for this package.
protected  File versioned
          Path used to store revisions of webapps.
protected  Wrapper wrapper
          The Wrapper container associated with this servlet.
 
Constructor Summary
ManagerServlet()
           
 
Method Summary
protected  void addServiced(String name)
          Invoke the addServiced method on the deployer.
protected  void check(String name)
          Invoke the check method on the deployer.
static boolean copy(File src, File dest)
          Copy the specified file or directory to the destination.
static boolean copyInternal(File src, File dest, byte[] buf)
          Copy the specified file or directory to the destination.
protected  void deploy(PrintWriter writer, ContextName cn, String tag, boolean update, HttpServletRequest request, StringManager smClient)
          Deploy a web application archive (included in the current request) at the specified context path.
protected  void deploy(PrintWriter writer, ContextName cn, String tag, StringManager smClient)
          Install an application for the specified path from the specified web application archive.
protected  void deploy(PrintWriter writer, String config, ContextName cn, String war, boolean update, StringManager smClient)
          Install an application for the specified path from the specified web application archive.
 void destroy()
          Finalize this servlet.
 void doGet(HttpServletRequest request, HttpServletResponse response)
          Process a GET request for the specified resource.
 void doPut(HttpServletRequest request, HttpServletResponse response)
          Process a PUT request for the specified resource.
protected  void expireSessions(PrintWriter writer, ContextName cn, HttpServletRequest req, StringManager smClient)
          Extract the expiration request parameter
protected  void findleaks(boolean statusLine, PrintWriter writer, StringManager smClient)
          Find potential memory leaks caused by web application reload.
protected  File getAppBase()
          Return a File object representing the "application root" directory for our associated Host.
protected  StringManager getStringManager(HttpServletRequest req)
           
 Wrapper getWrapper()
          Return the Wrapper with which we are associated.
 void init()
          Initialize this servlet.
protected  boolean isDeployed(String name)
          Invoke the isDeployed method on the deployer.
protected  boolean isServiced(String name)
          Invoke the isServiced method on the deployer.
protected  void list(PrintWriter writer, StringManager smClient)
          Render a list of the currently active Contexts in our virtual host.
protected  void printResources(PrintWriter writer, String prefix, Context namingContext, String type, Class<?> clazz, StringManager smClient)
          List the resources of the given context.
protected  void reload(PrintWriter writer, ContextName cn, StringManager smClient)
          Reload the web application at the specified context path.
protected  void removeServiced(String name)
          Invoke the removeServiced method on the deployer.
protected  void resources(PrintWriter writer, String type, StringManager smClient)
          Render a list of available global JNDI resources.
protected  void save(PrintWriter writer, String path, StringManager smClient)
          Store server configuration.
protected  void serverinfo(PrintWriter writer, StringManager smClient)
          Writes System OS and JVM properties.
protected  void sessions(PrintWriter writer, ContextName cn, int idle, StringManager smClient)
          Session information for the web application at the specified context path.
protected  void sessions(PrintWriter writer, ContextName cn, StringManager smClient)
          Session information for the web application at the specified context path.
 void setWrapper(Wrapper wrapper)
          Set the Wrapper with which we are associated.
protected  void start(PrintWriter writer, ContextName cn, StringManager smClient)
          Start the web application at the specified context path.
protected  void stop(PrintWriter writer, ContextName cn, StringManager smClient)
          Stop the web application at the specified context path.
protected  void undeploy(PrintWriter writer, ContextName cn, StringManager smClient)
          Undeploy the web application at the specified context path.
protected  boolean undeployDir(File dir)
          Delete the specified directory, including all of its contents and subdirectories recursively.
protected  void uploadWar(PrintWriter writer, HttpServletRequest request, File war, StringManager smClient)
          Upload the WAR file included in this request, and store it at the specified file location.
protected static boolean validateContextName(ContextName cn, PrintWriter writer, StringManager sm)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configBase

protected File configBase
Path where context descriptors should be deployed.


context

protected transient Context context
The Context container associated with our web application.


debug

protected int debug
The debugging detail level for this servlet.


deployed

protected File deployed
File object representing the directory into which the deploy() command will store the WAR and context configuration files that have been uploaded.


versioned

protected File versioned
Path used to store revisions of webapps.


contextDescriptors

protected File contextDescriptors
Path used to store context descriptors.


host

protected transient Host host
The associated host.


appBase

protected File appBase
The host appBase.


mBeanServer

protected transient MBeanServer mBeanServer
MBean server.


oname

protected ObjectName oname
The associated deployer ObjectName.


global

protected transient Context global
The global JNDI NamingContext for this server, if available.


sm

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


wrapper

protected transient Wrapper wrapper
The Wrapper container associated with this servlet.

Constructor Detail

ManagerServlet

public ManagerServlet()
Method Detail

getWrapper

public Wrapper getWrapper()
Return the Wrapper with which we are associated.

Specified by:
getWrapper in interface ContainerServlet

setWrapper

public void setWrapper(Wrapper wrapper)
Set the Wrapper with which we are associated.

Specified by:
setWrapper in interface ContainerServlet
Parameters:
wrapper - The new wrapper

destroy

public void destroy()
Finalize this servlet.

Specified by:
destroy in interface Servlet
Overrides:
destroy in class GenericServlet

doGet

public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
           throws IOException,
                  ServletException
Process a GET request for the specified resource.

Overrides:
doGet in class HttpServlet
Parameters:
request - The servlet request we are processing
response - The servlet response we are creating
Throws:
IOException - if an input/output error occurs
ServletException - if a servlet-specified error occurs
See Also:
ServletResponse.setContentType(java.lang.String)

doPut

public void doPut(HttpServletRequest request,
                  HttpServletResponse response)
           throws IOException,
                  ServletException
Process a PUT request for the specified resource.

Overrides:
doPut in class HttpServlet
Parameters:
request - The servlet request we are processing
response - The servlet response we are creating
Throws:
IOException - if an input/output error occurs
ServletException - if a servlet-specified error occurs

init

public void init()
          throws ServletException
Initialize this servlet.

Overrides:
init in class GenericServlet
Throws:
ServletException - if an exception occurs that interrupts the servlet's normal operation

findleaks

protected void findleaks(boolean statusLine,
                         PrintWriter writer,
                         StringManager smClient)
Find potential memory leaks caused by web application reload.


save

protected void save(PrintWriter writer,
                    String path,
                    StringManager smClient)
Store server configuration.

Parameters:
path - Optional context path to save

deploy

protected void deploy(PrintWriter writer,
                      ContextName cn,
                      String tag,
                      boolean update,
                      HttpServletRequest request,
                      StringManager smClient)
Deploy a web application archive (included in the current request) at the specified context path.

Parameters:
writer - Writer to render results to
cn - Name of the application to be installed
tag - Tag to be associated with the webapp
request - Servlet request we are processing

deploy

protected void deploy(PrintWriter writer,
                      ContextName cn,
                      String tag,
                      StringManager smClient)
Install an application for the specified path from the specified web application archive.

Parameters:
writer - Writer to render results to
tag - Revision tag to deploy from
cn - Name of the application to be installed

deploy

protected void deploy(PrintWriter writer,
                      String config,
                      ContextName cn,
                      String war,
                      boolean update,
                      StringManager smClient)
Install an application for the specified path from the specified web application archive.

Parameters:
writer - Writer to render results to
config - URL of the context configuration file to be installed
cn - Name of the application to be installed
war - URL of the web application archive to be installed
update - true to override any existing webapp on the path

list

protected void list(PrintWriter writer,
                    StringManager smClient)
Render a list of the currently active Contexts in our virtual host.

Parameters:
writer - Writer to render to

reload

protected void reload(PrintWriter writer,
                      ContextName cn,
                      StringManager smClient)
Reload the web application at the specified context path.

Parameters:
writer - Writer to render to
cn - Name of the application to be restarted

resources

protected void resources(PrintWriter writer,
                         String type,
                         StringManager smClient)
Render a list of available global JNDI resources.

Parameters:
type - Fully qualified class name of the resource type of interest, or null to list resources of all types

printResources

protected void printResources(PrintWriter writer,
                              String prefix,
                              Context namingContext,
                              String type,
                              Class<?> clazz,
                              StringManager smClient)
List the resources of the given context.


serverinfo

protected void serverinfo(PrintWriter writer,
                          StringManager smClient)
Writes System OS and JVM properties.

Parameters:
writer - Writer to render to

sessions

protected void sessions(PrintWriter writer,
                        ContextName cn,
                        int idle,
                        StringManager smClient)
Session information for the web application at the specified context path. Displays a profile of session thisAccessedTime listing number of sessions for each 10 minute interval up to 10 hours.

Parameters:
writer - Writer to render to
cn - Name of the application to list session information for
idle - Expire all sessions with idle time > idle for this context

sessions

protected void sessions(PrintWriter writer,
                        ContextName cn,
                        StringManager smClient)
Session information for the web application at the specified context path. Displays a profile of session thisAccessedTime listing number of sessions for each 10 minute interval up to 10 hours.

Parameters:
writer - Writer to render to
cn - Name of the application to list session information for

expireSessions

protected void expireSessions(PrintWriter writer,
                              ContextName cn,
                              HttpServletRequest req,
                              StringManager smClient)
Extract the expiration request parameter

Parameters:
cn -
req -

start

protected void start(PrintWriter writer,
                     ContextName cn,
                     StringManager smClient)
Start the web application at the specified context path.

Parameters:
writer - Writer to render to
cn - Name of the application to be started

stop

protected void stop(PrintWriter writer,
                    ContextName cn,
                    StringManager smClient)
Stop the web application at the specified context path.

Parameters:
writer - Writer to render to
cn - Name of the application to be stopped

undeploy

protected void undeploy(PrintWriter writer,
                        ContextName cn,
                        StringManager smClient)
Undeploy the web application at the specified context path.

Parameters:
writer - Writer to render to
cn - Name of the application to be removed

getAppBase

protected File getAppBase()
Return a File object representing the "application root" directory for our associated Host.


isDeployed

protected boolean isDeployed(String name)
                      throws Exception
Invoke the isDeployed method on the deployer.

Throws:
Exception

check

protected void check(String name)
              throws Exception
Invoke the check method on the deployer.

Throws:
Exception

isServiced

protected boolean isServiced(String name)
                      throws Exception
Invoke the isServiced method on the deployer.

Throws:
Exception

addServiced

protected void addServiced(String name)
                    throws Exception
Invoke the addServiced method on the deployer.

Throws:
Exception

removeServiced

protected void removeServiced(String name)
                       throws Exception
Invoke the removeServiced method on the deployer.

Throws:
Exception

undeployDir

protected boolean undeployDir(File dir)
Delete the specified directory, including all of its contents and subdirectories recursively. The code assumes that the directory exists.

Parameters:
dir - File object representing the directory to be deleted.

uploadWar

protected void uploadWar(PrintWriter writer,
                         HttpServletRequest request,
                         File war,
                         StringManager smClient)
                  throws IOException
Upload the WAR file included in this request, and store it at the specified file location.

Parameters:
writer - Writer to render to
request - The servlet request we are processing
war - The file into which we should store the uploaded WAR
smClient - The StringManager used to construct i18n messages based on the Locale of the client
Throws:
IOException - if an I/O error occurs during processing

getStringManager

protected StringManager getStringManager(HttpServletRequest req)

validateContextName

protected static boolean validateContextName(ContextName cn,
                                             PrintWriter writer,
                                             StringManager sm)

copy

public static boolean copy(File src,
                           File dest)
Copy the specified file or directory to the destination.

Parameters:
src - File object representing the source
dest - File object representing the destination

copyInternal

public static boolean copyInternal(File src,
                                   File dest,
                                   byte[] buf)
Copy the specified file or directory to the destination.

Parameters:
src - File object representing the source
dest - File object representing the destination

Apache Tomcat 7.0.28

Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.