Search in sources :

Example 36 with StandardHost

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

the class TestHostConfigAutomaticDeployment method doTestCopyXML.

private void doTestCopyXML(boolean copyXmlHost, boolean copyXmlWar, boolean external, boolean resultXml) throws Exception {
    Tomcat tomcat = getTomcatInstance();
    StandardHost host = (StandardHost) tomcat.getHost();
    host.setCopyXML(copyXmlHost);
    tomcat.start();
    File war;
    if (copyXmlWar) {
        war = createWar(WAR_XML_COPYXML_TRUE_SOURCE, !external);
    } else {
        war = createWar(WAR_XML_COPYXML_FALSE_SOURCE, !external);
    }
    if (external) {
        createXmlInConfigBaseForExternal(war);
    }
    host.backgroundProcess();
    File xml = new File(host.getConfigBaseFile(), APP_NAME.getBaseName() + ".xml");
    Assert.assertEquals(Boolean.valueOf(resultXml), Boolean.valueOf(xml.isFile()));
    Context context = (Context) host.findChild(APP_NAME.getName());
    if (external) {
        Assert.assertEquals(XML_COOKIE_NAME, context.getSessionCookieName());
    } else {
        Assert.assertEquals(WAR_COOKIE_NAME, context.getSessionCookieName());
    }
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) StandardHost(org.apache.catalina.core.StandardHost) File(java.io.File)

Example 37 with StandardHost

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

the class TestHostConfigAutomaticDeployment method doTestAddition.

private void doTestAddition(boolean startXml, boolean startExternalWar, boolean startExternalDir, boolean startWar, boolean startDir, boolean copyXML, boolean deployXML, int toAdd, boolean resultXml, boolean resultWar, boolean resultDir, String resultCookieName, int resultAction, LifecycleState state) throws Exception {
    Tomcat tomcat = getTomcatInstance();
    StandardHost host = (StandardHost) tomcat.getHost();
    // Init
    File xml = null;
    File ext = null;
    File war = null;
    File dir = null;
    if (startXml && !startExternalWar && !startExternalDir) {
        xml = createXmlInConfigBaseForAppbase();
    }
    if (startExternalWar) {
        ext = createWar(WAR_XML_SOURCE, false);
        xml = createXmlInConfigBaseForExternal(ext);
    }
    if (startExternalDir) {
        ext = createDirInExternal(true);
        xml = createXmlInConfigBaseForExternal(ext);
    }
    if (startWar) {
        war = createWar(WAR_XML_SOURCE, true);
    }
    if (startDir) {
        dir = createDirInAppbase(toAdd != DIR_XML);
    }
    if ((startWar || startExternalWar) && !startDir) {
        host.setUnpackWARs(false);
    }
    host.setCopyXML(copyXML);
    host.setDeployXML(deployXML);
    // Deploy the files we copied
    tomcat.start();
    host.backgroundProcess();
    // Change the specified file
    switch(toAdd) {
        case XML:
            if (xml == null) {
                xml = createXmlInConfigBaseForAppbase();
            } else {
                Assert.fail();
            }
            break;
        case EXT:
            if (ext == null && xml == null) {
                ext = createWar(WAR_XML_SOURCE, false);
                xml = createXmlInConfigBaseForExternal(ext);
            } else {
                Assert.fail();
            }
            break;
        case WAR:
            if (war == null) {
                war = createWar(WAR_XML_SOURCE, true);
            } else {
                Assert.fail();
            }
            break;
        case DIR:
            if (dir == null) {
                dir = createDirInAppbase(true);
            } else {
                Assert.fail();
            }
            break;
        case DIR_XML:
            dir = createDirXmlInAppbase();
            xml = getXmlInConfigBaseForAppbase();
            break;
        default:
            Assert.fail();
    }
    Context oldContext = (Context) host.findChild(APP_NAME.getName());
    StateTracker tracker = new StateTracker();
    oldContext.addLifecycleListener(tracker);
    // Trigger an auto-deployment cycle
    host.backgroundProcess();
    Context newContext = (Context) host.findChild(APP_NAME.getName());
    // Check the results
    if (resultXml) {
        if (xml == null) {
            Assert.fail();
        } else {
            Assert.assertTrue(xml.isFile());
        }
    }
    if (resultWar) {
        if (war == null) {
            Assert.fail();
        } else {
            Assert.assertTrue(war.isFile());
        }
    }
    if (resultDir) {
        if (dir == null) {
            Assert.fail();
        } else {
            Assert.assertTrue(dir.isDirectory());
        }
    }
    if (!resultXml && (startExternalWar || startExternalDir)) {
        Assert.assertNull(newContext);
    }
    if (!resultWar && !resultDir) {
        if (resultXml) {
            Assert.assertNotNull(newContext);
            if (!startExternalWar && !startExternalDir) {
                Assert.assertEquals(LifecycleState.FAILED, newContext.getState());
            } else {
                Assert.assertEquals(LifecycleState.STARTED, newContext.getState());
            }
        } else {
            Assert.assertNull(newContext);
        }
    }
    if (newContext != null) {
        Assert.assertEquals(resultCookieName, newContext.getSessionCookieName());
    }
    if (resultAction == NONE) {
        Assert.assertSame(oldContext, newContext);
        Assert.assertEquals("", tracker.getHistory());
    } else if (resultAction == RELOAD) {
        Assert.assertSame(oldContext, newContext);
        Assert.assertEquals("stopstart", tracker.getHistory());
    } else if (resultAction == REDEPLOY) {
        if (newContext == null) {
            Assert.fail();
        } else {
            Assert.assertEquals(state, newContext.getState());
        }
        Assert.assertNotSame(oldContext, newContext);
        // No init or start as that will be in a new context object
        Assert.assertEquals("stopafter_destroy", tracker.getHistory());
    } else {
        Assert.fail();
    }
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) StandardHost(org.apache.catalina.core.StandardHost) File(java.io.File)

