Search in sources :

Example 36 with Container

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

the class ContainerMBean method removeLifecycleListeners.

/**
     * Remove a LifecycleEvent listeners from this component.
     *
     * @param type The ClassName of the listeners to be removed.
     * Note that all the listeners having given ClassName will be removed.
     * @throws MBeanException propagated from the managed resource access
     */
public void removeLifecycleListeners(String type) throws MBeanException {
    Container container = doGetManagedResource();
    LifecycleListener[] listeners = container.findLifecycleListeners();
    for (LifecycleListener listener : listeners) {
        if (listener.getClass().getName().equals(type)) {
            container.removeLifecycleListener(listener);
        }
    }
}
Also used : Container(org.apache.catalina.Container) LifecycleListener(org.apache.catalina.LifecycleListener)

Example 37 with Container

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

the class ContainerMBean method addLifecycleListener.

/**
     * Add a LifecycleEvent listener to this component.
     *
     * @param type ClassName of the listener to add
     * @throws MBeanException if adding the listener failed
    */
public void addLifecycleListener(String type) throws MBeanException {
    LifecycleListener listener = (LifecycleListener) newInstance(type);
    Container container = doGetManagedResource();
    container.addLifecycleListener(listener);
}
Also used : Container(org.apache.catalina.Container) LifecycleListener(org.apache.catalina.LifecycleListener)

Example 38 with Container

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

the class ContainerMBean method addChild.

/**
     * Add a new child Container to those associated with this Container,
     * if supported. Won't start the child yet. Has to be started with a call to
     * Start method after necessary configurations are done.
     *
     * @param type ClassName of the child to be added
     * @param name Name of the child to be added
     *
     * @exception MBeanException if the child cannot be added
     */
public void addChild(String type, String name) throws MBeanException {
    Container contained = (Container) newInstance(type);
    contained.setName(name);
    if (contained instanceof StandardHost) {
        HostConfig config = new HostConfig();
        contained.addLifecycleListener(config);
    } else if (contained instanceof StandardContext) {
        ContextConfig config = new ContextConfig();
        contained.addLifecycleListener(config);
    }
    boolean oldValue = true;
    ContainerBase container = doGetManagedResource();
    try {
        oldValue = container.getStartChildren();
        container.setStartChildren(false);
        container.addChild(contained);
        contained.init();
    } catch (LifecycleException e) {
        throw new MBeanException(e);
    } finally {
        if (container != null) {
            container.setStartChildren(oldValue);
        }
    }
}
Also used : ContextConfig(org.apache.catalina.startup.ContextConfig) ContainerBase(org.apache.catalina.core.ContainerBase) Container(org.apache.catalina.Container) LifecycleException(org.apache.catalina.LifecycleException) StandardHost(org.apache.catalina.core.StandardHost) StandardContext(org.apache.catalina.core.StandardContext) HostConfig(org.apache.catalina.startup.HostConfig) MBeanException(javax.management.MBeanException)

Example 39 with Container

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

the class ManagerServlet method list.

/**
     * Render a list of the currently active Contexts in our virtual host.
     *
     * @param writer Writer to render to
     * @param smClient i18n support for current client's locale
     */
protected void list(PrintWriter writer, StringManager smClient) {
    if (debug >= 1)
        log("list: Listing contexts for virtual host '" + host.getName() + "'");
    writer.println(smClient.getString("managerServlet.listed", host.getName()));
    Container[] contexts = host.findChildren();
    for (int i = 0; i < contexts.length; i++) {
        Context context = (Context) contexts[i];
        if (context != null) {
            String displayPath = context.getPath();
            if (displayPath.equals(""))
                displayPath = "/";
            if (context.getState().isAvailable()) {
                writer.println(smClient.getString("managerServlet.listitem", displayPath, "running", "" + context.getManager().findSessions().length, context.getDocBase()));
            } else {
                writer.println(smClient.getString("managerServlet.listitem", displayPath, "stopped", "0", context.getDocBase()));
            }
        }
    }
}
Also used : Context(org.apache.catalina.Context) ServletContext(javax.servlet.ServletContext) Container(org.apache.catalina.Container)

Example 40 with Container

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

the class HostManagerServlet method list.

/**
     * Render a list of the currently active Contexts in our virtual host.
     *
     * @param writer Writer to render to
     * @param smClient StringManager for the client's locale
     */
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()));
    }
}
Also used : Container(org.apache.catalina.Container) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host)

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