Index: ManagerServlet.java =================================================================== RCS file: /home/cvspublic/jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/ManagerServlet.java,v retrieving revision 1.13 diff -u -r1.13 ManagerServlet.java --- ManagerServlet.java 29 Nov 2003 08:33:48 -0000 1.13 +++ ManagerServlet.java 12 Jan 2004 04:44:29 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/ManagerServlet.java,v 1.13 2003/11/29 08:33:48 remm Exp $ + * $Header: /home/cvs/jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/ManagerServlet.java,v 1.13 2003/11/29 08:33:48 remm Exp $ * $Revision: 1.13 $ * $Date: 2003/11/29 08:33:48 $ * @@ -201,6 +201,7 @@ * * @author Craig R. McClanahan * @author Remy Maucherat + * @author TANAKA Yoshihiro * @version $Revision: 1.13 $ $Date: 2003/11/29 08:33:48 $ */ @@ -208,6 +209,12 @@ extends HttpServlet implements ContainerServlet { + /** + * The attribute name of virtual host [host]. + */ + public static final String VIRTUAL_HOST = "host"; + + // ----------------------------------------------------- Instance Variables @@ -323,7 +330,8 @@ /** - * 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 @@ -334,6 +342,24 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + doGet(this.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 { // Verify that we were not accessed using the invoker servlet if (request.getAttribute(Globals.INVOKED_ATTR) != null) @@ -364,36 +390,36 @@ writer.println(sm.getString("managerServlet.noCommand")); } else if (command.equals("/deploy")) { if (war != null) { - deploy(writer, config, path, war, update); + deploy(deployer, writer, config, path, war, update); } else { - deploy(writer, path, tag); + deploy(deployer, writer, path, tag); } } else if (command.equals("/install")) { // Deprecated - deploy(writer, config, path, war, false); + deploy(deployer, writer, config, path, war, false); } else if (command.equals("/list")) { - list(writer); + list(deployer, writer); } else if (command.equals("/reload")) { - reload(writer, path); + reload(deployer, writer, path); } else if (command.equals("/remove")) { // Deprecated - remove(writer, path); + remove(deployer, writer, path); } else if (command.equals("/resources")) { resources(writer, type); } else if (command.equals("/roles")) { roles(writer); } else if (command.equals("/save")) { - save(writer, path); + save(deployer, writer, path); } else if (command.equals("/serverinfo")) { serverinfo(writer); } else if (command.equals("/sessions")) { - sessions(writer, path); + sessions(deployer, writer, path); } else if (command.equals("/start")) { - start(writer, path); + start(deployer, writer, path); } else if (command.equals("/stop")) { - stop(writer, path); + stop(deployer, writer, path); } else if (command.equals("/undeploy")) { - undeploy(writer, path); + undeploy(deployer, writer, path); } else { writer.println(sm.getString("managerServlet.unknownCommand", command)); @@ -407,7 +433,8 @@ /** - * Process a PUT request for the specified resource. + * Process a PUT 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 @@ -418,6 +445,24 @@ public void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + doPut(this.deployer, request, response); + } + + /** + * Process a PUT 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 doPut(Deployer deployer, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException { // Verify that we were not accessed using the invoker servlet if (request.getAttribute(Globals.INVOKED_ATTR) != null) @@ -444,7 +489,7 @@ if (command == null) { writer.println(sm.getString("managerServlet.noCommand")); } else if (command.equals("/deploy")) { - deploy(writer, path, tag, update, request); + deploy(deployer, writer, path, tag, update, request); } else { writer.println(sm.getString("managerServlet.unknownCommand", command)); @@ -538,11 +583,47 @@ /** - * Store server configuration. + * Find a Deployer for the specified virtual host. + * If null is specified, return default localhost deployer. + * + * @param host The virtual host + * @return A deployer for the specified virtual host + */ + protected Deployer getDeployer(String host) { + Deployer deployer = null; + Container[] hosts = context.getParent().getParent().findChildren(); + if (host != null) { + // find host + for (int i = 0; i < hosts.length; i++) { + if (host.equals(hosts[i].getName())) { + deployer = (Deployer)hosts[i]; + break; + } + } + } else { + deployer = this.deployer; + } + + return deployer; + } + + + /** + * Store server configuration using the localhost deployer. * * @param path Optional context path to save */ protected synchronized void save(PrintWriter writer, String path) { + save(this.deployer, writer, path); + } + + /** + * Store server configuration using the specified deployer. + * + * @param deployer Deployer of the virtual host + * @param path Optional context path to save + */ + protected synchronized void save(Deployer deployer, PrintWriter writer, String path) { Server server = ServerFactory.getServer(); @@ -588,7 +669,7 @@ /** * Deploy a web application archive (included in the current request) - * at the specified context path. + * at the specified context path using the localhost deployer. * * @param writer Writer to render results to * @param path Context path of the application to be installed @@ -598,6 +679,22 @@ protected synchronized void deploy (PrintWriter writer, String path, String tag, boolean update, HttpServletRequest request) { + deploy(this.deployer, writer, path, tag, update, request); + } + + /** + * Deploy a web application archive (included in the current request) + * at the specified context path using the specified deployer. + * + * @param deployer Deployer of the virtual host + * @param writer Writer to render results to + * @param path Context path of the application to be installed + * @param tag Tag to be associated with the webapp + * @param request Servlet request we are processing + */ + protected synchronized void deploy + (Deployer deployer, PrintWriter writer, String path, + String tag, boolean update, HttpServletRequest request) { if (debug >= 1) { log("deploy: Deploying web application at '" + path + "'"); @@ -617,7 +714,7 @@ Context context = deployer.findDeployedApp(path); if (update) { if (context != null) { - undeploy(writer, path); + undeploy(deployer, writer, path); } context = deployer.findDeployedApp(path); } @@ -629,6 +726,13 @@ } // Calculate the base path + String appBase = ((Host)deployer).getAppBase(); + deployed = new File(appBase); + log("appBase: Deploying web application to '" + appBase + "'"); + if (!deployed.isAbsolute()) { + deployed = new File(System.getProperty("catalina.base"), + appBase); + } File deployedPath = deployed; if (tag != null) { deployedPath = new File(versioned, tag); @@ -696,20 +800,33 @@ } // Deploy this web application - deploy(writer, config, path, war, update); + deploy(deployer, writer, config, path, war, update); } /** * Install an application for the specified path from the specified - * web application archive. + * web application archive using the localhost deployer. * * @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) { + deploy(this.deployer, writer, path, tag); + } + + /** + * Install an application for the specified path from the specified + * web application archive using the specified deployer. + * + * @param deployer Deployer of the virtual host + * @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(Deployer deployer, PrintWriter writer, String path, String tag) { // Validate the requested context path if ((path == null) || path.length() == 0 || !path.startsWith("/")) { @@ -735,7 +852,7 @@ // Check if app already exists, or undeploy it if updating Context context = deployer.findDeployedApp(path); if (context != null) { - undeploy(writer, path); + undeploy(deployer, writer, path); } // Copy WAR and XML to the host base @@ -779,14 +896,14 @@ } // Deploy webapp - deploy(writer, config, path, war, false); + deploy(deployer, writer, config, path, war, false); } /** * Install an application for the specified path from the specified - * web application archive. + * web application archive using the localhost deployer. * * @param writer Writer to render results to * @param config URL of the context configuration file to be installed @@ -796,6 +913,23 @@ */ protected void deploy(PrintWriter writer, String config, String path, String war, boolean update) { + deploy(this.deployer, writer, config, path, war, update); + } + + + /** + * Install an application for the specified path from the specified + * web application archive using the specified deployer. + * + * @param deployer Deployer of the virtual host + * @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(Deployer deployer, PrintWriter writer, String config, + String path, String war, boolean update) { if (war != null && war.length() == 0) { war = null; @@ -822,7 +956,7 @@ String appBase = null; File appBaseDir = null; if (context.getParent() instanceof Host) { - appBase = ((Host) context.getParent()).getAppBase(); + appBase = ((Host)deployer).getAppBase(); appBaseDir = new File(appBase); if (!appBaseDir.isAbsolute()) { appBaseDir = new File(System.getProperty("catalina.base"), @@ -912,7 +1046,7 @@ Context context = deployer.findDeployedApp(path); if (update) { if (context != null) { - undeploy(writer, path); + undeploy(deployer, writer, path); } context = deployer.findDeployedApp(path); } @@ -939,11 +1073,21 @@ /** - * Render a list of the currently active Contexts in our virtual host. + * Render a list of the currently active Contexts in the localhost. * * @param writer Writer to render to */ protected void list(PrintWriter writer) { + list(this.deployer, writer); + } + + /** + * Render a list of the currently active Contexts in the specified virtual host. + * + * @param deployer Deployer of the virtual host + * @param writer Writer to render to + */ + protected void list(Deployer deployer, PrintWriter writer) { if (debug >= 1) log("list: Listing contexts for virtual host '" + @@ -977,12 +1121,25 @@ /** - * Reload the web application at the specified context path. + * Reload the web application at the specified context path + * using the localhost deployer. * * @param writer Writer to render to * @param path Context path of the application to be restarted */ protected void reload(PrintWriter writer, String path) { + reload(this.deployer, writer, path); + } + + /** + * Reload the web application at the specified context path + * using the specified deployer. + * + * @param deployer Deployer of the virtual host + * @param writer Writer to render to + * @param path Context path of the application to be restarted + */ + protected void reload(Deployer deployer, PrintWriter writer, String path) { if (debug >= 1) log("restart: Reloading web application at '" + path + "'"); @@ -1029,13 +1186,27 @@ /** - * Remove the web application at the specified context path. + * Remove the web application at the specified context path + * using the localhost deployer. * * @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) { + remove(this.deployer, writer, path); + } + + /** + * Remove the web application at the specified context path + * using the specified deployer. + * + * @param deployer Deployer of the virtual host + * @param writer Writer to render to + * @param path Context path of the application to be removed + * @deprecated Replaced by undeploy + */ + protected void remove(Deployer deployer, PrintWriter writer, String path) { if (debug >= 1) log("remove: Removing web application at '" + path + "'"); @@ -1233,7 +1404,8 @@ } /** - * Session information for the web application at the specified context path. + * Session information for the web application at the specified context path + * using the localhost deployer. * Displays a profile of session MaxInactiveInterval timeouts listing number * of sessions for each 10 minute timeout interval up to 10 hours. * @@ -1241,6 +1413,20 @@ * @param path Context path of the application to list session information for */ protected void sessions(PrintWriter writer, String path) { + sessions(this.deployer, writer, path); + } + + /** + * Session information for the web application at the specified context path + * using the specified deployer. + * Displays a profile of session MaxInactiveInterval timeouts listing number + * of sessions for each 10 minute timeout interval up to 10 hours. + * + * @param deployer Deployer of the virtual host + * @param writer Writer to render to + * @param path Context path of the application to list session information for + */ + protected void sessions(Deployer deployer, PrintWriter writer, String path) { if (debug >= 1) log("sessions: Session information for web application at '" + path + "'"); @@ -1299,12 +1485,25 @@ /** - * Start the web application at the specified context path. + * Start the web application at the specified context path + * using the localhost deployer. * * @param writer Writer to render to * @param path Context path of the application to be started */ protected void start(PrintWriter writer, String path) { + start(this.deployer, writer, path); + } + + /** + * Start the web application at the specified context path + * using the specified deployer. + * + * @param deployer Deployer of the virtual host + * @param writer Writer to render to + * @param path Context path of the application to be started + */ + protected void start(Deployer deployer, PrintWriter writer, String path) { if (debug >= 1) log("start: Starting web application at '" + path + "'"); @@ -1344,12 +1543,25 @@ /** - * Stop the web application at the specified context path. + * Stop the web application at the specified context path + * using the localhost deployer. * * @param writer Writer to render to * @param path Context path of the application to be stopped */ protected void stop(PrintWriter writer, String path) { + stop(this.deployer, writer, path); + } + + /** + * Stop the web application at the specified context path + * using the specified deployer. + * + * @param deployer Deployer of the virtual host + * @param writer Writer to render to + * @param path Context path of the application to be stopped + */ + protected void stop(Deployer deployer, PrintWriter writer, String path) { if (debug >= 1) log("stop: Stopping web application at '" + path + "'"); @@ -1386,12 +1598,25 @@ /** - * Undeploy the web application at the specified context path. + * Undeploy the web application at the specified context path + * using the localhost deployer. * * @param writer Writer to render to * @param path Context path of the application to be removed */ protected void undeploy(PrintWriter writer, String path) { + undeploy(this.deployer, writer, path); + } + + /** + * Undeploy the web application at the specified context path. + * using the specified deployer. + * + * @param deployer Deployer of the virtual host + * @param writer Writer to render to + * @param path Context path of the application to be removed + */ + protected void undeploy(Deployer deployer, PrintWriter writer, String path) { if (debug >= 1) log("undeploy: Undeploying web application at '" + path + "'"); @@ -1418,7 +1643,7 @@ String appBase = null; File appBaseDir = null; if (context.getParent() instanceof Host) { - appBase = ((Host) context.getParent()).getAppBase(); + appBase = ((Host)deployer).getAppBase(); appBaseDir = new File(appBase); if (!appBaseDir.isAbsolute()) { appBaseDir = new File(System.getProperty("catalina.base"),