// The configuration is wrapped in a <xindice> element so we need to get the "root-collection" configuration.
//
try {
Configuration[] rootConfigurations = configuration.getChildren("root-collection");
if (rootConfigurations.length == 0) {
throw new ConfigurationException("The database configuration is missing the <root-collection> element");
}
for (int i = 0; i < rootConfigurations.length; i++) {
Configuration rootConfiguration = rootConfigurations[i];
String name = rootConfiguration.getAttribute(Database.NAME);
//
// We need to ensure that the database points to a place where it makes
// sense. If the path in the system.xml file is an absolute path, then
// honor it. If it's not, we first check for the system property "xindice.db.home"
// and if the lookup is successful we use it as the database root parent. If
// the property is not set, we use /WEB-INF relative to the servlet context, unless
// the war has not been unpacked. In this case, we throw an exception and
// ask the user to specify the location of database root
//
String dbRoot = rootConfiguration.getAttribute(Database.DBROOT, Database.DBROOT_DEFAULT);
//
// If there is no absolute path, we have to perform some checks.
//
if (!new File(dbRoot).isAbsolute()) {
// Stupid hack but spec compliant:
// If getRealPath() returns null the war archive has not been unpacked.
String realPath = servletConfig.getServletContext().getRealPath("/WEB-INF");
// Let's see if the property was specified.
String home = System.getProperty(Xindice.PROP_XINDICE_DB_HOME);
if (log.isDebugEnabled()) {
log.debug(Xindice.PROP_XINDICE_DB_HOME + " is set to " + home);
}
if (home != null) {
dbRoot = new File(home + File.separator + dbRoot).getCanonicalPath();
} else if (realPath != null) {
dbRoot = new File(realPath + File.separator + dbRoot).getCanonicalPath();
log.warn("The database '" + name + "' root directory has been set to " + dbRoot +
". Keep in mind that if a war upgrade will take place the database will be lost.");
} else {
throw new ConfigurationException(
"The database '" + name + "' configuration points to a relative path, "
+ "but there was no " + Xindice.PROP_XINDICE_DB_HOME + " property set. "
+ "Furthermore, the war was not unpacked by the application server "
+ "so Xindice was unable to find a database location "
+ "Please check /WEB-INF/system.xml and set an absolute path "
+ "as the \"dbroot\" attribute of \"root-collection\" "
+ "or specify a suitable " + Xindice.PROP_XINDICE_DB_HOME + " system property.");
}
rootConfiguration.setAttribute(Database.DBROOT, dbRoot);
}
//
// We need to use this method to be consistent between deployments (embed, standalone, etc)
// and let the Database object maintain the set of Databases.
//
Database.getDatabase(rootConfiguration);
log.info("Database '" + name + "' successfully opened");
}
// Setup the XML-RPC impl to support UTF-8 input via Xerces.
XmlRpc.setEncoding("UTF8");
/*
* Setup the SAX parser XML-RPC impl will use.
* The XmlRpc.setDriver() method takes either the classname or a shorthand
* name for the SAX parser it will use. The default (for backwards compatibility
* if nothing else) is xerces.
*/
String xmlrpcDriver = DEFAULT_XMLRPC_DRIVER;
Configuration xmlRpcConfiguration = configuration.getChild("xml-rpc");
if (xmlRpcConfiguration != null) {
Configuration xmlRpcDriverConfiguration = xmlRpcConfiguration.getChild("driver");
if (xmlRpcDriverConfiguration != null) {
// xmlrpcDriver will have non-empty value, guaranteed by providing default value
xmlrpcDriver = xmlRpcDriverConfiguration.getAttribute("name", DEFAULT_XMLRPC_DRIVER);
}
}
try {
XmlRpc.setDriver(xmlrpcDriver);
} catch (Exception e) {
throw new ConfigurationException("Failed to set driver for XmlRpc to: " + xmlrpcDriver, e);
}
// Create the XML-RPC server and add our handler as the default.
this.xmlrpcServer = new XmlRpcServer();
try {
this.xmlrpcServer.addHandler("$default", new RPCMessageInterface());
} catch (Exception e) {
throw new ConfigurationException("Failed to add default handler to XmlRpc server.", e);
}
log.info("Xindice server successfully started");
} catch (Exception e) {
log.fatal("Failed to initialize database, throwing ServletException", e);