// FIXME: could try to do stuff with EngineConfig and HostConfig, although neither
// should be useful in JBoss
// Create the Catalina instance
Catalina catalina = new Catalina();
catalina.setCatalinaHome(System.getProperty("jboss.server.home.dir"));
// Set the modeler Registry MBeanServer to the that of the tomcat service
Registry.getRegistry(null, null).setMBeanServer(server);
// Register the Catalina instance
Registry.getRegistry(null, null).registerComponent(catalina, objectName, "org.apache.catalina.startup.Catalina");
// Use the server.xml metadata to create a Server instance and assign it to the Catalina instance
// Server
org.apache.catalina.Server catalinaServer =
(org.apache.catalina.Server) getInstance(serverMetaData, "org.apache.catalina.core.StandardServer");
Registry.getRegistry(null, null).registerComponent(catalinaServer,
new ObjectName(tomcatDeployer.getDomain() + ":type=Server"), "org.apache.catalina.startup.StandardServer");
addLifecycleListeners(catalinaServer, serverMetaData.getListeners());
// Server/Service
if (serverMetaData.getServices() == null)
{
throw new IllegalArgumentException("No services");
}
Iterator<ServiceMetaData> serviceMetaDatas = serverMetaData.getServices().iterator();
if (serviceMetaDatas.hasNext())
{
ServiceMetaData serviceMetaData = serviceMetaDatas.next();
org.apache.catalina.Service service =
(org.apache.catalina.Service) getInstance(serviceMetaData, "org.apache.catalina.core.StandardService");
addLifecycleListeners(service, serviceMetaData.getListeners());
service.setName(serviceMetaData.getName());
service.setServer(catalinaServer);
catalinaServer.addService(service);
// Integrate support for on-demand contexts
onDemandContextIntegrator.registerMapper(service.getName(), service.getMapper());
// Server/Service/Executor
// Executor is useless in JBoss: the Executor will get injected in the executor field
// and used directly
// Server/Service/Connector
if (serviceMetaData.getConnectors() != null)
{
Iterator<ConnectorMetaData> connectorMetaDatas = serviceMetaData.getConnectors().iterator();
while (connectorMetaDatas.hasNext())
{
ConnectorMetaData connectorMetaData = connectorMetaDatas.next();
Connector connector = new Connector(connectorMetaData.getProtocol());
if (connectorMetaData.getAttributes() != null)
{
Iterator<QName> names = connectorMetaData.getAttributes().keySet().iterator();
while (names.hasNext())
{
QName name = names.next();
String value = (String) connectorMetaData.getAttributes().get(name);
// FIXME: This should be done by XB
value = StringPropertyReplacer.replaceProperties(value);
IntrospectionUtils.setProperty(connector, name.getLocalPart(), value);
}
}
if (executor != null)
{
IntrospectionUtils.callMethod1(connector.getProtocolHandler(), "setExecutor",
executor, java.util.concurrent.Executor.class.getName(), getClass().getClassLoader());
}
service.addConnector(connector);
}
}
// Server/Service/Engine
EngineMetaData engineMetaData = serviceMetaData.getEngine();
org.apache.catalina.Engine engine =
(org.apache.catalina.Engine) getInstance(engineMetaData, "org.apache.catalina.core.StandardEngine");
addLifecycleListeners(engine, engineMetaData.getListeners());
engine.setName(engineMetaData.getName());
// FIXME: This should be done by XB
if (engineMetaData.getJvmRoute() != null) {
engine.setJvmRoute(StringPropertyReplacer.replaceProperties(engineMetaData.getJvmRoute()));
}
engine.getPipeline().addValve(new ActiveRequestResponseCacheValve());
engine.setDefaultHost(engineMetaData.getDefaultHost());
service.setContainer(engine);
// Server/Service/Engine/Realm
if (engineMetaData.getRealm() != null) {
engine.setRealm((org.apache.catalina.Realm) getInstance(engineMetaData.getRealm(), null));
}
// Server/Service/Engine/Valve
addValves(engine, engineMetaData.getValves());
// Server/Service/Engine/Host
if (engineMetaData.getHosts() != null)
{
Iterator<HostMetaData> hostMetaDatas = engineMetaData.getHosts().iterator();
while (hostMetaDatas.hasNext())
{
HostMetaData hostMetaData = hostMetaDatas.next();
org.apache.catalina.Host host =
(org.apache.catalina.Host) getInstance(hostMetaData, "org.apache.catalina.core.StandardHost");
addLifecycleListeners(host, hostMetaData.getListeners());
host.setName(hostMetaData.getName());
engine.addChild(host);
// Server/Service/Engine/Host/Realm
if (hostMetaData.getRealm() != null) {
host.setRealm((org.apache.catalina.Realm) getInstance(hostMetaData.getRealm(), null));
}
// Server/Service/Engine/Host/Valve
addValves(host, hostMetaData.getValves());
// Server/Service/Engine/Host/Alias
if (hostMetaData.getAliases() != null) {
Iterator<String> aliases = hostMetaData.getAliases().iterator();
while (aliases.hasNext()) {
host.addAlias(aliases.next());
}
}
}
}
}
// Forbid more than one service
if (serviceMetaDatas.hasNext())
{
throw new IllegalArgumentException("Only one service declaration is allowed in server.xml");
}
// Set the resulting Server to the Catalina instance
catalina.setServer(catalinaServer);
// Start Tomcat
catalina.create();
catalinaServer.initialize();
catalina.start();
// Set up the authenticators in JNDI such that they can be configured for web apps
InitialContext ic = new InitialContext();
try
{