Search in sources :

Example 21 with StringManager

use of org.apache.tomcat.util.res.StringManager in project tomcat by apache.

the class HTMLManagerServlet method list.

/**
 * Render an HTML list of the currently active Contexts in our virtual host,
 * and memory and server status information.
 *
 * @param request The request
 * @param response The response
 * @param message a message to display
 * @param smClient internationalized strings
 * @throws IOException an IO error occurred
 */
protected void list(HttpServletRequest request, HttpServletResponse response, String message, StringManager smClient) throws IOException {
    if (debug >= 1) {
        log("list: Listing contexts for virtual host '" + host.getName() + "'");
    }
    PrintWriter writer = response.getWriter();
    Object[] args = new Object[2];
    args[0] = request.getContextPath();
    args[1] = smClient.getString("htmlManagerServlet.title");
    // HTML Header Section
    writer.print(MessageFormat.format(Constants.HTML_HEADER_SECTION, args));
    // Body Header Section
    writer.print(MessageFormat.format(Constants.BODY_HEADER_SECTION, args));
    // Message Section
    args = new Object[3];
    args[0] = smClient.getString("htmlManagerServlet.messageLabel");
    if (message == null || message.length() == 0) {
        args[1] = "OK";
    } else {
        args[1] = Escape.htmlElementContent(message);
    }
    writer.print(MessageFormat.format(Constants.MESSAGE_SECTION, args));
    // Manager Section
    args = new Object[9];
    args[0] = smClient.getString("htmlManagerServlet.manager");
    args[1] = response.encodeURL(request.getContextPath() + "/html/list");
    args[2] = smClient.getString("htmlManagerServlet.list");
    // External link
    args[3] = (request.getContextPath() + "/" + smClient.getString("htmlManagerServlet.helpHtmlManagerFile"));
    args[4] = smClient.getString("htmlManagerServlet.helpHtmlManager");
    // External link
    args[5] = (request.getContextPath() + "/" + smClient.getString("htmlManagerServlet.helpManagerFile"));
    args[6] = smClient.getString("htmlManagerServlet.helpManager");
    args[7] = response.encodeURL(request.getContextPath() + "/status");
    args[8] = smClient.getString("statusServlet.title");
    writer.print(MessageFormat.format(Constants.MANAGER_SECTION, args));
    // Apps Header Section
    args = new Object[7];
    args[0] = smClient.getString("htmlManagerServlet.appsTitle");
    args[1] = smClient.getString("htmlManagerServlet.appsPath");
    args[2] = smClient.getString("htmlManagerServlet.appsVersion");
    args[3] = smClient.getString("htmlManagerServlet.appsName");
    args[4] = smClient.getString("htmlManagerServlet.appsAvailable");
    args[5] = smClient.getString("htmlManagerServlet.appsSessions");
    args[6] = smClient.getString("htmlManagerServlet.appsTasks");
    writer.print(MessageFormat.format(APPS_HEADER_SECTION, args));
    // Apps Row Section
    // Create sorted map of deployed applications by context name.
    Container[] children = host.findChildren();
    String[] contextNames = new String[children.length];
    for (int i = 0; i < children.length; i++) {
        contextNames[i] = children[i].getName();
    }
    Arrays.sort(contextNames);
    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");
    String noVersion = "<i>" + smClient.getString("htmlManagerServlet.noVersion") + "</i>";
    boolean isHighlighted = true;
    boolean isDeployed = true;
    String highlightColor = null;
    for (String contextName : contextNames) {
        Context ctxt = (Context) host.findChild(contextName);
        if (ctxt != null) {
            // Bugzilla 34818, alternating row colors
            isHighlighted = !isHighlighted;
            if (isHighlighted) {
                highlightColor = "#C3F3C3";
            } else {
                highlightColor = "#FFFFFF";
            }
            String contextPath = ctxt.getPath();
            String displayPath = contextPath;
            if (displayPath.equals("")) {
                displayPath = "/";
            }
            StringBuilder tmp = new StringBuilder();
            tmp.append("path=");
            tmp.append(URLEncoder.DEFAULT.encode(displayPath, StandardCharsets.UTF_8));
            final String webappVersion = ctxt.getWebappVersion();
            if (webappVersion != null && webappVersion.length() > 0) {
                tmp.append("&version=");
                tmp.append(URLEncoder.DEFAULT.encode(webappVersion, StandardCharsets.UTF_8));
            }
            String pathVersion = tmp.toString();
            try {
                isDeployed = isDeployed(contextName);
            } catch (Exception e) {
                // Assume false on failure for safety
                isDeployed = false;
            }
            args = new Object[7];
            // External link
            args[0] = "<a href=\"" + URLEncoder.DEFAULT.encode(contextPath + "/", StandardCharsets.UTF_8) + "\" " + Constants.REL_EXTERNAL + ">" + Escape.htmlElementContent(displayPath) + "</a>";
            if (webappVersion == null || webappVersion.isEmpty()) {
                args[1] = noVersion;
            } else {
                args[1] = Escape.htmlElementContent(webappVersion);
            }
            if (ctxt.getDisplayName() == null) {
                args[2] = "&nbsp;";
            } else {
                args[2] = Escape.htmlElementContent(ctxt.getDisplayName());
            }
            args[3] = Boolean.valueOf(ctxt.getState().isAvailable());
            args[4] = Escape.htmlElementContent(response.encodeURL(request.getContextPath() + "/html/sessions?" + pathVersion));
            Manager manager = ctxt.getManager();
            if (manager instanceof DistributedManager && showProxySessions) {
                args[5] = Integer.valueOf(((DistributedManager) manager).getActiveSessionsFull());
            } else if (manager != null) {
                args[5] = Integer.valueOf(manager.getActiveSessions());
            } else {
                args[5] = Integer.valueOf(0);
            }
            args[6] = highlightColor;
            writer.print(MessageFormat.format(APPS_ROW_DETAILS_SECTION, args));
            args = new Object[14];
            args[0] = Escape.htmlElementContent(response.encodeURL(request.getContextPath() + "/html/start?" + pathVersion));
            args[1] = appsStart;
            args[2] = Escape.htmlElementContent(response.encodeURL(request.getContextPath() + "/html/stop?" + pathVersion));
            args[3] = appsStop;
            args[4] = Escape.htmlElementContent(response.encodeURL(request.getContextPath() + "/html/reload?" + pathVersion));
            args[5] = appsReload;
            args[6] = Escape.htmlElementContent(response.encodeURL(request.getContextPath() + "/html/undeploy?" + pathVersion));
            args[7] = appsUndeploy;
            args[8] = Escape.htmlElementContent(response.encodeURL(request.getContextPath() + "/html/expire?" + pathVersion));
            args[9] = appsExpire;
            args[10] = smClient.getString("htmlManagerServlet.expire.explain");
            if (manager == null) {
                args[11] = smClient.getString("htmlManagerServlet.noManager");
            } else {
                args[11] = Integer.valueOf(ctxt.getSessionTimeout());
            }
            args[12] = smClient.getString("htmlManagerServlet.expire.unit");
            args[13] = highlightColor;
            if (ctxt.getName().equals(this.context.getName())) {
                writer.print(MessageFormat.format(MANAGER_APP_ROW_BUTTON_SECTION, args));
            } else if (ctxt.getState().isAvailable() && isDeployed) {
                writer.print(MessageFormat.format(STARTED_DEPLOYED_APPS_ROW_BUTTON_SECTION, args));
            } else if (ctxt.getState().isAvailable() && !isDeployed) {
                writer.print(MessageFormat.format(STARTED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION, args));
            } else if (!ctxt.getState().isAvailable() && isDeployed) {
                writer.print(MessageFormat.format(STOPPED_DEPLOYED_APPS_ROW_BUTTON_SECTION, args));
            } else {
                writer.print(MessageFormat.format(STOPPED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION, args));
            }
        }
    }
    // Deploy Section
    args = new Object[8];
    args[0] = smClient.getString("htmlManagerServlet.deployTitle");
    args[1] = smClient.getString("htmlManagerServlet.deployServer");
    args[2] = response.encodeURL(request.getContextPath() + "/html/deploy");
    args[3] = smClient.getString("htmlManagerServlet.deployPath");
    args[4] = smClient.getString("htmlManagerServlet.deployVersion");
    args[5] = smClient.getString("htmlManagerServlet.deployConfig");
    args[6] = smClient.getString("htmlManagerServlet.deployWar");
    args[7] = smClient.getString("htmlManagerServlet.deployButton");
    writer.print(MessageFormat.format(DEPLOY_SECTION, args));
    args = new Object[4];
    args[0] = smClient.getString("htmlManagerServlet.deployUpload");
    args[1] = response.encodeURL(request.getContextPath() + "/html/upload");
    args[2] = smClient.getString("htmlManagerServlet.deployUploadFile");
    args[3] = smClient.getString("htmlManagerServlet.deployButton");
    writer.print(MessageFormat.format(UPLOAD_SECTION, args));
    // Config section
    args = new Object[5];
    args[0] = smClient.getString("htmlManagerServlet.configTitle");
    args[1] = smClient.getString("htmlManagerServlet.configSslReloadTitle");
    args[2] = response.encodeURL(request.getContextPath() + "/html/sslReload");
    args[3] = smClient.getString("htmlManagerServlet.configSslHostName");
    args[4] = smClient.getString("htmlManagerServlet.configReloadButton");
    writer.print(MessageFormat.format(CONFIG_SECTION, args));
    // Diagnostics section
    args = new Object[15];
    args[0] = smClient.getString("htmlManagerServlet.diagnosticsTitle");
    args[1] = smClient.getString("htmlManagerServlet.diagnosticsLeak");
    args[2] = response.encodeURL(request.getContextPath() + "/html/findleaks");
    args[3] = smClient.getString("htmlManagerServlet.diagnosticsLeakWarning");
    args[4] = smClient.getString("htmlManagerServlet.diagnosticsLeakButton");
    args[5] = smClient.getString("htmlManagerServlet.diagnosticsSsl");
    args[6] = response.encodeURL(request.getContextPath() + "/html/sslConnectorCiphers");
    args[7] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorCipherButton");
    args[8] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorCipherText");
    args[9] = response.encodeURL(request.getContextPath() + "/html/sslConnectorCerts");
    args[10] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorCertsButton");
    args[11] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorCertsText");
    args[12] = response.encodeURL(request.getContextPath() + "/html/sslConnectorTrustedCerts");
    args[13] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorTrustedCertsButton");
    args[14] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorTrustedCertsText");
    writer.print(MessageFormat.format(DIAGNOSTICS_SECTION, args));
    // Server Header Section
    args = new Object[9];
    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");
    args[7] = smClient.getString("htmlManagerServlet.serverHostname");
    args[8] = smClient.getString("htmlManagerServlet.serverIPAddress");
    writer.print(MessageFormat.format(Constants.SERVER_HEADER_SECTION, args));
    // Server Row Section
    args = new Object[8];
    args[0] = ServerInfo.getServerInfo();
    args[1] = System.getProperty("java.runtime.version");
    args[2] = System.getProperty("java.vm.vendor");
    args[3] = System.getProperty("os.name");
    args[4] = System.getProperty("os.version");
    args[5] = System.getProperty("os.arch");
    try {
        InetAddress address = InetAddress.getLocalHost();
        args[6] = address.getHostName();
        args[7] = address.getHostAddress();
    } catch (UnknownHostException e) {
        args[6] = "-";
        args[7] = "-";
    }
    writer.print(MessageFormat.format(Constants.SERVER_ROW_SECTION, args));
    // HTML Tail Section
    writer.print(Constants.HTML_TAIL_SECTION);
    // Finish up the response
    writer.flush();
    writer.close();
}
Also used : Context(org.apache.catalina.Context) UnknownHostException(java.net.UnknownHostException) DistributedManager(org.apache.catalina.DistributedManager) StringManager(org.apache.tomcat.util.res.StringManager) Manager(org.apache.catalina.Manager) ServletException(jakarta.servlet.ServletException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) DistributedManager(org.apache.catalina.DistributedManager) Container(org.apache.catalina.Container) InetAddress(java.net.InetAddress) PrintWriter(java.io.PrintWriter)

