📄 managerservlet.java
字号:
} catch (IOException e) {
log("managerServlet.extract[" + displayPath + "]", e);
writer.println(sm.getString("managerServlet.exception",
e.toString()));
return;
}
String config = null;
try {
if (localXml.exists()) {
URL url = localXml.toURL();
config = url.toString();
}
} catch (MalformedURLException e) {
log("managerServlet.badUrl[" + displayPath + "]", e);
writer.println(sm.getString("managerServlet.exception",
e.toString()));
return;
}
// Deploy this web application
deploy(writer, config, path, war, update);
}
/**
* Install an application for the specified path from the specified
* web application archive.
*
* @param writer Writer to render results to
* @param tag Revision tag to deploy from
* @param path Context path of the application to be installed
*/
protected void deploy(PrintWriter writer, String path, String tag) {
// Validate the requested context path
if ((path == null) || path.length() == 0 || !path.startsWith("/")) {
writer.println(sm.getString("managerServlet.invalidPath", path));
return;
}
String displayPath = path;
if( path.equals("/") )
path = "";
String basename = getConfigFile(path);
// Calculate the base path
File deployedPath = versioned;
if (tag != null) {
deployedPath = new File(deployedPath, tag);
}
// Find the local WAR file
File localWar = new File(deployedPath, basename + ".war");
// Find the local context deployment file (if any)
File localXml = new File(configBase, basename + ".xml");
// Check if app already exists, or undeploy it if updating
Context context = deployer.findDeployedApp(path);
if (context != null) {
undeploy(writer, displayPath);
}
// Copy WAR and XML to the host base
if (tag != null) {
File localWarCopy = new File(deployed, basename + ".war");
copy(localWar, localWarCopy);
try {
extractXml(localWar, localXml);
} catch (IOException e) {
log("managerServlet.extract[" + displayPath + "]", e);
writer.println(sm.getString("managerServlet.exception",
e.toString()));
return;
}
localWar = localWarCopy;
}
// Compute URLs
String war = null;
try {
URL url = localWar.toURL();
war = url.toString();
war = "jar:" + war + "!/";
} catch(MalformedURLException e) {
log("managerServlet.badUrl[" + displayPath + "]", e);
writer.println(sm.getString("managerServlet.exception",
e.toString()));
return;
}
String config = null;
try {
if (localXml.exists()) {
URL url = localXml.toURL();
config = url.toString();
}
} catch (MalformedURLException e) {
log("managerServlet.badUrl[" + displayPath + "]", e);
writer.println(sm.getString("managerServlet.exception",
e.toString()));
return;
}
// Deploy webapp
deploy(writer, config, path, war, false);
}
/**
* Install an application for the specified path from the specified
* web application archive.
*
* @param writer Writer to render results to
* @param config URL of the context configuration file to be installed
* @param path Context path of the application to be installed
* @param war URL of the web application archive to be installed
* @param update true to override any existing webapp on the path
*/
protected void deploy(PrintWriter writer, String config,
String path, String war, boolean update) {
if (war != null && war.length() == 0) {
war = null;
}
if (debug >= 1) {
if (config != null && config.length() > 0) {
if (war != null) {
log("install: Installing context configuration at '" +
config + "' from '" + war + "'");
} else {
log("install: Installing context configuration at '" +
config + "'");
}
} else {
log("install: Installing web application at '" + path +
"' from '" + war + "'");
}
}
// See if directory/war is relative to host appBase
if (war != null && war.indexOf('/') < 0 ) {
// Identify the appBase of the owning Host of this Context (if any)
String appBase = null;
File appBaseDir = null;
if (context.getParent() instanceof Host) {
appBase = ((Host) context.getParent()).getAppBase();
appBaseDir = new File(appBase);
if (!appBaseDir.isAbsolute()) {
appBaseDir = new File(System.getProperty("catalina.base"),
appBase);
}
File file = new File(appBaseDir, war);
try {
URL url = file.toURL();
war = url.toString();
if (war.toLowerCase().endsWith(".war")) {
war = "jar:" + war + "!/";
}
} catch(MalformedURLException e) {
;
}
}
}
if (config != null && config.length() > 0) {
if ((war != null) &&
(!war.startsWith("file:") && !war.startsWith("jar:"))) {
writer.println(sm.getString("managerServlet.invalidWar", war));
return;
}
try {
if (war == null) {
deployer.install(new URL(config), null);
} else {
deployer.install(new URL(config), new URL(war));
}
writer.println(sm.getString("managerServlet.configured",
config));
} catch (Throwable t) {
log("ManagerServlet.configure[" + config + "]", t);
writer.println(sm.getString("managerServlet.exception",
t.toString()));
return;
}
} else {
if ((war == null) ||
(!war.startsWith("file:") && !war.startsWith("jar:"))) {
writer.println(sm.getString("managerServlet.invalidWar", war));
return;
}
if (path == null || path.length() == 0) {
int end = war.length();
String filename = war.toLowerCase();
if (filename.endsWith("!/")) {
filename = filename.substring(0,filename.length()-2);
end -= 2;
}
if (filename.endsWith(".war")) {
filename = filename.substring(0,filename.length()-4);
end -= 4;
}
if (filename.endsWith("/")) {
filename = filename.substring(0,filename.length()-1);
end--;
}
int beg = filename.lastIndexOf('/') + 1;
if (beg < 0 || end < 0 || beg >= end) {
writer.println(sm.getString("managerServlet.invalidWar", war));
return;
}
path = "/" + war.substring(beg, end);
if (path.equals("/ROOT")) {
path = "/";
}
}
if (path == null || path.length() == 0 || !path.startsWith("/")) {
writer.println(sm.getString("managerServlet.invalidPath",
path));
return;
}
String displayPath = path;
if("/".equals(path)) {
path = "";
}
// Check if app already exists, or undeploy it if updating
Context context = deployer.findDeployedApp(path);
if (update) {
if (context != null) {
undeploy(writer, displayPath);
}
context = deployer.findDeployedApp(path);
}
if (context != null) {
writer.println
(sm.getString("managerServlet.alreadyContext",
displayPath));
return;
}
try {
deployer.install(path, new URL(war));
writer.println(sm.getString("managerServlet.deployed",
displayPath));
} catch (Throwable t) {
log("ManagerServlet.install[" + displayPath + "]", t);
writer.println(sm.getString("managerServlet.exception",
t.toString()));
}
}
}
/**
* Render a list of the currently active Contexts in our virtual host.
*
* @param writer Writer to render to
*/
protected void list(PrintWriter writer) {
if (debug >= 1)
log("list: Listing contexts for virtual host '" +
deployer.getName() + "'");
writer.println(sm.getString("managerServlet.listed",
deployer.getName()));
String contextPaths[] = deployer.findDeployedApps();
for (int i = 0; i < contextPaths.length; i++) {
Context context = deployer.findDeployedApp(contextPaths[i]);
String displayPath = contextPaths[i];
if( displayPath.equals("") )
displayPath = "/";
if (context != null ) {
if (context.getAvailable()) {
writer.println(sm.getString("managerServlet.listitem",
displayPath,
"running",
"" + context.getManager().findSessions().length,
context.getDocBase()));
} else {
writer.println(sm.getString("managerServlet.listitem",
displayPath,
"stopped",
"0",
context.getDocBase()));
}
}
}
}
/**
* Reload the web application at the specified context path.
*
* @param writer Writer to render to
* @param path Context path of the application to be restarted
*/
protected void reload(PrintWriter writer, String path) {
if (debug >= 1)
log("restart: Reloading 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;
}
DirContext resources = context.getResources();
if (resources instanceof ProxyDirContext) {
resources = ((ProxyDirContext) resources).getDirContext();
}
if (resources instanceof WARDirContext) {
writer.println(sm.getString
("managerServlet.noReload", displayPath));
return;
}
// It isn't possible for the manager to reload itself
if (context.getPath().equals(this.context.getPath())) {
writer.println(sm.getString("managerServlet.noSelf"));
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -