You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by vg...@apache.org on 2007/03/28 03:00:00 UTC

svn commit: r523128 - in /xml/xindice/trunk: build.xml config/web.xml java/src/org/apache/xindice/server/Xindice.java java/src/org/apache/xindice/server/XindiceServlet.java status.xml xindice.sh

Author: vgritsenko
Date: Tue Mar 27 18:00:00 2007
New Revision: 523128

URL: http://svn.apache.org/viewvc?view=rev&rev=523128
Log:
            <action dev="VG" type="update">
                Moved configuration file in WAR file to /WEB-INF/config. Updated
                XindiceServlet to check for xindice.configuration system property
                before attempting to load configuration from WAR file.
            </action>


Modified:
    xml/xindice/trunk/build.xml
    xml/xindice/trunk/config/web.xml
    xml/xindice/trunk/java/src/org/apache/xindice/server/Xindice.java
    xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java
    xml/xindice/trunk/status.xml
    xml/xindice/trunk/xindice.sh

Modified: xml/xindice/trunk/build.xml
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/build.xml?view=diff&rev=523128&r1=523127&r2=523128
==============================================================================
--- xml/xindice/trunk/build.xml (original)
+++ xml/xindice/trunk/build.xml Tue Mar 27 18:00:00 2007
@@ -296,11 +296,8 @@
 
         <war destfile="${dist.dir}/${project.filename}-${project.version}.war"
              update="false" webxml="config/web.xml">
-            <webinf dir="${config.dir}">
-                <include name="system.xml"/>
-            </webinf>
             <webinf dir=".">
-                <!-- TODO include name="${config.dir}/system.xml"/ -->
+                <include name="${config.dir}/system.xml"/>
                 <include name="${config.dir}/commands.xml"/>
             </webinf>
             <webinf dir="${build.dir}/war-bin">

Modified: xml/xindice/trunk/config/web.xml
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/config/web.xml?view=diff&rev=523128&r1=523127&r2=523128
==============================================================================
--- xml/xindice/trunk/config/web.xml (original)
+++ xml/xindice/trunk/config/web.xml Tue Mar 27 18:00:00 2007
@@ -45,7 +45,7 @@
       -->
     <init-param>
       <param-name>xindice.configuration</param-name>
-      <param-value>WEB-INF/system.xml</param-value>
+      <param-value>WEB-INF/config/system.xml</param-value>
     </init-param>
 
     <load-on-startup>1</load-on-startup>

Modified: xml/xindice/trunk/java/src/org/apache/xindice/server/Xindice.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/server/Xindice.java?view=diff&rev=523128&r1=523127&r2=523128
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/server/Xindice.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/server/Xindice.java Tue Mar 27 18:00:00 2007
@@ -39,7 +39,8 @@
     public static final String PROP_XINDICE_DB_HOME = "xindice.db.home";
 
     /**
-     * System property specyfying location of the Xindice configuration file (system.xml).
+     * System property specyfying location of the Xindice database configuration
+     * file (system.xml).
      */
     public static final String PROP_XINDICE_CONFIGURATION = "xindice.configuration";
 
@@ -51,23 +52,23 @@
     public static final String Codename = "Christmas+.2";
 
     // Copyright/Authorship Information
-    public static final String Title = "Xindice";
-    public static final String Author = "The Apache Foundation";
-    public static final String Year = "2003";
-    public static final String Company = "The Apache Foundation";
-    public static final String URL = "http://xml.apache.org/xindice/";
+    public static final String Title   = "Xindice";
+    public static final String Author  = "The Apache Software Foundation";
+    public static final String Year    = "2003";
+    public static final String Company = "The Apache Software Foundation";
+    public static final String URL     = "http://xml.apache.org/xindice/";
 
     // Default configuration if a system.xml file isn't available.
     public static final String DEFAULT_CONFIGURATION
             = "<xindice>"
-            + "    <root-collection dbroot=\"./db/\" name=\"db\">"
+            + "    <root-collection dbroot='./db/' name='db'>"
             + "        <queryengine>"
-            + "            <resolver autoindex=\"false\" class=\"org.apache.xindice.core.query.XPathQueryResolver\" />"
-            + "            <resolver class=\"org.apache.xindice.core.xupdate.XUpdateQueryResolver\" />"
+            + "            <resolver autoindex='false' class='org.apache.xindice.core.query.XPathQueryResolver'/>"
+            + "            <resolver class='org.apache.xindice.core.xupdate.XUpdateQueryResolver'/>"
             + "        </queryengine>"
             + "    </root-collection>"
             + "    <xml-rpc>"
