Search in sources :

Example 31 with Container

use of org.apache.catalina.Container in project tomcat by apache.

the class HTMLHostManagerServlet method list.

/**
     * Render a 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 StringManager for the client's locale
     * @throws IOException An IO error occurred
     */
public void list(HttpServletRequest request, HttpServletResponse response, String message, StringManager smClient) throws IOException {
    if (debug >= 1) {
        log(sm.getString("hostManagerServlet.list", engine.getName()));
    }
    PrintWriter writer = response.getWriter();
    // HTML Header Section
    writer.print(org.apache.catalina.manager.Constants.HTML_HEADER_SECTION);
    // Body Header Section
    Object[] args = new Object[2];
    args[0] = request.getContextPath();
    args[1] = smClient.getString("htmlHostManagerServlet.title");
    writer.print(MessageFormat.format(org.apache.catalina.manager.Constants.BODY_HEADER_SECTION, args));
    // Message Section
    args = new Object[3];
    args[0] = smClient.getString("htmlHostManagerServlet.messageLabel");
    if (message == null || message.length() == 0) {
        args[1] = "OK";
    } else {
        args[1] = RequestUtil.filter(message);
    }
    writer.print(MessageFormat.format(Constants.MESSAGE_SECTION, args));
    // Manager Section
    args = new Object[9];
    args[0] = smClient.getString("htmlHostManagerServlet.manager");
    args[1] = response.encodeURL(request.getContextPath() + "/html/list");
    args[2] = smClient.getString("htmlHostManagerServlet.list");
    args[3] = response.encodeURL(request.getContextPath() + "/" + smClient.getString("htmlHostManagerServlet.helpHtmlManagerFile"));
    args[4] = smClient.getString("htmlHostManagerServlet.helpHtmlManager");
    args[5] = response.encodeURL(request.getContextPath() + "/" + smClient.getString("htmlHostManagerServlet.helpManagerFile"));
    args[6] = smClient.getString("htmlHostManagerServlet.helpManager");
    args[7] = response.encodeURL("/manager/status");
    args[8] = smClient.getString("statusServlet.title");
    writer.print(MessageFormat.format(Constants.MANAGER_SECTION, args));
    // Hosts Header Section
    args = new Object[3];
    args[0] = smClient.getString("htmlHostManagerServlet.hostName");
    args[1] = smClient.getString("htmlHostManagerServlet.hostAliases");
    args[2] = smClient.getString("htmlHostManagerServlet.hostTasks");
    writer.print(MessageFormat.format(HOSTS_HEADER_SECTION, args));
    // Hosts Row Section
    // Create sorted map of host names.
    Container[] children = engine.findChildren();
    String[] hostNames = new String[children.length];
    for (int i = 0; i < children.length; i++) hostNames[i] = children[i].getName();
    TreeMap<String, String> sortedHostNamesMap = new TreeMap<>();
    for (int i = 0; i < hostNames.length; i++) {
        String displayPath = hostNames[i];
        sortedHostNamesMap.put(displayPath, hostNames[i]);
    }
    String hostsStart = smClient.getString("htmlHostManagerServlet.hostsStart");
    String hostsStop = smClient.getString("htmlHostManagerServlet.hostsStop");
    String hostsRemove = smClient.getString("htmlHostManagerServlet.hostsRemove");
    Iterator<Map.Entry<String, String>> iterator = sortedHostNamesMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<String, String> entry = iterator.next();
        String hostName = entry.getKey();
        Host host = (Host) engine.findChild(hostName);
        if (host != null) {
            args = new Object[2];
            args[0] = RequestUtil.filter(hostName);
            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]);
                }
            }
            if (buf.length() == 0) {
                buf.append("&nbsp;");
                args[1] = buf.toString();
            } else {
                args[1] = RequestUtil.filter(buf.toString());
            }
            writer.print(MessageFormat.format(HOSTS_ROW_DETAILS_SECTION, args));
            args = new Object[4];
            if (host.getState().isAvailable()) {
                args[0] = response.encodeURL(request.getContextPath() + "/html/stop?name=" + URLEncoder.encode(hostName, "UTF-8"));
                args[1] = hostsStop;
            } else {
                args[0] = response.encodeURL(request.getContextPath() + "/html/start?name=" + URLEncoder.encode(hostName, "UTF-8"));
                args[1] = hostsStart;
            }
            args[2] = response.encodeURL(request.getContextPath() + "/html/remove?name=" + URLEncoder.encode(hostName, "UTF-8"));
            args[3] = hostsRemove;
            if (host == this.installedHost) {
                writer.print(MessageFormat.format(MANAGER_HOST_ROW_BUTTON_SECTION, args));
            } else {
                writer.print(MessageFormat.format(HOSTS_ROW_BUTTON_SECTION, args));
            }
        }
    }
    // Add Section
    args = new Object[6];
    args[0] = smClient.getString("htmlHostManagerServlet.addTitle");
    args[1] = smClient.getString("htmlHostManagerServlet.addHost");
    args[2] = response.encodeURL(request.getContextPath() + "/html/add");
    args[3] = smClient.getString("htmlHostManagerServlet.addName");
    args[4] = smClient.getString("htmlHostManagerServlet.addAliases");
    args[5] = smClient.getString("htmlHostManagerServlet.addAppBase");
    writer.print(MessageFormat.format(ADD_SECTION_START, args));
    args = new Object[3];
    args[0] = smClient.getString("htmlHostManagerServlet.addAutoDeploy");
    args[1] = "autoDeploy";
    args[2] = "checked";
    writer.print(MessageFormat.format(ADD_SECTION_BOOLEAN, args));
    args[0] = smClient.getString("htmlHostManagerServlet.addDeployOnStartup");
    args[1] = "deployOnStartup";
    args[2] = "checked";
    writer.print(MessageFormat.format(ADD_SECTION_BOOLEAN, args));
    args[0] = smClient.getString("htmlHostManagerServlet.addDeployXML");
    args[1] = "deployXML";
    args[2] = "checked";
    writer.print(MessageFormat.format(ADD_SECTION_BOOLEAN, args));
    args[0] = smClient.getString("htmlHostManagerServlet.addUnpackWARs");
    args[1] = "unpackWARs";
    args[2] = "checked";
    writer.print(MessageFormat.format(ADD_SECTION_BOOLEAN, args));
    args[0] = smClient.getString("htmlHostManagerServlet.addManager");
    args[1] = "manager";
    args[2] = "checked";
    writer.print(MessageFormat.format(ADD_SECTION_BOOLEAN, args));
    args[0] = smClient.getString("htmlHostManagerServlet.addCopyXML");
    args[1] = "copyXML";
    args[2] = "";
    writer.print(MessageFormat.format(ADD_SECTION_BOOLEAN, args));
    args = new Object[1];
    args[0] = smClient.getString("htmlHostManagerServlet.addButton");
    writer.print(MessageFormat.format(ADD_SECTION_END, args));
    // Persist Configuration Section
    args = new Object[4];
    args[0] = smClient.getString("htmlHostManagerServlet.persistTitle");
    args[1] = response.encodeURL(request.getContextPath() + "/html/persist");
    args[2] = smClient.getString("htmlHostManagerServlet.persistAllButton");
    args[3] = smClient.getString("htmlHostManagerServlet.persistAll");
    writer.print(MessageFormat.format(PERSIST_SECTION, args));
    // Server Header Section
    args = new Object[7];
    args[0] = smClient.getString("htmlHostManagerServlet.serverTitle");
    args[1] = smClient.getString("htmlHostManagerServlet.serverVersion");
    args[2] = smClient.getString("htmlHostManagerServlet.serverJVMVersion");
    args[3] = smClient.getString("htmlHostManagerServlet.serverJVMVendor");
    args[4] = smClient.getString("htmlHostManagerServlet.serverOSName");
    args[5] = smClient.getString("htmlHostManagerServlet.serverOSVersion");
    args[6] = smClient.getString("htmlHostManagerServlet.serverOSArch");
    writer.print(MessageFormat.format(Constants.SERVER_HEADER_SECTION, args));
    // Server Row Section
    args = new Object[6];
    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");
    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 : Host(org.apache.catalina.Host) TreeMap(java.util.TreeMap) Container(org.apache.catalina.Container) TreeMap(java.util.TreeMap) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 32 with Container

