📄 managerservlet.java
字号:
}
context.reload();
writer.println
(sm.getString("managerServlet.reloaded", displayPath));
} catch (Throwable t) {
log("ManagerServlet.reload[" + displayPath + "]", t);
writer.println(sm.getString("managerServlet.exception",
t.toString()));
}
}
/**
* Remove the web application at the specified context path.
*
* @param writer Writer to render to
* @param path Context path of the application to be removed
* @deprecated Replaced by undeploy
*/
protected void remove(PrintWriter writer, String path) {
if (debug >= 1)
log("remove: Removing web application at '" + path + "'");
if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
writer.println(sm.getString("managerServlet.invalidPath", path));
return;
}
String displayPath = path;
if( path.equals("/") )
path = "";
try {
Context context = deployer.findDeployedApp(path);
if (context == null) {
writer.println(sm.getString("managerServlet.noContext", displayPath));
return;
}
// It isn't possible for the manager to remove itself
if (context.getPath().equals(this.context.getPath())) {
writer.println(sm.getString("managerServlet.noSelf"));
return;
}
deployer.remove(path,true);
writer.println(sm.getString("managerServlet.undeployed", displayPath));
} catch (Throwable t) {
log("ManagerServlet.remove[" + displayPath + "]", t);
writer.println(sm.getString("managerServlet.exception",
t.toString()));
}
}
/**
* Render a list of available global JNDI resources.
*
* @param type Fully qualified class name of the resource type of interest,
* or <code>null</code> to list resources of all types
*/
protected void resources(PrintWriter writer, String type) {
if (debug >= 1) {
if (type != null) {
log("resources: Listing resources of type " + type);
} else {
log("resources: Listing resources of all types");
}
}
// Is the global JNDI resources context available?
if (global == null) {
writer.println(sm.getString("managerServlet.noGlobal"));
return;
}
// Enumerate the global JNDI resources of the requested type
if (type != null) {
writer.println(sm.getString("managerServlet.resourcesType",
type));
} else {
writer.println(sm.getString("managerServlet.resourcesAll"));
}
Class clazz = null;
try {
if (type != null) {
clazz = Class.forName(type);
}
} catch (Throwable t) {
log("ManagerServlet.resources[" + type + "]", t);
writer.println(sm.getString("managerServlet.exception",
t.toString()));
return;
}
printResources(writer, "", global, type, clazz);
}
/**
* List the resources of the given context.
*/
protected void printResources(PrintWriter writer, String prefix,
javax.naming.Context namingContext,
String type, Class clazz) {
try {
NamingEnumeration items = namingContext.listBindings("");
while (items.hasMore()) {
Binding item = (Binding) items.next();
if (item.getObject() instanceof javax.naming.Context) {
printResources
(writer, prefix + item.getName() + "/",
(javax.naming.Context) item.getObject(), type, clazz);
} else {
if ((clazz != null) &&
(!(clazz.isInstance(item.getObject())))) {
continue;
}
writer.print(prefix + item.getName());
writer.print(':');
writer.print(item.getClassName());
// Do we want a description if available?
writer.println();
}
}
} catch (Throwable t) {
log("ManagerServlet.resources[" + type + "]", t);
writer.println(sm.getString("managerServlet.exception",
t.toString()));
}
}
/**
* Render a list of security role names (and corresponding descriptions)
* from the <code>org.apache.catalina.UserDatabase</code> resource that is
* connected to the <code>users</code> resource reference. Typically, this
* will be the global user database, but can be adjusted if you have
* different user databases for different virtual hosts.
*
* @param writer Writer to render to
*/
protected void roles(PrintWriter writer) {
if (debug >= 1) {
log("roles: List security roles from user database");
}
// Look up the UserDatabase instance we should use
UserDatabase database = null;
try {
InitialContext ic = new InitialContext();
database = (UserDatabase) ic.lookup("java:comp/env/users");
} catch (NamingException e) {
writer.println(sm.getString("managerServlet.userDatabaseError"));
log("java:comp/env/users", e);
return;
}
if (database == null) {
writer.println(sm.getString("managerServlet.userDatabaseMissing"));
return;
}
// Enumerate the available roles
writer.println(sm.getString("managerServlet.rolesList"));
Iterator roles = database.getRoles();
if (roles != null) {
while (roles.hasNext()) {
Role role = (Role) roles.next();
writer.print(role.getRolename());
writer.print(':');
if (role.getDescription() != null) {
writer.print(role.getDescription());
}
writer.println();
}
}
}
/**
* Writes System OS and JVM properties.
* @param writer Writer to render to
*/
protected void serverinfo(PrintWriter writer) {
if (debug >= 1)
log("serverinfo");
try {
StringBuffer props = new StringBuffer();
props.append("OK - Server info");
props.append("\nTomcat Version: ");
props.append(ServerInfo.getServerInfo());
props.append("\nOS Name: ");
props.append(System.getProperty("os.name"));
props.append("\nOS Version: ");
props.append(System.getProperty("os.version"));
props.append("\nOS Architecture: ");
props.append(System.getProperty("os.arch"));
props.append("\nJVM Version: ");
props.append(System.getProperty("java.runtime.version"));
props.append("\nJVM Vendor: ");
props.append(System.getProperty("java.vm.vendor"));
writer.println(props.toString());
} catch (Throwable t) {
getServletContext().log("ManagerServlet.serverinfo",t);
writer.println(sm.getString("managerServlet.exception",
t.toString()));
}
}
/**
* Session information for the web application at the specified context path.
* Displays a profile of session MaxInactiveInterval timeouts listing number
* of sessions for each 10 minute timeout interval up to 10 hours.
*
* @param writer Writer to render to
* @param path Context path of the application to list session information for
*/
protected void sessions(PrintWriter writer, String path) {
if (debug >= 1)
log("sessions: Session information for web application at '" + path + "'");
if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
writer.println(sm.getString("managerServlet.invalidPath", path));
return;
}
String displayPath = path;
if( path.equals("/") )
path = "";
try {
Context context = deployer.findDeployedApp(path);
if (context == null) {
writer.println(sm.getString("managerServlet.noContext", displayPath));
return;
}
writer.println(sm.getString("managerServlet.sessions", displayPath));
writer.println(sm.getString("managerServlet.sessiondefaultmax",
"" + context.getManager().getMaxInactiveInterval()/60));
Session [] sessions = context.getManager().findSessions();
int [] timeout = new int[60];
int notimeout = 0;
for (int i = 0; i < sessions.length; i++) {
int time = sessions[i].getMaxInactiveInterval()/(10*60);
if (time < 0)
notimeout++;
else if (time >= timeout.length)
timeout[timeout.length-1]++;
else
timeout[time]++;
}
if (timeout[0] > 0)
writer.println(sm.getString("managerServlet.sessiontimeout",
"<10" + timeout[0]));
for (int i = 1; i < timeout.length-1; i++) {
if (timeout[i] > 0)
writer.println(sm.getString("managerServlet.sessiontimeout",
"" + (i)*10 + " - <" + (i+1)*10,
"" + timeout[i]));
}
if (timeout[timeout.length-1] > 0)
writer.println(sm.getString("managerServlet.sessiontimeout",
">=" + timeout.length*10,
"" + timeout[timeout.length-1]));
if (notimeout > 0)
writer.println(sm.getString("managerServlet.sessiontimeout",
"unlimited","" + notimeout));
} catch (Throwable t) {
log("ManagerServlet.sessions[" + displayPath + "]", t);
writer.println(sm.getString("managerServlet.exception",
t.toString()));
}
}
/**
* Start the web application at the specified context path.
*
* @param writer Writer to render to
* @param path Context path of the application to be started
*/
protected void start(PrintWriter writer, String path) {
if (debug >= 1)
log("start: Starting web application at '" + path + "'");
if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
writer.println(sm.getString("managerServlet.invalidPath", path));
return;
}
String displayPath = path;
if( path.equals("/") )
path = "";
try {
Context context = deployer.findDeployedApp(path);
if (context == null) {
writer.println(sm.getString("managerServlet.noContext",
displayPath));
return;
}
deployer.start(path);
if (context.getAvailable())
writer.println
(sm.getString("managerServlet.started", displayPath));
else
writer.println
(sm.getString("managerServlet.startFailed", displayPath));
} catch (Throwable t) {
getServletContext().log
(sm.getString("managerServlet.startFailed", displayPath), t);
writer.println
(sm.getString("managerServlet.startFailed", displayPath));
writer.println(sm.getString("managerServlet.exception",
t.toString()));
}
}
/**
* Stop the web application at the specified context path.
*
* @param writer Writer to render to
* @param path Context path of the application to be stopped
*/
protected void stop(PrintWriter writer, String path) {
if (debug >= 1)
log("stop: Stopping web application at '" + path + "'");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -