org.apache.tomcat.util.res.StringManager Java Examples

The following examples show how to use org.apache.tomcat.util.res.StringManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HostManagerServlet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Persist the current configuration to server.xml.
 *
 * @param writer Writer to render to
 * @param smClient i18n resources localized for the client
 */
protected void persist(PrintWriter writer, StringManager smClient) {

    if (debug >= 1) {
        log(sm.getString("hostManagerServlet.persist"));
    }

    try {
        MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName oname = new ObjectName(engine.getDomain() + ":type=StoreConfig");
        platformMBeanServer.invoke(oname, "storeConfig", null, null);
        writer.println(smClient.getString("hostManagerServlet.persisted"));
    } catch (Exception e) {
        getServletContext().log(sm.getString("hostManagerServlet.persistFailed"), e);
        writer.println(smClient.getString("hostManagerServlet.persistFailed"));
        // catch InstanceNotFoundException when StoreConfig is not enabled instead of printing
        // the failure message
        if (e instanceof InstanceNotFoundException) {
            writer.println("Please enable StoreConfig to use this feature.");
        } else {
            writer.println(smClient.getString("hostManagerServlet.exception", e.toString()));
        }
        return;
    }
}
 
Example #2
Source File: HostManagerServlet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Add host with the given parameters.
 *
 * @param request The request
 * @param writer The output writer
 * @param name The host name
 * @param htmlMode Flag value
 * @param smClient StringManager for the client's locale
*/
protected void add(HttpServletRequest request, PrintWriter writer,
        String name, boolean htmlMode, StringManager smClient) {
    String aliases = request.getParameter("aliases");
    String appBase = request.getParameter("appBase");
    boolean manager = booleanParameter(request, "manager", false, htmlMode);
    boolean autoDeploy = booleanParameter(request, "autoDeploy", true, htmlMode);
    boolean deployOnStartup = booleanParameter(request, "deployOnStartup", true, htmlMode);
    boolean deployXML = booleanParameter(request, "deployXML", true, htmlMode);
    boolean unpackWARs = booleanParameter(request, "unpackWARs", true, htmlMode);
    boolean copyXML = booleanParameter(request, "copyXML", false, htmlMode);
    add(writer, name, aliases, appBase, manager,
        autoDeploy,
        deployOnStartup,
        deployXML,
        unpackWARs,
        copyXML,
        smClient);
}
 
Example #3
Source File: HTMLManagerServlet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * 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 the session id
 * @param attributeName the attribute name
 * @param smClient  StringManager for the client's locale
 * @return true if there was an attribute removed, false otherwise
 */
protected boolean removeSessionAttribute(ContextName cn, String sessionId,
        String attributeName, StringManager smClient) {
    HttpSession session =
        getSessionForNameAndId(cn, sessionId, smClient).getSession();
    if (null == session) {
        // Shouldn't happen, but let's play nice...
        if (debug >= 1) {
            log("WARNING: can't remove attribute '" + attributeName + "' for null session " + sessionId);
        }
        return false;
    }
    boolean wasPresent = (null != session.getAttribute(attributeName));
    try {
        session.removeAttribute(attributeName);
    } catch (IllegalStateException ise) {
        if (debug >= 1) {
            log("Can't remote attribute '" + attributeName + "' for invalidated session id " + sessionId);
        }
    }
    return wasPresent;
}
 
Example #4
Source File: HTMLManagerServlet.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * 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(ContextName cn, String sessionId,
        String attributeName, StringManager smClient) throws IOException {
    HttpSession session =
        getSessionForNameAndId(cn, sessionId, smClient).getSession();
    if (null == session) {
        // Shouldn't happen, but let's play nice...
        if (debug >= 1) {
            log("WARNING: can't remove attribute '" + attributeName + "' for null session " + sessionId);
        }
        return false;
    }
    boolean wasPresent = (null != session.getAttribute(attributeName));
    try {
        session.removeAttribute(attributeName);
    } catch (IllegalStateException ise) {
        if (debug >= 1) {
            log("Can't remote attribute '" + attributeName + "' for invalidated session id " + sessionId);
        }
    }
    return wasPresent;
}
 
Example #5
Source File: ManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: HostManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Render a list of the currently active Contexts in our virtual host.
 *
 * @param writer Writer to render to
 */
