Index: HTMLManagerServlet.java =================================================================== RCS file: /home/cvspublic/jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/HTMLManagerServlet.java,v retrieving revision 1.9 diff -u -r1.9 HTMLManagerServlet.java --- HTMLManagerServlet.java 3 Nov 2003 22:01:38 -0000 1.9 +++ HTMLManagerServlet.java 12 Jan 2004 04:44:59 -0000 @@ -1,5 +1,5 @@ /* -* $Header: /home/cvspublic/jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/HTMLManagerServlet.java,v 1.9 2003/11/03 22:01:38 remm Exp $ +* $Header: /home/cvs/jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/HTMLManagerServlet.java,v 1.9 2003/11/03 22:01:38 remm Exp $ * $Revision: 1.9 $ * $Date: 2003/11/03 22:01:38 $ * @@ -80,6 +80,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.catalina.Context; +import org.apache.catalina.Deployer; import org.apache.catalina.Host; import org.apache.catalina.util.ServerInfo; import org.apache.commons.fileupload.FileItem; @@ -98,23 +99,25 @@ * makes it easier to administrate. *

* However if you use a software that parses the output of -* ManagerServletManagerServlet you won't be able to upgrade * to this Servlet since the output are not in the * same format ar from ManagerServlet * * @author Bip Thelin * @author Malcolm Edgar * @author Glenn L. Nielsen +* @author TANAKA Yoshihiro * @version $Revision: 1.9 $, $Date: 2003/11/03 22:01:38 $ * @see ManagerServlet */ -public final class HTMLManagerServlet extends ManagerServlet { +public class HTMLManagerServlet extends ManagerServlet { // --------------------------------------------------------- Public Methods /** - * Process a GET request for the specified resource. + * Process a GET request for the specified resource + * using the localhost deployer. * * @param request The servlet request we are processing * @param response The servlet response we are creating @@ -125,6 +128,24 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + doGet(super.deployer, request, response); + } + + /** + * Process a GET request for the specified resource + * using the specified deployer. + * + * @param deployer Deployer of the virtual host + * @param request The servlet request we are processing + * @param response The servlet response we are creating + * + * @exception IOException if an input/output error occurs + * @exception ServletException if a servlet-specified error occurs + */ + protected void doGet(Deployer deployer, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException { // Identify the request parameters that we need String command = request.getPathInfo(); @@ -141,28 +162,29 @@ // Process the requested command if (command == null || command.equals("/")) { } else if (command.equals("/deploy")) { - message = deployInternal(deployConfig, deployPath, deployWar); + message = deployInternal(deployer, deployConfig, deployPath, deployWar); } else if (command.equals("/list")) { } else if (command.equals("/reload")) { - message = reload(path); + message = reload(deployer, path); } else if (command.equals("/undeploy")) { - message = undeploy(path); + message = undeploy(deployer, path); } else if (command.equals("/sessions")) { - message = sessions(path); + message = sessions(deployer, path); } else if (command.equals("/start")) { - message = start(path); + message = start(deployer, path); } else if (command.equals("/stop")) { - message = stop(path); + message = stop(deployer, path); } else { message = sm.getString("managerServlet.unknownCommand", command); } - list(request, response, message); + list(deployer, request, response, message); } /** - * Process a POST request for the specified resource. + * Process a POST request for the specified resource + * using the localhost deployer. * * @param request The servlet request we are processing * @param response The servlet response we are creating @@ -171,7 +193,25 @@ * @exception ServletException if a servlet-specified error occurs */ public void doPost(HttpServletRequest request, - HttpServletResponse response) + HttpServletResponse response) + throws IOException, ServletException { + doPost(super.deployer, request, response); + } + + /** + * Process a POST request for the specified resource + * using the specified deployer. + * + * @param deployer Deployer of the virtual host + * @param request The servlet request we are processing + * @param response The servlet response we are creating + * + * @exception IOException if an input/output error occurs + * @exception ServletException if a servlet-specified error occurs + */ + protected void doPost(Deployer deployer, + HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { // Identify the request parameters that we need @@ -241,7 +281,7 @@ // Identify the appBase of the owning Host of this Context // (if any) String appBase = null; - appBase = ((Host) context.getParent()).getAppBase(); + appBase = ((Host)deployer).getAppBase(); appBaseDir = new File(appBase); if (!appBaseDir.isAbsolute()) { appBaseDir = new File(System.getProperty("catalina.base"), @@ -249,6 +289,7 @@ } basename = war.substring(0, war.indexOf(".war")); File file = new File(appBaseDir, war); + log("war file: '" + file.getCanonicalPath() + "'"); if (file.exists()) { message = sm.getString ("htmlManagerServlet.deployUploadWarExists",war); @@ -297,15 +338,15 @@ // If there were no errors, deploy the WAR if (message.length() == 0) { - message = deployInternal(config, null, war); + message = deployInternal(deployer, config, null, war); } - list(request, response, message); + list(deployer, request, response, message); } /** * Deploy an application for the specified path from the specified - * web application archive. + * web application archive using the localhost deployer. * * @param config URL of the context configuration file to be deployed * @param path Context path of the application to be deployed @@ -313,23 +354,52 @@ * @return message String */ protected String deployInternal(String config, String path, String war) { + return deployInternal(super.deployer, config, path, war); + } + + /** + * Deploy an application for the specified path from the specified + * web application archive using the specified deployer. + * + * @param deployer Deployer of the virtual host + * @param config URL of the context configuration file to be deployed + * @param path Context path of the application to be deployed + * @param war URL of the web application archive to be deployed + * @return message String + */ + protected String deployInternal(Deployer deployer, String config, String path, String war) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.deploy(printWriter, config, path, war, false); + super.deploy(deployer, printWriter, config, path, war, false); return stringWriter.toString(); } /** * Render a HTML list of the currently active Contexts in our virtual host, - * and memory and server status information. + * and memory and server status information using the localhost deployer. * * @param writer Writer to render to * @param message a message to display */ - public void list(HttpServletRequest request, + protected void list(HttpServletRequest request, + HttpServletResponse response, + String message) throws IOException { + list(super.deployer, request, response, message); + } + + /** + * Render a HTML list of the currently active Contexts in our virtual host, + * and memory and server status information using the specified deployer. + * + * @param deployer Deployer of the virtual host + * @param writer Writer to render to + * @param message a message to display + */ + protected void list(Deployer deployer, + HttpServletRequest request, HttpServletResponse response, String message) throws IOException { @@ -337,6 +407,7 @@ log("list: Listing contexts for virtual host '" + deployer.getName() + "'"); + String servletPath = request.getServletPath(); PrintWriter writer = response.getWriter(); // HTML Header Section @@ -358,7 +429,7 @@ // Manager Section args = new Object[9]; args[0] = sm.getString("htmlManagerServlet.manager"); - args[1] = response.encodeURL(request.getContextPath() + "/html/list"); + args[1] = response.encodeURL(request.getContextPath() + servletPath + "/list"); args[2] = sm.getString("htmlManagerServlet.list"); args[3] = response.encodeURL (request.getContextPath() + "/" + @@ -419,7 +490,7 @@ args[2] = new Boolean(context.getAvailable()); args[3] = response.encodeURL (request.getContextPath() + - "/html/sessions?path=" + displayPath); + servletPath + "/sessions?path=" + displayPath); if (context.getManager() != null) { args[4] = new Integer (context.getManager().findSessions().length); @@ -432,19 +503,19 @@ args = new Object[8]; args[0] = response.encodeURL (request.getContextPath() + - "/html/start?path=" + displayPath); + servletPath + "/start?path=" + displayPath); args[1] = appsStart; args[2] = response.encodeURL (request.getContextPath() + - "/html/stop?path=" + displayPath); + servletPath + "/stop?path=" + displayPath); args[3] = appsStop; args[4] = response.encodeURL (request.getContextPath() + - "/html/reload?path=" + displayPath); + servletPath + "/reload?path=" + displayPath); args[5] = appsReload; args[6] = response.encodeURL (request.getContextPath() + - "/html/undeploy?path=" + displayPath); + servletPath + "/undeploy?path=" + displayPath); args[7] = appsUndeploy; if (context.getPath().equals(this.context.getPath())) { writer.print(MessageFormat.format( @@ -464,7 +535,7 @@ args = new Object[7]; args[0] = sm.getString("htmlManagerServlet.deployTitle"); args[1] = sm.getString("htmlManagerServlet.deployServer"); - args[2] = response.encodeURL(request.getContextPath() + "/html/deploy"); + args[2] = response.encodeURL(request.getContextPath() + servletPath + "/deploy"); args[3] = sm.getString("htmlManagerServlet.deployPath"); args[4] = sm.getString("htmlManagerServlet.deployConfig"); args[5] = sm.getString("htmlManagerServlet.deployWar"); @@ -473,7 +544,7 @@ args = new Object[4]; args[0] = sm.getString("htmlManagerServlet.deployUpload"); - args[1] = response.encodeURL(request.getContextPath() + "/html/upload"); + args[1] = response.encodeURL(request.getContextPath() + servletPath + "/upload"); args[2] = sm.getString("htmlManagerServlet.deployUploadFile"); args[3] = sm.getString("htmlManagerServlet.deployButton"); writer.print(MessageFormat.format(UPLOAD_SECTION, args)); @@ -508,8 +579,10 @@ writer.close(); } + /** - * Reload the web application at the specified context path. + * Reload the web application at the specified context path + * using the localhost deployer. * * @see ManagerServlet#reload(PrintWriter, String) * @@ -517,83 +590,153 @@ * @return message String */ protected String reload(String path) { + return reload(super.deployer, path); + } + /** + * Reload the web application at the specified context path + * using the specified deployer. + * + * @see ManagerServlet#reload(PrintWriter, String) + * + * @param deployer Deployer of the virtual host + * @param path Context path of the application to be restarted + * @return message String + */ + protected String reload(Deployer deployer, String path) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.reload(printWriter, path); + super.reload(deployer, printWriter, path); return stringWriter.toString(); } /** * Undeploy the web application at the specified context path. + * using the localhost deployer. * - * @see ManagerServlet#undeploy(PrintWriter, String) + * @see ManagerServlet#undeploy(Deployer, PrintWriter, String) * * @param path Context path of the application to be undeployd * @return message String */ protected String undeploy(String path) { + return undeploy(super.deployer, path); + } + /** + * Undeploy the web application at the specified context path + * using the specified deployer. + * + * @see ManagerServlet#undeploy(Deployer, PrintWriter, String) + * + * @param deployer Deployer of the virtual host + * @param path Context path of the application to be undeployd + * @return message String + */ + protected String undeploy(Deployer deployer, String path) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.undeploy(printWriter, path); + super.undeploy(deployer, printWriter, path); return stringWriter.toString(); } /** - * Display session information and invoke list. + * Display session information and invoke list + * using the localhost deployer. + * + * @see ManagerServlet#sessions(Deployer, PrintWriter, String) + * + * @param path Context path of the application to list session information + * @return message String + */ + protected String sessions(String path) { + return sessions(super.deployer, path); + } + + /** + * Display session information and invoke list + * using the specified deployer. * - * @see ManagerServlet#sessions(PrintWriter, String) + * @see ManagerServlet#sessions(Deployer, PrintWriter, String) * + * @param deployer Deployer of the virtual host * @param path Context path of the application to list session information * @return message String */ - public String sessions(String path) { + protected String sessions(Deployer deployer, String path) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.sessions(printWriter, path); + super.sessions(deployer, printWriter, path); return stringWriter.toString(); } /** - * Start the web application at the specified context path. + * Start the web application at the specified context path + * using the localhost deployer. * - * @see ManagerServlet#start(PrintWriter, String) + * @see ManagerServlet#start(Deployer, PrintWriter, String) * * @param path Context path of the application to be started * @return message String */ - public String start(String path) { + protected String start(String path) { + return start(super.deployer, path); + } + /** + * Start the web application at the specified context path + * using the specified deployer. + * + * @see ManagerServlet#start(Deployer, PrintWriter, String) + * + * @param deployer Deployer of the virtual host + * @param path Context path of the application to be started + * @return message String + */ + protected String start(Deployer deployer, String path) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.start(printWriter, path); + super.start(deployer, printWriter, path); return stringWriter.toString(); } /** - * Stop the web application at the specified context path. + * Stop the web application at the specified context path + * using the localhost deployer. * - * @see ManagerServlet#stop(PrintWriter, String) + * @see ManagerServlet#stop(Deployer, PrintWriter, String) * * @param path Context path of the application to be stopped * @return message String */ protected String stop(String path) { + return stop(super.deployer, path); + } + /** + * Stop the web application at the specified context path + * using the specified deployer. + * + * @see ManagerServlet#stop(Deployer, PrintWriter, String) + * + * @param deployer Deployer of the virtual host + * @param path Context path of the application to be stopped + * @return message String + */ + protected String stop(Deployer deployer, String path) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.stop(printWriter, path); + super.stop(deployer, printWriter, path); return stringWriter.toString(); } @@ -604,7 +747,7 @@ // limited number of subsitutions MessageFormat can process // (maximium of 10). - private static final String APPS_HEADER_SECTION = + protected static final String APPS_HEADER_SECTION = "\n" + "\n" + " \n" + @@ -617,7 +760,7 @@ " \n" + "\n"; - private static final String APPS_ROW_DETAILS_SECTION = + protected static final String APPS_ROW_DETAILS_SECTION = "\n" + " \n" + @@ -626,7 +769,7 @@ " \n"; - private static final String MANAGER_APP_ROW_BUTTON_SECTION = + protected static final String MANAGER_APP_ROW_BUTTON_SECTION = " \n" + "\n"; - private static final String STARTED_APPS_ROW_BUTTON_SECTION = + protected static final String STARTED_APPS_ROW_BUTTON_SECTION = " \n" + "\n"; - private static final String STOPPED_APPS_ROW_BUTTON_SECTION = + protected static final String STOPPED_APPS_ROW_BUTTON_SECTION = " \n" + "\n"; - private static final String DEPLOY_SECTION = + protected static final String DEPLOY_SECTION = "
{0}{5}
{0}" + "" + "{4}\n" + " \n" + "  {1} \n" + @@ -637,7 +780,7 @@ "
\n" + " \n" + "  {1} \n" + @@ -648,7 +791,7 @@ "
\n" + " \n" + "  {1} \n" + @@ -659,7 +802,7 @@ "
\n" + "
\n" + "\n" + @@ -710,7 +853,7 @@ "\n" + "\n"; - private static final String UPLOAD_SECTION = + protected static final String UPLOAD_SECTION = "\n" + " \n" + "\n" +
{0}