Java Code Examples for org.apache.catalina.Engine#addChild()

The following examples show how to use org.apache.catalina.Engine#addChild() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Tomcat.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Sets the current host - all future webapps will
 * be added to this host. When tomcat starts, the
 * host will be the default host.
 *
 * @param host The current host
 */
public void setHost(Host host) {
    Engine engine = getEngine();
    boolean found = false;
    for (Container engineHost : engine.findChildren()) {
        if (engineHost == host) {
            found = true;
        }
    }
    if (!found) {
        engine.addChild(host);
    }
}
 
Example 2
Source File: MBeanFactory.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Create a new StandardHost.
 *
 * @param parent MBean Name of the associated parent component
 * @param name Unique name of this Host
 * @param appBase Application base directory name
 * @param autoDeploy Should we auto deploy?
 * @param deployOnStartup Deploy on server startup?
 * @param deployXML Should we deploy Context XML config files property?
 * @param unpackWARs Should we unpack WARs when auto deploying?
 * @return the object name of the created host
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardHost(String parent, String name,
                                 String appBase,
                                 boolean autoDeploy,
                                 boolean deployOnStartup,
                                 boolean deployXML,
                                 boolean unpackWARs)
    throws Exception {

    // Create a new StandardHost instance
    StandardHost host = new StandardHost();
    host.setName(name);
    host.setAppBase(appBase);
    host.setAutoDeploy(autoDeploy);
    host.setDeployOnStartup(deployOnStartup);
    host.setDeployXML(deployXML);
    host.setUnpackWARs(unpackWARs);

    // add HostConfig for active reloading
    HostConfig hostConfig = new HostConfig();
    host.addLifecycleListener(hostConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Service service = getService(pname);
    Engine engine = service.getContainer();
    engine.addChild(host);

    // Return the corresponding MBean name
    return host.getObjectName().toString();

}
 
Example 3
Source File: MBeanFactory.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new StandardHost.
 *
 * @param parent MBean Name of the associated parent component
 * @param name Unique name of this Host
 * @param appBase Application base directory name
 * @param autoDeploy Should we auto deploy?
 * @param deployOnStartup Deploy on server startup?
 * @param deployXML Should we deploy Context XML config files property?
 * @param unpackWARs Should we unpack WARs when auto deploying?
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardHost(String parent, String name,
                                 String appBase,
                                 boolean autoDeploy,
                                 boolean deployOnStartup,
                                 boolean deployXML,                                       
                                 boolean unpackWARs)
    throws Exception {

    // Create a new StandardHost instance
    StandardHost host = new StandardHost();
    host.setName(name);
    host.setAppBase(appBase);
    host.setAutoDeploy(autoDeploy);
    host.setDeployOnStartup(deployOnStartup);
    host.setDeployXML(deployXML);
    host.setUnpackWARs(unpackWARs);

    // add HostConfig for active reloading
    HostConfig hostConfig = new HostConfig();
    host.addLifecycleListener(hostConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Service service = getService(pname);
    Engine engine = (Engine) service.getContainer();
    engine.addChild(host);

    // Return the corresponding MBean name
    return (host.getObjectName().toString());

}
 
Example 4
Source File: MBeanFactory.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new StandardHost.
 *
 * @param parent MBean Name of the associated parent component
 * @param name Unique name of this Host
 * @param appBase Application base directory name
 * @param autoDeploy Should we auto deploy?
 * @param deployOnStartup Deploy on server startup?
 * @param deployXML Should we deploy Context XML config files property?
 * @param unpackWARs Should we unpack WARs when auto deploying?
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardHost(String parent, String name,
                                 String appBase,
                                 boolean autoDeploy,
                                 boolean deployOnStartup,
                                 boolean deployXML,                                       
                                 boolean unpackWARs)
    throws Exception {

    // Create a new StandardHost instance
    StandardHost host = new StandardHost();
    host.setName(name);
    host.setAppBase(appBase);
    host.setAutoDeploy(autoDeploy);
    host.setDeployOnStartup(deployOnStartup);
    host.setDeployXML(deployXML);
    host.setUnpackWARs(unpackWARs);

    // add HostConfig for active reloading
    HostConfig hostConfig = new HostConfig();
    host.addLifecycleListener(hostConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Service service = getService(pname);
    Engine engine = (Engine) service.getContainer();
    engine.addChild(host);

    // Return the corresponding MBean name
    return (host.getObjectName().toString());

}
 
Example 5
Source File: VirtualHostClusterUtil.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public static Host addHostToEngine(String hostName) {
    String hostBaseDir = CarbonUtils.getCarbonRepository() + "/webapps/";
    CarbonTomcatService carbonTomcatService = DataHolder.getInstance().getCarbonTomcatService();
    // adding virtual host to tomcat engine
    Engine engine = carbonTomcatService.getTomcat().getEngine();
    StandardHost host = new StandardHost();
    host.setAppBase(hostBaseDir);
    host.setName(hostName);
    host.setUnpackWARs(false);
    host.addValve(new CarbonContextCreatorValve());
    host.addValve(new CompositeValve());
    engine.addChild(host);
    log.info("host added to the tomcat: " + host);
    return host;
}
 
Example 6
Source File: TomcatServer.java    From staash with Apache License 2.0 4 votes vote down vote up
public TomcatServer(String contextPath, int port, String appBase, boolean shutdownHook) {
    if(contextPath == null || appBase == null || appBase.length() == 0) {
        throw new IllegalArgumentException("Context path or appbase should not be null");
    }
    if(!contextPath.startsWith("/")) {
        contextPath = "/" + contextPath;
    }

    this.port = port;

    tomcat  = new Embedded();
    tomcat.setName("TomcatEmbeddedtomcat");

    Host localHost = tomcat.createHost("localhost", appBase);
    localHost.setAutoDeploy(false);

    StandardContext rootContext = (StandardContext) tomcat.createContext(contextPath, "webapp");
    rootContext.setDefaultWebXml("web.xml");
    localHost.addChild(rootContext);

    Engine engine = tomcat.createEngine();
    engine.setDefaultHost(localHost.getName());
    engine.setName("TomcatEngine");
    engine.addChild(localHost);

    tomcat.addEngine(engine);

    Connector connector = tomcat.createConnector(localHost.getName(), port, false);
    tomcat.addConnector(connector);

    // register shutdown hook
    if(shutdownHook) {
        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {
                if(isRunning) {
                    if(isInfo) LOG.info("Stopping the Tomcat tomcat, through shutdown hook");
                    try {
                        if (tomcat != null) {
                            tomcat.stop();
                        }
                    } catch (LifecycleException e) {
                        LOG.error("Error while stopping the Tomcat tomcat, through shutdown hook", e);
                    }
                }
            }
        });
    }

}