-            + "        <driver name=\"xerces\" />"
+            + "        <driver name='xerces'/>"
             + "    </xml-rpc>"
             + "</xindice>";
 }

Modified: xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java?view=diff&rev=523128&r1=523127&r2=523128
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java Tue Mar 27 18:00:00 2007
@@ -37,6 +37,7 @@
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -110,63 +111,64 @@
             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);
+            }
+
+            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.");
                     }
 
-                    //
-                    // 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");
+                    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.
@@ -215,43 +217,52 @@
     /**
      * Loads the Xindice configuration file. The file is searched in the following locations:
      * <ul>
-     * <li>the <tt>ServletConfig.getInitParameter(Xindice.PROP_XINDICE_CONFIGURATION)</tt> variable located in the servlet
-     * configuration file</li>
-     * <li>use the default configuration stored in the <tt>Xindice</tt> class</li>
+     * <li>the <i>System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION)</i> system property.
+     * <li>the <i>ServletConfig.getInitParameter(Xindice.PROP_XINDICE_CONFIGURATION)</i> servlet
+     * configuration parameter in web.xml file.</li>
+     * <li>default configuration stored in the <tt>Xindice</tt> class</li>
      * </ul>
      *
-     * <br/>
-     * TODO: we should probably try to load from the file system if we can't load it this way.
+     * @return Xindice configuration
+     * @throws ConfigurationException if unable to read configuration file or parse it
      */
     public Configuration loadConfiguration(ServletConfig servletConfig) {
         try {
-            Document configurationDocument;
-
-            String path = servletConfig.getInitParameter(Xindice.PROP_XINDICE_CONFIGURATION);
-            if (path != null) {
-                InputStream inputStream;
-                if (path.startsWith("/")) {
-                    // Absolute file path
-                    log.debug("Loading configuration from filesystem path " + path);
-                    inputStream = new FileInputStream(path);
-                } else {
-                    // Relative (to the context) path
-                    log.debug("Loading configuration from context path " + path);
-                    ServletContext context = servletConfig.getServletContext();
-                    inputStream = context.getResourceAsStream("/" + path);
+            InputStream in = null;
+            String path = System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION);
+            if (path != null && path.length() > 0) {
+                // Configuration file specified by system property
+                log.info("Loading configuration from file path " + path + " (system property)");
+                in = new FileInputStream(path);
+            } else {
+                path = servletConfig.getInitParameter(Xindice.PROP_XINDICE_CONFIGURATION);
+                if (path != null && path.length() > 0) {
+                    if (path.startsWith("/")) {
+                        // Absolute file path
+                        log.info("Loading configuration from file path " + path);
+                        in = new FileInputStream(path);
+                    } else {
+                        // Relative (to the context) path
+                        log.info("Loading configuration from context path " + path);
+                        ServletContext context = servletConfig.getServletContext();
+                        in = context.getResourceAsStream("/" + path);
+                    }
                 }
+            }
 
+            Document doc;
+            if (in != null) {
                 try {
-                    configurationDocument = DOMParser.toDocument(inputStream);
+                    doc = DOMParser.toDocument(in);
                 } finally {
-                    inputStream.close();
+                    in.close();
                 }
             } else {
-                log.debug("Loading the standard configuration");
-                configurationDocument = DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION);
+                log.warn("Loading the standard configuration");
+                doc = DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION);
             }
 
-            return new Configuration(configurationDocument, false);
+            return new Configuration(doc, false);
         } catch (Exception e) {
             throw new ConfigurationException("Failed to load configuration.", e);
         }

Modified: xml/xindice/trunk/status.xml
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/status.xml?view=diff&rev=523128&r1=523127&r2=523128
==============================================================================
--- xml/xindice/trunk/status.xml (original)
+++ xml/xindice/trunk/status.xml Tue Mar 27 18:00:00 2007
@@ -117,7 +117,12 @@
     </todo>
 
     <changes>
-        <release version="1.1b5-dev" date="Mar 1 2007">
+        <release version="1.1b5-dev" date="(not released)">
+            <action dev="VG" type="update">
+                Moved configuration file in WAR file to /WEB-INF/config. Updated
+                XindiceServlet to check for xindice.configuration system property
+                before attempting to load configuration from WAR file.
+            </action>
             <action dev="VG" type="fix" fixes-bug="33148" due-to="Natalia Shilenkova">
                 Eliminate gap when index is registered but not created yet, causing
                 corruption of index file.