use of org.apache.catalina.Container in project tomcat by apache.

the class HostManagerServlet method remove.

/**
     * Remove the specified host.
     *
     * @param writer Writer to render results to
     * @param name host name
     * @param smClient StringManager for the client's locale
     */
protected synchronized void remove(PrintWriter writer, String name, StringManager smClient) {
    if (debug >= 1) {
        log(sm.getString("hostManagerServlet.remove", name));
    }
    // Validate the requested host name
    if ((name == null) || name.length() == 0) {
        writer.println(smClient.getString("hostManagerServlet.invalidHostName", name));
        return;
    }
    // Check if host exists
    if (engine.findChild(name) == null) {
        writer.println(smClient.getString("hostManagerServlet.noHost", name));
        return;
    }
    // Prevent removing our own host
    if (engine.findChild(name) == installedHost) {
        writer.println(smClient.getString("hostManagerServlet.cannotRemoveOwnHost", name));
        return;
    }
    // Note that the host will not get physically removed
    try {
        Container child = engine.findChild(name);
        engine.removeChild(child);
        if (child instanceof ContainerBase)
            ((ContainerBase) child).destroy();
    } catch (Exception e) {
        writer.println(smClient.getString("hostManagerServlet.exception", e.toString()));
        return;
    }
    Host host = (StandardHost) engine.findChild(name);
    if (host == null) {
        writer.println(smClient.getString("hostManagerServlet.remove", name));
    } else {
        // Something failed
        writer.println(smClient.getString("hostManagerServlet.removeFailed", name));
    }
}
Also used : ContainerBase(org.apache.catalina.core.ContainerBase) Container(org.apache.catalina.Container) StandardHost(org.apache.catalina.core.StandardHost) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) ServletException(javax.servlet.ServletException) InstanceNotFoundException(javax.management.InstanceNotFoundException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Example 33 with Container

use of org.apache.catalina.Container in project tomcat by apache.

the class MapperListener method addListeners.

/**
     * Add this mapper to the container and all child containers
     *
     * @param container
     */
private void addListeners(Container container) {
    container.addContainerListener(this);
    container.addLifecycleListener(this);
    for (Container child : container.findChildren()) {
        addListeners(child);
    }
}
Also used : Container(org.apache.catalina.Container)

Example 34 with Container

use of org.apache.catalina.Container in project tomcat by apache.

the class MapperListener method startInternal.

// ------------------------------------------------------- Lifecycle Methods
@Override
public void startInternal() throws LifecycleException {
    setState(LifecycleState.STARTING);
    Engine engine = service.getContainer();
    if (engine == null) {
        return;
    }
    findDefaultHost();
    addListeners(engine);
    Container[] conHosts = engine.findChildren();
    for (Container conHost : conHosts) {
        Host host = (Host) conHost;
        if (!LifecycleState.NEW.equals(host.getState())) {
            // Registering the host will register the context and wrappers
            registerHost(host);
        }
    }
}
Also used : Container(org.apache.catalina.Container) Host(org.apache.catalina.Host) Engine(org.apache.catalina.Engine)

Example 35 with Container

use of org.apache.catalina.Container in project tomcat by apache.

the class ContainerMBean method addValve.

/**
     * Adds a valve to this Container instance.
     *
     * @param valveType ClassName of the valve to be added
     * @return the MBean name of the new valve
     * @throws MBeanException if adding the valve failed
     */
public String addValve(String valveType) throws MBeanException {
    Valve valve = (Valve) newInstance(valveType);
    Container container = doGetManagedResource();
    container.getPipeline().addValve(valve);
    if (valve instanceof JmxEnabled) {
        return ((JmxEnabled) valve).getObjectName().toString();
    } else {
        return null;
    }
}
Also used : Container(org.apache.catalina.Container) Valve(org.apache.catalina.Valve) JmxEnabled(org.apache.catalina.JmxEnabled)

Aggregations

Container (org.apache.catalina.Container)163 Context (org.apache.catalina.Context)28 IOException (java.io.IOException)24 Host (org.apache.catalina.Host)22 StandardContext (org.apache.catalina.core.StandardContext)21 Engine (org.apache.catalina.Engine)18 LifecycleException (org.apache.catalina.LifecycleException)17 File (java.io.File)15 ObjectName (javax.management.ObjectName)15 Wrapper (org.apache.catalina.Wrapper)13 StandardHost (org.apache.catalina.core.StandardHost)13 ArrayList (java.util.ArrayList)12 ServletException (javax.servlet.ServletException)11 MalformedURLException (java.net.MalformedURLException)10 Valve (org.apache.catalina.Valve)10 StandardWrapper (org.apache.catalina.core.StandardWrapper)10 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)10 NamingException (javax.naming.NamingException)9 Lifecycle (org.apache.catalina.Lifecycle)9 Realm (org.apache.catalina.Realm)9