protected void list(PrintWriter writer, StringManager smClient) {

    if (debug >= 1) {
        log(sm.getString("hostManagerServlet.list", engine.getName()));
    }

    writer.println(smClient.getString("hostManagerServlet.listed",
            engine.getName()));
    Container[] hosts = engine.findChildren();
    for (int i = 0; i < hosts.length; i++) {
        Host host = (Host) hosts[i];
        String name = host.getName();
        String[] aliases = host.findAliases();
        StringBuilder buf = new StringBuilder();
        if (aliases.length > 0) {
            buf.append(aliases[0]);
            for (int j = 1; j < aliases.length; j++) {
                buf.append(',').append(aliases[j]);
            }
        }
        writer.println(smClient.getString("hostManagerServlet.listitem",
                                    name, buf.toString()));
    }
}
 
Example #7
Source File: ManagerServlet.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #8
Source File: ManagerServlet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void writeDeployResult(PrintWriter writer, StringManager smClient,
        String name, String displayPath) {
    Context deployed = (Context) host.findChild(name);
    if (deployed != null && deployed.getConfigured() &&
            deployed.getState().isAvailable()) {
        writer.println(smClient.getString(
                "managerServlet.deployed", displayPath));
    } else if (deployed!=null && !deployed.getState().isAvailable()) {
        writer.println(smClient.getString(
                "managerServlet.deployedButNotStarted", displayPath));
    } else {
        // Something failed
        writer.println(smClient.getString(
                "managerServlet.deployFailed", displayPath));
    }
}
 
Example #9
Source File: HTMLManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * 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(ContextName cn, String sessionId,
        String attributeName, StringManager smClient) throws IOException {
    HttpSession session =
        getSessionForNameAndId(cn, sessionId, smClient).getSession();
    if (null == session) {
        // Shouldn't happen, but let's play nice...
        if (debug >= 1) {
            log("WARNING: can't remove attribute '" + attributeName + "' for null session " + sessionId);
        }
        return false;
    }
    boolean wasPresent = (null != session.getAttribute(attributeName));
    try {
        session.removeAttribute(attributeName);
    } catch (IllegalStateException ise) {
        if (debug >= 1) {
            log("Can't remote attribute '" + attributeName + "' for invalidated session id " + sessionId);
        }
    }
    return wasPresent;
}
 
Example #10
Source File: ManagerServlet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
protected Map<String,List<String>> getConnectorCiphers(StringManager smClient) {
    Map<String,List<String>> result = new HashMap<>();

    Connector connectors[] = getConnectors();
    for (Connector connector : connectors) {
        if (Boolean.TRUE.equals(connector.getProperty("SSLEnabled"))) {
            SSLHostConfig[] sslHostConfigs = connector.getProtocolHandler().findSslHostConfigs();
            for (SSLHostConfig sslHostConfig : sslHostConfigs) {
                String name = connector.toString() + "-" + sslHostConfig.getHostName();
                /* Add cipher list, keep order but remove duplicates */
                result.put(name, new ArrayList<>(new LinkedHashSet<>(
                    Arrays.asList(sslHostConfig.getEnabledCiphers()))));
            }
        } else {
            ArrayList<String> cipherList = new ArrayList<>(1);
            cipherList.add(smClient.getString("managerServlet.notSslConnector"));
            result.put(connector.toString(), cipherList);
        }
    }
    return result;
}
 
Example #11
Source File: HTMLManagerServlet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Find potential memory leaks caused by web application reload.
 *
 * @see ManagerServlet#findleaks(boolean, PrintWriter, StringManager)
 *
 * @param smClient  StringManager for the client's locale
 *
 * @return message String
 */
protected String findleaks(StringManager smClient) {

    StringBuilder msg = new StringBuilder();

    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);

    super.findleaks(false, printWriter, smClient);

    String writerText = stringWriter.toString();

    if (writerText.length() > 0) {
        if (!writerText.startsWith("FAIL -")) {
            msg.append(smClient.getString(
                    "htmlManagerServlet.findleaksList"));
        }
        msg.append(writerText);
    } else {
        msg.append(smClient.getString("htmlManagerServlet.findleaksNone"));
    }

    return msg.toString();
}
 