Modified: xml/xindice/trunk/xindice.sh
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/xindice.sh?view=diff&rev=523128&r1=523127&r2=523128
==============================================================================
--- xml/xindice/trunk/xindice.sh (original)
+++ xml/xindice/trunk/xindice.sh Tue Mar 27 18:00:00 2007
@@ -84,6 +84,9 @@
   XINDICE_HOME=`pwd`
 fi
 
+if [ "$XINDICE_DB_HOME" = "" ] ; then XINDICE_DB_HOME=$XINDICE_HOME ; fi
+if [ "$XINDICE_CONFIG" = "" ] ; then XINDICE_CONFIG=$XINDICE_HOME/config/system.xml ; fi
+
 if [ "$JETTY_PORT" = "" ] ; then
   JETTY_PORT=8888
 fi
@@ -129,6 +132,8 @@
   JETTY_CONFIG=`cygpath --path --windows "$JETTY_CONFIG"`
   JETTY_WEBAPP=`cygpath --path --windows "$JETTY_WEBAPP"`
   XINDICE_HOME=`cygpath --path --windows "$XINDICE_HOME"`
+  XINDICE_DB_HOME=`cygpath --path --windows "$XINDICE_DB_HOME"`
+  XINDICE_CONFIG=`cygpath --path --windows "$XINDICE_CONFIG"`
 fi
 
 case "$ACTION" in
@@ -147,14 +152,14 @@
         echo "Starting Xindice - Log files are under $XINDICE_HOME/logs"
         echo
 
-        nohup "$JAVACMD" $JAVA_OPTIONS -classpath "$CP" -Djava.endorsed.dirs=lib/endorsed -Dxindice.home="$XINDICE_HOME" -Dxindice.db.home="$XINDICE_HOME" -Dwebapp="$JETTY_WEBAPP" -Dorg.xml.sax.parser=org.apache.xerces.parsers.SAXParser -Djetty.port=$JETTY_PORT -Djetty.admin.port=$JETTY_ADMIN_PORT org.mortbay.jetty.Server "$JETTY_CONFIG" >> $XINDICE_HOME/logs/xindice.out 2>&1 &
+        nohup "$JAVACMD" $JAVA_OPTIONS -classpath "$CP" -Djava.endorsed.dirs=lib/endorsed -Dxindice.home="$XINDICE_HOME" -Dxindice.db.home="$XINDICE_DB_HOME" -Dxindice.configuration="$XINDICE_CONFIG" -Dwebapp="$JETTY_WEBAPP" -Dorg.xml.sax.parser=org.apache.xerces.parsers.SAXParser -Djetty.port=$JETTY_PORT -Djetty.admin.port=$JETTY_ADMIN_PORT org.mortbay.jetty.Server "$JETTY_CONFIG" >> $XINDICE_HOME/logs/xindice.out 2>&1 &
 
         echo $! > $XINDICE_PID
         echo "Xindice is running with PID `cat $XINDICE_PID`"
         ;;
 
   debug)
-        "$JAVACMD" $JAVA_OPTIONS -Xdebug -Xrunjdwp:transport=dt_socket,address=$JAVA_DEBUG_PORT,server=y,suspend=n -classpath "$CP" -Djava.endorsed.dirs=lib/endorsed -Dxindice.home="$XINDICE_HOME" -Dxindice.db.home="$XINDICE_HOME" -Dwebapp="$JETTY_WEBAPP" -Dorg.xml.sax.parser=org.apache.xerces.parsers.SAXParser -Djetty.port=$JETTY_PORT -Djetty.admin.port=$JETTY_ADMIN_PORT org.mortbay.jetty.Server "$JETTY_CONFIG" "$XINDICE_HOME/tools/jetty/conf/admin.xml" >> $XINDICE_HOME/logs/xindice.out 2>&1
+        "$JAVACMD" $JAVA_OPTIONS -Xdebug -Xrunjdwp:transport=dt_socket,address=$JAVA_DEBUG_PORT,server=y,suspend=n -classpath "$CP" -Djava.endorsed.dirs=lib/endorsed -Dxindice.home="$XINDICE_HOME" -Dxindice.db.home="$XINDICE_DB_HOME" -Dxindice.configuration="$XINDICE_CONFIG" -Dwebapp="$JETTY_WEBAPP" -Dorg.xml.sax.parser=org.apache.xerces.parsers.SAXParser -Djetty.port=$JETTY_PORT -Djetty.admin.port=$JETTY_ADMIN_PORT org.mortbay.jetty.Server "$JETTY_CONFIG" "$XINDICE_HOME/tools/jetty/conf/admin.xml" >> $XINDICE_HOME/logs/xindice.out 2>&1
         ;;
 
   stop)