Search in sources :

Example 21 with StandardHost

use of org.apache.catalina.core.StandardHost 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)

Example 22 with StandardHost

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

the class WebappDeployer method check.

private void check() {
    final StandardServer server = TomcatHelper.getServer();
    for (final Service service : server.findServices()) {
        if (service.getContainer() instanceof Engine) {
            final Engine engine = (Engine) service.getContainer();
            for (final Container engineChild : engine.findChildren()) {
                if (engineChild instanceof StandardHost) {
                    final StandardHost host = (StandardHost) engineChild;
                    webappBuilder.checkHost(host);
                }
            }
        }
    }
}
Also used : Container(org.apache.catalina.Container) StandardServer(org.apache.catalina.core.StandardServer) StandardHost(org.apache.catalina.core.StandardHost) Service(org.apache.catalina.Service) Engine(org.apache.catalina.Engine)

Example 23 with StandardHost

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

the class StoreContextAppender method isPrintValue.

/**
     * Print Context Values. <ul><li> Special handling to default workDir.
     * </li><li> Don't save path at external context.xml </li><li> Don't
     * generate docBase for host.appBase webapps <LI></ul>
     *
     * @see org.apache.catalina.storeconfig.StoreAppender#isPrintValue(java.lang.Object,
     *      java.lang.Object, java.lang.String,
     *      org.apache.catalina.storeconfig.StoreDescription)
     */
@Override
public boolean isPrintValue(Object bean, Object bean2, String attrName, StoreDescription desc) {
    boolean isPrint = super.isPrintValue(bean, bean2, attrName, desc);
    if (isPrint) {
        StandardContext context = ((StandardContext) bean);
        if ("workDir".equals(attrName)) {
            String defaultWorkDir = getDefaultWorkDir(context);
            isPrint = !defaultWorkDir.equals(context.getWorkDir());
        } else if ("path".equals(attrName)) {
            isPrint = desc.isStoreSeparate() && desc.isExternalAllowed() && context.getConfigFile() == null;
        } else if ("docBase".equals(attrName)) {
            Container host = context.getParent();
            if (host instanceof StandardHost) {
                File appBase = getAppBase(((StandardHost) host));
                File docBase = getDocBase(context, appBase);
                isPrint = !appBase.equals(docBase.getParentFile());
            }
        }
    }
    return isPrint;
}
Also used : Container(org.apache.catalina.Container) StandardHost(org.apache.catalina.core.StandardHost) StandardContext(org.apache.catalina.core.StandardContext) File(java.io.File)

Example 24 with StandardHost

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

the class StoreContextAppender method getDefaultWorkDir.

/**
     * Make default Work Dir.
     *
     * @param context The context
     * @return The default working directory for the context.
     */
protected String getDefaultWorkDir(StandardContext context) {
    String defaultWorkDir = null;
    String contextWorkDir = context.getName();
    if (contextWorkDir.length() == 0)
        contextWorkDir = "_";
    if (contextWorkDir.startsWith("/"))
        contextWorkDir = contextWorkDir.substring(1);
    Container host = context.getParent();
    if (host instanceof StandardHost) {
        String hostWorkDir = ((StandardHost) host).getWorkDir();
        if (hostWorkDir != null) {
            defaultWorkDir = hostWorkDir + File.separator + contextWorkDir;
        } else {
            String engineName = context.getParent().getParent().getName();
            String hostName = context.getParent().getName();
            defaultWorkDir = "work" + File.separator + engineName + File.separator + hostName + File.separator + contextWorkDir;
        }
    }
    return defaultWorkDir;
}
Also used : Container(org.apache.catalina.Container) StandardHost(org.apache.catalina.core.StandardHost)

Example 25 with StandardHost

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

the class TestHandlerIntegration method testToURI.

@Test
public void testToURI() 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();
    URL url = ctx.getServletContext().getResource("/index.html");
    try {
        url.toURI();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    }
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) StandardHost(org.apache.catalina.core.StandardHost) File(java.io.File) URL(java.net.URL) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

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