Search in sources :

Example 21 with Engine

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

the class FailedContext method getMBeanKeyProperties.

@Override
public String getMBeanKeyProperties() {
    Container c = this;
    StringBuilder keyProperties = new StringBuilder();
    int containerCount = 0;
    // each container
    while (!(c instanceof Engine)) {
        if (c instanceof Context) {
            keyProperties.append(",context=");
            ContextName cn = new ContextName(c.getName(), false);
            keyProperties.append(cn.getDisplayName());
        } else if (c instanceof Host) {
            keyProperties.append(",host=");
            keyProperties.append(c.getName());
        } else if (c == null) {
            // May happen in unit testing and/or some embedding scenarios
            keyProperties.append(",container");
            keyProperties.append(containerCount++);
            keyProperties.append("=null");
            break;
        } else {
            // Should never happen...
            keyProperties.append(",container");
            keyProperties.append(containerCount++);
            keyProperties.append('=');
            keyProperties.append(c.getName());
        }
        c = c.getParent();
    }
    return keyProperties.toString();
}
Also used : Context(org.apache.catalina.Context) ServletContext(javax.servlet.ServletContext) Container(org.apache.catalina.Container) Host(org.apache.catalina.Host) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) Engine(org.apache.catalina.Engine) ContextName(org.apache.catalina.util.ContextName)

Example 22 with Engine

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

the class Tomcat method getHost.

public Host getHost() {
    Engine engine = getEngine();
    if (engine.findChildren().length > 0) {
        return (Host) engine.findChildren()[0];
    }
    Host host = new StandardHost();
    host.setName(hostname);
    getEngine().addChild(host);
    return host;
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine)

Example 23 with Engine

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

the class ManagerServlet method init.

/**
     * Initialize this servlet.
     */
@Override
public void init() throws ServletException {
    // Ensure that our ContainerServlet properties have been set
    if ((wrapper == null) || (context == null))
        throw new UnavailableException(sm.getString("managerServlet.noWrapper"));
    // Set our properties from the initialization parameters
    String value = null;
    try {
        value = getServletConfig().getInitParameter("debug");
        debug = Integer.parseInt(value);
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
    }
    // Acquire global JNDI resources if available
    Server server = ((Engine) host.getParent()).getService().getServer();
    if (server != null) {
        global = server.getGlobalNamingContext();
    }
    // Calculate the directory into which we will be deploying applications
    versioned = (File) getServletContext().getAttribute(ServletContext.TEMPDIR);
    configBase = new File(context.getCatalinaBase(), "conf");
    Container container = context;
    Container host = null;
    Container engine = null;
    while (container != null) {
        if (container instanceof Host)
            host = container;
        if (container instanceof Engine)
            engine = container;
        container = container.getParent();
    }
    if (engine != null) {
        configBase = new File(configBase, engine.getName());
    }
    if (host != null) {
        configBase = new File(configBase, host.getName());
    }
    // Log debugging messages as necessary
    if (debug >= 1) {
        log("init: Associated with Deployer '" + oname + "'");
        if (global != null) {
            log("init: Global resources are available");
        }
    }
}
Also used : Container(org.apache.catalina.Container) MBeanServer(javax.management.MBeanServer) Server(org.apache.catalina.Server) UnavailableException(javax.servlet.UnavailableException) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) File(java.io.File) Engine(org.apache.catalina.Engine)

Example 24 with Engine

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

the class MapperListener method findDefaultHost.

// ------------------------------------------------------ Protected Methods
private void findDefaultHost() {
    Engine engine = service.getContainer();
    String defaultHost = engine.getDefaultHost();
    boolean found = false;
    if (defaultHost != null && defaultHost.length() > 0) {
        Container[] containers = engine.findChildren();
        for (Container container : containers) {
            Host host = (Host) container;
            if (defaultHost.equalsIgnoreCase(host.getName())) {
                found = true;
                break;
            }
            String[] aliases = host.findAliases();
            for (String alias : aliases) {
                if (defaultHost.equalsIgnoreCase(alias)) {
                    found = true;
                    break;
                }
            }
        }
    }
    if (found) {
        mapper.setDefaultHostName(defaultHost);
    } else {
        log.warn(sm.getString("mapperListener.unknownDefaultHost", defaultHost, service));
    }
}
Also used : Container(org.apache.catalina.Container) Host(org.apache.catalina.Host) Engine(org.apache.catalina.Engine)

Example 25 with Engine

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

the class MBeanFactory method removeContext.

/**
     * Remove an existing Context.
     *
     * @param contextName MBean Name of the component to remove
     *
     * @exception Exception if a component cannot be removed
     */
public void removeContext(String contextName) throws Exception {
    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(contextName);
    String domain = oname.getDomain();
    StandardService service = (StandardService) getService(oname);
    Engine engine = service.getContainer();
    String name = oname.getKeyProperty("name");
    name = name.substring(2);
    int i = name.indexOf('/');
    String hostName = name.substring(0, i);
    String path = name.substring(i);
    ObjectName deployer = new ObjectName(domain + ":type=Deployer,host=" + hostName);
    String pathStr = getPathStr(path);
    if (mserver.isRegistered(deployer)) {
        mserver.invoke(deployer, "addServiced", new Object[] { pathStr }, new String[] { "java.lang.String" });
        mserver.invoke(deployer, "unmanageApp", new Object[] { pathStr }, new String[] { "java.lang.String" });
        mserver.invoke(deployer, "removeServiced", new Object[] { pathStr }, new String[] { "java.lang.String" });
    } else {
        log.warn("Deployer not found for " + hostName);
        Host host = (Host) engine.findChild(hostName);
        Context context = (Context) host.findChild(pathStr);
        // Remove this component from its parent component
        host.removeChild(context);
        if (context instanceof StandardContext)
            try {
                ((StandardContext) context).destroy();
            } catch (Exception e) {
                log.warn("Error during context [" + context.getName() + "] destroy ", e);
            }
    }
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) StandardContext(org.apache.catalina.core.StandardContext) StandardService(org.apache.catalina.core.StandardService) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine) ObjectName(javax.management.ObjectName)

Aggregations

Engine (org.apache.catalina.Engine)36 Container (org.apache.catalina.Container)18 Host (org.apache.catalina.Host)18 Service (org.apache.catalina.Service)12 Context (org.apache.catalina.Context)9 StandardEngine (org.apache.catalina.core.StandardEngine)8 StandardHost (org.apache.catalina.core.StandardHost)8 StandardService (org.apache.catalina.core.StandardService)7 ObjectName (javax.management.ObjectName)6 Connector (org.apache.catalina.connector.Connector)6 File (java.io.File)5 IOException (java.io.IOException)5 StandardContext (org.apache.catalina.core.StandardContext)4 ServletContext (javax.servlet.ServletContext)2 UnavailableException (javax.servlet.UnavailableException)2 LifecycleException (org.apache.catalina.LifecycleException)2 Server (org.apache.catalina.Server)2 Wrapper (org.apache.catalina.Wrapper)2 ContextName (org.apache.catalina.util.ContextName)2 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)1