remm 2003/06/15 11:31:45 Modified: webapps/manager/WEB-INF/classes/org/apache/catalina/manager HTMLManagerServlet.java LocalStrings.properties ManagerServlet.java Log: - Update the manager to implement the new functionality as described in the docs. - Pausing won't be implemented, due to difficulties, and the likelihood of bringing the whole server to its knees (thanks to Glenn for poiting that out). - Versioning is not tested yet. - Known issue: locking occurs on an uploaded WAR, for reasons which elude me right now. - Known issue 2: to deploy local WARs, a jar:file: URL must be used. Revision Changes Path 1.3 +53 -50 jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/HTMLManagerServlet.java Index: HTMLManagerServlet.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/HTMLManagerServlet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HTMLManagerServlet.java 4 Jun 2003 07:58:58 -0000 1.2 +++ HTMLManagerServlet.java 15 Jun 2003 18:31:45 -0000 1.3 @@ -88,7 +88,7 @@ import org.apache.commons.fileupload.FileUploadException; /** -* Servlet that enables remote management of the web applications installed +* Servlet that enables remote management of the web applications deployed * within the same virtual host as this web application is. Normally, this * functionality will be protected by a security constraint in the web * application deployment descriptor. However, this requirement can be @@ -131,9 +131,9 @@ String command = request.getPathInfo(); String path = request.getParameter("path"); - String installPath = request.getParameter("installPath"); - String installConfig = request.getParameter("installConfig"); - String installWar = request.getParameter("installWar"); + String deployPath = request.getParameter("deployPath"); + String deployConfig = request.getParameter("deployConfig"); + String deployWar = request.getParameter("deployWar"); // Prepare our output writer to generate the response message Locale locale = Locale.getDefault(); @@ -144,13 +144,13 @@ String message = ""; // Process the requested command if (command == null || command.equals("/")) { - } else if (command.equals("/install")) { - message = install(installConfig, installPath, installWar); + } else if (command.equals("/deploy")) { + message = deployInternal(deployConfig, deployPath, deployWar); } else if (command.equals("/list")) { } else if (command.equals("/reload")) { message = reload(path); - } else if (command.equals("/remove")) { - message = remove(path); + } else if (command.equals("/undeploy")) { + message = undeploy(path); } else if (command.equals("/sessions")) { message = sessions(path); } else if (command.equals("/start")) { @@ -216,7 +216,7 @@ FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { - if (item.getFieldName().equals("installWar") && + if (item.getFieldName().equals("deployWar") && warUpload == null) { warUpload = item; } else { @@ -227,13 +227,13 @@ while(true) { if (warUpload == null) { message = sm.getString - ("htmlManagerServlet.installUploadNoFile"); + ("htmlManagerServlet.deployUploadNoFile"); break; } war = warUpload.getName(); if (!war.toLowerCase().endsWith(".war")) { message = sm.getString - ("htmlManagerServlet.installUploadNotWar",war); + ("htmlManagerServlet.deployUploadNotWar",war); break; } // Get the filename if uploaded name includes a path @@ -256,10 +256,12 @@ File file = new File(appBaseDir,war); if (file.exists()) { message = sm.getString - ("htmlManagerServlet.installUploadWarExists",war); + ("htmlManagerServlet.deployUploadWarExists",war); break; } warUpload.write(file); + war = file.getAbsolutePath(); + /* try { URL url = file.toURL(); war = url.toString(); @@ -268,11 +270,12 @@ file.delete(); throw e; } + */ break; } } catch(Exception e) { message = sm.getString - ("htmlManagerServlet.installUploadFail", e.getMessage()); + ("htmlManagerServlet.deployUploadFail", e.getMessage()); log(message, e); } finally { if (warUpload != null) { @@ -281,29 +284,29 @@ warUpload = null; } - // If there were no errors, install the WAR + // If there were no errors, deploy the WAR if (message.length() == 0) { - message = install(null, null, war); + message = deployInternal(null, null, war); } list(request, response, message); } /** - * Install an application for the specified path from the specified + * Deploy an application for the specified path from the specified * web application archive. * - * @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 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 install(String config, String path, String war) { + protected String deployInternal(String config, String path, String war) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.install(printWriter, config, path, war); + super.deploy(printWriter, config, path, war, false); return stringWriter.toString(); } @@ -379,7 +382,7 @@ String appsStart = sm.getString("htmlManagerServlet.appsStart"); String appsStop = sm.getString("htmlManagerServlet.appsStop"); String appsReload = sm.getString("htmlManagerServlet.appsReload"); - String appsRemove = sm.getString("htmlManagerServlet.appsRemove"); + String appsUndeploy = sm.getString("htmlManagerServlet.appsUndeploy"); Iterator iterator = sortedContextPathsMap.entrySet().iterator(); while (iterator.hasNext()) { @@ -422,8 +425,8 @@ args[5] = appsReload; args[6] = response.encodeURL (request.getContextPath() + - "/html/remove?path=" + displayPath); - args[7] = appsRemove; + "/html/undeploy?path=" + displayPath); + args[7] = appsUndeploy; if (context.getPath().equals(this.context.getPath())) { writer.print(MessageFormat.format( MANAGER_APP_ROW_BUTTON_SECTION, args)); @@ -438,22 +441,22 @@ } } - // Install Section + // Deploy Section args = new Object[7]; - args[0] = sm.getString("htmlManagerServlet.installTitle"); - args[1] = sm.getString("htmlManagerServlet.installServer"); - args[2] = response.encodeURL(request.getContextPath() + "/html/install"); - args[3] = sm.getString("htmlManagerServlet.installPath"); - args[4] = sm.getString("htmlManagerServlet.installConfig"); - args[5] = sm.getString("htmlManagerServlet.installWar"); - args[6] = sm.getString("htmlManagerServlet.installButton"); - writer.print(MessageFormat.format(INSTALL_SECTION, args)); + args[0] = sm.getString("htmlManagerServlet.deployTitle"); + args[1] = sm.getString("htmlManagerServlet.deployServer"); + args[2] = response.encodeURL(request.getContextPath() + "/html/deploy"); + args[3] = sm.getString("htmlManagerServlet.deployPath"); + args[4] = sm.getString("htmlManagerServlet.deployConfig"); + args[5] = sm.getString("htmlManagerServlet.deployWar"); + args[6] = sm.getString("htmlManagerServlet.deployButton"); + writer.print(MessageFormat.format(DEPLOY_SECTION, args)); args = new Object[4]; - args[0] = sm.getString("htmlManagerServlet.installUpload"); + args[0] = sm.getString("htmlManagerServlet.deployUpload"); args[1] = response.encodeURL(request.getContextPath() + "/html/upload"); - args[2] = sm.getString("htmlManagerServlet.installUploadFile"); - args[3] = sm.getString("htmlManagerServlet.installButton"); + args[2] = sm.getString("htmlManagerServlet.deployUploadFile"); + args[3] = sm.getString("htmlManagerServlet.deployButton"); writer.print(MessageFormat.format(UPLOAD_SECTION, args)); // Server Header Section @@ -504,19 +507,19 @@ } /** - * Remove the web application at the specified context path. + * Undeploy the web application at the specified context path. * - * @see ManagerServlet#remove(PrintWriter, String) + * @see ManagerServlet#undeploy(PrintWriter, String) * - * @param path Context path of the application to be removed + * @param path Context path of the application to be undeployd * @return message String */ - protected String remove(String path) { + protected String undeploy(String path) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.remove(printWriter, path); + super.undeploy(printWriter, path); return stringWriter.toString(); } @@ -751,7 +754,7 @@ " </td>\n" + "</tr>\n"; - private static final String INSTALL_SECTION = + private static final String DEPLOY_SECTION = "</table>\n" + "<br>\n" + "<table border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n" + @@ -770,7 +773,7 @@ " <small>{3}</small>\n" + " </td>\n" + " <td class=\"row-left\">\n" + - " <input type=\"text\" name=\"installPath\" size=\"20\">\n" + + " <input type=\"text\" name=\"deployPath\" size=\"20\">\n" + " </td>\n" + "</tr>\n" + "<tr>\n" + @@ -778,7 +781,7 @@ " <small>{4}</small>\n" + " </td>\n" + " <td class=\"row-left\">\n" + - " <input type=\"text\" name=\"installConfig\" size=\"20\">\n" + + " <input type=\"text\" name=\"deployConfig\" size=\"20\">\n" + " </td>\n" + "</tr>\n" + "<tr>\n" + @@ -786,7 +789,7 @@ " <small>{5}</small>\n" + " </td>\n" + " <td class=\"row-left\">\n" + - " <input type=\"text\" name=\"installWar\" size=\"40\">\n" + + " <input type=\"text\" name=\"deployWar\" size=\"40\">\n" + " </td>\n" + "</tr>\n" + "<tr>\n" + @@ -816,7 +819,7 @@ " <small>{2}</small>\n" + " </td>\n" + " <td class=\"row-left\">\n" + - " <input type=\"file\" name=\"installWar\" size=\"40\">\n" + + " <input type=\"file\" name=\"deployWar\" size=\"40\">\n" + " </td>\n" + "</tr>\n" + "<tr>\n" + 1.2 +18 -18 jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/LocalStrings.properties Index: LocalStrings.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/LocalStrings.properties,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LocalStrings.properties 26 Mar 2003 09:49:18 -0000 1.1 +++ LocalStrings.properties 15 Jun 2003 18:31:45 -0000 1.2 @@ -2,7 +2,7 @@ htmlManagerServlet.appsName=Display Name htmlManagerServlet.appsPath=Path htmlManagerServlet.appsReload=Reload -htmlManagerServlet.appsRemove=Remove +htmlManagerServlet.appsUndeploy=Undeploy htmlManagerServlet.appsSessions=Sessions htmlManagerServlet.appsStart=Start htmlManagerServlet.appsStop=Stop @@ -12,18 +12,18 @@ htmlManagerServlet.helpHtmlManagerFile=html-manager-howto.html htmlManagerServlet.helpManager=Manager Help htmlManagerServlet.helpManagerFile=manager-howto.html -htmlManagerServlet.installButton=Install -htmlManagerServlet.installConfig=XML Configuration file URL: -htmlManagerServlet.installPath=Context Path (optional): -htmlManagerServlet.installServer=Install directory or WAR file located on server -htmlManagerServlet.installTitle=Install -htmlManagerServlet.installUpload=Upload a WAR file to install -htmlManagerServlet.installUploadFail=FAIL - Install Upload Failed, Exception: {0} -htmlManagerServlet.installUploadFile=Select WAR file to upload -htmlManagerServlet.installUploadNotWar=FAIL - File uploaded \"{0}\" must be a .war -htmlManagerServlet.installUploadNoFile=FAIL - File upload failed, no file -htmlManagerServlet.installUploadWarExists=FAIL - War file \"{0}\" already exists on server -htmlManagerServlet.installWar=WAR or Directory URL: +htmlManagerServlet.deployButton=Deploy +htmlManagerServlet.deployConfig=XML Configuration file URL: +htmlManagerServlet.deployPath=Context Path (optional): +htmlManagerServlet.deployServer=Deploy directory or WAR file located on server +htmlManagerServlet.deployTitle=Deploy +htmlManagerServlet.deployUpload=Upload a WAR file to deploy +htmlManagerServlet.deployUploadFail=FAIL - Deploy Upload Failed, Exception: {0} +htmlManagerServlet.deployUploadFile=Select WAR file to upload +htmlManagerServlet.deployUploadNotWar=FAIL - File uploaded \"{0}\" must be a .war +htmlManagerServlet.deployUploadNoFile=FAIL - File upload failed, no file +htmlManagerServlet.deployUploadWarExists=FAIL - War file \"{0}\" already exists on server +htmlManagerServlet.deployWar=WAR or Directory URL: htmlManagerServlet.list=List Applications htmlManagerServlet.manager=Manager htmlManagerServlet.messageLabel=Message: @@ -38,10 +38,10 @@ managerServlet.alreadyContext=FAIL - Application already exists at path {0} managerServlet.alreadyDocBase=FAIL - Directory {0} is already in use managerServlet.cannotInvoke=Cannot invoke manager servlet through invoker -managerServlet.configured=OK - Installed application from context file {0} +managerServlet.configured=OK - Deployed application from context file {0} managerServlet.deployed=OK - Deployed application at context path {0} managerServlet.exception=FAIL - Encountered exception {0} -managerServlet.installed=OK - Installed application at context path {0} +managerServlet.deployed=OK - Deployed application at context path {0} managerServlet.invalidPath=FAIL - Invalid context path {0} was specified managerServlet.invalidWar=FAIL - Invalid application URL {0} was specified managerServlet.listed=OK - Listed applications for virtual host {0} @@ -50,15 +50,15 @@ managerServlet.noCommand=FAIL - No command was specified managerServlet.noContext=FAIL - No context exists for path {0} managerServlet.noDirectory=FAIL - Non-directory document base for path {0} -managerServlet.noDocBase=FAIL - Cannot remove document base for path {0} +managerServlet.noDocBase=FAIL - Cannot undeploy document base for path {0} managerServlet.noGlobal=FAIL - No global JNDI resources are available managerServlet.noReload=FAIL - Reload not supported on WAR deployed at path {0} managerServlet.noRename=FAIL - Cannot deploy uploaded WAR for path {0} managerServlet.noRole=FAIL - User does not possess role {0} -managerServlet.noSelf=FAIL - The manager can not reload, remove, stop, or undeploy itself +managerServlet.noSelf=FAIL - The manager can not reload, undeploy, stop, or undeploy itself managerServlet.noWrapper=Container has not called setWrapper() for this servlet managerServlet.reloaded=OK - Reloaded application at context path {0} -managerServlet.removed=OK - Removed application at context path {0} +managerServlet.undeployd=OK - Undeployd application at context path {0} managerServlet.resourcesAll=OK - Listed global resources of all types managerServlet.resourcesType=OK - Listed global resources of type {0} managerServlet.rolesList=OK - Listed security roles 1.2 +257 -55 jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/ManagerServlet.java Index: ManagerServlet.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/ManagerServlet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ManagerServlet.java 26 Mar 2003 09:49:19 -0000 1.1 +++ ManagerServlet.java 15 Jun 2003 18:31:45 -0000 1.2 @@ -67,6 +67,7 @@ import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.IOException; @@ -93,6 +94,7 @@ import org.apache.catalina.ContainerServlet; import org.apache.catalina.Context; import org.apache.catalina.Deployer; +import org.apache.catalina.Engine; import org.apache.catalina.Globals; import org.apache.catalina.Host; import org.apache.catalina.Role; @@ -120,17 +122,17 @@ * The following actions and parameters (starting after the servlet path) * are supported: * <ul> - * <li><b>/install?config={config-url}</b> - Install and start a new + * <li><b>/deploy?config={config-url}</b> - Install and start a new * web application, based on the contents of the context configuration * file found at the specified URL. The <code>docBase</code> attribute * of the context configuration file is used to locate the actual * WAR or directory containing the application.</li> - * <li><b>/install?config={config-url}&war={war-url}/</b> - Install and start + * <li><b>/deploy?config={config-url}&war={war-url}/</b> - Install and start * a new web application, based on the contents of the context * configuration file found at <code>{config-url}</code>, overriding the * <code>docBase</code> attribute with the contents of the web * application archive found at <code>{war-url}</code>.</li> - * <li><b>/install?path=/xxx&war={war-url}</b> - Install and start a new + * <li><b>/deploy?path=/xxx&war={war-url}</b> - Install and start a new * web application attached to context path <code>/xxx</code>, based * on the contents of the web application archive found at the * specified URL.</li> @@ -140,10 +142,7 @@ * Where path is the context path. Status is either running or stopped. * Sessions is the number of active Sessions.</li> * <li><b>/reload?path=/xxx</b> - Reload the Java classes and resources for - * the application at the specified path, but do not reread the web.xml - * configuration files.</li> - * <li><b>/remove?path=/xxx</b> - Shutdown and remove the web application - * attached to context path <code>/xxx</code> for this virtual host.</li> + * the application at the specified path.</li> * <li><b>/resources?type=xxxx</b> - Enumerate the available global JNDI * resources, optionally limited to those of the specified type * (fully qualified Java class name), if available.</li> @@ -202,6 +201,7 @@ * </ul> * * @author Craig R. McClanahan + * @author Remy Maucherat * @version $Revision$ $Date$ */ @@ -213,6 +213,12 @@ /** + * Path where context descriptors should be deployed. + */ + protected File configBase = null; + + + /** * The Context container associated with our web application. */ protected Context context = null; @@ -233,6 +239,18 @@ /** + * Path used to store revisions of webapps. + */ + protected File versioned = null; + + + /** + * Path used to store context descriptors. + */ + protected File contextDescriptors = null; + + + /** * The Deployer container that contains our own web application's Context, * along with the associated Contexts for web applications that we * are managing. @@ -331,6 +349,12 @@ String path = request.getParameter("path"); String type = request.getParameter("type"); String war = request.getParameter("war"); + String tag = request.getParameter("tag"); + boolean update = false; + if ((request.getParameter("update") != null) + && (request.getParameter("update").equals("true"))) { + update = false; + } // Prepare our output writer to generate the response message Locale locale = Locale.getDefault(); @@ -342,13 +366,21 @@ // Process the requested command (note - "/deploy" is not listed here) if (command == null) { writer.println(sm.getString("managerServlet.noCommand")); + } else if (command.equals("/deploy")) { + if (war != null) { + deploy(writer, config, path, war, update); + } else { + deploy(writer, path, tag); + } } else if (command.equals("/install")) { - install(writer, config, path, war); + // Deprecated + deploy(writer, config, path, war, false); } else if (command.equals("/list")) { list(writer); } else if (command.equals("/reload")) { reload(writer, path); } else if (command.equals("/remove")) { + // Deprecated remove(writer, path); } else if (command.equals("/resources")) { resources(writer, type); @@ -399,6 +431,12 @@ if (command == null) command = request.getServletPath(); String path = request.getParameter("path"); + String tag = request.getParameter("tag"); + boolean update = false; + if ((request.getParameter("update") != null) + && (request.getParameter("update").equals("true"))) { + update = false; + } // Prepare our output writer to generate the response message response.setContentType("text/plain"); @@ -410,13 +448,14 @@ if (command == null) { writer.println(sm.getString("managerServlet.noCommand")); } else if (command.equals("/deploy")) { - deploy(writer, path, request); + deploy(writer, path, tag, update, request); } else { writer.println(sm.getString("managerServlet.unknownCommand", command)); } // Saving configuration + /* Server server = ServerFactory.getServer(); if ((server != null) && (server instanceof StandardServer)) { try { @@ -426,6 +465,7 @@ e.getMessage())); } } + */ // Finish up the response writer.flush(); @@ -468,9 +508,36 @@ } // Calculate the directory into which we will be deploying applications - deployed = (File) getServletContext().getAttribute + versioned = (File) getServletContext().getAttribute ("javax.servlet.context.tempdir"); + // Identify the appBase of the owning Host of this Context + // (if any) + String appBase = ((Host) context.getParent()).getAppBase(); + deployed = new File(appBase); + if (!deployed.isAbsolute()) { + deployed = new File(System.getProperty("catalina.base"), + appBase); + } + configBase = new File(System.getProperty("catalina.base"), "conf"); + Container container = context; + Container host = null; + Container engine = null; + while (container != null) { + if (container instanceof Host) + host = container; + if (container instanceof Engine) + engine = container; + container = container.getParent(); + } + if (engine != null) { + configBase = new File(configBase, engine.getName()); + } + if (host != null) { + configBase = new File(configBase, host.getName()); + } + // Note: The directory must exist for this to work. + // Log debugging messages as necessary if (debug >= 1) { log("init: Associated with Deployer '" + @@ -493,10 +560,12 @@ * * @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(PrintWriter writer, String path, - HttpServletRequest request) { + protected synchronized void deploy + (PrintWriter writer, String path, + String tag, boolean update, HttpServletRequest request) { if (debug >= 1) { log("deploy: Deploying web application at '" + path + "'"); @@ -514,16 +583,32 @@ if (path.equals("")) { basename = "_"; } else { - basename = path.substring(1); + basename = path.substring(1).replace('/', '_'); } - if (deployer.findDeployedApp(path) != null) { + + // Check if app already exists, or undeploy it if updating + Context context = deployer.findDeployedApp(path); + if (update) { + if (context != null) { + undeploy(writer, path); + } + context = deployer.findDeployedApp(path); + } + if (context != null) { writer.println - (sm.getString("managerServlet.alreadyContext", displayPath)); + (sm.getString("managerServlet.alreadyContext", + displayPath)); return; } + // Calculate the base path + File deployedPath = deployed; + if (tag != null) { + deployedPath = new File(versioned, tag); + } + // Upload the web application archive to a local WAR file - File localWar = new File(deployed, basename + ".war"); + File localWar = new File(deployedPath, basename + ".war"); if (debug >= 2) { log("Uploading WAR file to " + localWar); } @@ -536,8 +621,16 @@ return; } + // Copy WAR and XML to the host base + if (tag != null) { + deployedPath = deployed; + File localWarCopy = new File(deployedPath, basename + ".war"); + copy(localWar, localWarCopy); + localWar = localWarCopy; + } + // Extract the nested context deployment file (if any) - File localXml = new File(deployed, basename + ".xml"); + File localXml = new File(configBase, basename + ".xml"); if (debug >= 2) { log("Extracting XML file to " + localXml); } @@ -551,26 +644,8 @@ } // Deploy this web application - try { - URL warURL = - new URL("jar:file:" + localWar.getAbsolutePath() + "!/"); - URL xmlURL = null; - if (localXml.exists()) { - xmlURL = new URL("file:" + localXml.getAbsolutePath()); - } - if (xmlURL != null) { - deployer.install(xmlURL, warURL); - } else { - deployer.install(path, warURL); - } - } catch (Throwable t) { - log("ManagerServlet.deploy[" + displayPath + "]", t); - writer.println(sm.getString("managerServlet.exception", - t.toString())); - localWar.delete(); - localXml.delete(); - return; - } + deploy(writer, localXml.getAbsolutePath(), path, + localWar.getAbsolutePath(), update); // Acknowledge successful completion of this deploy command writer.println(sm.getString("managerServlet.installed", @@ -584,12 +659,87 @@ * 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 = null; + if (path.equals("")) { + basename = "_"; + } else { + basename = path.substring(1).replace('/', '_'); + } + + // 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, path); + } + + // Copy WAR and XML to the host base + if (tag != null) { + deployedPath = deployed; + File localWarCopy = new File(deployedPath, 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; + } + + String war = null; + String config = null; + if (localWar.exists()) { + war = localWar.getAbsolutePath(); + } + if (localXml.exists()) { + config = localXml.getAbsolutePath(); + } + + // 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 install(PrintWriter writer, String config, - String path, String war) { + protected void deploy(PrintWriter writer, String config, + String path, String war, boolean update) { if (war != null && war.length() == 0) { war = null; @@ -622,7 +772,7 @@ appBaseDir = new File(System.getProperty("catalina.base"), appBase); } - File file = new File(appBaseDir,war); + File file = new File(appBaseDir, war); try { URL url = file.toURL(); war = url.toString(); @@ -701,14 +851,22 @@ path = ""; } - try { - Context context = deployer.findDeployedApp(path); + // Check if app already exists, or undeploy it if updating + Context context = deployer.findDeployedApp(path); + if (update) { if (context != null) { - writer.println - (sm.getString("managerServlet.alreadyContext", - displayPath)); - return; + undeploy(writer, path); } + 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.installed", displayPath)); @@ -815,6 +973,7 @@ * * @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) { @@ -1077,6 +1236,7 @@ } + /** * Start the web application at the specified context path. * @@ -1099,7 +1259,8 @@ try { Context context = deployer.findDeployedApp(path); if (context == null) { - writer.println(sm.getString("managerServlet.noContext", displayPath)); + writer.println(sm.getString("managerServlet.noContext", + displayPath)); return; } deployer.start(path); @@ -1143,7 +1304,8 @@ try { Context context = deployer.findDeployedApp(path); if (context == null) { - writer.println(sm.getString("managerServlet.noContext", displayPath)); + writer.println(sm.getString("managerServlet.noContext", + displayPath)); return; } // It isn't possible for the manager to stop itself @@ -1232,9 +1394,7 @@ } else { docBaseDir.delete(); // Delete the WAR file } - String docBaseXmlPath = - docBasePath.substring(0, docBasePath.length() - 4) + ".xml"; - File docBaseXml = new File(docBaseXmlPath); + File docBaseXml = new File(configBase, context.getPath() + ".xml"); docBaseXml.delete(); writer.println(sm.getString("managerServlet.undeployed", displayPath)); @@ -1246,6 +1406,7 @@ } // Saving configuration + /* Server server = ServerFactory.getServer(); if ((server != null) && (server instanceof StandardServer)) { try { @@ -1255,6 +1416,7 @@ e.getMessage())); } } + */ } @@ -1418,6 +1580,46 @@ } } + } + + + /** + * Copy a file. + */ + private boolean copy(File src, File dest) { + FileInputStream is = null; + FileOutputStream os = null; + try { + is = new FileInputStream(src); + os = new FileOutputStream(dest); + byte[] buf = new byte[4096]; + while (true) { + int len = is.read(buf); + if (len < 0) + break; + os.write(buf, 0, len); + } + is.close(); + os.close(); + } catch (IOException e) { + return false; + } finally { + try { + if (is != null) { + is.close(); + } + } catch (Exception e) { + // Ignore + } + try { + if (os != null) { + os.close(); + } + } catch (Exception e) { + // Ignore + } + } + return true; }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]