if (!warDir.exists() && !warDir.mkdirs()) {
getTopLogger().log(TreeLogger.ERROR, "Unable to create war directory " + warDir);
return -1;
}
Event jettyStartupEvent = SpeedTracerLogger.start(DevModeEventType.JETTY_STARTUP);
boolean clearCallback = true;
try {
ui.setCallback(RestartServerEvent.getType(), this);
ServletContainerLauncher scl = options.getServletContainerLauncher();
TreeLogger serverLogger = ui.getWebServerLogger(getWebServerName(), scl.getIconBytes());
String sclArgs = options.getServletContainerLauncherArgs();
if (sclArgs != null) {
if (!scl.processArguments(serverLogger, sclArgs)) {
return -1;
}
}
isHttps = scl.isSecure();
// Tell the UI if the web server is secure
if (isHttps) {
ui.setWebServerSecure(serverLogger);
}
/*
* TODO: This is a hack to pass the base log level to the SCL. We'll have
* to figure out a better way to do this for SCLs in general.
*/
if (scl instanceof JettyLauncher) {
JettyLauncher jetty = (JettyLauncher) scl;
jetty.setBaseRequestLogLevel(getBaseLogLevelForUI());
}
scl.setBindAddress(options.getBindAddress());
if (serverLogger.isLoggable(TreeLogger.TRACE)) {
serverLogger.log(TreeLogger.TRACE, "Starting HTTP on port " + getPort(), null);
}
server = scl.start(serverLogger, getPort(), options.getWarDir());
assert (server != null);
clearCallback = false;
return server.getPort();
} catch (BindException e) {
System.err.println("Port " + options.getBindAddress() + ':' + getPort()
+ " is already is use; you probably still have another session active");
} catch (Exception e) {
System.err.println("Unable to start embedded HTTP server");
e.printStackTrace();
} finally {
jettyStartupEvent.end();
if (clearCallback) {
// Clear the callback if we failed to start the server
ui.setCallback(RestartServerEvent.getType(), null);
}
}