Example 38 with StandardHost

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

the class TestHostConfigAutomaticDeployment method doTestModify.

private void doTestModify(boolean startXml, boolean startExternalWar, boolean startExternalDir, boolean startWar, boolean startDir, int toModify, boolean resultXml, boolean resultWar, boolean resultDir, String resultCookieName, int resultAction, LifecycleState resultState) throws Exception {
    Tomcat tomcat = getTomcatInstance();
    StandardHost host = (StandardHost) tomcat.getHost();
    // Init
    File xml = null;
    File ext = null;
    File war = null;
    File dir = null;
    if (startXml && !startExternalWar && !startExternalDir) {
        xml = createXmlInConfigBaseForAppbase();
    }
    if (startExternalWar) {
        ext = createWar(WAR_XML_SOURCE, false);
        xml = createXmlInConfigBaseForExternal(ext);
    }
    if (startExternalDir) {
        ext = createDirInAppbase(true);
        xml = createXmlInConfigBaseForExternal(ext);
    }
    if (startWar) {
        war = createWar(WAR_XML_SOURCE, true);
    }
    if (startDir) {
        dir = createDirInAppbase(true);
    }
    if ((startWar || startExternalWar) && !startDir) {
        host.setUnpackWARs(false);
    }
    // Deploy the files we copied
    tomcat.start();
    host.backgroundProcess();
    // in modification time that HostConfig can detect.
    switch(toModify) {
        case XML:
            if (xml == null) {
                Assert.fail();
            } else {
                xml.setLastModified(System.currentTimeMillis() - 10 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS);
            }
            break;
        case EXT:
            if (ext == null) {
                Assert.fail();
            } else {
                ext.setLastModified(System.currentTimeMillis() - 10 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS);
            }
            break;
        case WAR:
            if (war == null) {
                Assert.fail();
            } else {
                war.setLastModified(System.currentTimeMillis() - 10 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS);
            }
            break;
        case DIR:
            if (dir == null) {
                Assert.fail();
            } else {
                dir.setLastModified(System.currentTimeMillis() - 10 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS);
            }
            break;
        default:
            Assert.fail();
    }
    Context oldContext = (Context) host.findChild(APP_NAME.getName());
    StateTracker tracker = new StateTracker();
    oldContext.addLifecycleListener(tracker);
    // Trigger an auto-deployment cycle
    host.backgroundProcess();
    Context newContext = (Context) host.findChild(APP_NAME.getName());
    // Check the results
    if (resultXml) {
        if (xml == null) {
            Assert.fail();
        } else {
            Assert.assertTrue(xml.isFile());
        }
    }
    if (resultWar) {
        if (war == null) {
            Assert.fail();
        } else {
            Assert.assertTrue(war.isFile());
        }
    }
    if (resultDir) {
        if (dir == null) {
            Assert.fail();
        } else {
            Assert.assertTrue(dir.isDirectory());
        }
    }
    if (!resultXml && (startExternalWar || startExternalDir)) {
        Assert.assertNull(newContext);
    }
    if (!resultWar && !resultDir) {
        if (resultXml) {
            Assert.assertNotNull(newContext);
            if (!startExternalWar && !startExternalDir) {
                Assert.assertEquals(LifecycleState.FAILED, newContext.getState());
            } else {
                Assert.assertEquals(LifecycleState.STARTED, newContext.getState());
            }
        } else {
            Assert.assertNull(newContext);
        }
    }
    if (newContext != null) {
        Assert.assertEquals(resultCookieName, newContext.getSessionCookieName());
        Assert.assertEquals(resultState, newContext.getState());
    }
    if (resultAction == NONE) {
        Assert.assertSame(oldContext, newContext);
        Assert.assertEquals("", tracker.getHistory());
    } else if (resultAction == RELOAD) {
        Assert.assertSame(oldContext, newContext);
        Assert.assertEquals("stopstart", tracker.getHistory());
    } else if (resultAction == REDEPLOY) {
        Assert.assertNotSame(oldContext, newContext);
        // No init or start as that will be in a new context object
        Assert.assertEquals("stopafter_destroy", tracker.getHistory());
    } else {
        Assert.fail();
    }
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) StandardHost(org.apache.catalina.core.StandardHost) File(java.io.File)

