Search in sources :

Example 16 with StandardHost

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

the class TestAbstractArchiveResource method testNestedJarGetURL.

@Test
public void testNestedJarGetURL() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File docBase = new File("test/webresources/war-url-connection.war");
    Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath());
    skipTldsForResourceJars(ctx);
    ((StandardHost) tomcat.getHost()).setUnpackWARs(false);
    tomcat.start();
    WebResource webResource = ctx.getResources().getClassLoaderResource("/META-INF/resources/index.html");
    StringBuilder expectedURL = new StringBuilder("jar:war:");
    expectedURL.append(docBase.getAbsoluteFile().toURI().toURL().toString());
    expectedURL.append("*/WEB-INF/lib/test.jar!/META-INF/resources/index.html");
    Assert.assertEquals(expectedURL.toString(), webResource.getURL().toString());
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) StandardHost(org.apache.catalina.core.StandardHost) WebResource(org.apache.catalina.WebResource) File(java.io.File) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 17 with StandardHost

use of org.apache.catalina.core.StandardHost in project pinpoint by naver.

the class StandardHostValveInvokeModifierTest method setUp.

/**
     * Sets the up.
     *
     * @throws Exception the exception
     */
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    initMockRequest();
    // StandardHost's default constructor sets StandardHostValve as the first item in the pipeline.
    host = new StandardHost();
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) Before(org.junit.Before)

Example 18 with StandardHost

use of org.apache.catalina.core.StandardHost in project pinpoint by naver.

the class StandardHostValveInvokeModifierTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    initMockRequest();
    // StandardHost's default constructor sets StandardHostValve as the first item in the pipeline.
    host = new StandardHost();
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) Before(org.junit.Before)

Example 19 with StandardHost

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

the class GlobalListenerSupport method lifecycleEvent.

/**
     * {@inheritDoc}
     */
public void lifecycleEvent(final LifecycleEvent event) {
    final Object source = event.getSource();
    if (source instanceof StandardContext) {
        final StandardContext standardContext = (StandardContext) source;
        if (standardContext instanceof IgnoredStandardContext) {
            return;
        }
        final String type = event.getType();
        switch(// better than if cause it prevent duplicates
        type) {
            case INIT_EVENT:
            case Lifecycle.BEFORE_INIT_EVENT:
                contextListener.init(standardContext);
                break;
            case Lifecycle.BEFORE_START_EVENT:
                contextListener.beforeStart(standardContext);
                break;
            case Lifecycle.START_EVENT:
                standardContext.addParameter("openejb.start.late", "true");
                contextListener.start(standardContext);
                break;
            case Lifecycle.AFTER_START_EVENT:
                contextListener.afterStart(standardContext);
                standardContext.removeParameter("openejb.start.late");
                break;
            case Lifecycle.BEFORE_STOP_EVENT:
                contextListener.beforeStop(standardContext);
                break;
            case Lifecycle.STOP_EVENT:
                contextListener.stop(standardContext);
                break;
            case Lifecycle.AFTER_STOP_EVENT:
                contextListener.afterStop(standardContext);
                break;
            case DESTROY_EVENT:
            case Lifecycle.AFTER_DESTROY_EVENT:
                contextListener.destroy(standardContext);
                break;
            case Lifecycle.CONFIGURE_START_EVENT:
                contextListener.configureStart(event, standardContext);
                break;
            default:
        }
    } else if (StandardHost.class.isInstance(source)) {
        final StandardHost standardHost = (StandardHost) source;
        final String type = event.getType();
        if (Lifecycle.PERIODIC_EVENT.equals(type)) {
            contextListener.checkHost(standardHost);
        } else if (Lifecycle.AFTER_START_EVENT.equals(type) && REMOTE_SUPPORT) {
            final TomEERemoteWebapp child = new TomEERemoteWebapp();
            if (!hasChild(standardHost, child.getName())) {
                standardHost.addChild(child);
            }
        // else old tomee webapp surely
        }
    } else if (StandardServer.class.isInstance(source)) {
        final StandardServer standardServer = (StandardServer) source;
        final String type = event.getType();
        if (Lifecycle.START_EVENT.equals(type)) {
            contextListener.start(standardServer);
        }
        if (Lifecycle.BEFORE_STOP_EVENT.equals(type)) {
            TomcatHelper.setStopping(true);
            final TomEEClusterListener tomEEClusterListener = SystemInstance.get().getComponent(TomEEClusterListener.class);
            if (tomEEClusterListener != null) {
                TomEEClusterListener.stop();
            }
        }
        if (Lifecycle.AFTER_STOP_EVENT.equals(type)) {
            contextListener.afterStop(standardServer);
        }
    }
    // Notify
    // here this way we are sure we get it even in embedded mode. TODO: we miss then few boot events, is it an issue.
    SystemInstance.get().fireEvent(event);
}
Also used : TomEEClusterListener(org.apache.tomee.catalina.cluster.TomEEClusterListener) StandardHost(org.apache.catalina.core.StandardHost) TomEERemoteWebapp(org.apache.tomee.catalina.remote.TomEERemoteWebapp) StandardServer(org.apache.catalina.core.StandardServer) StandardContext(org.apache.catalina.core.StandardContext)

Example 20 with StandardHost

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

the class Contexts method oldRealWarPath.

@Deprecated
private static File oldRealWarPath(final Context standardContext) {
    String doc = standardContext.getDocBase();
    // handle ROOT case
    if (doc == null || doc.length() == 0) {
        doc = "ROOT";
    }
    File war = new File(doc);
    if (war.exists()) {
        return war;
    }
    final StandardHost host = (StandardHost) standardContext.getParent();
    final String base = host.getAppBase();
    war = new File(base, doc);
    if (war.exists()) {
        return war;
    }
    war = new File(new File(System.getProperty("catalina.home"), base), doc);
    if (war.exists()) {
        return war;
    }
    // shouldn't occur
    return new File(new File(System.getProperty("catalina.base"), base), doc);
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) File(java.io.File)

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