public void configure(String[] args) throws StartupException {
Config config = getConfig(args);
if (config == null) {
return;
}
checkClassDependencies();
ServerConfig serverConfig = config.getServerConfig();
Registry registry= createRegistry(serverConfig.getAdminPort());
Enumeration contextManagers = serverConfig.getContextManagers();
while (contextManagers.hasMoreElements()) {
ContextManagerConfig contextManagerConfig =
(ContextManagerConfig)contextManagers.nextElement();
ContextManager contextManager = new ContextManager();
Enumeration contexts = contextManagerConfig.getContextConfigs();
while (contexts.hasMoreElements()) {
ContextConfig contextConfig =
(ContextConfig)contexts.nextElement();
Context context = contextManager.addContext(
contextConfig.getPath(),
contextConfig.getDocumentBase());
String contextWorkDirPath =
getContextWorkDirPath(serverConfig,
contextManagerConfig,
contextConfig.getPath());
context.setSessionTimeOut(
contextConfig.getDefaultSessionTimeOut());
context.setInvokerEnabled(contextConfig.isInvokerEnabled());
context.setIsWARExpanded(contextConfig.isWARExpanded());
context.setIsWARValidated(contextConfig.isWARValidated());
context.setWorkDir(contextWorkDirPath,
contextConfig.isWorkDirPersistent());
context.setIsWARValidated(contextConfig.isWARValidated());
if (contextConfig.getPath().equals(
org.apache.tomcat.core.Constants.Context.Default.Path)) {
contextManager.setDefaultContext(context);
contextManager.setServerInfo(
contextManager.getDefaultContext().getEngineHeader());
}
}
InetAddress inetAddress = null;
try {
inetAddress = InetAddress.getByName(
contextManagerConfig.getINet());
} catch (java.net.UnknownHostException uhe) {
String msg = sm.getString("startup.setinit.uhe1",
contextManagerConfig.getINet());
System.out.println(msg);
}
try {
HttpServer server = new HttpServer(
contextManagerConfig.getPort(), inetAddress,
contextManagerConfig.getHostName(), contextManager);
Enumeration conE=contextManagerConfig.getConnectorConfigs();
while( conE.hasMoreElements() ) {
ConnectorConfig conC=(ConnectorConfig) conE.nextElement();
String cn=conC.getClassName();
ServerConnector conn=null;
try {
Class c=Class.forName( cn );
conn=(ServerConnector)c.newInstance();
} catch(Exception ex) {
ex.printStackTrace();
// XXX
}
Enumeration props=conC.getParameterKeys();
while( props.hasMoreElements() ) {
String k=(String)props.nextElement();
String v=(String)conC.getParameter( k );
conn.setProperty( k, v );
}
server.addConnector( conn );
}
// XXX
// instead of HTTPServer it should be EndpointManager,
// ContextManager, Handler, etc
if( registry != null )
registry.bind(Constants.Registry.Service + ":" +
server.getPort(), new AdminImpl(server));
// XXX
// start/stop individual components
server.start();
} catch (HttpServerException hse) {
String msg = sm.getString("startup.server.hse");
System.out.println(msg);
hse.printStackTrace();
throw new StartupException();
// "problem starting server" can't help
// the user detect that the port is taken.
// ( or another tcp-related problem )
// Please, let the stack trace until we have a better
// message ( that shows what failed)
} catch (RemoteException re) {
String msg = sm.getString("startup.server.re");
System.out.println(msg);
re.printStackTrace();
throw new StartupException();
// The original message is useless,
// I had no idea what to do - if we can't figure a better
// message, please let the stack trace in
// in my case - I had no eth card, and it couldn't find the hostname
} catch (AlreadyBoundException abe) {
String msg = sm.getString("startup.server.abe");
System.out.println(msg);
abe.printStackTrace();
throw new StartupException();
}
}
}
|