use of org.apache.catalina.core.StandardHost in project Payara by payara.
the class ManagerBase method init.
public void init() {
if (initialized)
return;
initialized = true;
if (oname == null) {
try {
StandardContext ctx = (StandardContext) this.getContainer();
domain = ctx.getEngineName();
distributable = ctx.getDistributable();
StandardHost hst = (StandardHost) ctx.getParent();
String path = ctx.getEncodedPath();
if (path.equals("")) {
path = "/";
}
oname = new ObjectName(domain + ":type=Manager,path=" + path + ",host=" + hst.getName());
} catch (Exception e) {
log.log(Level.SEVERE, LogFacade.ERROR_REGISTERING_EXCEPTION_SEVERE, e);
}
}
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "Registering {0}", oname);
}
}
use of org.apache.catalina.core.StandardHost in project tomcat70 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 tomcat70 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 {
if (!ext.setLastModified(System.currentTimeMillis() - 10 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS)) {
Assert.fail("Failed to set last modified time for " + "external WAR file. This is expected (due to " + "a JVM bug) with Java 6 on Windows.");
}
}
break;
case WAR:
if (war == null) {
Assert.fail();
} else {
if (!war.setLastModified(System.currentTimeMillis() - 10 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS)) {
Assert.fail("Failed to set last modified time for WAR " + "file. This is expected (due to a JVM bug) " + "with Java 6 on Windows.");
}
}
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();
}
}
use of org.apache.catalina.core.StandardHost in project tomcat70 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();
}
}
use of org.apache.catalina.core.StandardHost in project tomcat70 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(getConfigBaseFile(host), 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());
}
}
Aggregations