Search in sources :

Example 11 with Container

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

the class MBeanFactory method createValve.

/**
     * Create a new Valve and associate it with a {@link Container}.
     *
     * @param className The fully qualified class name of the {@link Valve} to
     *                  create
     * @param parent    The MBean name of the associated parent
     *                  {@link Container}.
     *
     * @return  The MBean name of the {@link Valve} that was created or
     *          <code>null</code> if the {@link Valve} does not implement
     *          {@link JmxEnabled}.
     * @exception Exception if an MBean cannot be created or registered
     */
public String createValve(String className, String parent) throws Exception {
    // Look for the parent
    ObjectName parentName = new ObjectName(parent);
    Container container = getParentContainerFromParent(parentName);
    if (container == null) {
        // TODO
        throw new IllegalArgumentException();
    }
    Valve valve = (Valve) Class.forName(className).newInstance();
    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) ObjectName(javax.management.ObjectName) JmxEnabled(org.apache.catalina.JmxEnabled)

Example 12 with Container

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

the class MBeanFactory method removeValve.

/**
     * Remove an existing Valve.
     *
     * @param name MBean Name of the component to remove
     *
     * @exception Exception if a component cannot be removed
     */
public void removeValve(String name) throws Exception {
    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    Container container = getParentContainerFromChild(oname);
    Valve[] valves = container.getPipeline().getValves();
    for (int i = 0; i < valves.length; i++) {
        ObjectName voname = ((JmxEnabled) valves[i]).getObjectName();
        if (voname.equals(oname)) {
            container.getPipeline().removeValve(valves[i]);
        }
    }
}
Also used : Container(org.apache.catalina.Container) Valve(org.apache.catalina.Valve) ObjectName(javax.management.ObjectName) JmxEnabled(org.apache.catalina.JmxEnabled)

Example 13 with Container

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

the class MBeanFactory method removeLoader.

/**
     * Remove an existing Loader.
     *
     * @param name MBean Name of the component to remove
     *
     * @exception Exception if a component cannot be removed
     */
public void removeLoader(String name) throws Exception {
    ObjectName oname = new ObjectName(name);
    // Acquire a reference to the component to be removed
    Container container = getParentContainerFromChild(oname);
    if (container instanceof Context) {
        ((Context) container).setLoader(null);
    }
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) Container(org.apache.catalina.Container) ObjectName(javax.management.ObjectName)

Example 14 with Container

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

the class MBeanFactory method getParentContainerFromChild.

/**
     * Get Parent ContainerBase to add its child component
     * from child component's ObjectName  as a String
     */
private Container getParentContainerFromChild(ObjectName oname) throws Exception {
    String hostName = oname.getKeyProperty("host");
    String path = oname.getKeyProperty("path");
    Service service = getService(oname);
    Container engine = service.getContainer();
    if (hostName == null) {
        // child's container is Engine
        return engine;
    } else if (path == null) {
        // child's container is Host
        Container host = engine.findChild(hostName);
        return host;
    } else {
        // child's container is Context
        Container host = engine.findChild(hostName);
        path = getPathStr(path);
        Container context = host.findChild(path);
        return context;
    }
}
Also used : Container(org.apache.catalina.Container) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service)

Example 15 with Container

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

the class MBeanFactory method getParentContainerFromParent.

/**
     * Get Parent Container to add its child component
     * from parent's ObjectName
     */
private Container getParentContainerFromParent(ObjectName pname) throws Exception {
    String type = pname.getKeyProperty("type");
    String j2eeType = pname.getKeyProperty("j2eeType");
    Service service = getService(pname);
    StandardEngine engine = (StandardEngine) service.getContainer();
    if ((j2eeType != null) && (j2eeType.equals("WebModule"))) {
        String name = pname.getKeyProperty("name");
        name = name.substring(2);
        int i = name.indexOf('/');
        String hostName = name.substring(0, i);
        String path = name.substring(i);
        Container host = engine.findChild(hostName);
        String pathStr = getPathStr(path);
        Container context = host.findChild(pathStr);
        return context;
    } else if (type != null) {
        if (type.equals("Engine")) {
            return engine;
        } else if (type.equals("Host")) {
            String hostName = pname.getKeyProperty("host");
            Container host = engine.findChild(hostName);
            return host;
        }
    }
    return null;
}
Also used : Container(org.apache.catalina.Container) StandardEngine(org.apache.catalina.core.StandardEngine) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service)

Aggregations

Container (org.apache.catalina.Container)125 Context (org.apache.catalina.Context)26 Host (org.apache.catalina.Host)20 Engine (org.apache.catalina.Engine)18 IOException (java.io.IOException)17 StandardContext (org.apache.catalina.core.StandardContext)17 ObjectName (javax.management.ObjectName)15 StandardHost (org.apache.catalina.core.StandardHost)13 Wrapper (org.apache.catalina.Wrapper)11 ArrayList (java.util.ArrayList)10 Valve (org.apache.catalina.Valve)10 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)10 Realm (org.apache.catalina.Realm)9 File (java.io.File)8 LifecycleException (org.apache.catalina.LifecycleException)8 StandardWrapper (org.apache.catalina.core.StandardWrapper)8 ServletContext (javax.servlet.ServletContext)7 ServletException (javax.servlet.ServletException)7 Lifecycle (org.apache.catalina.Lifecycle)7 Service (org.apache.catalina.Service)7