Example 39 with StandardHost

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

the class TestHostConfigAutomaticDeployment method doTestDeployment.

private void doTestDeployment(boolean deployXML, boolean copyXML, boolean unpackWARs, LifecycleState resultState, String cookieName, boolean resultXml, boolean resultWar, boolean resultDir) throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // Start the instance
    tomcat.start();
    // Set the attributes
    StandardHost host = (StandardHost) tomcat.getHost();
    host.setDeployXML(deployXML);
    host.setCopyXML(copyXML);
    host.setUnpackWARs(unpackWARs);
    // Trigger automatic deployment
    host.backgroundProcess();
    // Test the results
    Context ctxt = (Context) tomcat.getHost().findChild(APP_NAME.getPath());
    if (resultState == null) {
        Assert.assertNull(ctxt);
    } else {
        Assert.assertNotNull(ctxt);
        Assert.assertEquals(resultState, ctxt.getState());
        Assert.assertEquals(cookieName, ctxt.getSessionCookieName());
    }
    File xml = new File(host.getConfigBaseFile(), APP_NAME.getBaseName() + ".xml");
    Assert.assertEquals(Boolean.valueOf(resultXml), Boolean.valueOf(xml.isFile()));
    File war = new File(host.getAppBaseFile(), APP_NAME.getBaseName() + ".war");
    Assert.assertEquals(Boolean.valueOf(resultWar), Boolean.valueOf(war.isFile()));
    File dir = new File(host.getAppBase(), APP_NAME.getBaseName());
    Assert.assertEquals(Boolean.valueOf(resultDir), Boolean.valueOf(dir.isDirectory()));
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) StandardHost(org.apache.catalina.core.StandardHost) File(java.io.File)

Example 40 with StandardHost

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

the class TesterDigestAuthenticatorPerformance method setUp.

@Before
public void setUp() throws Exception {
    ConcurrentMessageDigest.init("MD5");
    // Configure the Realm
    TesterMapRealm realm = new TesterMapRealm();
    realm.addUser(USER, PWD);
    realm.addUserRole(USER, ROLE);
    // Add the Realm to the Context
    Context context = new StandardContext();
    context.setName(CONTEXT_PATH);
    context.setRealm(realm);
    Host host = new StandardHost();
    context.setParent(host);
    Engine engine = new StandardEngine();
    host.setParent(engine);
    Service service = new StandardService();
    engine.setService(service);
    // Configure the Login config
    LoginConfig config = new LoginConfig();
    config.setRealmName(REALM);
    context.setLoginConfig(config);
    // Make the Context and Realm visible to the Authenticator
    authenticator.setContainer(context);
    authenticator.setNonceCountWindowSize(8 * 1024);
    authenticator.start();
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) TesterMapRealm(org.apache.catalina.startup.TesterMapRealm) StandardEngine(org.apache.catalina.core.StandardEngine) StandardHost(org.apache.catalina.core.StandardHost) StandardContext(org.apache.catalina.core.StandardContext) LoginConfig(org.apache.tomcat.util.descriptor.web.LoginConfig) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) StandardService(org.apache.catalina.core.StandardService) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine) Before(org.junit.Before)

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