Search in sources :

Example 41 with Container

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

the class MapperListener method registerHost.

/**
     * Register host.
     */
private void registerHost(Host host) {
    String[] aliases = host.findAliases();
    mapper.addHost(host.getName(), aliases, host);
    for (Container container : host.findChildren()) {
        if (container.getState().isAvailable()) {
            registerContext((Context) container);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("mapperListener.registerHost", host.getName(), domain, service));
    }
}
Also used : Container(org.apache.catalina.Container)

Example 42 with Container

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

the class MapperListener method containerEvent.

// --------------------------------------------- Container Listener methods
@Override
public void containerEvent(ContainerEvent event) {
    if (Container.ADD_CHILD_EVENT.equals(event.getType())) {
        Container child = (Container) event.getData();
        addListeners(child);
        // to register the child so register it here
        if (child.getState().isAvailable()) {
            if (child instanceof Host) {
                registerHost((Host) child);
            } else if (child instanceof Context) {
                registerContext((Context) child);
            } else if (child instanceof Wrapper) {
                // will have its own "after_start" life-cycle event later.
                if (child.getParent().getState().isAvailable()) {
                    registerWrapper((Wrapper) child);
                }
            }
        }
    } else if (Container.REMOVE_CHILD_EVENT.equals(event.getType())) {
        Container child = (Container) event.getData();
        removeListeners(child);
    // No need to unregister - life-cycle listener will handle this when
    // the child stops
    } else if (Host.ADD_ALIAS_EVENT.equals(event.getType())) {
        // Handle dynamically adding host aliases
        mapper.addHostAlias(((Host) event.getSource()).getName(), event.getData().toString());
    } else if (Host.REMOVE_ALIAS_EVENT.equals(event.getType())) {
        // Handle dynamically removing host aliases
        mapper.removeHostAlias(event.getData().toString());
    } else if (Wrapper.ADD_MAPPING_EVENT.equals(event.getType())) {
        // Handle dynamically adding wrappers
        Wrapper wrapper = (Wrapper) event.getSource();
        Context context = (Context) wrapper.getParent();
        String contextPath = context.getPath();
        if ("/".equals(contextPath)) {
            contextPath = "";
        }
        String version = context.getWebappVersion();
        String hostName = context.getParent().getName();
        String wrapperName = wrapper.getName();
        String mapping = (String) event.getData();
        boolean jspWildCard = ("jsp".equals(wrapperName) && mapping.endsWith("/*"));
        mapper.addWrapper(hostName, contextPath, version, mapping, wrapper, jspWildCard, context.isResourceOnlyServlet(wrapperName));
    } else if (Wrapper.REMOVE_MAPPING_EVENT.equals(event.getType())) {
        // Handle dynamically removing wrappers
        Wrapper wrapper = (Wrapper) event.getSource();
        Context context = (Context) wrapper.getParent();
        String contextPath = context.getPath();
        if ("/".equals(contextPath)) {
            contextPath = "";
        }
        String version = context.getWebappVersion();
        String hostName = context.getParent().getName();
        String mapping = (String) event.getData();
        mapper.removeWrapper(hostName, contextPath, version, mapping);
    } else if (Context.ADD_WELCOME_FILE_EVENT.equals(event.getType())) {
        // Handle dynamically adding welcome files
        Context context = (Context) event.getSource();
        String hostName = context.getParent().getName();
        String contextPath = context.getPath();
        if ("/".equals(contextPath)) {
            contextPath = "";
        }
        String welcomeFile = (String) event.getData();
        mapper.addWelcomeFile(hostName, contextPath, context.getWebappVersion(), welcomeFile);
    } else if (Context.REMOVE_WELCOME_FILE_EVENT.equals(event.getType())) {
        // Handle dynamically removing welcome files
        Context context = (Context) event.getSource();
        String hostName = context.getParent().getName();
        String contextPath = context.getPath();
        if ("/".equals(contextPath)) {
            contextPath = "";
        }
        String welcomeFile = (String) event.getData();
        mapper.removeWelcomeFile(hostName, contextPath, context.getWebappVersion(), welcomeFile);
    } else if (Context.CLEAR_WELCOME_FILES_EVENT.equals(event.getType())) {
        // Handle dynamically clearing welcome files
        Context context = (Context) event.getSource();
        String hostName = context.getParent().getName();
        String contextPath = context.getPath();
        if ("/".equals(contextPath)) {
            contextPath = "";
        }
        mapper.clearWelcomeFiles(hostName, contextPath, context.getWebappVersion());
    }
}
Also used : Context(org.apache.catalina.Context) Wrapper(org.apache.catalina.Wrapper) Container(org.apache.catalina.Container) Host(org.apache.catalina.Host)

Example 43 with Container

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

the class SimpleTcpCluster method getObjectNameKeyProperties.

@Override
protected String getObjectNameKeyProperties() {
    StringBuilder name = new StringBuilder("type=Cluster");
    Container container = getContainer();
    if (container != null) {
        name.append(container.getMBeanKeyProperties());
    }
    return name.toString();
}
Also used : Container(org.apache.catalina.Container)

Example 44 with Container

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

the class SimpleTcpCluster method getManagerName.

@Override
public String getManagerName(String name, Manager manager) {
    String clusterName = name;
    if (clusterName == null)
        clusterName = manager.getContext().getName();
    if (getContainer() instanceof Engine) {
        Context context = manager.getContext();
        Container host = context.getParent();
        if (host instanceof Host && clusterName != null && !(clusterName.startsWith(host.getName() + "#"))) {
            clusterName = host.getName() + "#" + clusterName;
        }
    }
    return clusterName;
}
Also used : Context(org.apache.catalina.Context) Container(org.apache.catalina.Container) Host(org.apache.catalina.Host) Engine(org.apache.catalina.Engine)

Example 45 with Container

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

the class SimpleTcpCluster method initInternal.

// ------------------------------------------------------ public
@Override
protected void initInternal() throws LifecycleException {
    super.initInternal();
    if (clusterDeployer != null) {
        StringBuilder name = new StringBuilder("type=Cluster");
        Container container = getContainer();
        if (container != null) {
            name.append(container.getMBeanKeyProperties());
        }
        name.append(",component=Deployer");
        onameClusterDeployer = register(clusterDeployer, name.toString());
    }
}
Also used : Container(org.apache.catalina.Container)

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