Example #12
Source File: HTMLManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Find potential memory leaks caused by web application reload.
 *
 * @see ManagerServlet#findleaks(boolean, PrintWriter, StringManager) 
 * 
 * @param smClient  StringManager for the client's locale
 *
 * @return message String
 */
protected String findleaks(StringManager smClient) {

    StringBuilder msg = new StringBuilder();

    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);

    super.findleaks(false, printWriter, smClient);

    String writerText = stringWriter.toString();

    if (writerText.length() > 0) {
        if (!writerText.startsWith("FAIL -")) {
            msg.append(smClient.getString(
                    "htmlManagerServlet.findleaksList"));
        }
        msg.append(writerText);
    } else {
        msg.append(smClient.getString("htmlManagerServlet.findleaksNone"));
    }
    
    return msg.toString();
}
 
Example #13
Source File: HostManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Add host with the given parameters.
 *
 * @param request The request
 * @param writer The output writer
 * @param name The host name
 * @param htmlMode Flag value
 */
protected void add(HttpServletRequest request, PrintWriter writer,
        String name, boolean htmlMode, StringManager smClient) {
    String aliases = request.getParameter("aliases");
    String appBase = request.getParameter("appBase");
    boolean manager = booleanParameter(request, "manager", false, htmlMode);
    boolean autoDeploy = booleanParameter(request, "autoDeploy", true, htmlMode);
    boolean deployOnStartup = booleanParameter(request, "deployOnStartup", true, htmlMode);
    boolean deployXML = booleanParameter(request, "deployXML", true, htmlMode);
    boolean unpackWARs = booleanParameter(request, "unpackWARs", true, htmlMode);
    boolean copyXML = booleanParameter(request, "copyXML", false, htmlMode);
    add(writer, name, aliases, appBase, manager,
        autoDeploy,
        deployOnStartup,
        deployXML,                                       
        unpackWARs,
        copyXML,
        smClient);
}
 
Example #14
Source File: ManagerServlet.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private void writeDeployResult(PrintWriter writer, StringManager smClient,
        String name, String displayPath) {
    Context deployed = (Context) host.findChild(name);
    if (deployed != null && deployed.getConfigured() &&
            deployed.getState().isAvailable()) {
        writer.println(smClient.getString(
                "managerServlet.deployed", displayPath));
    } else if (deployed!=null && !deployed.getState().isAvailable()) {
        writer.println(smClient.getString(
                "managerServlet.deployedButNotStarted", displayPath));
    } else {
        // Something failed
        writer.println(smClient.getString(
                "managerServlet.deployFailed", displayPath));
    }
}
 
Example #15
Source File: TestImportHandler.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Import a valid class.
 */
@Test
public void testImportClass01() {
    ImportHandler handler = new ImportHandler();

    handler.importClass("org.apache.tomcat.util.res.StringManager");

    Class<?> result = handler.resolveClass("StringManager");

    Assert.assertEquals(StringManager.class, result);
}
 
Example #16
Source File: HostManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link StringManager#getManager(String, Enumeration)}.
 *             This method will be removed in Tomcat 8.
 */
@Deprecated
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;
}
 
Example #17
Source File: HTMLHostManagerServlet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Add a host using the specified parameters.
 *
 * @param request The Servlet request
 * @param name Host name
 * @param smClient StringManager for the client's locale
 * @return output
 */
protected String add(HttpServletRequest request,String name,
        StringManager smClient) {

    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);

    super.add(request,printWriter,name,true, smClient);

    return stringWriter.toString();
}
 
Example #18
Source File: HTMLManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Deploy an application for the specified path from the specified
 * web application archive.
 *
 * @param config URL of the context configuration file 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, ContextName cn, String war,
        StringManager smClient) {

    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);

    super.deploy(printWriter, config, cn, war, false, smClient);

    return stringWriter.toString();
}
 
Example #19
Source File: ManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Writes System OS and JVM properties.
 * @param writer Writer to render to
 */
