import org.apache.catalina.util.ServerInfo;
import org.apache.catalina.util.URLEncoder;
import org.apache.tomcat.util.http.fileupload.ParameterParser;
+import org.apache.tomcat.util.res.StringManager;
/**
* Servlet that enables remote management of the web applications deployed
HttpServletResponse response)
throws IOException, ServletException {
+ StringManager smClient = getStringManager(request);
+
// Identify the request parameters that we need
// By obtaining the command from the pathInfo, per-command security can
// be configured in web.xml
// List always displayed - nothing to do here
} else if (command.equals("/sessions")) {
try {
- doSessions(path, request, response);
+ doSessions(path, request, response, smClient);
return;
} catch (Exception e) {
log("HTMLManagerServlet.sessions[" + path + "]", e);
- message = sm.getString("managerServlet.exception",
+ message = smClient.getString("managerServlet.exception",
e.toString());
}
} else if (command.equals("/upload") || command.equals("/deploy") ||
command.equals("/expire") || command.equals("/start") ||
command.equals("/stop")) {
message =
- sm.getString("managerServlet.postCommand", command);
+ smClient.getString("managerServlet.postCommand", command);
} else {
message =
- sm.getString("managerServlet.unknownCommand", command);
+ smClient.getString("managerServlet.unknownCommand", command);
}
- list(request, response, message);
+ list(request, response, message, smClient);
}
/**
HttpServletResponse response)
throws IOException, ServletException {
+ StringManager smClient = getStringManager(request);
+
// Identify the request parameters that we need
// By obtaining the command from the pathInfo, per-command security can
// be configured in web.xml
// No command == list
// List always displayed -> do nothing
} else if (command.equals("/upload")) {
- message = upload(request);
+ message = upload(request, smClient);
} else if (command.equals("/deploy")) {
- message = deployInternal(deployConfig, deployPath, deployWar);
+ message = deployInternal(deployConfig, deployPath, deployWar,
+ smClient);
} else if (command.equals("/reload")) {
- message = reload(path);
+ message = reload(path, smClient);
} else if (command.equals("/undeploy")) {
- message = undeploy(path);
+ message = undeploy(path, smClient);
} else if (command.equals("/expire")) {
- message = expireSessions(path, request);
+ message = expireSessions(path, request, smClient);
} else if (command.equals("/start")) {
- message = start(path);
+ message = start(path, smClient);
} else if (command.equals("/stop")) {
- message = stop(path);
+ message = stop(path, smClient);
} else if (command.equals("/findleaks")) {
- message = findleaks();
+ message = findleaks(smClient);
} else {
// Try GET
doGet(request,response);
return;
}
- list(request, response, message);
+ list(request, response, message, smClient);
}
/**
return buffer.toString();
}
- protected String upload(HttpServletRequest request)
+ protected String upload(HttpServletRequest request, StringManager smClient)
throws IOException, ServletException {
String message = "";
while (true) {
if (warPart == null) {
- message =
- sm.getString("htmlManagerServlet.deployUploadNoFile");
+ message = smClient.getString(
+ "htmlManagerServlet.deployUploadNoFile");
break;
}
filename =
extractFilename(warPart.getHeader("Content-Disposition"));
if (!filename.toLowerCase(Locale.ENGLISH).endsWith(".war")) {
- message = sm.getString(
+ message = smClient.getString(
"htmlManagerServlet.deployUploadNotWar", filename);
break;
}
filename.toLowerCase(Locale.ENGLISH).indexOf(".war"));
File file = new File(getAppBase(), filename);
if (file.exists()) {
- message = sm.getString(
+ message = smClient.getString(
"htmlManagerServlet.deployUploadWarExists",
filename);
break;
}
if ((host.findChild(path) != null) && !isDeployed(path)) {
- message = sm.getString(
+ message = smClient.getString(
"htmlManagerServlet.deployUploadInServerXml",
filename);
break;
break;
}
} catch(Exception e) {
- message = sm.getString
+ message = smClient.getString
("htmlManagerServlet.deployUploadFail", e.getMessage());
log(message, e);
} finally {
* @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, String path, String war,
+ StringManager smClient) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
- super.deploy(printWriter, config, path, war, false);
+ super.deploy(printWriter, config, path, war, false, smClient);
return stringWriter.toString();
}
*/
public void list(HttpServletRequest request,
HttpServletResponse response,
- String message) throws IOException {
+ String message,
+ StringManager smClient) throws IOException {
if (debug >= 1)
log("list: Listing contexts for virtual host '" +
// Body Header Section
Object[] args = new Object[2];
args[0] = request.getContextPath();
- args[1] = sm.getString("htmlManagerServlet.title");
+ args[1] = smClient.getString("htmlManagerServlet.title");
writer.print(MessageFormat.format
(Constants.BODY_HEADER_SECTION, args));
// Message Section
args = new Object[3];
- args[0] = sm.getString("htmlManagerServlet.messageLabel");
+ args[0] = smClient.getString("htmlManagerServlet.messageLabel");
if (message == null || message.length() == 0) {
args[1] = "OK";
} else {
// Manager Section
args = new Object[9];
- args[0] = sm.getString("htmlManagerServlet.manager");
+ args[0] = smClient.getString("htmlManagerServlet.manager");
args[1] = response.encodeURL(request.getContextPath() + "/html/list");
- args[2] = sm.getString("htmlManagerServlet.list");
+ args[2] = smClient.getString("htmlManagerServlet.list");
args[3] = response.encodeURL
(request.getContextPath() + "/" +
- sm.getString("htmlManagerServlet.helpHtmlManagerFile"));
- args[4] = sm.getString("htmlManagerServlet.helpHtmlManager");
+ smClient.getString("htmlManagerServlet.helpHtmlManagerFile"));
+ args[4] = smClient.getString("htmlManagerServlet.helpHtmlManager");
args[5] = response.encodeURL
(request.getContextPath() + "/" +
- sm.getString("htmlManagerServlet.helpManagerFile"));
- args[6] = sm.getString("htmlManagerServlet.helpManager");
+ smClient.getString("htmlManagerServlet.helpManagerFile"));
+ args[6] = smClient.getString("htmlManagerServlet.helpManager");
args[7] = response.encodeURL
(request.getContextPath() + "/status");
- args[8] = sm.getString("statusServlet.title");
+ args[8] = smClient.getString("statusServlet.title");
writer.print(MessageFormat.format(Constants.MANAGER_SECTION, args));
// Apps Header Section
args = new Object[6];
- args[0] = sm.getString("htmlManagerServlet.appsTitle");
- args[1] = sm.getString("htmlManagerServlet.appsPath");
- args[2] = sm.getString("htmlManagerServlet.appsName");
- args[3] = sm.getString("htmlManagerServlet.appsAvailable");
- args[4] = sm.getString("htmlManagerServlet.appsSessions");
- args[5] = sm.getString("htmlManagerServlet.appsTasks");
+ args[0] = smClient.getString("htmlManagerServlet.appsTitle");
+ args[1] = smClient.getString("htmlManagerServlet.appsPath");
+ args[2] = smClient.getString("htmlManagerServlet.appsName");
+ args[3] = smClient.getString("htmlManagerServlet.appsAvailable");
+ args[4] = smClient.getString("htmlManagerServlet.appsSessions");
+ args[5] = smClient.getString("htmlManagerServlet.appsTasks");
writer.print(MessageFormat.format(APPS_HEADER_SECTION, args));
// Apps Row Section
sortedContextPathsMap.put(displayPath, contextPaths[i]);
}
- String appsStart = sm.getString("htmlManagerServlet.appsStart");
- String appsStop = sm.getString("htmlManagerServlet.appsStop");
- String appsReload = sm.getString("htmlManagerServlet.appsReload");
- String appsUndeploy = sm.getString("htmlManagerServlet.appsUndeploy");
- String appsExpire = sm.getString("htmlManagerServlet.appsExpire");
+ String appsStart = smClient.getString("htmlManagerServlet.appsStart");
+ String appsStop = smClient.getString("htmlManagerServlet.appsStop");
+ String appsReload = smClient.getString("htmlManagerServlet.appsReload");
+ String appsUndeploy = smClient.getString("htmlManagerServlet.appsUndeploy");
+ String appsExpire = smClient.getString("htmlManagerServlet.appsExpire");
Iterator<Map.Entry<String,String>> iterator =
sortedContextPathsMap.entrySet().iterator();
(request.getContextPath() +
"/html/expire?path=" + URL_ENCODER.encode(displayPath));
args[9] = appsExpire;
- args[10] = sm.getString("htmlManagerServlet.expire.explain");
+ args[10] = smClient.getString(
+ "htmlManagerServlet.expire.explain");
if (manager == null) {
- args[11] = sm.getString("htmlManagerServlet.noManager");
+ args[11] = smClient.getString(
+ "htmlManagerServlet.noManager");
} else {
args[11] = new Integer(
ctxt.getManager().getMaxInactiveInterval()/60);
}
- args[12] = sm.getString("htmlManagerServlet.expire.unit");
+ args[12] = smClient.getString("htmlManagerServlet.expire.unit");
args[13] = highlightColor;
if (ctxt.getPath().equals(this.context.getPath())) {
// Deploy Section
args = new Object[7];
- args[0] = sm.getString("htmlManagerServlet.deployTitle");
- args[1] = sm.getString("htmlManagerServlet.deployServer");
+ args[0] = smClient.getString("htmlManagerServlet.deployTitle");
+ args[1] = smClient.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");
+ args[3] = smClient.getString("htmlManagerServlet.deployPath");
+ args[4] = smClient.getString("htmlManagerServlet.deployConfig");
+ args[5] = smClient.getString("htmlManagerServlet.deployWar");
+ args[6] = smClient.getString("htmlManagerServlet.deployButton");
writer.print(MessageFormat.format(DEPLOY_SECTION, args));
args = new Object[4];
- args[0] = sm.getString("htmlManagerServlet.deployUpload");
+ args[0] = smClient.getString("htmlManagerServlet.deployUpload");
args[1] = response.encodeURL(request.getContextPath() + "/html/upload");
- args[2] = sm.getString("htmlManagerServlet.deployUploadFile");
- args[3] = sm.getString("htmlManagerServlet.deployButton");
+ args[2] = smClient.getString("htmlManagerServlet.deployUploadFile");
+ args[3] = smClient.getString("htmlManagerServlet.deployButton");
writer.print(MessageFormat.format(UPLOAD_SECTION, args));
// Diagnostics section
args = new Object[5];
- args[0] = sm.getString("htmlManagerServlet.diagnosticsTitle");
- args[1] = sm.getString("htmlManagerServlet.diagnosticsLeak");
+ args[0] = smClient.getString("htmlManagerServlet.diagnosticsTitle");
+ args[1] = smClient.getString("htmlManagerServlet.diagnosticsLeak");
args[2] = response.encodeURL(
request.getContextPath() + "/html/findleaks");
- args[3] = sm.getString("htmlManagerServlet.diagnosticsLeakWarning");
- args[4] = sm.getString("htmlManagerServlet.diagnosticsLeakButton");
+ args[3] = smClient.getString("htmlManagerServlet.diagnosticsLeakWarning");
+ args[4] = smClient.getString("htmlManagerServlet.diagnosticsLeakButton");
writer.print(MessageFormat.format(DIAGNOSTICS_SECTION, args));
// Server Header Section
args = new Object[7];
- args[0] = sm.getString("htmlManagerServlet.serverTitle");
- args[1] = sm.getString("htmlManagerServlet.serverVersion");
- args[2] = sm.getString("htmlManagerServlet.serverJVMVersion");
- args[3] = sm.getString("htmlManagerServlet.serverJVMVendor");
- args[4] = sm.getString("htmlManagerServlet.serverOSName");
- args[5] = sm.getString("htmlManagerServlet.serverOSVersion");
- args[6] = sm.getString("htmlManagerServlet.serverOSArch");
+ args[0] = smClient.getString("htmlManagerServlet.serverTitle");
+ args[1] = smClient.getString("htmlManagerServlet.serverVersion");
+ args[2] = smClient.getString("htmlManagerServlet.serverJVMVersion");
+ args[3] = smClient.getString("htmlManagerServlet.serverJVMVendor");
+ args[4] = smClient.getString("htmlManagerServlet.serverOSName");
+ args[5] = smClient.getString("htmlManagerServlet.serverOSVersion");
+ args[6] = smClient.getString("htmlManagerServlet.serverOSArch");
writer.print(MessageFormat.format
(Constants.SERVER_HEADER_SECTION, args));
* @param path Context path of the application to be restarted
* @return message String
*/
- protected String reload(String path) {
+ protected String reload(String path, StringManager smClient) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
- super.reload(printWriter, path);
+ super.reload(printWriter, path, smClient);
return stringWriter.toString();
}
* @param path Context path of the application to be undeployed
* @return message String
*/
- protected String undeploy(String path) {
+ protected String undeploy(String path, StringManager smClient) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
- super.undeploy(printWriter, path);
+ super.undeploy(printWriter, path, smClient);
return stringWriter.toString();
}
* @param idle Expire all sessions with idle time ≥ idle for this context
* @return message String
*/
- public String sessions(String path, int idle) {
+ public String sessions(String path, int idle, StringManager smClient) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
- super.sessions(printWriter, path, idle);
+ super.sessions(printWriter, path, idle, smClient);
return stringWriter.toString();
}
* @param path Context path of the application to list session information
* @return message String
*/
- public String sessions(String path) {
+ public String sessions(String path, StringManager smClient) {
- return sessions(path, -1);
+ return sessions(path, -1, smClient);
}
/**
* @param path Context path of the application to be started
* @return message String
*/
- public String start(String path) {
+ public String start(String path, StringManager smClient) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
- super.start(printWriter, path);
+ super.start(printWriter, path, smClient);
return stringWriter.toString();
}
* @param path Context path of the application to be stopped
* @return message String
*/
- protected String stop(String path) {
+ protected String stop(String path, StringManager smClient) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
- super.stop(printWriter, path);
+ super.stop(printWriter, path, smClient);
return stringWriter.toString();
}
*
* @return message String
*/
- protected String findleaks() {
+ protected String findleaks(StringManager smClient) {
StringBuilder msg = new StringBuilder();
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
- super.findleaks(printWriter);
+ super.findleaks(printWriter, smClient);
if (stringWriter.getBuffer().length() > 0) {
- msg.append(sm.getString("htmlManagerServlet.findleaksList"));
+ msg.append(smClient.getString("htmlManagerServlet.findleaksList"));
msg.append(stringWriter.toString());
} else {
- msg.append(sm.getString("htmlManagerServlet.findleaksNone"));
+ msg.append(smClient.getString("htmlManagerServlet.findleaksNone"));
}
return msg.toString();
* @param path
* @param req
*/
- protected String expireSessions(String path, HttpServletRequest req) {
+ protected String expireSessions(String path, HttpServletRequest req,
+ StringManager smClient) {
int idle = -1;
String idleParam = req.getParameter("idle");
if (idleParam != null) {
log("Could not parse idle parameter to an int: " + idleParam);
}
}
- return sessions(path, idle);
+ return sessions(path, idle, smClient);
}
/**
* @throws ServletException
* @throws IOException
*/
- protected void doSessions(String path, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ protected void doSessions(String path, HttpServletRequest req,
+ HttpServletResponse resp, StringManager smClient)
+ throws ServletException, IOException {
req.setAttribute("path", path);
String action = req.getParameter("action");
if (debug >= 1) {
}
if ("sessionDetail".equals(action)) {
String sessionId = req.getParameter("sessionId");
- displaySessionDetailPage(req, resp, path, sessionId);
+ displaySessionDetailPage(req, resp, path, sessionId, smClient);
return;
} else if ("invalidateSessions".equals(action)) {
String[] sessionIds = req.getParameterValues("sessionIds");
- int i = invalidateSessions(path, sessionIds);
+ int i = invalidateSessions(path, 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);
+ boolean removed =
+ removeSessionAttribute(path, 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()));
return;
} // else
- displaySessionsListPage(path, req, resp);
+ displaySessionsListPage(path, req, resp, smClient);
}
- protected List<Session> getSessionsForPath(String path) {
+ protected List<Session> getSessionsForPath(String path,
+ StringManager smClient) {
if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
- throw new IllegalArgumentException(sm.getString("managerServlet.invalidPath",
- RequestUtil.filter(path)));
+ throw new IllegalArgumentException(smClient.getString(
+ "managerServlet.invalidPath", RequestUtil.filter(path)));
}
String searchPath = path;
if( path.equals("/") )
searchPath = "";
Context ctxt = (Context) host.findChild(searchPath);
if (null == ctxt) {
- throw new IllegalArgumentException(sm.getString("managerServlet.noContext",
- RequestUtil.filter(path)));
+ throw new IllegalArgumentException(smClient.getString(
+ "managerServlet.noContext", RequestUtil.filter(path)));
}
Manager manager = ctxt.getManager();
List<Session> sessions = new ArrayList<Session>();
}
return sessions;
}
- protected Session getSessionForPathAndId(String path, String id) throws IOException {
+ protected Session getSessionForPathAndId(String path, String id,
+ StringManager smClient) throws IOException {
if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
- throw new IllegalArgumentException(sm.getString("managerServlet.invalidPath",
- RequestUtil.filter(path)));
+ throw new IllegalArgumentException(smClient.getString(
+ "managerServlet.invalidPath", RequestUtil.filter(path)));
}
String searchPath = path;
if( path.equals("/") )
searchPath = "";
Context ctxt = (Context) host.findChild(searchPath);
if (null == ctxt) {
- throw new IllegalArgumentException(sm.getString("managerServlet.noContext",
- RequestUtil.filter(path)));
+ throw new IllegalArgumentException(smClient.getString(
+ "managerServlet.noContext", RequestUtil.filter(path)));
}
Session session = ctxt.getManager().findSession(id);
return session;
* @throws ServletException
* @throws IOException
*/
- protected void displaySessionsListPage(String path, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- List<Session> sessions = getSessionsForPath(path);
+ protected void displaySessionsListPage(String path, HttpServletRequest req,
+ HttpServletResponse resp, StringManager smClient)
+ throws ServletException, IOException {
+ List<Session> sessions = getSessionsForPath(path, smClient);
String sortBy = req.getParameter("sort");
String orderBy = null;
if (null != sortBy && !"".equals(sortBy.trim())) {
* @throws ServletException
* @throws IOException
*/
- protected void displaySessionDetailPage(HttpServletRequest req, HttpServletResponse resp, String path, String sessionId) throws ServletException, IOException {
- Session session = getSessionForPathAndId(path, sessionId);
+ protected void displaySessionDetailPage(HttpServletRequest req,
+ HttpServletResponse resp, String path, String sessionId,
+ StringManager smClient) throws ServletException, IOException {
+ Session session = getSessionForPathAndId(path, sessionId, smClient);
//strong>NOTE</strong> - This header will be overridden
// automatically if a <code>RequestDispatcher.forward()</code> call is
// ultimately invoked.
* @return number of invalidated sessions
* @throws IOException
*/
- public int invalidateSessions(String path, String[] sessionIds) throws IOException {
+ public int invalidateSessions(String path, String[] sessionIds,
+ StringManager smClient) throws IOException {
if (null == sessionIds) {
return 0;
}
int nbAffectedSessions = 0;
for (int i = 0; i < sessionIds.length; ++i) {
String sessionId = sessionIds[i];
- HttpSession session = getSessionForPathAndId(path, sessionId).getSession();
+ HttpSession session = getSessionForPathAndId(path, sessionId, smClient).getSession();
if (null == session) {
// Shouldn't happen, but let's play nice...
if (debug >= 1) {
* @return true if there was an attribute removed, false otherwise
* @throws IOException
*/
- public boolean removeSessionAttribute(String path, String sessionId, String attributeName) throws IOException {
- HttpSession session = getSessionForPathAndId(path, sessionId).getSession();
+ public boolean removeSessionAttribute(String path, String sessionId,
+ String attributeName, StringManager smClient) throws IOException {
+ HttpSession session = getSessionForPathAndId(path, sessionId, smClient).getSession();
if (null == session) {
// Shouldn't happen, but let's play nice...
if (debug >= 1) {
* @return old value for maxInactiveInterval
* @throws IOException
*/
- public int setSessionMaxInactiveInterval(String path, String sessionId, int maxInactiveInterval) throws IOException {
- HttpSession session = getSessionForPathAndId(path, sessionId).getSession();
+ public int setSessionMaxInactiveInterval(String path, String sessionId,
+ int maxInactiveInterval, StringManager smClient) throws IOException {
+ HttpSession session = getSessionForPathAndId(path, sessionId, smClient).getSession();
if (null == session) {
// Shouldn't happen, but let's play nice...
if (debug >= 1) {
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.Enumeration;
import java.util.Iterator;
+import java.util.Locale;
import javax.management.MBeanServer;
import javax.management.ObjectName;
HttpServletResponse response)
throws IOException, ServletException {
+ StringManager smClient = getStringManager(request);
+
// Identify the request parameters that we need
String command = request.getPathInfo();
if (command == null)
// Process the requested command (note - "/deploy" is not listed here)
if (command == null) {
- writer.println(sm.getString("managerServlet.noCommand"));
+ writer.println(smClient.getString("managerServlet.noCommand"));
} else if (command.equals("/deploy")) {
if (war != null || config != null) {
- deploy(writer, config, path, war, update);
+ deploy(writer, config, path, war, update, smClient);
} else {
- deploy(writer, path, tag);
+ deploy(writer, path, tag, smClient);
}
} else if (command.equals("/list")) {
- list(writer);
+ list(writer, smClient);
} else if (command.equals("/reload")) {
- reload(writer, path);
+ reload(writer, path, smClient);
} else if (command.equals("/resources")) {
- resources(writer, type);
+ resources(writer, type, smClient);
} else if (command.equals("/roles")) {
- roles(writer);
+ roles(writer, smClient);
} else if (command.equals("/save")) {
- save(writer, path);
+ save(writer, path, smClient);
} else if (command.equals("/serverinfo")) {
- serverinfo(writer);
+ serverinfo(writer, smClient);
} else if (command.equals("/sessions")) {
- expireSessions(writer, path, request);
+ expireSessions(writer, path, request, smClient);
} else if (command.equals("/expire")) {
- expireSessions(writer, path, request);
+ expireSessions(writer, path, request, smClient);
} else if (command.equals("/start")) {
- start(writer, path);
+ start(writer, path, smClient);
} else if (command.equals("/stop")) {
- stop(writer, path);
+ stop(writer, path, smClient);
} else if (command.equals("/undeploy")) {
- undeploy(writer, path);
+ undeploy(writer, path, smClient);
} else if (command.equals("/findleaks")) {
- findleaks(writer);
+ findleaks(writer, smClient);
} else {
- writer.println(sm.getString("managerServlet.unknownCommand",
- command));
+ writer.println(smClient.getString("managerServlet.unknownCommand",
+ command));
}
// Finish up the response
HttpServletResponse response)
throws IOException, ServletException {
+ StringManager smClient = getStringManager(request);
+
// Identify the request parameters that we need
String command = request.getPathInfo();
if (command == null)
// Process the requested command
if (command == null) {
- writer.println(sm.getString("managerServlet.noCommand"));
+ writer.println(smClient.getString("managerServlet.noCommand"));
} else if (command.equals("/deploy")) {
- deploy(writer, path, tag, update, request);
+ deploy(writer, path, tag, update, request, smClient);
} else {
- writer.println(sm.getString("managerServlet.unknownCommand",
- command));
+ writer.println(smClient.getString("managerServlet.unknownCommand",
+ command));
}
// Finish up the response
// Ensure that our ContainerServlet properties have been set
if ((wrapper == null) || (context == null))
- throw new UnavailableException
- (sm.getString("managerServlet.noWrapper"));
+ throw new UnavailableException(
+ sm.getString("managerServlet.noWrapper"));
// Set our properties from the initialization parameters
String value = null;
/**
* Find potential memory leaks caused by web application reload.
*/
- protected void findleaks(PrintWriter writer) {
+ protected void findleaks(PrintWriter writer, StringManager smClient) {
if (!(host instanceof StandardHost)) {
- writer.println(sm.getString("managerServlet.findleaksFail"));
+ writer.println(smClient.getString("managerServlet.findleaksFail"));
return;
}
*
* @param path Optional context path to save
*/
- protected synchronized void save(PrintWriter writer, String path) {
+ protected synchronized void save(PrintWriter writer, String path,
+ StringManager smClient) {
Server server = ((Engine)host.getParent()).getService().getServer();
if (!(server instanceof StandardServer)) {
- writer.println(sm.getString("managerServlet.saveFail", server));
+ writer.println(smClient.getString("managerServlet.saveFail",
+ server));
return;
}
if ((path == null) || path.length() == 0 || !path.startsWith("/")) {
try {
((StandardServer) server).storeConfig();
- writer.println(sm.getString("managerServlet.saved"));
+ writer.println(smClient.getString("managerServlet.saved"));
} catch (Exception e) {
log("managerServlet.storeConfig", e);
- writer.println(sm.getString("managerServlet.exception",
- e.toString()));
+ writer.println(smClient.getString("managerServlet.exception",
+ e.toString()));
return;
}
} else {
}
Context context = (Context) host.findChild(contextPath);
if (context == null) {
- writer.println(sm.getString("managerServlet.noContext", path));
+ writer.println(smClient.getString("managerServlet.noContext",
+ path));
return;
}
try {
((StandardServer) server).storeContext(context);
- writer.println(sm.getString("managerServlet.savedContext",
- path));
+ writer.println(smClient.getString("managerServlet.savedContext",
+ path));
} catch (Exception e) {
log("managerServlet.save[" + path + "]", e);
- writer.println(sm.getString("managerServlet.exception",
- e.toString()));
+ writer.println(smClient.getString("managerServlet.exception",
+ e.toString()));
return;
}
}
*/
protected synchronized void deploy
(PrintWriter writer, String path,
- String tag, boolean update, HttpServletRequest request) {
+ String tag, boolean update, HttpServletRequest request,
+ StringManager smClient) {
if (debug >= 1) {
log("deploy: Deploying web application at '" + path + "'");
// Validate the requested context path
if ((path == null) || path.length() == 0 || !path.startsWith("/")) {
- writer.println(sm.getString("managerServlet.invalidPath", path));
+ writer.println(smClient.getString(
+ "managerServlet.invalidPath", path));
return;
}
String displayPath = path;
Context context = (Context) host.findChild(path);
if (update) {
if (context != null) {
- undeploy(writer, displayPath);
+ undeploy(writer, displayPath, smClient);
}
context = (Context) host.findChild(path);
}
if (context != null) {
- writer.println
- (sm.getString("managerServlet.alreadyContext",
- displayPath));
+ writer.println(smClient.getString("managerServlet.alreadyContext",
+ displayPath));
return;
}
}
} catch (Exception e) {
log("managerServlet.check[" + displayPath + "]", e);
- writer.println(sm.getString("managerServlet.exception",
- e.toString()));
+ writer.println(smClient.getString("managerServlet.exception",
+ e.toString()));
return;
}
context = (Context) host.findChild(path);
if (context != null && context.getConfigured()) {
- writer.println(sm.getString("managerServlet.deployed", displayPath));
+ writer.println(smClient.getString(
+ "managerServlet.deployed", displayPath));
} else {
// Something failed
- writer.println(sm.getString("managerServlet.deployFailed", displayPath));
+ writer.println(smClient.getString(
+ "managerServlet.deployFailed", displayPath));
}
}
* @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) {
+ protected void deploy(PrintWriter writer, String path, String tag,
+ StringManager smClient) {
// Validate the requested context path
if ((path == null) || path.length() == 0 || !path.startsWith("/")) {
- writer.println(sm.getString("managerServlet.invalidPath", path));
+ writer.println(smClient.getString(
+ "managerServlet.invalidPath", path));
return;
}
String displayPath = path;
// Check if app already exists, or undeploy it if updating
Context context = (Context) host.findChild(path);
if (context != null) {
- undeploy(writer, displayPath);
+ undeploy(writer, displayPath, smClient);
}
// Copy WAR to appBase
}
} catch (Exception e) {
log("managerServlet.check[" + displayPath + "]", e);
- writer.println(sm.getString("managerServlet.exception",
- e.toString()));
+ writer.println(smClient.getString("managerServlet.exception",
+ e.toString()));
return;
}
context = (Context) host.findChild(path);
if (context != null && context.getConfigured()) {
- writer.println(sm.getString("managerServlet.deployed", displayPath));
+ writer.println(smClient.getString("managerServlet.deployed",
+ displayPath));
} else {
// Something failed
- writer.println(sm.getString("managerServlet.deployFailed", displayPath));
+ writer.println(smClient.getString("managerServlet.deployFailed",
+ displayPath));
}
}
* @param update true to override any existing webapp on the path
*/
protected void deploy(PrintWriter writer, String config,
- String path, String war, boolean update) {
+ String path, String war, boolean update, StringManager smClient) {
if (config != null && config.length() == 0) {
config = null;
}
if (path == null || path.length() == 0 || !path.startsWith("/")) {
- writer.println(sm.getString("managerServlet.invalidPath",
- RequestUtil.filter(path)));
+ writer.println(smClient.getString("managerServlet.invalidPath",
+ RequestUtil.filter(path)));
return;
}
String displayPath = path;
Context context = (Context) host.findChild(path);
if (update) {
if (context != null) {
- undeploy(writer, displayPath);
+ undeploy(writer, displayPath, smClient);
}
context = (Context) host.findChild(path);
}
if (context != null) {
- writer.println
- (sm.getString("managerServlet.alreadyContext",
+ writer.println(smClient.getString("managerServlet.alreadyContext",
displayPath));
return;
}
}
context = (Context) host.findChild(path);
if (context != null && context.getConfigured() && context.getAvailable()) {
- writer.println(sm.getString("managerServlet.deployed", displayPath));
+ writer.println(smClient.getString(
+ "managerServlet.deployed", displayPath));
} else if (context!=null && !context.getAvailable()) {
- writer.println(sm.getString("managerServlet.deployedButNotStarted", displayPath));
+ writer.println(smClient.getString(
+ "managerServlet.deployedButNotStarted", displayPath));
} else {
// Something failed
- writer.println(sm.getString("managerServlet.deployFailed", displayPath));
+ writer.println(smClient.getString(
+ "managerServlet.deployFailed", displayPath));
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log("ManagerServlet.install[" + displayPath + "]", t);
- writer.println(sm.getString("managerServlet.exception",
+ writer.println(smClient.getString("managerServlet.exception",
t.toString()));
}
*
* @param writer Writer to render to
*/
- protected void list(PrintWriter writer) {
+ protected void list(PrintWriter writer, StringManager smClient) {
if (debug >= 1)
log("list: Listing contexts for virtual host '" +
host.getName() + "'");
- writer.println(sm.getString("managerServlet.listed",
+ writer.println(smClient.getString("managerServlet.listed",
host.getName()));
Container[] contexts = host.findChildren();
for (int i = 0; i < contexts.length; i++) {
if( displayPath.equals("") )
displayPath = "/";
if (context.getAvailable()) {
- writer.println(sm.getString("managerServlet.listitem",
- displayPath,
- "running",
- "" + context.getManager().findSessions().length,
- context.getDocBase()));
+ writer.println(smClient.getString("managerServlet.listitem",
+ displayPath,
+ "running",
+ "" + context.getManager().findSessions().length,
+ context.getDocBase()));
} else {
- writer.println(sm.getString("managerServlet.listitem",
- displayPath,
- "stopped",
- "0",
- context.getDocBase()));
+ writer.println(smClient.getString("managerServlet.listitem",
+ displayPath,
+ "stopped",
+ "0",
+ context.getDocBase()));
}
}
}
* @param writer Writer to render to
* @param path Context path of the application to be restarted
*/
- protected void reload(PrintWriter writer, String path) {
+ protected void reload(PrintWriter writer, String path,
+ StringManager smClient) {
if (debug >= 1)
log("restart: Reloading web application at '" + path + "'");
if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
- writer.println(sm.getString("managerServlet.invalidPath",
- RequestUtil.filter(path)));
+ writer.println(smClient.getString("managerServlet.invalidPath",
+ RequestUtil.filter(path)));
return;
}
String displayPath = path;
try {
Context context = (Context) host.findChild(path);
if (context == null) {
- writer.println(sm.getString
- ("managerServlet.noContext",
- RequestUtil.filter(displayPath)));
+ writer.println(smClient.getString("managerServlet.noContext",
+ RequestUtil.filter(displayPath)));
return;
}
// It isn't possible for the manager to reload itself
if (context.getPath().equals(this.context.getPath())) {
- writer.println(sm.getString("managerServlet.noSelf"));
+ writer.println(smClient.getString("managerServlet.noSelf"));
return;
}
context.reload();
writer.println
- (sm.getString("managerServlet.reloaded", displayPath));
+ (smClient.getString("managerServlet.reloaded", displayPath));
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log("ManagerServlet.reload[" + displayPath + "]", t);
- writer.println(sm.getString("managerServlet.exception",
- t.toString()));
+ writer.println(smClient.getString("managerServlet.exception",
+ t.toString()));
}
}
* @param type Fully qualified class name of the resource type of interest,
* or <code>null</code> to list resources of all types
*/
- protected void resources(PrintWriter writer, String type) {
+ protected void resources(PrintWriter writer, String type,
+ StringManager smClient) {
if (debug >= 1) {
if (type != null) {
// Is the global JNDI resources context available?
if (global == null) {
- writer.println(sm.getString("managerServlet.noGlobal"));
+ writer.println(smClient.getString("managerServlet.noGlobal"));
return;
}
// Enumerate the global JNDI resources of the requested type
if (type != null) {
- writer.println(sm.getString("managerServlet.resourcesType",
- type));
+ writer.println(smClient.getString("managerServlet.resourcesType",
+ type));
} else {
- writer.println(sm.getString("managerServlet.resourcesAll"));
+ writer.println(smClient.getString("managerServlet.resourcesAll"));
}
Class<?> clazz = null;
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log("ManagerServlet.resources[" + type + "]", t);
- writer.println(sm.getString("managerServlet.exception",
- t.toString()));
+ writer.println(smClient.getString("managerServlet.exception",
+ t.toString()));
return;
}
- printResources(writer, "", global, type, clazz);
+ printResources(writer, "", global, type, clazz, smClient);
}
*/
protected void printResources(PrintWriter writer, String prefix,
javax.naming.Context namingContext,
- String type, Class<?> clazz) {
+ String type, Class<?> clazz,
+ StringManager smClient) {
try {
NamingEnumeration<Binding> items = namingContext.listBindings("");
if (item.getObject() instanceof javax.naming.Context) {
printResources
(writer, prefix + item.getName() + "/",
- (javax.naming.Context) item.getObject(), type, clazz);
+ (javax.naming.Context) item.getObject(), type, clazz,
+ smClient);
} else {
if ((clazz != null) &&
(!(clazz.isInstance(item.getObject())))) {
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log("ManagerServlet.resources[" + type + "]", t);
- writer.println(sm.getString("managerServlet.exception",
- t.toString()));
+ writer.println(smClient.getString("managerServlet.exception",
+ t.toString()));
}
}
*
* @param writer Writer to render to
*/
- protected void roles(PrintWriter writer) {
+ protected void roles(PrintWriter writer, StringManager smClient) {
if (debug >= 1) {
log("roles: List security roles from user database");
InitialContext ic = new InitialContext();
database = (UserDatabase) ic.lookup("java:comp/env/users");
} catch (NamingException e) {
- writer.println(sm.getString("managerServlet.userDatabaseError"));
+ writer.println(smClient.getString(
+ "managerServlet.userDatabaseError"));
log("java:comp/env/users", e);
return;
}
if (database == null) {
- writer.println(sm.getString("managerServlet.userDatabaseMissing"));
+ writer.println(smClient.getString(
+ "managerServlet.userDatabaseMissing"));
return;
}
// Enumerate the available roles
- writer.println(sm.getString("managerServlet.rolesList"));
+ writer.println(smClient.getString("managerServlet.rolesList"));
Iterator<Role> roles = database.getRoles();
if (roles != null) {
while (roles.hasNext()) {
* Writes System OS and JVM properties.
* @param writer Writer to render to
*/
- protected void serverinfo(PrintWriter writer) {
+ protected void serverinfo(PrintWriter writer, StringManager smClient) {
if (debug >= 1)
log("serverinfo");
try {
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
getServletContext().log("ManagerServlet.serverinfo",t);
- writer.println(sm.getString("managerServlet.exception",
- t.toString()));
+ writer.println(smClient.getString("managerServlet.exception",
+ t.toString()));
}
}
* @param path Context path 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, String path, int idle,
+ StringManager smClient) {
if (debug >= 1) {
log("sessions: Session information for web application at '" + path + "'");
}
if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
- writer.println(sm.getString("managerServlet.invalidPath",
- RequestUtil.filter(path)));
+ writer.println(smClient.getString("managerServlet.invalidPath",
+ RequestUtil.filter(path)));
return;
}
String displayPath = path;
try {
Context context = (Context) host.findChild(path);
if (context == null) {
- writer.println(sm.getString("managerServlet.noContext",
- RequestUtil.filter(displayPath)));
+ writer.println(smClient.getString("managerServlet.noContext",
+ RequestUtil.filter(displayPath)));
return;
}
Manager manager = context.getManager() ;
if(manager == null) {
- writer.println(sm.getString("managerServlet.noManager",
+ writer.println(smClient.getString("managerServlet.noManager",
RequestUtil.filter(displayPath)));
return;
}
if ( histoInterval * maxCount < maxInactiveInterval )
maxCount++;
- writer.println(sm.getString("managerServlet.sessions", displayPath));
- writer.println(sm.getString("managerServlet.sessiondefaultmax",
- "" + maxInactiveInterval));
+ writer.println(smClient.getString("managerServlet.sessions",
+ displayPath));
+ writer.println(smClient.getString(
+ "managerServlet.sessiondefaultmax",
+ "" + maxInactiveInterval));
Session [] sessions = manager.findSessions();
int [] timeout = new int[maxCount];
int notimeout = 0;
timeout[time]++;
}
if (timeout[0] > 0)
- writer.println(sm.getString("managerServlet.sessiontimeout",
- "<" + histoInterval, "" + timeout[0]));
+ writer.println(smClient.getString(
+ "managerServlet.sessiontimeout",
+ "<" + histoInterval, "" + timeout[0]));
for (int i = 1; i < maxCount-1; i++) {
if (timeout[i] > 0)
- writer.println(sm.getString("managerServlet.sessiontimeout",
- "" + (i)*histoInterval + " - <" + (i+1)*histoInterval,
- "" + timeout[i]));
+ writer.println(smClient.getString(
+ "managerServlet.sessiontimeout",
+ "" + (i)*histoInterval + " - <" + (i+1)*histoInterval,
+ "" + timeout[i]));
}
if (timeout[maxCount-1] > 0)
- writer.println(sm.getString("managerServlet.sessiontimeout",
- ">=" + maxCount*histoInterval,
- "" + timeout[maxCount-1]));
+ writer.println(smClient.getString(
+ "managerServlet.sessiontimeout",
+ ">=" + maxCount*histoInterval,
+ "" + timeout[maxCount-1]));
if (notimeout > 0)
- writer.println(sm.getString("managerServlet.sessiontimeout.unlimited",
- "" + notimeout));
+ writer.println(smClient.getString(
+ "managerServlet.sessiontimeout.unlimited",
+ "" + notimeout));
if (idle >= 0)
- writer.println(sm.getString("managerServlet.sessiontimeout.expired",
- "" + idle,"" + expired));
+ writer.println(smClient.getString(
+ "managerServlet.sessiontimeout.expired",
+ "" + idle,"" + expired));
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log("ManagerServlet.sessions[" + displayPath + "]", t);
- writer.println(sm.getString("managerServlet.exception",
- t.toString()));
+ writer.println(smClient.getString("managerServlet.exception",
+ t.toString()));
}
}
* @param writer Writer to render to
* @param path Context path of the application to list session information for
*/
- protected void sessions(PrintWriter writer, String path) {
- sessions(writer, path, -1);
+ protected void sessions(PrintWriter writer, String path,
+ StringManager smClient) {
+ sessions(writer, path, -1, smClient);
}
* @param path
* @param req
*/
- protected void expireSessions(PrintWriter writer, String path, HttpServletRequest req) {
+ protected void expireSessions(PrintWriter writer, String path,
+ HttpServletRequest req, StringManager smClient) {
int idle = -1;
String idleParam = req.getParameter("idle");
if (idleParam != null) {
log("Could not parse idle parameter to an int: " + idleParam);
}
}
- sessions(writer, path, idle);
+ sessions(writer, path, idle, smClient);
}
/**
* @param writer Writer to render to
* @param path Context path of the application to be started
*/
- protected void start(PrintWriter writer, String path) {
+ protected void start(PrintWriter writer, String path,
+ StringManager smClient) {
if (debug >= 1)
log("start: Starting web application at '" + path + "'");
if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
- writer.println(sm.getString("managerServlet.invalidPath",
- RequestUtil.filter(path)));
+ writer.println(smClient.getString("managerServlet.invalidPath",
+ RequestUtil.filter(path)));
return;
}
String displayPath = path;
try {
Context context = (Context) host.findChild(path);
if (context == null) {
- writer.println(sm.getString("managerServlet.noContext",
- RequestUtil.filter(displayPath)));
+ writer.println(smClient.getString("managerServlet.noContext",
+ RequestUtil.filter(displayPath)));
return;
}
context.start();
if (context.getAvailable())
- writer.println
- (sm.getString("managerServlet.started", displayPath));
+ writer.println(smClient.getString("managerServlet.started",
+ displayPath));
else
- writer.println
- (sm.getString("managerServlet.startFailed", displayPath));
+ writer.println(smClient.getString("managerServlet.startFailed",
+ displayPath));
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
- getServletContext().log
- (sm.getString("managerServlet.startFailed", displayPath), t);
- writer.println
- (sm.getString("managerServlet.startFailed", displayPath));
- writer.println(sm.getString("managerServlet.exception",
- t.toString()));
+ getServletContext().log(sm.getString("managerServlet.startFailed",
+ displayPath), t);
+ writer.println(smClient.getString("managerServlet.startFailed",
+ displayPath));
+ writer.println(smClient.getString("managerServlet.exception",
+ t.toString()));
}
}
* @param writer Writer to render to
* @param path Context path of the application to be stopped
*/
- protected void stop(PrintWriter writer, String path) {
+ protected void stop(PrintWriter writer, String path,
+ StringManager smClient) {
if (debug >= 1)
log("stop: Stopping web application at '" + path + "'");
if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
- writer.println(sm.getString("managerServlet.invalidPath",
- RequestUtil.filter(path)));
+ writer.println(smClient.getString("managerServlet.invalidPath",
+ RequestUtil.filter(path)));
return;
}
String displayPath = path;
try {
Context context = (Context) host.findChild(path);
if (context == null) {
- writer.println(sm.getString("managerServlet.noContext",
- RequestUtil.filter(displayPath)));
+ writer.println(smClient.getString("managerServlet.noContext",
+ RequestUtil.filter(displayPath)));
return;
}
// It isn't possible for the manager to stop itself
if (context.getPath().equals(this.context.getPath())) {
- writer.println(sm.getString("managerServlet.noSelf"));
+ writer.println(smClient.getString("managerServlet.noSelf"));
return;
}
context.stop();
- writer.println(sm.getString("managerServlet.stopped", displayPath));
+ writer.println(smClient.getString(
+ "managerServlet.stopped", displayPath));
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log("ManagerServlet.stop[" + displayPath + "]", t);
- writer.println(sm.getString("managerServlet.exception",
- t.toString()));
+ writer.println(smClient.getString("managerServlet.exception",
+ t.toString()));
}
}
* @param writer Writer to render to
* @param path Context path of the application to be removed
*/
- protected void undeploy(PrintWriter writer, String path) {
+ protected void undeploy(PrintWriter writer, String path,
+ StringManager smClient) {
if (debug >= 1)
log("undeploy: Undeploying web application at '" + path + "'");
if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
- writer.println(sm.getString("managerServlet.invalidPath",
- RequestUtil.filter(path)));
+ writer.println(smClient.getString("managerServlet.invalidPath",
+ RequestUtil.filter(path)));
return;
}
String displayPath = path;
// Validate the Context of the specified application
Context context = (Context) host.findChild(path);
if (context == null) {
- writer.println(sm.getString("managerServlet.noContext",
- RequestUtil.filter(displayPath)));
+ writer.println(smClient.getString("managerServlet.noContext",
+ RequestUtil.filter(displayPath)));
return;
}
if (!isDeployed(path)) {
- writer.println(sm.getString("managerServlet.notDeployed",
+ writer.println(smClient.getString("managerServlet.notDeployed",
RequestUtil.filter(displayPath)));
return;
}
removeServiced(path.replace('#','/'));
}
}
- writer.println(sm.getString("managerServlet.undeployed",
- displayPath));
+ writer.println(smClient.getString("managerServlet.undeployed",
+ displayPath));
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log("ManagerServlet.undeploy[" + displayPath + "]", t);
- writer.println(sm.getString("managerServlet.exception",
- t.toString()));
+ writer.println(smClient.getString("managerServlet.exception",
+ t.toString()));
}
}
}
+ protected StringManager getStringManager(HttpServletRequest req) {
+ Enumeration<Locale> requestedLocales = req.getLocales();
+ while (requestedLocales.hasMoreElements()) {
+ Locale locale = requestedLocales.nextElement();
+ StringManager result = StringManager.getManager(Constants.Package,
+ locale);
+ if (result.getLocale().equals(locale)) {
+ return result;
+ }
+ }
+ // Return the default
+ return sm;
+ }
+
+
/**
* Copy the specified file or directory to the destination.
*