Author: markt Date: Fri Nov 19 12:55:27 2010 New Revision: 1036828 URL: http://svn.apache.org/viewvc?rev=1036828&view=rev Log: Changes to Manager and HTML Manager to support parallel deployment
Modified: tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java tomcat/trunk/webapps/manager/WEB-INF/jsp/sessionDetail.jsp tomcat/trunk/webapps/manager/WEB-INF/jsp/sessionsList.jsp Modified: tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java?rev=1036828&r1=1036827&r2=1036828&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java (original) +++ tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java Fri Nov 19 12:55:27 2010 @@ -125,6 +125,10 @@ public final class HTMLManagerServlet ex String command = request.getPathInfo(); String path = request.getParameter("path"); + ContextName cn = null; + if (path != null) { + cn = new ContextName(path, request.getParameter("version")); + } // Prepare our output writer to generate the response message response.setContentType("text/html; charset=" + Constants.CHARSET); @@ -137,10 +141,10 @@ public final class HTMLManagerServlet ex // List always displayed - nothing to do here } else if (command.equals("/sessions")) { try { - doSessions(path, request, response, smClient); + doSessions(cn, request, response, smClient); return; } catch (Exception e) { - log("HTMLManagerServlet.sessions[" + path + "]", e); + log("HTMLManagerServlet.sessions[" + cn + "]", e); message = smClient.getString("managerServlet.exception", e.toString()); } @@ -180,7 +184,16 @@ public final class HTMLManagerServlet ex String command = request.getPathInfo(); String path = request.getParameter("path"); + ContextName cn = null; + if (path != null) { + cn = new ContextName(path, request.getParameter("version")); + } String deployPath = request.getParameter("deployPath"); + ContextName deployCn = null; + if (deployPath != null) { + deployCn = new ContextName(deployPath, + request.getParameter("deployVersion")); + } String deployConfig = request.getParameter("deployConfig"); String deployWar = request.getParameter("deployWar"); @@ -195,18 +208,18 @@ public final class HTMLManagerServlet ex } else if (command.equals("/upload")) { message = upload(request, smClient); } else if (command.equals("/deploy")) { - message = deployInternal(deployConfig, deployPath, deployWar, + message = deployInternal(deployConfig, deployCn, deployWar, smClient); } else if (command.equals("/reload")) { - message = reload(path, smClient); + message = reload(cn, smClient); } else if (command.equals("/undeploy")) { - message = undeploy(path, smClient); + message = undeploy(cn, smClient); } else if (command.equals("/expire")) { - message = expireSessions(path, request, smClient); + message = expireSessions(cn, request, smClient); } else if (command.equals("/start")) { - message = start(path, smClient); + message = start(cn, smClient); } else if (command.equals("/stop")) { - message = stop(path, smClient); + message = stop(cn, smClient); } else if (command.equals("/findleaks")) { message = findleaks(smClient); } else { @@ -370,17 +383,17 @@ public final class HTMLManagerServlet ex * web application archive. * * @param config URL of the context configuration file to be deployed - * @param path Context path of the application to be deployed + * @param cn Name of the application to be deployed * @param war URL of the web application archive to be deployed * @return message String */ - protected String deployInternal(String config, String path, String war, + protected String deployInternal(String config, ContextName cn, String war, StringManager smClient) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.deploy(printWriter, config, path, war, false, smClient); + super.deploy(printWriter, config, cn, war, false, smClient); return stringWriter.toString(); } @@ -493,6 +506,15 @@ public final class HTMLManagerServlet ex displayPath = "/"; } + StringBuilder tmp = new StringBuilder(); + tmp.append("path="); + tmp.append(URL_ENCODER.encode(displayPath)); + if (ctxt.getWebappVersion().length() > 0) { + tmp.append("&version="); + tmp.append(URL_ENCODER.encode(ctxt.getWebappVersion())); + } + String pathVersion = tmp.toString(); + try { isDeployed = isDeployed(contextName); } catch (Exception e) { @@ -512,9 +534,8 @@ public final class HTMLManagerServlet ex args[2] = " "; } args[3] = new Boolean(ctxt.getAvailable()); - args[4] = response.encodeURL - (request.getContextPath() + - "/html/sessions?path=" + URL_ENCODER.encode(displayPath)); + args[4] = response.encodeURL(request.getContextPath() + + "/html/sessions?" + pathVersion); Manager manager = ctxt.getManager(); if (manager instanceof DistributedManager && showProxySessions) { args[5] = new Integer( @@ -531,26 +552,20 @@ public final class HTMLManagerServlet ex (MessageFormat.format(APPS_ROW_DETAILS_SECTION, args)); args = new Object[14]; - args[0] = response.encodeURL - (request.getContextPath() + - "/html/start?path=" + URL_ENCODER.encode(displayPath)); + args[0] = response.encodeURL(request.getContextPath() + + "/html/start?" + pathVersion); args[1] = appsStart; - args[2] = response.encodeURL - (request.getContextPath() + - "/html/stop?path=" + URL_ENCODER.encode(displayPath)); + args[2] = response.encodeURL(request.getContextPath() + + "/html/stop?" + pathVersion); args[3] = appsStop; - args[4] = response.encodeURL - (request.getContextPath() + - "/html/reload?path=" + URL_ENCODER.encode(displayPath)); + args[4] = response.encodeURL(request.getContextPath() + + "/html/reload?" + pathVersion); args[5] = appsReload; - args[6] = response.encodeURL - (request.getContextPath() + - "/html/undeploy?path=" + URL_ENCODER.encode(displayPath)); + args[6] = response.encodeURL(request.getContextPath() + + "/html/undeploy?" + pathVersion); args[7] = appsUndeploy; - - args[8] = response.encodeURL - (request.getContextPath() + - "/html/expire?path=" + URL_ENCODER.encode(displayPath)); + args[8] = response.encodeURL(request.getContextPath() + + "/html/expire?" + pathVersion); args[9] = appsExpire; args[10] = smClient.getString( "htmlManagerServlet.expire.explain"); @@ -645,17 +660,18 @@ public final class HTMLManagerServlet ex /** * Reload the web application at the specified context path. * - * @see ManagerServlet#reload(PrintWriter, String, StringManager) + * @see ManagerServlet#reload(PrintWriter, ContextName, StringManager) * - * @param path Context path of the application to be restarted + * @param cn Name of the application to be restarted + * @param smClient StringManager for the client's locale * @return message String */ - protected String reload(String path, StringManager smClient) { + protected String reload(ContextName cn, StringManager smClient) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.reload(printWriter, path, smClient); + super.reload(printWriter, cn, smClient); return stringWriter.toString(); } @@ -665,15 +681,16 @@ public final class HTMLManagerServlet ex * * @see ManagerServlet#undeploy(PrintWriter, String, StringManager) * - * @param path Context path of the application to be undeployed + * @param cn Name of the application to be undeployed + * @param smClient StringManager for the client's locale * @return message String */ - protected String undeploy(String path, StringManager smClient) { + protected String undeploy(ContextName cn, StringManager smClient) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.undeploy(printWriter, path, smClient); + super.undeploy(printWriter, cn, smClient); return stringWriter.toString(); } @@ -683,16 +700,17 @@ public final class HTMLManagerServlet ex * * @see ManagerServlet#sessions(PrintWriter, String, int, StringManager) * - * @param path Context path of the application to list session information + * @param cn Name of the application to list session information * @param idle Expire all sessions with idle time ≥ idle for this context + * @param smClient StringManager for the client's locale * @return message String */ - protected String sessions(String path, int idle, StringManager smClient) { + protected String sessions(ContextName cn, int idle, StringManager smClient) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.sessions(printWriter, path, idle, smClient); + super.sessions(printWriter, cn, idle, smClient); return stringWriter.toString(); } @@ -702,15 +720,16 @@ public final class HTMLManagerServlet ex * * @see ManagerServlet#start(PrintWriter, String, StringManager) * - * @param path Context path of the application to be started + * @param cn Name of the application to be started + * @param smClient StringManager for the client's locale * @return message String */ - protected String start(String path, StringManager smClient) { + protected String start(ContextName cn, StringManager smClient) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.start(printWriter, path, smClient); + super.start(printWriter, cn, smClient); return stringWriter.toString(); } @@ -720,15 +739,16 @@ public final class HTMLManagerServlet ex * * @see ManagerServlet#stop(PrintWriter, String, StringManager) * - * @param path Context path of the application to be stopped + * @param cn Name of the application to be stopped + * @param smClient StringManager for the client's locale * @return message String */ - protected String stop(String path, StringManager smClient) { + protected String stop(ContextName cn, StringManager smClient) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); - super.stop(printWriter, path, smClient); + super.stop(printWriter, cn, smClient); return stringWriter.toString(); } @@ -737,6 +757,8 @@ public final class HTMLManagerServlet ex * Find potential memory leaks caused by web application reload. * * @see ManagerServlet#findleaks(PrintWriter, StringManager) + * + * @param smClient StringManager for the client's locale * * @return message String */ @@ -787,10 +809,11 @@ public final class HTMLManagerServlet ex * * Extract the expiration request parameter * - * @param path + * @param cn Name of the application from which to expire sessions * @param req + * @param smClient StringManager for the client's locale */ - protected String expireSessions(String path, HttpServletRequest req, + protected String expireSessions(ContextName cn, HttpServletRequest req, StringManager smClient) { int idle = -1; String idleParam = req.getParameter("idle"); @@ -801,58 +824,66 @@ public final class HTMLManagerServlet ex log("Could not parse idle parameter to an int: " + idleParam); } } - return sessions(path, idle, smClient); + return sessions(cn, idle, smClient); } /** * * @param req * @param resp + * @param smClient StringManager for the client's locale * @throws ServletException * @throws IOException */ - protected void doSessions(String path, HttpServletRequest req, + protected void doSessions(ContextName cn, HttpServletRequest req, HttpServletResponse resp, StringManager smClient) throws ServletException, IOException { - req.setAttribute("path", path); + req.setAttribute("path", cn.getPath()); + req.setAttribute("version", cn.getVersion()); String action = req.getParameter("action"); if (debug >= 1) { - log("sessions: Session action '" + action + "' for web application at '" + path + "'"); + log("sessions: Session action '" + action + + "' for web application '" + cn.getDisplayName() + "'"); } if ("sessionDetail".equals(action)) { String sessionId = req.getParameter("sessionId"); - displaySessionDetailPage(req, resp, path, sessionId, smClient); + displaySessionDetailPage(req, resp, cn, sessionId, smClient); return; } else if ("invalidateSessions".equals(action)) { String[] sessionIds = req.getParameterValues("sessionIds"); - int i = invalidateSessions(path, sessionIds, smClient); + int i = invalidateSessions(cn, sessionIds, smClient); req.setAttribute(APPLICATION_MESSAGE, "" + i + " sessions invalidated."); } else if ("removeSessionAttribute".equals(action)) { String sessionId = req.getParameter("sessionId"); String name = req.getParameter("attributeName"); boolean removed = - removeSessionAttribute(path, sessionId, name, smClient); + removeSessionAttribute(cn, sessionId, name, smClient); String outMessage = removed ? "Session attribute '" + name + "' removed." : "Session did not contain any attribute named '" + name + "'"; req.setAttribute(APPLICATION_MESSAGE, outMessage); - resp.sendRedirect(resp.encodeRedirectURL(req.getRequestURL().append("?path=").append(path).append("&action=sessionDetail&sessionId=").append(sessionId).toString())); + resp.sendRedirect(resp.encodeRedirectURL(req.getRequestURL().append("?path=").append(cn.getPath()).append("&action=sessionDetail&sessionId=").append(sessionId).toString())); return; } // else - displaySessionsListPage(path, req, resp, smClient); + displaySessionsListPage(cn, req, resp, smClient); } - protected List<Session> getSessionsForPath(String path, + protected List<Session> getSessionsForName(ContextName cn, StringManager smClient) { - if ((path == null) || (!path.startsWith("/") && path.equals(""))) { + if ((cn == null) || (!cn.getPath().startsWith("/") && + cn.getPath().equals(""))) { + String path = null; + if (cn != null) { + path = cn.getPath(); + } throw new IllegalArgumentException(smClient.getString( - "managerServlet.invalidPath", RequestUtil.filter(path))); + "managerServlet.invalidPath", + RequestUtil.filter(path))); } - String searchPath = path; - if( path.equals("/") ) - searchPath = ""; - Context ctxt = (Context) host.findChild(searchPath); + + Context ctxt = (Context) host.findChild(cn.getName()); if (null == ctxt) { throw new IllegalArgumentException(smClient.getString( - "managerServlet.noContext", RequestUtil.filter(path))); + "managerServlet.noContext", + RequestUtil.filter(cn.getDisplayName()))); } Manager manager = ctxt.getManager(); List<Session> sessions = new ArrayList<Session>(); @@ -872,19 +903,24 @@ public final class HTMLManagerServlet ex } return sessions; } - protected Session getSessionForPathAndId(String path, String id, + protected Session getSessionForNameAndId(ContextName cn, String id, StringManager smClient) throws IOException { - if ((path == null) || (!path.startsWith("/") && path.equals(""))) { + if ((cn == null) || (!cn.getPath().startsWith("/") && + cn.getPath().equals(""))) { + String path = null; + if (cn != null) { + path = cn.getPath(); + } throw new IllegalArgumentException(smClient.getString( - "managerServlet.invalidPath", RequestUtil.filter(path))); + "managerServlet.invalidPath", + RequestUtil.filter(path))); } - String searchPath = path; - if( path.equals("/") ) - searchPath = ""; - Context ctxt = (Context) host.findChild(searchPath); + + Context ctxt = (Context) host.findChild(cn.getName()); if (null == ctxt) { throw new IllegalArgumentException(smClient.getString( - "managerServlet.noContext", RequestUtil.filter(path))); + "managerServlet.noContext", + RequestUtil.filter(cn.getDisplayName()))); } Session session = ctxt.getManager().findSession(id); return session; @@ -892,15 +928,18 @@ public final class HTMLManagerServlet ex /** * + * @param cn Name of the application for which the sessions will be listed * @param req * @param resp + * @param smClient StringManager for the client's locale * @throws ServletException * @throws IOException */ - protected void displaySessionsListPage(String path, HttpServletRequest req, - HttpServletResponse resp, StringManager smClient) + protected void displaySessionsListPage(ContextName cn, + HttpServletRequest req, HttpServletResponse resp, + StringManager smClient) throws ServletException, IOException { - List<Session> sessions = getSessionsForPath(path, smClient); + List<Session> sessions = getSessionsForName(cn, smClient); String sortBy = req.getParameter("sort"); String orderBy = null; if (null != sortBy && !"".equals(sortBy.trim())) { @@ -940,13 +979,14 @@ public final class HTMLManagerServlet ex * * @param req * @param resp + * @param smClient StringManager for the client's locale * @throws ServletException * @throws IOException */ protected void displaySessionDetailPage(HttpServletRequest req, - HttpServletResponse resp, String path, String sessionId, + HttpServletResponse resp, ContextName cn, String sessionId, StringManager smClient) throws ServletException, IOException { - Session session = getSessionForPathAndId(path, sessionId, smClient); + Session session = getSessionForNameAndId(cn, sessionId, smClient); //strong>NOTE</strong> - This header will be overridden // automatically if a <code>RequestDispatcher.forward()</code> call is // ultimately invoked. @@ -959,11 +999,14 @@ public final class HTMLManagerServlet ex /** * Invalidate HttpSessions + * @param cn Name of the application for which sessions are to be + * invalidated * @param sessionIds + * @param smClient StringManager for the client's locale * @return number of invalidated sessions * @throws IOException */ - protected int invalidateSessions(String path, String[] sessionIds, + protected int invalidateSessions(ContextName cn, String[] sessionIds, StringManager smClient) throws IOException { if (null == sessionIds) { return 0; @@ -971,7 +1014,8 @@ public final class HTMLManagerServlet ex int nbAffectedSessions = 0; for (int i = 0; i < sessionIds.length; ++i) { String sessionId = sessionIds[i]; - HttpSession session = getSessionForPathAndId(path, sessionId, smClient).getSession(); + HttpSession session = + getSessionForNameAndId(cn, sessionId, smClient).getSession(); if (null == session) { // Shouldn't happen, but let's play nice... if (debug >= 1) { @@ -996,14 +1040,18 @@ public final class HTMLManagerServlet ex /** * Removes an attribute from an HttpSession + * @param cn Name of the application hosting the session from which the + * attribute is to be removed * @param sessionId * @param attributeName + * @param smClient StringManager for the client's locale * @return true if there was an attribute removed, false otherwise * @throws IOException */ - protected boolean removeSessionAttribute(String path, String sessionId, + protected boolean removeSessionAttribute(ContextName cn, String sessionId, String attributeName, StringManager smClient) throws IOException { - HttpSession session = getSessionForPathAndId(path, sessionId, smClient).getSession(); + HttpSession session = + getSessionForNameAndId(cn, sessionId, smClient).getSession(); if (null == session) { // Shouldn't happen, but let's play nice... if (debug >= 1) { Modified: tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java?rev=1036828&r1=1036827&r2=1036828&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java (original) +++ tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java Fri Nov 19 12:55:27 2010 @@ -159,8 +159,9 @@ import org.apache.tomcat.util.res.String * @version $Id$ */ -public class ManagerServlet - extends HttpServlet implements ContainerServlet { +public class ManagerServlet extends HttpServlet implements ContainerServlet { + + private static final long serialVersionUID = 1L; // ----------------------------------------------------- Instance Variables @@ -254,6 +255,7 @@ public class ManagerServlet /** * Return the Wrapper with which we are associated. */ + @Override public Wrapper getWrapper() { return (this.wrapper); @@ -266,6 +268,7 @@ public class ManagerServlet * * @param wrapper The new wrapper */ + @Override public void setWrapper(Wrapper wrapper) { this.wrapper = wrapper; @@ -327,6 +330,10 @@ public class ManagerServlet command = request.getServletPath(); String config = request.getParameter("config"); String path = request.getParameter("path"); + ContextName cn = null; + if (path != null) { + cn = new ContextName(path, request.getParameter("version")); + } String type = request.getParameter("type"); String war = request.getParameter("war"); String tag = request.getParameter("tag"); @@ -345,14 +352,14 @@ public class ManagerServlet writer.println(smClient.getString("managerServlet.noCommand")); } else if (command.equals("/deploy")) { if (war != null || config != null) { - deploy(writer, config, path, war, update, smClient); + deploy(writer, config, cn, war, update, smClient); } else { - deploy(writer, path, tag, smClient); + deploy(writer, cn, tag, smClient); } } else if (command.equals("/list")) { list(writer, smClient); } else if (command.equals("/reload")) { - reload(writer, path, smClient); + reload(writer, cn, smClient); } else if (command.equals("/resources")) { resources(writer, type, smClient); } else if (command.equals("/roles")) { @@ -362,15 +369,15 @@ public class ManagerServlet } else if (command.equals("/serverinfo")) { serverinfo(writer, smClient); } else if (command.equals("/sessions")) { - expireSessions(writer, path, request, smClient); + expireSessions(writer, cn, request, smClient); } else if (command.equals("/expire")) { - expireSessions(writer, path, request, smClient); + expireSessions(writer, cn, request, smClient); } else if (command.equals("/start")) { - start(writer, path, smClient); + start(writer, cn, smClient); } else if (command.equals("/stop")) { - stop(writer, path, smClient); + stop(writer, cn, smClient); } else if (command.equals("/undeploy")) { - undeploy(writer, path, smClient); + undeploy(writer, cn, smClient); } else if (command.equals("/findleaks")) { findleaks(writer, smClient); } else { @@ -406,6 +413,10 @@ public class ManagerServlet if (command == null) command = request.getServletPath(); String path = request.getParameter("path"); + ContextName cn = null; + if (path != null) { + cn = new ContextName(path, request.getParameter("version")); + } String tag = request.getParameter("tag"); boolean update = false; if ((request.getParameter("update") != null) @@ -421,7 +432,7 @@ public class ManagerServlet if (command == null) { writer.println(smClient.getString("managerServlet.noCommand")); } else if (command.equals("/deploy")) { - deploy(writer, path, tag, update, request, smClient); + deploy(writer, cn, tag, update, request, smClient); } else { writer.println(smClient.getString("managerServlet.unknownCommand", command)); @@ -586,36 +597,32 @@ public class ManagerServlet * at the specified context path. * * @param writer Writer to render results to - * @param path Context path of the application to be installed + * @param cn Name 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, + (PrintWriter writer, ContextName cn, String tag, boolean update, HttpServletRequest request, StringManager smClient) { if (debug >= 1) { - log("deploy: Deploying web application at '" + path + "'"); + log("deploy: Deploying web application '" + cn + "'"); } // Validate the requested context path - if ((path == null) || path.length() == 0 || !path.startsWith("/")) { - writer.println(smClient.getString( - "managerServlet.invalidPath", path)); + if (!validateContextName(cn, writer, smClient)) { return; } - String displayPath = path; - - ContextName cn = new ContextName(path, null); String name = cn.getName(); String baseName = cn.getBaseName(); + String displayPath = cn.getDisplayName(); // Check if app already exists, or undeploy it if updating Context context = (Context) host.findChild(name); if (update) { if (context != null) { - undeploy(writer, displayPath, smClient); + undeploy(writer, cn, smClient); } context = (Context) host.findChild(name); } @@ -685,21 +692,19 @@ public class ManagerServlet * * @param writer Writer to render results to * @param tag Revision tag to deploy from - * @param path Context path of the application to be installed + * @param cn Name of the application to be installed */ - protected void deploy(PrintWriter writer, String path, String tag, + protected void deploy(PrintWriter writer, ContextName cn, String tag, StringManager smClient) { // Validate the requested context path - if ((path == null) || path.length() == 0 || !path.startsWith("/")) { - writer.println(smClient.getString( - "managerServlet.invalidPath", path)); + if (!validateContextName(cn, writer, smClient)) { return; } - String displayPath = path; - ContextName cn = new ContextName(path, null); + String baseName = cn.getBaseName(); String name = cn.getName(); + String displayPath = cn.getDisplayName(); // Calculate the base path File deployedPath = versioned; @@ -713,7 +718,7 @@ public class ManagerServlet // Check if app already exists, or undeploy it if updating Context context = (Context) host.findChild(name); if (context != null) { - undeploy(writer, displayPath, smClient); + undeploy(writer, cn, smClient); } // Copy WAR to appBase @@ -754,12 +759,12 @@ public class ManagerServlet * * @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 cn Name 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(PrintWriter writer, String config, - String path, String war, boolean update, StringManager smClient) { + protected void deploy(PrintWriter writer, String config, ContextName cn, + String war, boolean update, StringManager smClient) { if (config != null && config.length() == 0) { config = null; @@ -778,8 +783,8 @@ public class ManagerServlet config + "'"); } } else { - if (path != null && path.length() > 0) { - log("install: Installing web application at '" + path + + if (cn != null) { + log("install: Installing web application '" + cn + "' from '" + war + "'"); } else { log("install: Installing web application from '" + war + "'"); @@ -787,21 +792,18 @@ public class ManagerServlet } } - if (path == null || path.length() == 0 || !path.startsWith("/")) { - writer.println(smClient.getString("managerServlet.invalidPath", - RequestUtil.filter(path))); + if (!validateContextName(cn, writer, smClient)) { return; } - String displayPath = path; - ContextName cn = new ContextName(path, null); String name = cn.getName(); String baseName = cn.getBaseName(); + String displayPath = cn.getDisplayName(); // Check if app already exists, or undeploy it if updating Context context = (Context) host.findChild(name); if (update) { if (context != null) { - undeploy(writer, displayPath, smClient); + undeploy(writer, cn, smClient); } context = (Context) host.findChild(name); } @@ -906,28 +908,23 @@ public class ManagerServlet * Reload the web application at the specified context path. * * @param writer Writer to render to - * @param path Context path of the application to be restarted + * @param cn Name of the application to be restarted */ - protected void reload(PrintWriter writer, String path, + protected void reload(PrintWriter writer, ContextName cn, StringManager smClient) { if (debug >= 1) - log("restart: Reloading web application at '" + path + "'"); + log("restart: Reloading web application '" + cn + "'"); - if ((path == null) || (!path.startsWith("/") && path.equals(""))) { - writer.println(smClient.getString("managerServlet.invalidPath", - RequestUtil.filter(path))); + if (!validateContextName(cn, writer, smClient)) { return; } - String displayPath = path; - if( path.equals("/") ) - path = ""; try { - Context context = (Context) host.findChild(path); + Context context = (Context) host.findChild(cn.getName()); if (context == null) { writer.println(smClient.getString("managerServlet.noContext", - RequestUtil.filter(displayPath))); + RequestUtil.filter(cn.getDisplayName()))); return; } // It isn't possible for the manager to reload itself @@ -936,11 +933,11 @@ public class ManagerServlet return; } context.reload(); - writer.println - (smClient.getString("managerServlet.reloaded", displayPath)); + writer.println(smClient.getString("managerServlet.reloaded", + cn.getDisplayName())); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); - log("ManagerServlet.reload[" + displayPath + "]", t); + log("ManagerServlet.reload[" + cn.getDisplayName() + "]", t); writer.println(smClient.getString("managerServlet.exception", t.toString())); } @@ -1124,28 +1121,26 @@ public class ManagerServlet * of sessions for each 10 minute interval up to 10 hours. * * @param writer Writer to render to - * @param path Context path of the application to list session information for + * @param cn Name of the application to list session information for * @param idle Expire all sessions with idle time > idle for this context */ - protected void sessions(PrintWriter writer, String path, int idle, + protected void sessions(PrintWriter writer, ContextName cn, int idle, StringManager smClient) { if (debug >= 1) { - log("sessions: Session information for web application at '" + path + "'"); + log("sessions: Session information for web application '" + cn + "'"); if (idle >= 0) - log("sessions: Session expiration for " + idle + " minutes '" + path + "'"); + log("sessions: Session expiration for " + idle + " minutes '" + cn + "'"); } - if ((path == null) || (!path.startsWith("/") && path.equals(""))) { - writer.println(smClient.getString("managerServlet.invalidPath", - RequestUtil.filter(path))); + if (!validateContextName(cn, writer, smClient)) { return; } - String displayPath = path; - if( path.equals("/") ) - path = ""; + + String displayPath = cn.getDisplayName(); + try { - Context context = (Context) host.findChild(path); + Context context = (Context) host.findChild(cn.getName()); if (context == null) { writer.println(smClient.getString("managerServlet.noContext", RequestUtil.filter(displayPath))); @@ -1232,11 +1227,11 @@ public class ManagerServlet * of sessions for each 10 minute interval up to 10 hours. * * @param writer Writer to render to - * @param path Context path of the application to list session information for + * @param cn Name of the application to list session information for */ - protected void sessions(PrintWriter writer, String path, + protected void sessions(PrintWriter writer, ContextName cn, StringManager smClient) { - sessions(writer, path, -1, smClient); + sessions(writer, cn, -1, smClient); } @@ -1244,10 +1239,10 @@ public class ManagerServlet * * Extract the expiration request parameter * - * @param path + * @param cn * @param req */ - protected void expireSessions(PrintWriter writer, String path, + protected void expireSessions(PrintWriter writer, ContextName cn, HttpServletRequest req, StringManager smClient) { int idle = -1; String idleParam = req.getParameter("idle"); @@ -1258,32 +1253,29 @@ public class ManagerServlet log("Could not parse idle parameter to an int: " + idleParam); } } - sessions(writer, path, idle, smClient); + sessions(writer, cn, idle, smClient); } /** * Start the web application at the specified context path. * * @param writer Writer to render to - * @param path Context path of the application to be started + * @param cn Name of the application to be started */ - protected void start(PrintWriter writer, String path, + protected void start(PrintWriter writer, ContextName cn, StringManager smClient) { if (debug >= 1) - log("start: Starting web application at '" + path + "'"); + log("start: Starting web application '" + cn + "'"); - if ((path == null) || (!path.startsWith("/") && path.equals(""))) { - writer.println(smClient.getString("managerServlet.invalidPath", - RequestUtil.filter(path))); + if (!validateContextName(cn, writer, smClient)) { return; } - String displayPath = path; - if( path.equals("/") ) - path = ""; + + String displayPath = cn.getDisplayName(); try { - Context context = (Context) host.findChild(path); + Context context = (Context) host.findChild(cn.getName()); if (context == null) { writer.println(smClient.getString("managerServlet.noContext", RequestUtil.filter(displayPath))); @@ -1313,25 +1305,22 @@ public class ManagerServlet * Stop the web application at the specified context path. * * @param writer Writer to render to - * @param path Context path of the application to be stopped + * @param cn Name of the application to be stopped */ - protected void stop(PrintWriter writer, String path, + protected void stop(PrintWriter writer, ContextName cn, StringManager smClient) { if (debug >= 1) - log("stop: Stopping web application at '" + path + "'"); + log("stop: Stopping web application '" + cn + "'"); - if ((path == null) || (!path.startsWith("/") && path.equals(""))) { - writer.println(smClient.getString("managerServlet.invalidPath", - RequestUtil.filter(path))); + if (!validateContextName(cn, writer, smClient)) { return; } - String displayPath = path; - if( path.equals("/") ) - path = ""; + + String displayPath = cn.getDisplayName(); try { - Context context = (Context) host.findChild(path); + Context context = (Context) host.findChild(cn.getName()); if (context == null) { writer.println(smClient.getString("managerServlet.noContext", RequestUtil.filter(displayPath))); @@ -1359,23 +1348,21 @@ public class ManagerServlet * Undeploy the web application at the specified context path. * * @param writer Writer to render to - * @param path Context path of the application to be removed + * @param cn Name of the application to be removed */ - protected void undeploy(PrintWriter writer, String path, + protected void undeploy(PrintWriter writer, ContextName cn, StringManager smClient) { if (debug >= 1) - log("undeploy: Undeploying web application at '" + path + "'"); + log("undeploy: Undeploying web application at '" + cn + "'"); - if ((path == null) || (!path.startsWith("/") && path.equals(""))) { - writer.println(smClient.getString("managerServlet.invalidPath", - RequestUtil.filter(path))); + if (!validateContextName(cn, writer, smClient)) { return; } - String displayPath = path; - ContextName cn = new ContextName(path, null); + String name = cn.getName(); String baseName = cn.getBaseName(); + String displayPath = cn.getDisplayName(); try { @@ -1613,6 +1600,24 @@ public class ManagerServlet } + protected static boolean validateContextName(ContextName cn, + PrintWriter writer, StringManager sm) { + + // ContextName should be non-null with a path that is empty or starts + // with / + if (cn != null && + (cn.getPath().startsWith("/") || cn.getPath().equals(""))) { + return true; + } + + String path = null; + if (cn != null) { + path = RequestUtil.filter(cn.getPath()); + } + writer.println(sm.getString("managerServlet.invalidPath", path)); + return false; + } + /** * Copy the specified file or directory to the destination. * @@ -1680,12 +1685,14 @@ public class ManagerServlet try { is.close(); } catch (IOException e) { + // Ignore } } if (os != null) { try { os.close(); } catch (IOException e) { + // Ignore } } } Modified: tomcat/trunk/webapps/manager/WEB-INF/jsp/sessionDetail.jsp URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/manager/WEB-INF/jsp/sessionDetail.jsp?rev=1036828&r1=1036827&r2=1036828&view=diff ============================================================================== --- tomcat/trunk/webapps/manager/WEB-INF/jsp/sessionDetail.jsp (original) +++ tomcat/trunk/webapps/manager/WEB-INF/jsp/sessionDetail.jsp Fri Nov 19 12:55:27 2010 @@ -20,6 +20,7 @@ <%...@page import="javax.servlet.http.HttpSession" %> <%...@page import="org.apache.catalina.Session" %> <%...@page import="org.apache.catalina.manager.JspHelper" %> +<%...@page import="org.apache.catalina.util.ContextName" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";> @@ -28,11 +29,14 @@ <html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en"> <% String path = (String) request.getAttribute("path"); + String version = (String) request.getAttribute("version"); + ContextName cn = new ContextName(path, version); Session currentSession = (Session)request.getAttribute("currentSession"); HttpSession currentHttpSession = currentSession.getSession(); String currentSessionId = currentSession.getId(); String submitUrl = response.encodeURL(((HttpServletRequest) - pageContext.getRequest()).getRequestURL().toString()); + pageContext.getRequest()).getRequestURI() + "?path=" + path + + "&version=" + version); %> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/> @@ -89,7 +93,6 @@ <form method="post" action="<%= submitUrl %>"> <div> - <input type="hidden" name="path" value="<%= path %>" /> <input type="hidden" name="sessionId" value="<%= currentSessionId %>" /> <input type="hidden" name="action" value="sessionDetail" /> <input type="submit" value="Refresh" /> @@ -131,7 +134,6 @@ <td align="center"> <form method="post" action="<%= submitUrl %>"> <div> - <input type="hidden" name="path" value="<%= path %>" /> <input type="hidden" name="action" value="removeSessionAttribute" /> <input type="hidden" name="sessionId" value="<%= currentSessionId %>" /> <input type="hidden" name="attributeName" value="<%= attributeName %>" /> Modified: tomcat/trunk/webapps/manager/WEB-INF/jsp/sessionsList.jsp URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/manager/WEB-INF/jsp/sessionsList.jsp?rev=1036828&r1=1036827&r2=1036828&view=diff ============================================================================== --- tomcat/trunk/webapps/manager/WEB-INF/jsp/sessionsList.jsp (original) +++ tomcat/trunk/webapps/manager/WEB-INF/jsp/sessionsList.jsp Fri Nov 19 12:55:27 2010 @@ -21,6 +21,7 @@ <%...@page import="org.apache.catalina.manager.JspHelper" %> <%...@page import="org.apache.catalina.Session" %> <%...@page import="org.apache.catalina.ha.session.DeltaSession" %> +<%...@page import="org.apache.catalina.util.ContextName" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> @@ -28,8 +29,11 @@ <%...@page import="org.apache.catalina.manager.DummyProxySession"%><html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en"> <% String path = (String) request.getAttribute("path"); + String version = (String) request.getAttribute("version"); + ContextName cn = new ContextName(path, version); String submitUrl = response.encodeURL(((HttpServletRequest) - pageContext.getRequest()).getRequestURI() + "?path=" + path); + pageContext.getRequest()).getRequestURI() + "?path=" + path + + "&version=" + version); Collection activeSessions = (Collection) request.getAttribute("activeSessions"); %> <head> @@ -41,10 +45,10 @@ <meta name="author" content="Cedrik LIME"/> <meta name="copyright" content="copyright 2005-2010 the Apache Software Foundation"/> <meta name="robots" content="noindex,nofollow,noarchive"/> - <title>Sessions Administration for <%= path %></title> + <title>Sessions Administration for <%= cn.getDisplayName() %></title> </head> <body> -<h1>Sessions Administration for <%= path %></h1> +<h1>Sessions Administration for <%= cn.getDisplayName() %></h1> <p>Tips:</p> <ul> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org