protected void serverinfo(PrintWriter writer,  StringManager smClient) {
    if (debug >= 1)
        log("serverinfo");
    try {
        StringBuilder props = new StringBuilder();
        props.append("OK - Server info");
        props.append("\nTomcat Version: ");
        props.append(ServerInfo.getServerInfo());
        props.append("\nOS Name: ");
        props.append(System.getProperty("os.name"));
        props.append("\nOS Version: ");
        props.append(System.getProperty("os.version"));
        props.append("\nOS Architecture: ");
        props.append(System.getProperty("os.arch"));
        props.append("\nJVM Version: ");
        props.append(System.getProperty("java.runtime.version"));
        props.append("\nJVM Vendor: ");
        props.append(System.getProperty("java.vm.vendor"));
        writer.println(props.toString());
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        getServletContext().log("ManagerServlet.serverinfo",t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }
}
 
Example #20
Source File: HTMLHostManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Add a host using the specified parameters.
 *
 * @param name host name
 */
protected String add(HttpServletRequest request,String name,
        StringManager smClient) {

    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);

    super.add(request,printWriter,name,true, smClient);

    return stringWriter.toString();
}
 
Example #21
Source File: ManagerServlet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
protected void sslReload(PrintWriter writer, String tlsHostName, StringManager smClient) {
    Connector connectors[] = getConnectors();
    boolean found = false;
    for (Connector connector : connectors) {
        if (Boolean.TRUE.equals(connector.getProperty("SSLEnabled"))) {
            ProtocolHandler protocol = connector.getProtocolHandler();
            if (protocol instanceof AbstractHttp11Protocol<?>) {
                AbstractHttp11Protocol<?> http11Protoocol = (AbstractHttp11Protocol<?>) protocol;
                if (tlsHostName == null || tlsHostName.length() == 0) {
                    found = true;
                    http11Protoocol.reloadSslHostConfigs();
                } else {
                    SSLHostConfig[] sslHostConfigs = http11Protoocol.findSslHostConfigs();
                    for (SSLHostConfig sslHostConfig : sslHostConfigs) {
                        if (sslHostConfig.getHostName().equalsIgnoreCase(tlsHostName)) {
                            found = true;
                            http11Protoocol.reloadSslHostConfig(tlsHostName);
                        }
                    }
                }
            }
        }
    }
    if (found) {
        if (tlsHostName == null || tlsHostName.length() == 0) {
            writer.println(smClient.getString("managerServlet.sslReloadAll"));
        } else {
            writer.println(smClient.getString("managerServlet.sslReload", tlsHostName));
        }
    } else {
        writer.println(smClient.getString("managerServlet.sslReloadFail"));
    }
}
 
Example #22
Source File: TestImportHandler.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Import duplicate classes (i.e. the same class twice).
 */
@Test
public void testImportClass04() {
    ImportHandler handler = new ImportHandler();

    handler.importClass("org.apache.tomcat.util.res.StringManager");
    handler.importClass("org.apache.tomcat.util.res.StringManager");

    Class<?> result = handler.resolveClass("StringManager");

    Assert.assertEquals(StringManager.class, result);
}
 
Example #23
Source File: ManagerServlet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Start the web application at the specified context path.
 *
 * @param writer Writer to render to
 * @param cn Name of the application to be started
 * @param smClient i18n support for current client's locale
 */
protected void start(PrintWriter writer, ContextName cn,
        StringManager smClient) {

    if (debug >= 1)
        log("start: Starting web application '" + cn + "'");

    if (!validateContextName(cn, writer, smClient)) {
        return;
    }

    String displayPath = cn.getDisplayName();

    try {
        Context context = (Context) host.findChild(cn.getName());
        if (context == null) {
            writer.println(smClient.getString("managerServlet.noContext",
                    Escape.htmlElementContent(displayPath)));
            return;
        }
        context.start();
        if (context.getState().isAvailable())
            writer.println(smClient.getString("managerServlet.started",
                    displayPath));
        else
            writer.println(smClient.getString("managerServlet.startFailed",
                    displayPath));
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        getServletContext().log(sm.getString("managerServlet.startFailed",
                displayPath), t);
        writer.println(smClient.getString("managerServlet.startFailed",
                displayPath));
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }

}
 
