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()));
}
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());
}
}
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);
}
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
}
}
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));
}
}
Aggregations