use of org.apache.catalina.startup.HostConfig in project tomcat70 by apache.
the class MBeanFactory method createStandardHost.
/**
* Create a new StandardHost.
*
* @param parent MBean Name of the associated parent component
* @param name Unique name of this Host
* @param appBase Application base directory name
* @param autoDeploy Should we auto deploy?
* @param deployOnStartup Deploy on server startup?
* @param deployXML Should we deploy Context XML config files property?
* @param unpackWARs Should we unpack WARs when auto deploying?
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createStandardHost(String parent, String name, String appBase, boolean autoDeploy, boolean deployOnStartup, boolean deployXML, boolean unpackWARs) throws Exception {
// Create a new StandardHost instance
StandardHost host = new StandardHost();
host.setName(name);
host.setAppBase(appBase);
host.setAutoDeploy(autoDeploy);
host.setDeployOnStartup(deployOnStartup);
host.setDeployXML(deployXML);
host.setUnpackWARs(unpackWARs);
// add HostConfig for active reloading
HostConfig hostConfig = new HostConfig();
host.addLifecycleListener(hostConfig);
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
Service service = getService(pname);
Engine engine = (Engine) service.getContainer();
engine.addChild(host);
// Return the corresponding MBean name
return (host.getObjectName().toString());
}
use of org.apache.catalina.startup.HostConfig in project tomcat70 by apache.
the class ContainerMBean method addChild.
/**
* Add a new child Container to those associated with this Container,
* if supported. Won't start the child yet. Has to be started with a call to
* Start method after necessary configurations are done.
*
* @param type ClassName of the child to be added
* @param name Name of the child to be added
*
* @exception MBeanException if the child cannot be added
*/
public void addChild(String type, String name) throws MBeanException {
Container contained = null;
try {
contained = (Container) Class.forName(type).newInstance();
contained.setName(name);
if (contained instanceof StandardHost) {
HostConfig config = new HostConfig();
contained.addLifecycleListener(config);
} else if (contained instanceof StandardContext) {
ContextConfig config = new ContextConfig();
contained.addLifecycleListener(config);
}
} catch (InstantiationException e) {
throw new MBeanException(e);
} catch (IllegalAccessException e) {
throw new MBeanException(e);
} catch (ClassNotFoundException e) {
throw new MBeanException(e);
}
boolean oldValue = true;
ContainerBase container = null;
try {
container = (ContainerBase) getManagedResource();
oldValue = container.getStartChildren();
container.setStartChildren(false);
container.addChild(contained);
contained.init();
} catch (InstanceNotFoundException e) {
throw new MBeanException(e);
} catch (RuntimeOperationsException e) {
throw new MBeanException(e);
} catch (InvalidTargetObjectTypeException e) {
throw new MBeanException(e);
} catch (LifecycleException e) {
throw new MBeanException(e);
} finally {
if (container != null) {
container.setStartChildren(oldValue);
}
}
}
use of org.apache.catalina.startup.HostConfig in project tomee by apache.
the class TomcatWebAppBuilder method deployWar.
public void deployWar(final StandardContext standardContext, final String host, final AppInfo info) {
// TODO: instead of storing deployers, we could just lookup the right hostconfig for the server.
final HostConfig deployer = deployers.get(host);
if (isReady(deployer)) {
// if not ready using directly host to avoid a NPE
if (info != null) {
final ContextInfo contextInfo = addContextInfo(host, standardContext);
contextInfo.appInfo = info;
contextInfo.deployer = deployer;
contextInfo.module = extractModule(standardContext, info);
}
deployer.manageApp(standardContext);
} else {
final Host theHost = hosts.get(host);
if (theHost != null) {
if (info != null) {
final ContextInfo contextInfo = addContextInfo(host, standardContext);
contextInfo.appInfo = info;
contextInfo.host = theHost;
contextInfo.module = extractModule(standardContext, info);
}
theHost.addChild(standardContext);
} else {
throw new IllegalStateException("Host '" + host + "' not found for application " + standardContext.getPath());
}
}
}
use of org.apache.catalina.startup.HostConfig in project tomee by apache.
the class TomcatWebAppBuilder method afterStop.
/**
* {@inheritDoc}
*/
@Override
public synchronized void afterStop(final StandardServer standardServer) {
// clean ear based webapps after shutdown
for (final ContextInfo contextInfo : infos.values()) {
if (contextInfo != null && contextInfo.deployer != null) {
final StandardContext standardContext = contextInfo.standardContext;
final HostConfig deployer = contextInfo.deployer;
deployer.unmanageApp(standardContext.getPath());
final File realPath = Contexts.warPath(standardContext);
if (realPath != null) {
deleteDir(realPath);
}
}
}
TomcatLoader.destroy();
}
use of org.apache.catalina.startup.HostConfig 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/")));
}
Aggregations