Search in sources :

Example 6 with StandardHost

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

the class TestHostConfigAutomaticDeployment method doTestUnpackWAR.

private void doTestUnpackWAR(boolean unpackWARs, boolean unpackWAR, boolean external, boolean resultDir) throws Exception {
    Tomcat tomcat = getTomcatInstance();
    StandardHost host = (StandardHost) tomcat.getHost();
    host.setUnpackWARs(unpackWARs);
    tomcat.start();
    File war;
    if (unpackWAR) {
        war = createWar(WAR_XML_UNPACKWAR_TRUE_SOURCE, !external);
    } else {
        war = createWar(WAR_XML_UNPACKWAR_FALSE_SOURCE, !external);
    }
    if (external) {
        createXmlInConfigBaseForExternal(war);
    }
    host.backgroundProcess();
    File dir = new File(host.getAppBase(), APP_NAME.getBaseName());
    Assert.assertEquals(Boolean.valueOf(resultDir), Boolean.valueOf(dir.isDirectory()));
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) File(java.io.File)

Example 7 with StandardHost

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

the class TestHostConfigAutomaticDeployment method testBrokenAppWithAntiLocking.

private void testBrokenAppWithAntiLocking(boolean unpackWARs) throws Exception {
    Tomcat tomcat = getTomcatInstance();
    StandardHost host = (StandardHost) tomcat.getHost();
    host.setUnpackWARs(unpackWARs);
    File war = createWar(WAR_BROKEN_SOURCE, false);
    createXmlInConfigBaseForExternal(war, true);
    File dir = new File(host.getAppBaseFile(), APP_NAME.getBaseName());
    tomcat.start();
    // Simulate deploy on start-up
    tomcat.getHost().backgroundProcess();
    Assert.assertTrue(war.isFile());
    if (unpackWARs) {
        Assert.assertTrue(dir.isDirectory());
    }
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) File(java.io.File)

Example 8 with StandardHost

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

the class TestHostConfigAutomaticDeployment method doTestUpdateWarOffline.

private void doTestUpdateWarOffline(File srcWar, boolean deployOnStartUp, boolean autoDeploy) throws Exception {
    Tomcat tomcat = getTomcatInstance();
    StandardHost host = (StandardHost) tomcat.getHost();
    host.setDeployOnStartup(deployOnStartUp);
    File war = createWar(srcWar, true);
    // Make the WAR appear to have been created earlier
    war.setLastModified(war.lastModified() - 2 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS);
    tomcat.addWebapp(APP_NAME.getPath(), war.getAbsolutePath());
    tomcat.start();
    // Get the last modified timestamp for the expanded dir
    File dir = new File(host.getAppBase(), APP_NAME.getBaseName());
    // Make the DIR appear to have been created earlier
    long lastModified = war.lastModified() - 2 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS;
    dir.setLastModified(lastModified);
    host.stop();
    war.setLastModified(System.currentTimeMillis());
    host.start();
    if (autoDeploy) {
        host.backgroundProcess();
    }
    long newLastModified = dir.lastModified();
    Assert.assertNotEquals("Timestamp hasn't changed", lastModified, newLastModified);
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) File(java.io.File)

Example 9 with StandardHost

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

the class TestTomcat method testGetBrokenContextPerAddContext.

@Test
public void testGetBrokenContextPerAddContext() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClass("InvalidContextClassName");
    }
    // No file system docBase required
    try {
        tomcat.addContext(null, "", null);
        fail();
    } catch (IllegalArgumentException e) {
    // OK
    }
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) Test(org.junit.Test)

Example 10 with StandardHost

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

the class HostManagerServlet method remove.

/**
     * Remove the specified host.
     *
     * @param writer Writer to render results to
     * @param name host name
     * @param smClient StringManager for the client's locale
     */
protected synchronized void remove(PrintWriter writer, String name, StringManager smClient) {
    if (debug >= 1) {
        log(sm.getString("hostManagerServlet.remove", name));
    }
    // Validate the requested host name
    if ((name == null) || name.length() == 0) {
        writer.println(smClient.getString("hostManagerServlet.invalidHostName", name));
        return;
    }
    // Check if host exists
    if (engine.findChild(name) == null) {
        writer.println(smClient.getString("hostManagerServlet.noHost", name));
        return;
    }
    // Prevent removing our own host
    if (engine.findChild(name) == installedHost) {
        writer.println(smClient.getString("hostManagerServlet.cannotRemoveOwnHost", name));
        return;
    }
    // Note that the host will not get physically removed
    try {
        Container child = engine.findChild(name);
        engine.removeChild(child);
        if (child instanceof ContainerBase)
            ((ContainerBase) child).destroy();
    } catch (Exception e) {
        writer.println(smClient.getString("hostManagerServlet.exception", e.toString()));
        return;
    }
    Host host = (StandardHost) engine.findChild(name);
    if (host == null) {
        writer.println(smClient.getString("hostManagerServlet.remove", name));
    } else {
        // Something failed
        writer.println(smClient.getString("hostManagerServlet.removeFailed", name));
    }
}
Also used : ContainerBase(org.apache.catalina.core.ContainerBase) Container(org.apache.catalina.Container) StandardHost(org.apache.catalina.core.StandardHost) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) ServletException(javax.servlet.ServletException) InstanceNotFoundException(javax.management.InstanceNotFoundException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

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