throws LifecycleException {
if (topLogger == null) {
throw new NullPointerException("No logger specified");
}
final TreeLogger logger = topLogger.branch(TreeLogger.INFO,
"Starting HTTP on port " + listeningPort, null);
startupBranchLogger = logger;
// Make myself the one static instance.
// NOTE: there is only one small implementation reason that this has
// to be a singleton, which is that the commons logger LogFactory insists
// on creating your logger class which must have a constructor with
// exactly one String argument, and since we want LoggerAdapter to delegate
// to the logger instance available through instance host, there is no
// way I can think of to delegate without accessing a static field.
// An inner class is almost right, except there's no outer instance.
//
sTomcat = this;
// Assume the working directory is simply the user's current directory.
//
File topWorkDir = new File(System.getProperty("user.dir"));
// Tell Tomcat its base directory so that it won't complain.
//
String catBase = System.getProperty("catalina.base");
if (catBase == null) {
// we (briefly) supported catalina.base.create, so let's not cut support
// until the deprecated sunset
catBase = System.getProperty("catalina.base.create");
if (catBase != null) {
logger.log(TreeLogger.WARN, "catalina.base.create is deprecated. " +
"Use catalina.base, and it will be created if necessary.");
topWorkDir = new File(catBase);
}
catBase = generateDefaultCatalinaBase(logger, topWorkDir);
System.setProperty("catalina.base", catBase);
}
// Some debug messages for ourselves.
//
logger.log(TreeLogger.DEBUG, "catalina.base = " + catBase, null);
// Set up the logger that will be returned by the Commons logging factory.
//
String adapterClassName = CommonsLoggerAdapter.class.getName();
System.setProperty("org.apache.commons.logging.Log", adapterClassName);
// And set up an adapter that will work with the Catalina logger family.
//
Logger catalinaLogger = new CatalinaLoggerAdapter(topLogger);
// Create an embedded server.
//
catEmbedded = new Embedded();
catEmbedded.setDebug(0);
catEmbedded.setLogger(catalinaLogger);
// The embedded engine is called "gwt".
//
catEngine = catEmbedded.createEngine();
catEngine.setName("gwt");
catEngine.setDefaultHost("localhost");
catEngine.setParentClassLoader(this.getClass().getClassLoader());
// It answers localhost requests.
//
// String appBase = fCatalinaBaseDir.getAbsolutePath();
String appBase = catBase + "/webapps";
catHost = (StandardHost) catEmbedded.createHost("localhost", appBase);
// Hook up a host config to search for and pull in webapps.
//
HostConfig hostConfig = new HostConfig();
catHost.addLifecycleListener(hostConfig);
// Hook pre-install events so that we can add attributes to allow loaded
// instances to find their development instance host.
//
catHost.addContainerListener(new ContainerListener() {
public void containerEvent(ContainerEvent event) {
if (StandardHost.PRE_INSTALL_EVENT.equals(event.getType())) {
StandardContext webapp = (StandardContext) event.getData();
publishShellLoggerAttribute(logger, topLogger, webapp);
publishShellWorkDirsAttribute(logger, workDirs, webapp);
publishShouldAutoGenerateResourcesAttribute(logger,
shouldAutoGenerateResources, webapp);
}
}
});
// Tell the engine about the host.
//
catEngine.addChild(catHost);
catEngine.setDefaultHost(catHost.getName());
// Tell the embedded manager about the engine.
//
catEmbedded.addEngine(catEngine);
InetAddress nullAddr = null;
Connector connector = catEmbedded.createConnector(nullAddr, listeningPort,
false);
catEmbedded.addConnector(connector);
// start up!
catEmbedded.start();
port = computeLocalPort(connector);
if (port != listeningPort) {
logger.log(TreeLogger.INFO, "HTTP listening on port " + port, null);
}
}