Unmarshaller u = UnmarshallerFactory.newInstance().newUnmarshaller();
u.setSchemaValidation(false);
u.setValidation(false);
u.setEntityResolver(new JBossEntityResolver());
InputStream is = null;
ServerMetaData serverMetaData = null;
try {
File configFile = new File(tomcatDeployer.getConfigFile());
if (configFile.exists())
{
is = new FileInputStream(configFile);
}
else
{
is = getClass().getClassLoader().getResourceAsStream(tomcatDeployer.getConfigFile());
}
if (is == null) {
log.error("Could not read configured server.xml (will try default): " + tomcatDeployer.getConfigFile());
is = getClass().getClassLoader().getResourceAsStream("server.xml");
}
serverMetaData = ServerMetaData.class.cast(u.unmarshal(is, schema));
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// Ignore
}
}
}
// 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"));
catalina.setUseNaming(false);
catalina.setUseShutdownHook(false);
catalina.setAwait(false);
catalina.setRedirectStreams(false);
// 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();
while (serviceMetaDatas.hasNext())
{
ServiceMetaData serviceMetaData = serviceMetaDatas.next();
org.apache.catalina.Service service =
(org.apache.catalina.Service) getInstance(serviceMetaData, "org.apache.catalina.core.StandardService");