Example 22 with StringManager

use of org.apache.tomcat.util.res.StringManager in project tomcat by apache.

the class HTMLManagerServlet method doPost.

/**
 * Process a POST request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    StringManager smClient = StringManager.getManager(Constants.Package, request.getLocales());
    // Identify the request parameters that we need
    // By obtaining the command from the pathInfo, per-command security can
    // be configured in web.xml
    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");
    String deployWar = request.getParameter("deployWar");
    String deployConfig = request.getParameter("deployConfig");
    ContextName deployCn = null;
    if (deployPath != null && deployPath.length() > 0) {
        deployCn = new ContextName(deployPath, request.getParameter("deployVersion"));
    } else if (deployConfig != null && deployConfig.length() > 0) {
        deployCn = ContextName.extractFromPath(deployConfig);
    } else if (deployWar != null && deployWar.length() > 0) {
        deployCn = ContextName.extractFromPath(deployWar);
    }
    String tlsHostName = request.getParameter("tlsHostName");
    // Prepare our output writer to generate the response message
    response.setContentType("text/html; charset=" + Constants.CHARSET);
    String message = "";
    if (command == null || command.length() == 0) {
    // No command == list
    // List always displayed -> do nothing
    } else if (command.equals("/upload")) {
        message = upload(request, smClient);
    } else if (command.equals("/deploy")) {
        message = deployInternal(deployConfig, deployCn, deployWar, smClient);
    } else if (command.equals("/reload")) {
        message = reload(cn, smClient);
    } else if (command.equals("/undeploy")) {
        message = undeploy(cn, smClient);
    } else if (command.equals("/expire")) {
        message = expireSessions(cn, request, smClient);
    } else if (command.equals("/start")) {
        message = start(cn, smClient);
    } else if (command.equals("/stop")) {
        message = stop(cn, smClient);
    } else if (command.equals("/findleaks")) {
        message = findleaks(smClient);
    } else if (command.equals("/sslReload")) {
        message = sslReload(tlsHostName, smClient);
    } else {
        // Try GET
        doGet(request, response);
        return;
    }
    list(request, response, message, smClient);
}
Also used : StringManager(org.apache.tomcat.util.res.StringManager) ContextName(org.apache.catalina.util.ContextName)

Example 23 with StringManager

use of org.apache.tomcat.util.res.StringManager in project tomcat by apache.

the class StatusManagerServlet method doGet.

/**
 * Process a GET request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    StringManager smClient = StringManager.getManager(Constants.Package, request.getLocales());
    // mode is flag for HTML or XML output
    int mode = 0;
    // if ?XML=true, set the mode to XML
    if (request.getParameter("XML") != null && request.getParameter("XML").equals("true")) {
        mode = 1;
    }
    StatusTransformer.setContentType(response, mode);
    PrintWriter writer = response.getWriter();
    boolean completeStatus = false;
    if ((request.getPathInfo() != null) && (request.getPathInfo().equals("/all"))) {
        completeStatus = true;
    }
    // use StatusTransformer to output status
    Object[] args = new Object[1];
    args[0] = request.getContextPath();
    StatusTransformer.writeHeader(writer, args, mode);
    // Body Header Section
    args = new Object[2];
    args[0] = request.getContextPath();
    if (completeStatus) {
        args[1] = smClient.getString("statusServlet.complete");
    } else {
        args[1] = smClient.getString("statusServlet.title");
    }
    // use StatusTransformer to output status
    StatusTransformer.writeBody(writer, args, mode);
    // Manager Section
    args = new Object[9];
    args[0] = smClient.getString("htmlManagerServlet.manager");
    args[1] = response.encodeURL(request.getContextPath() + "/html/list");
    args[2] = smClient.getString("htmlManagerServlet.list");
    // External link
    args[3] = (request.getContextPath() + "/" + smClient.getString("htmlManagerServlet.helpHtmlManagerFile"));
    args[4] = smClient.getString("htmlManagerServlet.helpHtmlManager");
    // External link
    args[5] = (request.getContextPath() + "/" + smClient.getString("htmlManagerServlet.helpManagerFile"));
    args[6] = smClient.getString("htmlManagerServlet.helpManager");
    if (completeStatus) {
        args[7] = response.encodeURL(request.getContextPath() + "/status");
        args[8] = smClient.getString("statusServlet.title");
    } else {
        args[7] = response.encodeURL(request.getContextPath() + "/status/all");
        args[8] = smClient.getString("statusServlet.complete");
    }
    // use StatusTransformer to output status
    StatusTransformer.writeManager(writer, args, mode);
    // Server Header Section
    args = new Object[9];
    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");
    args[7] = smClient.getString("htmlManagerServlet.serverHostname");
    args[8] = smClient.getString("htmlManagerServlet.serverIPAddress");
    // use StatusTransformer to output status
    StatusTransformer.writePageHeading(writer, args, mode);
    // Server Row Section
    args = new Object[8];
    args[0] = ServerInfo.getServerInfo();
    args[1] = System.getProperty("java.runtime.version");
    args[2] = System.getProperty("java.vm.vendor");
    args[3] = System.getProperty("os.name");
    args[4] = System.getProperty("os.version");
    args[5] = System.getProperty("os.arch");
    try {
        InetAddress address = InetAddress.getLocalHost();
        args[6] = address.getHostName();
        args[7] = address.getHostAddress();
    } catch (UnknownHostException e) {
        args[6] = "-";
        args[7] = "-";
    }
    // use StatusTransformer to output status
    StatusTransformer.writeServerInfo(writer, args, mode);
    try {
        // Display virtual machine statistics
        args = new Object[9];
        args[0] = smClient.getString("htmlManagerServlet.jvmFreeMemory");
        args[1] = smClient.getString("htmlManagerServlet.jvmTotalMemory");
        args[2] = smClient.getString("htmlManagerServlet.jvmMaxMemory");
        args[3] = smClient.getString("htmlManagerServlet.jvmTableTitleMemoryPool");
        args[4] = smClient.getString("htmlManagerServlet.jvmTableTitleType");
        args[5] = smClient.getString("htmlManagerServlet.jvmTableTitleInitial");
        args[6] = smClient.getString("htmlManagerServlet.jvmTableTitleTotal");
        args[7] = smClient.getString("htmlManagerServlet.jvmTableTitleMaximum");
        args[8] = smClient.getString("htmlManagerServlet.jvmTableTitleUsed");
        // use StatusTransformer to output status
        StatusTransformer.writeVMState(writer, mode, args);
        Enumeration<ObjectName> enumeration = threadPools.elements();
        while (enumeration.hasMoreElements()) {
            ObjectName objectName = enumeration.nextElement();
            String name = objectName.getKeyProperty("name");
            args = new Object[19];
            args[0] = smClient.getString("htmlManagerServlet.connectorStateMaxThreads");
            args[1] = smClient.getString("htmlManagerServlet.connectorStateThreadCount");
            args[2] = smClient.getString("htmlManagerServlet.connectorStateThreadBusy");
            args[3] = smClient.getString("htmlManagerServlet.connectorStateAliveSocketCount");
            args[4] = smClient.getString("htmlManagerServlet.connectorStateMaxProcessingTime");
            args[5] = smClient.getString("htmlManagerServlet.connectorStateProcessingTime");
            args[6] = smClient.getString("htmlManagerServlet.connectorStateRequestCount");
            args[7] = smClient.getString("htmlManagerServlet.connectorStateErrorCount");
            args[8] = smClient.getString("htmlManagerServlet.connectorStateBytesReceived");
            args[9] = smClient.getString("htmlManagerServlet.connectorStateBytesSent");
            args[10] = smClient.getString("htmlManagerServlet.connectorStateTableTitleStage");
            args[11] = smClient.getString("htmlManagerServlet.connectorStateTableTitleTime");
            args[12] = smClient.getString("htmlManagerServlet.connectorStateTableTitleBSent");
            args[13] = smClient.getString("htmlManagerServlet.connectorStateTableTitleBRecv");
            args[14] = smClient.getString("htmlManagerServlet.connectorStateTableTitleClientForw");
            args[15] = smClient.getString("htmlManagerServlet.connectorStateTableTitleClientAct");
            args[16] = smClient.getString("htmlManagerServlet.connectorStateTableTitleVHost");
            args[17] = smClient.getString("htmlManagerServlet.connectorStateTableTitleRequest");
            args[18] = smClient.getString("htmlManagerServlet.connectorStateHint");
            // use StatusTransformer to output status
            StatusTransformer.writeConnectorState(writer, objectName, name, mBeanServer, globalRequestProcessors, requestProcessors, mode, args);
        }
        if ((request.getPathInfo() != null) && (request.getPathInfo().equals("/all"))) {
            // Note: Retrieving the full status is much slower
            // use StatusTransformer to output status
            StatusTransformer.writeDetailedState(writer, mBeanServer, mode);
        }
    } catch (Exception e) {
        throw new ServletException(e);
    }
    // use StatusTransformer to output status
    StatusTransformer.writeFooter(writer, mode);
}
Also used : UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) ServletException(jakarta.servlet.ServletException) UnknownHostException(java.net.UnknownHostException) StringManager(org.apache.tomcat.util.res.StringManager) ObjectName(javax.management.ObjectName) ServletException(jakarta.servlet.ServletException) InetAddress(java.net.InetAddress) PrintWriter(java.io.PrintWriter)

Example 24 with StringManager

use of org.apache.tomcat.util.res.StringManager in project tomcat by apache.

the class HostManagerServlet method doGet.

/**
 * Process a GET request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    StringManager smClient = StringManager.getManager(Constants.Package, request.getLocales());
    // Identify the request parameters that we need
    String command = request.getPathInfo();
    if (command == null) {
        command = request.getServletPath();
    }
    String name = request.getParameter("name");
    // Prepare our output writer to generate the response message
    response.setContentType("text/plain; charset=" + Constants.CHARSET);
    // Stop older versions of IE thinking they know best. We set text/plain
    // in the line above for a reason. IE's behaviour is unwanted at best
    // and dangerous at worst.
    response.setHeader("X-Content-Type-Options", "nosniff");
    PrintWriter writer = response.getWriter();
    // Process the requested command
    if (command == null) {
        writer.println(smClient.getString("hostManagerServlet.noCommand"));
    } else if (command.equals("/add")) {
        add(request, writer, name, false, smClient);
    } else if (command.equals("/remove")) {
        remove(writer, name, smClient);
    } else if (command.equals("/list")) {
        list(writer, smClient);
    } else if (command.equals("/start")) {
        start(writer, name, smClient);
    } else if (command.equals("/stop")) {
        stop(writer, name, smClient);
    } else if (command.equals("/persist")) {
        persist(writer, smClient);
    } else {
        writer.println(smClient.getString("hostManagerServlet.unknownCommand", command));
    }
    // Finish up the response
    writer.flush();
    writer.close();
}
Also used : StringManager(org.apache.tomcat.util.res.StringManager) PrintWriter(java.io.PrintWriter)

Example 25 with StringManager

use of org.apache.tomcat.util.res.StringManager in project tomcat by apache.

the class ManagerServlet method doGet.

/**
 * Process a GET request for the specified resource.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet-specified error occurs
 */
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    StringManager smClient = StringManager.getManager(Constants.Package, request.getLocales());
    // Identify the request parameters that we need
    String command = request.getPathInfo();
    if (command == null) {
        command = request.getServletPath();
    }
    String path = request.getParameter("path");
    String war = request.getParameter("war");
    String config = request.getParameter("config");
    ContextName cn = null;
    if (path != null) {
        cn = new ContextName(path, request.getParameter("version"));
    } else if (config != null) {
        cn = ContextName.extractFromPath(config);
    } else if (war != null) {
        cn = ContextName.extractFromPath(war);
    }
    String type = request.getParameter("type");
    String tag = request.getParameter("tag");
    boolean update = false;
    if ((request.getParameter("update") != null) && (request.getParameter("update").equals("true"))) {
        update = true;
    }
    String tlsHostName = request.getParameter("tlsHostName");
    boolean statusLine = false;
    if ("true".equals(request.getParameter("statusLine"))) {
        statusLine = true;
    }
    // Prepare our output writer to generate the response message
    response.setContentType("text/plain; charset=" + Constants.CHARSET);
    // Stop older versions of IE thinking they know best. We set text/plain
    // in the line above for a reason. IE's behaviour is unwanted at best
    // and dangerous at worst.
    response.setHeader("X-Content-Type-Options", "nosniff");
    PrintWriter writer = response.getWriter();
    // Process the requested command
    if (command == null) {
        writer.println(smClient.getString("managerServlet.noCommand"));
    } else if (command.equals("/deploy")) {
        if (war != null || config != null) {
            deploy(writer, config, cn, war, update, smClient);
        } else if (tag != null) {
            deploy(writer, cn, tag, smClient);
        } else {
            writer.println(smClient.getString("managerServlet.invalidCommand", command));
        }
    } else if (command.equals("/list")) {
        list(writer, smClient);
    } else if (command.equals("/reload")) {
        reload(writer, cn, smClient);
    } else if (command.equals("/resources")) {
        resources(writer, type, smClient);
    } else if (command.equals("/save")) {
        save(writer, path, smClient);
    } else if (command.equals("/serverinfo")) {
        serverinfo(writer, smClient);
    } else if (command.equals("/sessions")) {
        expireSessions(writer, cn, request, smClient);
    } else if (command.equals("/expire")) {
        expireSessions(writer, cn, request, smClient);
    } else if (command.equals("/start")) {
        start(writer, cn, smClient);
    } else if (command.equals("/stop")) {
        stop(writer, cn, smClient);
    } else if (command.equals("/undeploy")) {
        undeploy(writer, cn, smClient);
    } else if (command.equals("/findleaks")) {
        findleaks(statusLine, writer, smClient);
    } else if (command.equals("/vminfo")) {
        vmInfo(writer, smClient, request.getLocales());
    } else if (command.equals("/threaddump")) {
        threadDump(writer, smClient, request.getLocales());
    } else if (command.equals("/sslConnectorCiphers")) {
        sslConnectorCiphers(writer, smClient);
    } else if (command.equals("/sslConnectorCerts")) {
        sslConnectorCerts(writer, smClient);
    } else if (command.equals("/sslConnectorTrustedCerts")) {
        sslConnectorTrustedCerts(writer, smClient);
    } else if (command.equals("/sslReload")) {
        sslReload(writer, tlsHostName, smClient);
    } else {
        writer.println(smClient.getString("managerServlet.unknownCommand", command));
    }
    // Finish up the response
    writer.flush();
    writer.close();
}
Also used : StringManager(org.apache.tomcat.util.res.StringManager) ContextName(org.apache.catalina.util.ContextName) PrintWriter(java.io.PrintWriter)

Aggregations

StringManager (org.apache.tomcat.util.res.StringManager)27 PrintWriter (java.io.PrintWriter)9 IOException (java.io.IOException)8 ContextName (org.apache.catalina.util.ContextName)8 Context (org.apache.catalina.Context)6 Manager (org.apache.catalina.Manager)6 UnknownHostException (java.net.UnknownHostException)5 DistributedManager (org.apache.catalina.DistributedManager)4 Session (org.apache.catalina.Session)4 ServletException (jakarta.servlet.ServletException)3 Writer (java.io.Writer)3 InetAddress (java.net.InetAddress)3 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 Scanner (java.util.Scanner)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ServletException (javax.servlet.ServletException)2 Container (org.apache.catalina.Container)2 ServletContext (jakarta.servlet.ServletContext)1 HttpSession (jakarta.servlet.http.HttpSession)1