1 17 18 19 package org.apache.catalina.manager.host; 20 21 import java.io.IOException ; 22 import java.io.PrintWriter ; 23 import java.io.StringWriter ; 24 import java.text.MessageFormat ; 25 import java.util.Iterator ; 26 import java.util.Map ; 27 import java.util.TreeMap ; 28 29 import javax.servlet.ServletException ; 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 33 import org.apache.catalina.Container; 34 import org.apache.catalina.Host; 35 import org.apache.catalina.util.ServerInfo; 36 37 59 60 public final class HTMLHostManagerServlet extends HostManagerServlet { 61 62 64 73 public void doGet(HttpServletRequest request, 74 HttpServletResponse response) 75 throws IOException , ServletException { 76 77 String command = request.getPathInfo(); 79 80 String name = request.getParameter("name"); 81 82 response.setContentType("text/html; charset=" + Constants.CHARSET); 84 85 String message = ""; 86 if (command == null) { 88 } else if (command.equals("/add")) { 89 message = add(request, name); 90 } else if (command.equals("/remove")) { 91 message = remove(name); 92 } else if (command.equals("/list")) { 93 } else if (command.equals("/start")) { 94 message = start(name); 95 } else if (command.equals("/stop")) { 96 message = stop(name); 97 } else { 98 message = 99 sm.getString("hostManagerServlet.unknownCommand", command); 100 } 101 102 list(request, response, message); 103 } 104 105 106 111 protected String add(HttpServletRequest request,String name) { 112 113 StringWriter stringWriter = new StringWriter (); 114 PrintWriter printWriter = new PrintWriter (stringWriter); 115 116 super.add(request,printWriter,name,true); 117 118 return stringWriter.toString(); 119 } 120 121 122 128 protected String remove(String name) { 129 130 StringWriter stringWriter = new StringWriter (); 131 PrintWriter printWriter = new PrintWriter (stringWriter); 132 133 super.remove(printWriter, name); 134 135 return stringWriter.toString(); 136 } 137 138 139 144 protected String start(String name) { 145 146 StringWriter stringWriter = new StringWriter (); 147 PrintWriter printWriter = new PrintWriter (stringWriter); 148 149 super.start(printWriter, name); 150 151 return stringWriter.toString(); 152 } 153 154 155 160 protected String stop(String name) { 161 162 StringWriter stringWriter = new StringWriter (); 163 PrintWriter printWriter = new PrintWriter (stringWriter); 164 165 super.stop(printWriter, name); 166 167 return stringWriter.toString(); 168 } 169 170 171 179 public void list(HttpServletRequest request, 180 HttpServletResponse response, 181 String message) throws IOException { 182 183 PrintWriter writer = response.getWriter(); 184 185 writer.print(Constants.HTML_HEADER_SECTION); 187 188 Object [] args = new Object [2]; 190 args[0] = request.getContextPath(); 191 args[1] = sm.getString("htmlHostManagerServlet.title"); 192 writer.print(MessageFormat.format 193 (Constants.BODY_HEADER_SECTION, args)); 194 195 args = new Object [3]; 197 args[0] = sm.getString("htmlHostManagerServlet.messageLabel"); 198 args[1] = (message == null || message.length() == 0) ? "OK" : message; 199 writer.print(MessageFormat.format(Constants.MESSAGE_SECTION, args)); 200 201 args = new Object [9]; 203 args[0] = sm.getString("htmlHostManagerServlet.manager"); 204 args[1] = response.encodeURL(request.getContextPath() + "/html/list"); 205 args[2] = sm.getString("htmlHostManagerServlet.list"); 206 args[3] = response.encodeURL 207 (request.getContextPath() + "/" + 208 sm.getString("htmlHostManagerServlet.helpHtmlManagerFile")); 209 args[4] = sm.getString("htmlHostManagerServlet.helpHtmlManager"); 210 args[5] = response.encodeURL 211 (request.getContextPath() + "/" + 212 sm.getString("htmlHostManagerServlet.helpManagerFile")); 213 args[6] = sm.getString("htmlHostManagerServlet.helpManager"); 214 args[7] = response.encodeURL("/manager/status"); 215 args[8] = sm.getString("statusServlet.title"); 216 writer.print(MessageFormat.format(Constants.MANAGER_SECTION, args)); 217 218 args = new Object [3]; 220 args[0] = sm.getString("htmlHostManagerServlet.hostName"); 221 args[1] = sm.getString("htmlHostManagerServlet.hostAliases"); 222 args[2] = sm.getString("htmlHostManagerServlet.hostTasks"); 223 writer.print(MessageFormat.format(HOSTS_HEADER_SECTION, args)); 224 225 Container[] children = engine.findChildren(); 228 String hostNames[] = new String [children.length]; 229 for (int i = 0; i < children.length; i++) 230 hostNames[i] = children[i].getName(); 231 232 TreeMap sortedHostNamesMap = new TreeMap (); 233 234 for (int i = 0; i < hostNames.length; i++) { 235 String displayPath = hostNames[i]; 236 sortedHostNamesMap.put(displayPath, hostNames[i]); 237 } 238 239 String hostsStart = sm.getString("htmlHostManagerServlet.hostsStart"); 240 String hostsStop = sm.getString("htmlHostManagerServlet.hostsStop"); 241 String hostsRemove = sm.getString("htmlHostManagerServlet.hostsRemove"); 242 243 Iterator iterator = sortedHostNamesMap.entrySet().iterator(); 244 while (iterator.hasNext()) { 245 Map.Entry entry = (Map.Entry ) iterator.next(); 246 String hostName = (String ) entry.getKey(); 247 Host host = (Host) engine.findChild(hostName); 248 249 if (host != null ) { 250 args = new Object [2]; 251 args[0] = hostName; 252 String [] aliases = host.findAliases(); 253 StringBuffer buf = new StringBuffer (); 254 if (aliases.length > 0) { 255 buf.append(aliases[0]); 256 for (int j = 1; j < aliases.length; j++) { 257 buf.append(", ").append(aliases[j]); 258 } 259 } 260 261 if (buf.length() == 0) { 262 buf.append(" "); 263 } 264 265 args[1] = buf.toString(); 266 writer.print 267 (MessageFormat.format(HOSTS_ROW_DETAILS_SECTION, args)); 268 269 args = new Object [7]; 270 args[0] = response.encodeURL 271 (request.getContextPath() + 272 "/html/start?name=" + hostName); 273 args[1] = hostsStart; 274 args[2] = response.encodeURL 275 (request.getContextPath() + 276 "/html/stop?name=" + hostName); 277 args[3] = hostsStop; 278 args[4] = response.encodeURL 279 (request.getContextPath() + 280 "/html/remove?name=" + hostName); 281 args[5] = hostsRemove; 282 args[6] = hostName; 283 if (host == this.host) { 284 writer.print(MessageFormat.format( 285 MANAGER_HOST_ROW_BUTTON_SECTION, args)); 286 } else { 287 writer.print(MessageFormat.format( 288 HOSTS_ROW_BUTTON_SECTION, args)); 289 } 290 291 } 292 } 293 294 args = new Object [6]; 296 args[0] = sm.getString("htmlHostManagerServlet.addTitle"); 297 args[1] = sm.getString("htmlHostManagerServlet.addHost"); 298 args[2] = response.encodeURL(request.getContextPath() + "/html/add"); 299 args[3] = sm.getString("htmlHostManagerServlet.addName"); 300 args[4] = sm.getString("htmlHostManagerServlet.addAliases"); 301 args[5] = sm.getString("htmlHostManagerServlet.addAppBase"); 302 writer.print(MessageFormat.format(ADD_SECTION_START, args)); 303 304 args = new Object [3]; 305 args[0] = sm.getString("htmlHostManagerServlet.addAutoDeploy"); 306 args[1] = "autoDeploy"; 307 args[2] = "checked"; 308 writer.print(MessageFormat.format(ADD_SECTION_BOOLEAN, args)); 309 args[0] = sm.getString("htmlHostManagerServlet.addDeployOnStartup"); 310 args[1] = "deployOnStartup"; 311 args[2] = "checked"; 312 writer.print(MessageFormat.format(ADD_SECTION_BOOLEAN, args)); 313 args[0] = sm.getString("htmlHostManagerServlet.addDeployXML"); 314 args[1] = "deployXML"; 315 args[2] = "checked"; 316 writer.print(MessageFormat.format(ADD_SECTION_BOOLEAN, args)); 317 args[0] = sm.getString("htmlHostManagerServlet.addUnpackWARs"); 318 args[1] = "unpackWARs"; 319 args[2] = "checked"; 320 writer.print(MessageFormat.format(ADD_SECTION_BOOLEAN, args)); 321 args[0] = sm.getString("htmlHostManagerServlet.addXmlNamespaceAware"); 322 args[1] = "xmlNamespaceAware"; 323 args[2] = ""; 324 writer.print(MessageFormat.format(ADD_SECTION_BOOLEAN, args)); 325 args[0] = sm.getString("htmlHostManagerServlet.addXmlValidation"); 326 args[1] = "xmlValidation"; 327 args[2] = ""; 328 writer.print(MessageFormat.format(ADD_SECTION_BOOLEAN, args)); 329 330 args[0] = sm.getString("htmlHostManagerServlet.addManager"); 331 args[1] = "manager"; 332 args[2] = "checked"; 333 writer.print(MessageFormat.format(ADD_SECTION_BOOLEAN, args)); 334 335 args = new Object [1]; 336 args[0] = sm.getString("htmlHostManagerServlet.addButton"); 337 writer.print(MessageFormat.format(ADD_SECTION_END, args)); 338 339 args = new Object [7]; 341 args[0] = sm.getString("htmlHostManagerServlet.serverTitle"); 342 args[1] = sm.getString("htmlHostManagerServlet.serverVersion"); 343 args[2] = sm.getString("htmlHostManagerServlet.serverJVMVersion"); 344 args[3] = sm.getString("htmlHostManagerServlet.serverJVMVendor"); 345 args[4] = sm.getString("htmlHostManagerServlet.serverOSName"); 346 args[5] = sm.getString("htmlHostManagerServlet.serverOSVersion"); 347 args[6] = sm.getString("htmlHostManagerServlet.serverOSArch"); 348 writer.print(MessageFormat.format 349 (Constants.SERVER_HEADER_SECTION, args)); 350 351 args = new Object [6]; 353 args[0] = ServerInfo.getServerInfo(); 354 args[1] = System.getProperty("java.runtime.version"); 355 args[2] = System.getProperty("java.vm.vendor"); 356 args[3] = System.getProperty("os.name"); 357 args[4] = System.getProperty("os.version"); 358 args[5] = System.getProperty("os.arch"); 359 writer.print(MessageFormat.format(Constants.SERVER_ROW_SECTION, args)); 360 361 writer.print(Constants.HTML_TAIL_SECTION); 363 364 writer.flush(); 366 writer.close(); 367 } 368 369 370 372 376 private static final String HOSTS_HEADER_SECTION = 377 "<table border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n" + 378 "<tr>\n" + 379 " <td colspan=\"5\" class=\"title\">{0}</td>\n" + 380 "</tr>\n" + 381 "<tr>\n" + 382 " <td class=\"header-left\"><small>{0}</small></td>\n" + 383 " <td class=\"header-center\"><small>{1}</small></td>\n" + 384 " <td class=\"header-center\"><small>{2}</small></td>\n" + 385 "</tr>\n"; 386 387 private static final String HOSTS_ROW_DETAILS_SECTION = 388 "<tr>\n" + 389 " <td class=\"row-left\"><small><a HREF=\"http://{0}\">{0}</a>" + 390 "</small></td>\n" + 391 " <td class=\"row-center\"><small>{1}</small></td>\n"; 392 393 private static final String MANAGER_HOST_ROW_BUTTON_SECTION = 394 " <td class=\"row-left\">\n" + 395 " <small>\n" + 396 " {1} \n" + 397 " {3} \n" + 398 " {5} \n" + 399 " </small>\n" + 400 " </td>\n" + 401 "</tr>\n"; 402 403 private static final String HOSTS_ROW_BUTTON_SECTION = 404 " <td class=\"row-left\" NOWRAP>\n" + 405 " <small>\n" + 406 " <a HREF=\"{0}\" onclick=\"return(confirm(''{1} {6}\\n\\nAre you sure?''))\">{1}</a> \n" + 407 " <a HREF=\"{2}\" onclick=\"return(confirm(''{3} {6}\\n\\nAre you sure?''))\">{3}</a> \n" + 408 " <a HREF=\"{4}\" onclick=\"return(confirm(''{5} {6}\\n\\nAre you sure?''))\">{5}</a> \n" + 409 " </small>\n" + 410 " </td>\n" + 411 "</tr>\n"; 412 413 private static final String ADD_SECTION_START = 414 "</table>\n" + 415 "<br>\n" + 416 "<table border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n" + 417 "<tr>\n" + 418 " <td colspan=\"2\" class=\"title\">{0}</td>\n" + 419 "</tr>\n" + 420 "<tr>\n" + 421 " <td colspan=\"2\" class=\"header-left\"><small>{1}</small></td>\n" + 422 "</tr>\n" + 423 "<tr>\n" + 424 " <td colspan=\"2\">\n" + 425 "<form method=\"get\" action=\"{2}\">\n" + 426 "<table cellspacing=\"0\" cellpadding=\"3\">\n" + 427 "<tr>\n" + 428 " <td class=\"row-right\">\n" + 429 " <small>{3}</small>\n" + 430 " </td>\n" + 431 " <td class=\"row-left\">\n" + 432 " <input type=\"text\" name=\"name\" size=\"20\">\n" + 433 " </td>\n" + 434 "</tr>\n" + 435 "<tr>\n" + 436 " <td class=\"row-right\">\n" + 437 " <small>{4}</small>\n" + 438 " </td>\n" + 439 " <td class=\"row-left\">\n" + 440 " <input type=\"text\" name=\"aliases\" size=\"64\">\n" + 441 " </td>\n" + 442 "</tr>\n" + 443 "<tr>\n" + 444 " <td class=\"row-right\">\n" + 445 " <small>{5}</small>\n" + 446 " </td>\n" + 447 " <td class=\"row-left\">\n" + 448 " <input type=\"text\" name=\"appBase\" size=\"64\">\n" + 449 " </td>\n" + 450 "</tr>\n" ; 451 452 private static final String ADD_SECTION_BOOLEAN = 453 "<tr>\n" + 454 " <td class=\"row-right\">\n" + 455 " <small>{0}</small>\n" + 456 " </td>\n" + 457 " <td class=\"row-left\">\n" + 458 " <input type=\"checkbox\" name=\"{1}\" {2}>\n" + 459 " </td>\n" + 460 "</tr>\n" ; 461 462 private static final String ADD_SECTION_END = 463 "<tr>\n" + 464 " <td class=\"row-right\">\n" + 465 " \n" + 466 " </td>\n" + 467 " <td class=\"row-left\">\n" + 468 " <input type=\"submit\" value=\"{0}\">\n" + 469 " </td>\n" + 470 "</tr>\n" + 471 "</table>\n" + 472 "</form>\n" + 473 "</td>\n" + 474 "</tr>\n" + 475 "</table>\n" + 476 "<br>\n" + 477 "\n"; 478 479 } 480 | Popular Tags |