Package org.apache.xindice.util

Examples of org.apache.xindice.util.ConfigurationException


        // The configuration is wrapped in a <xindice> element so we need to get the "root-collection" configuration.
        //
        try {
            Configuration rootCollectionConfiguration = configuration.getChild("root-collection");
            if (rootCollectionConfiguration == null) {
                throw new ConfigurationException("The database configuration is missing the <root-collection> element");
            } else {

                //
                // 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 = rootCollectionConfiguration.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 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 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.");
                    }
                    rootCollectionConfiguration.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.
                //
                this.database = Database.getDatabase(rootCollectionConfiguration);
            }

            // 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("Database successfully started");
        } catch (Exception e) {
            log.fatal("Failed to initialize database, throwing ServletException", e);
View Full Code Here


                configurationDocument = DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION);
            }

            return new Configuration(configurationDocument, false);
        } catch (Exception e) {
            throw new ConfigurationException("Failed to load configuration.", e);
        }
    }
View Full Code Here

        String name = config.getAttribute(Database.NAME);

        // No name in the config file ... can't get the database
        if (null == name) {
            throw new ConfigurationException("Database configuration didn't contain a database name");
        }

        Database database = (Database) databases.get(name);
        if (null == database) {
            // In case it's currently being added (only pay the sync hit on a miss)
            synchronized (databases) {
                // Was it created while we waited?
                database = (Database) databases.get(name);
                if (null == database) {
                    database = new Database();

                    try {
                        database.setConfig(config);
                    } catch (XindiceException x) {
                        // TODO: Configurable interface should use ConfigurationException instead of XindiceException.
                        throw new ConfigurationException(x);
                    }

                    databases.put(database.getName(), database);
                }
            }
View Full Code Here

        // 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);
View Full Code Here

                doc = DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION);
            }

            return new Configuration(doc, false);
        } catch (Exception e) {
            throw new ConfigurationException("Failed to load configuration.", e);
        }
    }
View Full Code Here

    public static Database getDatabase(Configuration config) {
        String name = config.getAttribute(Database.NAME);

        // No name in the config file ... can't get the database
        if (name == null) {
            throw new ConfigurationException("Database configuration didn't contain a database name");
        }

        Database database = (Database) databases.get(name);
        if (database == null) {
            // In case it's currently being added (only pay the sync hit on a miss)
            synchronized (databases) {
                // Was it created while we waited?
                database = (Database) databases.get(name);
                if (database == null) {
                    database = new Database();
                    try {
                        database.setConfig(config);
                    } catch (XindiceException x) {
                        // TODO: Configurable interface should use ConfigurationException instead of XindiceException... Right?
                        throw new ConfigurationException("XindiceException: " + x.getMessage(), x);
                    }

                    databases.put(database.getName(), database);
                }
            }
View Full Code Here

        // 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");
            } else {
                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);
View Full Code Here

                configurationDocument = DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION);
            }

            return new Configuration(configurationDocument, false);
        } catch (Exception e) {
            throw new ConfigurationException("Failed to load configuration.", e);
        }
    }
View Full Code Here

        String name = config.getAttribute(Database.NAME);

        // No name in the config file ... can't get the database
        if (null == name) {
            throw new ConfigurationException("Database configuration didn't contain a database name");
        }

        Database database = (Database) databases.get(name);
        if (null == database) {
            // In case it's currently being added (only pay the sync hit on a miss)
            synchronized (databases) {
                // Was it created while we waited?
                database = (Database) databases.get(name);
                if (null == database) {
                    database = new Database();

                    try {
                        database.setConfig(config);
                    } catch (XindiceException x) {
                        // TODO: Configurable interface should use ConfigurationException instead of XindiceException.
                        throw new ConfigurationException(x);
                    }

                    databases.put(database.getName(), database);
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.xindice.util.ConfigurationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.