Search in sources :

Example 1 with HostConfig

use of org.apache.catalina.startup.HostConfig in project tomcat70 by apache.

the class MBeanFactory method createStandardHost.

/**
 * 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());
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) HostConfig(org.apache.catalina.startup.HostConfig) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine) ObjectName(javax.management.ObjectName)

Example 2 with HostConfig

use of org.apache.catalina.startup.HostConfig in project tomcat70 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 = null;
    try {
        contained = (Container) Class.forName(type).newInstance();
        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);
        }
    } catch (InstantiationException e) {
        throw new MBeanException(e);
    } catch (IllegalAccessException e) {
        throw new MBeanException(e);
    } catch (ClassNotFoundException e) {
        throw new MBeanException(e);
    }
    boolean oldValue = true;
    ContainerBase container = null;
    try {
        container = (ContainerBase) getManagedResource();
        oldValue = container.getStartChildren();
        container.setStartChildren(false);
        container.addChild(contained);
        contained.init();
    } catch (InstanceNotFoundException e) {
        throw new MBeanException(e);
    } catch (RuntimeOperationsException e) {
        throw new MBeanException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new MBeanException(e);
    } catch (LifecycleException e) {
        throw new MBeanException(e);
    } finally {
        if (container != null) {
            container.setStartChildren(oldValue);
        }
    }
}
Also used : ContainerBase(org.apache.catalina.core.ContainerBase) LifecycleException(org.apache.catalina.LifecycleException) InstanceNotFoundException(javax.management.InstanceNotFoundException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) ContextConfig(org.apache.catalina.startup.ContextConfig) Container(org.apache.catalina.Container) StandardHost(org.apache.catalina.core.StandardHost) StandardContext(org.apache.catalina.core.StandardContext) HostConfig(org.apache.catalina.startup.HostConfig) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 3 with HostConfig

use of org.apache.catalina.startup.HostConfig in project tomee by apache.

the class TomcatWebAppBuilder method deployWar.

public void deployWar(final StandardContext standardContext, final String host, final AppInfo info) {
    // TODO: instead of storing deployers, we could just lookup the right hostconfig for the server.
    final HostConfig deployer = deployers.get(host);
    if (isReady(deployer)) {
        // if not ready using directly host to avoid a NPE
        if (info != null) {
            final ContextInfo contextInfo = addContextInfo(host, standardContext);
            contextInfo.appInfo = info;
            contextInfo.deployer = deployer;
            contextInfo.module = extractModule(standardContext, info);
        }
        deployer.manageApp(standardContext);
    } else {
        final Host theHost = hosts.get(host);
        if (theHost != null) {
            if (info != null) {
                final ContextInfo contextInfo = addContextInfo(host, standardContext);
                contextInfo.appInfo = info;
                contextInfo.host = theHost;
                contextInfo.module = extractModule(standardContext, info);
            }
            theHost.addChild(standardContext);
        } else {
            throw new IllegalStateException("Host '" + host + "' not found for application " + standardContext.getPath());
        }
    }
}
Also used : HostConfig(org.apache.catalina.startup.HostConfig) Host(org.apache.catalina.Host) StandardHost(org.apache.catalina.core.StandardHost)

Example 4 with HostConfig

use of org.apache.catalina.startup.HostConfig in project tomee by apache.

the class TomcatWebAppBuilder method afterStop.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void afterStop(final StandardServer standardServer) {
    // clean ear based webapps after shutdown
    for (final ContextInfo contextInfo : infos.values()) {
        if (contextInfo != null && contextInfo.deployer != null) {
            final StandardContext standardContext = contextInfo.standardContext;
            final HostConfig deployer = contextInfo.deployer;
            deployer.unmanageApp(standardContext.getPath());
            final File realPath = Contexts.warPath(standardContext);
            if (realPath != null) {
                deleteDir(realPath);
            }
        }
    }
    TomcatLoader.destroy();
}
Also used : StandardContext(org.apache.catalina.core.StandardContext) HostConfig(org.apache.catalina.startup.HostConfig) File(java.io.File) JarFile(java.util.jar.JarFile)

Example 5 with HostConfig

use of org.apache.catalina.startup.HostConfig in project tomee by apache.

the class TomEEUndeployTest method justAContextStop.

@Test
public void justAContextStop() throws Exception {
    container.start();
    assertEquals(0, webapps().length);
    final StandardHost standardHost = StandardHost.class.cast(TomcatHelper.getServer().findService("Tomcat").getContainer().findChild("localhost"));
    // not done in embedded but that's the way autodeploy works in normal tomcat
    final HostConfig listener = new HostConfig();
    standardHost.addLifecycleListener(listener);
    createWebapp(new File(WORK_DIR, "tomee/webapps/my-webapp"));
    listener.lifecycleEvent(new LifecycleEvent(standardHost, Lifecycle.START_EVENT, standardHost));
    assertEquals(1, webapps().length);
    webapps()[0].stop();
    assertEquals(1, webapps().length);
    webapps()[0].start();
    assertEquals(1, webapps().length);
    assertEquals("test", IO.slurp(new URL("http://localhost:" + http + "/my-webapp/")));
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) HostConfig(org.apache.catalina.startup.HostConfig) LifecycleEvent(org.apache.catalina.LifecycleEvent) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

HostConfig (org.apache.catalina.startup.HostConfig)11 StandardHost (org.apache.catalina.core.StandardHost)9 File (java.io.File)6 StandardContext (org.apache.catalina.core.StandardContext)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 StringTokenizer (java.util.StringTokenizer)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 MBeanException (javax.management.MBeanException)2 ObjectName (javax.management.ObjectName)2 Container (org.apache.catalina.Container)2 Engine (org.apache.catalina.Engine)2 Host (org.apache.catalina.Host)2 LifecycleEvent (org.apache.catalina.LifecycleEvent)2 LifecycleException (org.apache.catalina.LifecycleException)2 Service (org.apache.catalina.Service)2 ContainerBase (org.apache.catalina.core.ContainerBase)2 StandardEngine (org.apache.catalina.core.StandardEngine)2 StandardService (org.apache.catalina.core.StandardService)2 ContextConfig (org.apache.catalina.startup.ContextConfig)2