Search in sources :

Example 41 with StandardHost

use of org.apache.catalina.core.StandardHost in project tomee by apache.

the class TomEEUndeployTest method tomcatLifecycle.

@Test
public void tomcatLifecycle() 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);
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) HostConfig(org.apache.catalina.startup.HostConfig) LifecycleEvent(org.apache.catalina.LifecycleEvent) File(java.io.File) Test(org.junit.Test)

Example 42 with StandardHost

use of org.apache.catalina.core.StandardHost in project tomee by apache.

the class OpenEJBListener method tryToFindAndExtractWar.

private static File tryToFindAndExtractWar(final StandardServer source) {
    if (System.getProperties().containsKey("openejb.war")) {
        return new File(System.getProperty("openejb.war"));
    }
    for (final Service service : source.findServices()) {
        final Container container = service.getContainer();
        if (container instanceof StandardEngine) {
            final StandardEngine engine = (StandardEngine) container;
            for (final Container child : engine.findChildren()) {
                if (child instanceof StandardHost) {
                    final StandardHost host = (StandardHost) child;
                    final File base = hostDir(System.getProperty("catalina.base"), host.getAppBase());
                    final File[] files = base.listFiles();
                    if (files != null) {
                        for (final File file : files) {
                            if (isTomEEWar(file)) {
                                return file;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : Container(org.apache.catalina.Container) StandardEngine(org.apache.catalina.core.StandardEngine) StandardHost(org.apache.catalina.core.StandardHost) Service(org.apache.catalina.Service) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 43 with StandardHost

use of org.apache.catalina.core.StandardHost in project tomee by apache.

the class OpenEJBListener method findOpenEjbWar.

private static File findOpenEjbWar() {
    // in Tomcat 5.5 the OpenEjb war is in the server/webapps director
    final String catalinaBase = System.getProperty("catalina.base");
    final File serverWebapps = new File(catalinaBase, "server/webapps");
    File openEjbWar = findOpenEjbWar(serverWebapps);
    if (openEjbWar != null) {
        return openEjbWar;
    }
    try {
        // scan all hosts directories
        for (final Service service : TomcatHelper.getServer().findServices()) {
            final Container container = service.getContainer();
            if (container instanceof StandardEngine) {
                final StandardEngine engine = (StandardEngine) container;
                for (final Container child : engine.findChildren()) {
                    if (child instanceof StandardHost) {
                        final StandardHost host = (StandardHost) child;
                        final File hostDir = hostDir(catalinaBase, host.getAppBase());
                        openEjbWar = findOpenEjbWar(hostDir);
                        if (openEjbWar != null) {
                            return openEjbWar;
                        } else {
                            return findOpenEjbWar(host);
                        }
                    }
                }
            }
        }
    } catch (final Exception e) {
        LOGGER.log(Level.WARNING, "OpenEJBListener.findOpenEjbWar: " + e.getMessage());
    }
    return null;
}
Also used : Container(org.apache.catalina.Container) StandardEngine(org.apache.catalina.core.StandardEngine) StandardHost(org.apache.catalina.core.StandardHost) Service(org.apache.catalina.Service) JarFile(java.util.jar.JarFile) File(java.io.File) IOException(java.io.IOException)

Example 44 with StandardHost

use of org.apache.catalina.core.StandardHost in project tomee by apache.

the class GlobalListenerSupport method engineRemoved.

/**
     * Engine is removed.
     *
     * @param engine tomcat engine
     */
private void engineRemoved(final StandardEngine engine) {
    for (final Container child : engine.findChildren()) {
        if (child instanceof StandardHost) {
            final StandardHost host = (StandardHost) child;
            hostRemoved(host);
        }
    }
}
Also used : Container(org.apache.catalina.Container) StandardHost(org.apache.catalina.core.StandardHost)

Example 45 with StandardHost

use of org.apache.catalina.core.StandardHost in project tomee by apache.

the class GlobalListenerSupport method engineAdded.

/**
     * Engine is added.
     *
     * @param engine tomcat engine
     */
private void engineAdded(final StandardEngine engine) {
    addContextListener(engine);
    for (final Container child : engine.findChildren()) {
        if (child instanceof StandardHost) {
            final StandardHost host = (StandardHost) child;
            hostAdded(host);
        }
    }
}
Also used : Container(org.apache.catalina.Container) StandardHost(org.apache.catalina.core.StandardHost)

Aggregations

StandardHost (org.apache.catalina.core.StandardHost)45 File (java.io.File)26 Context (org.apache.catalina.Context)19 StandardContext (org.apache.catalina.core.StandardContext)16 Test (org.junit.Test)15 Host (org.apache.catalina.Host)13 Container (org.apache.catalina.Container)10 Tomcat (org.apache.catalina.startup.Tomcat)7 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)7 Service (org.apache.catalina.Service)5 StandardEngine (org.apache.catalina.core.StandardEngine)5 HostConfig (org.apache.catalina.startup.HostConfig)5 IOException (java.io.IOException)4 Engine (org.apache.catalina.Engine)4 URL (java.net.URL)3 JarFile (java.util.jar.JarFile)3 InitialContext (javax.naming.InitialContext)3 ReplicatedContext (org.apache.catalina.ha.context.ReplicatedContext)3 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)3 Before (org.junit.Before)3