Example #24
Source File: ManagerServlet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
protected void sslConnectorCiphers(PrintWriter writer, StringManager smClient) {
    writer.println(smClient.getString("managerServlet.sslConnectorCiphers"));
    Map<String,List<String>> connectorCiphers = getConnectorCiphers(smClient);
    for (Map.Entry<String,List<String>> entry : connectorCiphers.entrySet()) {
        writer.println(entry.getKey());
        for (String cipher : entry.getValue()) {
            writer.print("  ");
            writer.println(cipher);
        }
    }
}
 
Example #25
Source File: ManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Find potential memory leaks caused by web application reload.
 */
protected void findleaks(boolean statusLine, PrintWriter writer,
        StringManager smClient) {
    
    if (!(host instanceof StandardHost)) {
        writer.println(smClient.getString("managerServlet.findleaksFail"));
        return;
    }
    
    String[] results =
        ((StandardHost) host).findReloadedContextMemoryLeaks();
    
    if (results.length > 0) {
        if (statusLine) {
            writer.println(
                    smClient.getString("managerServlet.findleaksList"));
        }
        for (String result : results) {
            if ("".equals(result)) {
                result = "/";
            }
            writer.println(result);
        }
    } else if (statusLine) {
        writer.println(smClient.getString("managerServlet.findleaksNone"));
    }
}
 
Example #26
Source File: LoginServices.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
private static boolean TomcatSSOLogin(HttpServletRequest request, String userName, String currentPassword) {
    try {
        request.login(userName, currentPassword);
    } catch (ServletException e) {
        StringManager sm = StringManager.getManager("org.apache.catalina.connector");
        if (sm.getString("coyoteRequest.alreadyAuthenticated").equals(e.getMessage())){
            return true;
        } else {
            Debug.logError(e, module);
            return false;
        }
    }
    return true;
}
 
Example #27
Source File: HostManagerServlet.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link StringManager#getManager(String, Enumeration)}.
 *             This method will be removed in Tomcat 8.
 */
@Deprecated
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;
}
 
Example #28
Source File: ManagerServlet.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 *
 * Extract the expiration request parameter
 *
 * @param cn
 * @param req
 */
protected void expireSessions(PrintWriter writer, ContextName cn,
        HttpServletRequest req, StringManager smClient) {
    int idle = -1;
    String idleParam = req.getParameter("idle");
    if (idleParam != null) {
        try {
            idle = Integer.parseInt(idleParam);
        } catch (NumberFormatException e) {
            log("Could not parse idle parameter to an int: " + idleParam);
        }
    }
    sessions(writer, cn, idle, smClient);
}
 
Example #29
Source File: ManagerServlet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Upload the WAR file included in this request, and store it at the
 * specified file location.
 *
 * @param writer    Writer to render to
 * @param request   The servlet request we are processing
 * @param war       The file into which we should store the uploaded WAR
 * @param smClient  The StringManager used to construct i18n messages based
 *                  on the Locale of the client
 *
 * @exception IOException if an I/O error occurs during processing
 */
protected void uploadWar(PrintWriter writer, HttpServletRequest request,
        File war, StringManager smClient) throws IOException {

    if (war.exists() && !war.delete()) {
        String msg = smClient.getString("managerServlet.deleteFail", war);
        throw new IOException(msg);
    }

    try (ServletInputStream istream = request.getInputStream();
            BufferedOutputStream ostream =
                    new BufferedOutputStream(new FileOutputStream(war), 1024)) {
        byte buffer[] = new byte[1024];
        while (true) {
            int n = istream.read(buffer);
            if (n < 0) {
                break;
            }
            ostream.write(buffer, 0, n);
        }
    } catch (IOException e) {
        if (war.exists() && !war.delete()) {
            writer.println(
                    smClient.getString("managerServlet.deleteFail", war));
        }
        throw e;
    }

}
 
Example #30
Source File: HTMLHostManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * 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();

    // Prepare our output writer to generate the response message
    response.setContentType("text/html; charset=" + Constants.CHARSET);

    String message = "";
    // Process the requested command
    if (command == null) {
        // No command == list
    } else if (command.equals("/list")) {
        // Nothing to do - always generate list
    } else if (command.equals("/add") || command.equals("/remove") ||
            command.equals("/start") || command.equals("/stop")) {
        message = smClient.getString(
                "hostManagerServlet.postCommand", command);
    } else {
        message = smClient.getString(
                "hostManagerServlet.unknownCommand", command);
    }

    list(request, response, message, smClient);
}