in java/org/apache/catalina/manager/HTMLManagerServlet.java [297:566]
protected void list(HttpServletRequest request, HttpServletResponse response, String message,
StringManager smClient) throws IOException {
if (debug >= 1) {
log("list: Listing contexts for virtual host '" + host.getName() + "'");
}
PrintWriter writer = response.getWriter();
Object[] args = new Object[2];
args[0] = getServletContext().getContextPath();
args[1] = smClient.getString("htmlManagerServlet.title");
if (htmlSubTitle != null) {
args[1] += "</font><br/><font size=\"+1\">" + htmlSubTitle;
}
// HTML Header Section
writer.print(MessageFormat.format(Constants.HTML_HEADER_SECTION, args));
// Body Header Section
writer.print(MessageFormat.format(Constants.BODY_HEADER_SECTION, args));
// Message Section
args = new Object[3];
args[0] = smClient.getString("htmlManagerServlet.messageLabel");
if (message == null || message.isEmpty()) {
args[1] = "OK";
} else {
args[1] = Escape.htmlElementContent(message);
}
writer.print(MessageFormat.format(Constants.MESSAGE_SECTION, args));
// Manager Section
args = new Object[9];
args[0] = smClient.getString("htmlManagerServlet.manager");
args[1] = response.encodeURL(getServletContext().getContextPath() + "/html/list");
args[2] = smClient.getString("htmlManagerServlet.list");
args[3] = // External link
getServletContext().getContextPath() + "/" +
smClient.getString("htmlManagerServlet.helpHtmlManagerFile");
args[4] = smClient.getString("htmlManagerServlet.helpHtmlManager");
args[5] = // External link
getServletContext().getContextPath() + "/" + smClient.getString("htmlManagerServlet.helpManagerFile");
args[6] = smClient.getString("htmlManagerServlet.helpManager");
args[7] = response.encodeURL(getServletContext().getContextPath() + "/status");
args[8] = smClient.getString("statusServlet.title");
writer.print(MessageFormat.format(Constants.MANAGER_SECTION, args));
// Apps Header Section
args = new Object[7];
args[0] = smClient.getString("htmlManagerServlet.appsTitle");
args[1] = smClient.getString("htmlManagerServlet.appsPath");
args[2] = smClient.getString("htmlManagerServlet.appsVersion");
args[3] = smClient.getString("htmlManagerServlet.appsName");
args[4] = smClient.getString("htmlManagerServlet.appsAvailable");
args[5] = smClient.getString("htmlManagerServlet.appsSessions");
args[6] = smClient.getString("htmlManagerServlet.appsTasks");
writer.print(MessageFormat.format(APPS_HEADER_SECTION, args));
// Apps Row Section
// Create sorted map of deployed applications by context name.
Container[] children = host.findChildren();
String[] contextNames = new String[children.length];
for (int i = 0; i < children.length; i++) {
contextNames[i] = children[i].getName();
}
Arrays.sort(contextNames);
String appsStart = smClient.getString("htmlManagerServlet.appsStart");
String appsStop = smClient.getString("htmlManagerServlet.appsStop");
String appsReload = smClient.getString("htmlManagerServlet.appsReload");
String appsUndeploy = smClient.getString("htmlManagerServlet.appsUndeploy");
String appsExpire = smClient.getString("htmlManagerServlet.appsExpire");
String noVersion = "<i>" + smClient.getString("htmlManagerServlet.noVersion") + "</i>";
boolean isHighlighted = true;
boolean isDeployed;
String highlightColor;
for (String contextName : contextNames) {
Context ctxt = (Context) host.findChild(contextName);
if (ctxt != null) {
// Bugzilla 34818, alternating row colors
isHighlighted = !isHighlighted;
if (isHighlighted) {
highlightColor = "#C3F3C3";
} else {
highlightColor = "#FFFFFF";
}
String contextPath = ctxt.getPath();
String displayPath = contextPath;
if (displayPath.isEmpty()) {
displayPath = "/";
}
StringBuilder tmp = new StringBuilder();
tmp.append("path=");
tmp.append(URLEncoder.DEFAULT.encode(displayPath, StandardCharsets.UTF_8));
final String webappVersion = ctxt.getWebappVersion();
if (webappVersion != null && !webappVersion.isEmpty()) {
tmp.append("&version=");
tmp.append(URLEncoder.DEFAULT.encode(webappVersion, StandardCharsets.UTF_8));
}
String pathVersion = tmp.toString();
try {
isDeployed = isDeployed(contextName);
} catch (Exception e) {
// Assume false on failure for safety
isDeployed = false;
}
args = new Object[7];
args[0] = // External link
"<a href=\"" + URLEncoder.DEFAULT.encode(contextPath + "/", StandardCharsets.UTF_8) + "\" " +
Constants.REL_EXTERNAL + ">" + Escape.htmlElementContent(displayPath) + "</a>";
if (webappVersion == null || webappVersion.isEmpty()) {
args[1] = noVersion;
} else {
args[1] = Escape.htmlElementContent(webappVersion);
}
if (ctxt.getDisplayName() == null) {
args[2] = " ";
} else {
args[2] = Escape.htmlElementContent(ctxt.getDisplayName());
}
args[3] = Boolean.valueOf(ctxt.getState().isAvailable());
args[4] = Escape.htmlElementContent(
response.encodeURL(getServletContext().getContextPath() + "/html/sessions?" + pathVersion));
Manager manager = ctxt.getManager();
if (manager instanceof DistributedManager && showProxySessions) {
args[5] = Integer.valueOf(((DistributedManager) manager).getActiveSessionsFull());
} else if (manager != null) {
args[5] = Integer.valueOf(manager.getActiveSessions());
} else {
args[5] = Integer.valueOf(0);
}
args[6] = highlightColor;
writer.print(MessageFormat.format(APPS_ROW_DETAILS_SECTION, args));
args = new Object[14];
args[0] = Escape.htmlElementContent(
response.encodeURL(request.getContextPath() + "/html/start?" + pathVersion));
args[1] = appsStart;
args[2] = Escape
.htmlElementContent(response.encodeURL(request.getContextPath() + "/html/stop?" + pathVersion));
args[3] = appsStop;
args[4] = Escape.htmlElementContent(
response.encodeURL(request.getContextPath() + "/html/reload?" + pathVersion));
args[5] = appsReload;
args[6] = Escape.htmlElementContent(
response.encodeURL(request.getContextPath() + "/html/undeploy?" + pathVersion));
args[7] = appsUndeploy;
args[8] = Escape.htmlElementContent(
response.encodeURL(request.getContextPath() + "/html/expire?" + pathVersion));
args[9] = appsExpire;
args[10] = smClient.getString("htmlManagerServlet.expire.explain");
if (manager == null) {
args[11] = smClient.getString("htmlManagerServlet.noManager");
} else {
args[11] = Integer.valueOf(ctxt.getSessionTimeout());
}
args[12] = smClient.getString("htmlManagerServlet.expire.unit");
args[13] = highlightColor;
if (ctxt.getName().equals(this.context.getName())) {
writer.print(MessageFormat.format(MANAGER_APP_ROW_BUTTON_SECTION, args));
} else if (ctxt.getState().isAvailable() && isDeployed) {
writer.print(MessageFormat.format(STARTED_DEPLOYED_APPS_ROW_BUTTON_SECTION, args));
} else if (ctxt.getState().isAvailable() && !isDeployed) {
writer.print(MessageFormat.format(STARTED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION, args));
} else if (!ctxt.getState().isAvailable() && isDeployed) {
writer.print(MessageFormat.format(STOPPED_DEPLOYED_APPS_ROW_BUTTON_SECTION, args));
} else {
writer.print(MessageFormat.format(STOPPED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION, args));
}
}
}
// Deploy Section
args = new Object[8];
args[0] = smClient.getString("htmlManagerServlet.deployTitle");
args[1] = smClient.getString("htmlManagerServlet.deployServer");
args[2] = response.encodeURL(getServletContext().getContextPath() + "/html/deploy");
args[3] = smClient.getString("htmlManagerServlet.deployPath");
args[4] = smClient.getString("htmlManagerServlet.deployVersion");
args[5] = smClient.getString("htmlManagerServlet.deployConfig");
args[6] = smClient.getString("htmlManagerServlet.deployWar");
args[7] = smClient.getString("htmlManagerServlet.deployButton");
writer.print(MessageFormat.format(DEPLOY_SECTION, args));
args = new Object[4];
args[0] = smClient.getString("htmlManagerServlet.deployUpload");
args[1] = response.encodeURL(getServletContext().getContextPath() + "/html/upload");
args[2] = smClient.getString("htmlManagerServlet.deployUploadFile");
args[3] = smClient.getString("htmlManagerServlet.deployButton");
writer.print(MessageFormat.format(UPLOAD_SECTION, args));
// Config section
args = new Object[5];
args[0] = smClient.getString("htmlManagerServlet.configTitle");
args[1] = smClient.getString("htmlManagerServlet.configSslReloadTitle");
args[2] = response.encodeURL(getServletContext().getContextPath() + "/html/sslReload");
args[3] = smClient.getString("htmlManagerServlet.configSslHostName");
args[4] = smClient.getString("htmlManagerServlet.configReloadButton");
writer.print(MessageFormat.format(CONFIG_SECTION, args));
// Diagnostics section
args = new Object[15];
args[0] = smClient.getString("htmlManagerServlet.diagnosticsTitle");
args[1] = smClient.getString("htmlManagerServlet.diagnosticsLeak");
args[2] = response.encodeURL(getServletContext().getContextPath() + "/html/findleaks");
args[3] = smClient.getString("htmlManagerServlet.diagnosticsLeakWarning");
args[4] = smClient.getString("htmlManagerServlet.diagnosticsLeakButton");
args[5] = smClient.getString("htmlManagerServlet.diagnosticsSsl");
args[6] = response.encodeURL(getServletContext().getContextPath() + "/html/sslConnectorCiphers");
args[7] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorCipherButton");
args[8] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorCipherText");
args[9] = response.encodeURL(getServletContext().getContextPath() + "/html/sslConnectorCerts");
args[10] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorCertsButton");
args[11] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorCertsText");
args[12] = response.encodeURL(getServletContext().getContextPath() + "/html/sslConnectorTrustedCerts");
args[13] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorTrustedCertsButton");
args[14] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorTrustedCertsText");
writer.print(MessageFormat.format(DIAGNOSTICS_SECTION, args));
// Server Header Section
args = new Object[9];
args[0] = smClient.getString("htmlManagerServlet.serverTitle");
args[1] = smClient.getString("htmlManagerServlet.serverVersion");
args[2] = smClient.getString("htmlManagerServlet.serverJVMVersion");
args[3] = smClient.getString("htmlManagerServlet.serverJVMVendor");
args[4] = smClient.getString("htmlManagerServlet.serverOSName");
args[5] = smClient.getString("htmlManagerServlet.serverOSVersion");
args[6] = smClient.getString("htmlManagerServlet.serverOSArch");
args[7] = smClient.getString("htmlManagerServlet.serverHostname");
args[8] = smClient.getString("htmlManagerServlet.serverIPAddress");
writer.print(MessageFormat.format(Constants.SERVER_HEADER_SECTION, args));
// Server Row Section
args = new Object[8];
args[0] = ServerInfo.getServerInfo();
args[1] = System.getProperty("java.runtime.version");
args[2] = System.getProperty("java.vm.vendor");
args[3] = System.getProperty("os.name");
args[4] = System.getProperty("os.version");
args[5] = System.getProperty("os.arch");
try {
InetAddress address = InetAddress.getLocalHost();
args[6] = address.getHostName();
args[7] = address.getHostAddress();
} catch (UnknownHostException e) {
args[6] = "-";
args[7] = "-";
}
writer.print(MessageFormat.format(Constants.SERVER_ROW_SECTION, args));
// HTML Tail Section
writer.print(Constants.HTML_TAIL_SECTION);
// Finish up the response
writer.flush();
writer.close();
}