Finally got it all working and tested. The things I needed to do in
order to get it working were:
XindiceServlet looks in the system.xml file for the parser to use on
the server side.
xmlrpc.DatabaseImpl supports an "xmlrpc-driver" property through its
Configurable interface. This is tricky because the user interacts
with the client.DatabaseImpl class, which lazily creates the
xmlrpc.DatabaseImpl, so the user never gets a chance to see the
xmlrpc.DatabaseImpl class and call its setProperty() method. I
dealt with that by having the xmlrpc.DatabaseImpl configuration be a
clone of the client.DatabaseImpl configuration. The user remains
unaware that there are three DatabaseImpl classes.
xmlrpc.CollectionImpl takes an xmlrpcDriver argument to the
constructor. It uses (in order of declining priority):
the xmlrpcDriver value (if non-null),
the xindice.xmlrpc.driver System property (if non-null)
the local default (currently "xindice")
IntegrationXmlRpcTests looks for a test.xmlrpc.driver system
property and uses it to set a property on the Database object.
Also ran into a variety of inconveniences while learning my way around
the package, and made some changes to allow more flexible configuration
of the XML-RPC client. Some of the test-related changes may be
obsoleted by Vladimir's upcoming Jetty work.
XmlDbClient (in the tests) was throwing NPEs if the tomcat server
wasn't running. Now throws a XindiceException with a semi-helpful
message instead.
xmlrpc.DatabaseImpl supports a "service-location" property through its
Configurable interface. The service location specifies the path to
the XML-RPC service on the web server.
xmlrpc.CollectionImpl takes an serviceLocation argument to the
constructor. It uses (in order of declining priority):
the serviceLocation value (if non-null),
the xindice.xmlrpc.service-location System property (if non-null)
the local default (currently "/Xindice/")
Added three properties to the build.properties file:
test.xmlrpc.driver (SAX driver)
test.xmlrpc.hostport (host:port)
test.xmlrpc.service-location (/Xindice/ or whatever)
Modified the test-integration-xmlrpc target to use <java> instead
of <junit> so that exceptions get reported properly; added the three
test.* properties.
IntegrationXmlRpcTests looks for a test.xmlrpc.service-location
system property. property and uses it to set a property on the
Database object.
All this stuff works nicely. The CollectionImpl and XindiceServlet are
hard to test so there are no unit tests for those changes.
Attached find the (tested!) patches.
GaryIndex: build.properties.sample
===================================================================
RCS file: /home/cvspublic/xml-xindice/build.properties.sample,v
retrieving revision 1.1
diff -u -r1.1 build.properties.sample
--- build.properties.sample 27 Oct 2002 00:06:39 -0000 1.1
+++ build.properties.sample 22 Feb 2003 19:21:26 -0000
@@ -3,11 +3,38 @@
#
# Version: $Revision: 1.1 $ $Date: 2002/10/27 00:06:39 $
# Author: Vladimir R. Bossicard ([EMAIL PROTECTED])
+# Author: Gary Shea ([EMAIL PROTECTED])
#
# location of the Jakarta Tomcat directory. Modify and uncomment this property
# if you don't want Xindice to use the TOMCAT_HOME directory (of if this
# environment variable is not set).
-
# tomcat.home=/usr/local/java/jakarta-tomcat-4.1.12
+
+# The host:port where the xindice server is running.
+# This property is used by the test-integration-xmlrpc target.
+# Defaults to "localhost:8080".
+# test.xmlrpc.hostport=localhost:8080
+
+# The location of the Xindice directory in the
+# local portion of the http namespace.
+# For tomcat, a webapp named Xindice.war is automatically
+# deployed as /Xindice.
+# This property is used by the test-integration-xmlrpc target.
+# Defaults to "/Xindice/".
+# test.xmlrpc.service-location=/Xindice/
+
+# The SAX parser to be used by Apace XmlRpc.
+# Apache XmlRpc has an internal list of keywords for known
+# parsers; the following list is given in terms of those keywords.
+# The test.xmlrpc.driver value may be set to either the
+# keyword or the full classname.
+# Tested:
+# xerces [org.apache.xerces.parsers.SAXParser] ok
+# xp [com.jclark.xml.sax.Driver] NOT ok
+# net.sf.saxon.aelfred.SAXDriver ok
+# This is a re-packaging of an early aelfred version.
+#
+# This property is used by the test-integration-xmlrpc target.
+# test.xmlrpc.driver=xerces
Index: build.xml
===================================================================
RCS file: /home/cvspublic/xml-xindice/build.xml,v
retrieving revision 1.38
diff -u -r1.38 build.xml
--- build.xml 30 Dec 2002 11:06:06 -0000 1.38
+++ build.xml 22 Feb 2003 19:21:26 -0000
@@ -64,6 +64,11 @@
<!-- External projects properties -->
<property name="tomcat.home" value="${ENVIRONMENT.TOMCAT_HOME}" />
+ <!-- Testing properties -->
+ <property name="test.xmlrpc.driver" value="xerces" />
+ <property name="test.xmlrpc.hostport" value="localhost:8080" />
+ <property name="test.xmlrpc.service-location" value="/Xindice/" />
+
<!-- Compilation properties -->
<property name="compile.debug" value="on"/>
<property name="compile.optimize" value="off"/>
@@ -73,6 +78,7 @@
<fileset dir="${jar.dir}"
id="core.jars">
+ <include name="saxon-aelfred.jar" />
<include name="commons-logging-1.0.1.jar" />
<include name="xalan-2.4.0.jar"/>
<include name="xercesImpl-2.1.0.jar"/>
@@ -266,11 +272,17 @@
<target name="test-integration-xmlrpc"
depends="test-build, test-validate">
+
+<!--
<junit fork="yes" printsummary="yes" haltonfailure="no">
<jvmarg
value="-DPropertyManager.file=${test.dir}/config/test-configuration.props" />
<jvmarg value="-Dxindice.home=${basedir}" />
<jvmarg
value="-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog"
/>
<jvmarg
value="-Dorg.apache.commons.logging.simplelog.defaultlog=debug" />
+ <jvmarg
+
value="-Dxindice.xmlrpc.hostport=${xmlrpc.hostport}" />
+ <jvmarg
+
value="-Dxindice.xmlrpc.service-location=${xmlrpc.service-location}" />
<test name="org.apache.xindice.IntegrationXmlRpcTests" />
<formatter type="plain" usefile="no" />
<classpath>
@@ -278,6 +290,29 @@
<pathelement location="${test.build.dir}"/>
</classpath>
</junit>
+-->
+
+ <echo message="XML-RPC driver='${test.xmlrpc.driver}'" />
+ <echo message="XML-RPC host/port='${test.xmlrpc.hostport}'" />
+ <echo message="XML-RPC service
location='${test.xmlrpc.service-location}'" />
+ <java classname="junit.textui.TestRunner" fork="yes">
+ <arg line="-class org.apache.xindice.IntegrationXmlRpcTests" />
+ <jvmarg value="-Dxindice.home=${basedir}" />
+ <jvmarg
+
value="-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog"
/>
+ <jvmarg
+
value="-Dorg.apache.commons.logging.simplelog.defaultlog=debug" />
+ <jvmarg
+
value="-Dtest.xmlrpc.hostport=${test.xmlrpc.hostport}" />
+ <jvmarg
+
value="-Dtest.xmlrpc.service-location=${test.xmlrpc.service-location}" />
+ <jvmarg
+
value="-Dtest.xmlrpc.driver=${test.xmlrpc.driver}" />
+ <classpath>
+ <path refid="project.class.path"/>
+ <pathelement location="${test.build.dir}"/>
+ </classpath>
+ </java>
</target>
<target name="test-validate">
Index: config/system.xml
===================================================================
RCS file: /home/cvspublic/xml-xindice/config/system.xml,v
retrieving revision 1.9
diff -u -r1.9 system.xml
--- config/system.xml 27 Dec 2002 18:37:23 -0000 1.9
+++ config/system.xml 22 Feb 2003 19:21:26 -0000
@@ -13,4 +13,7 @@
<resolver
class="org.apache.xindice.core.xupdate.XUpdateQueryResolver" />
</queryengine>
</root-collection>
+ <xml-rpc>
+ <driver name="xerces" />
+ </xml-rpc>
</xindice>
Index: java/src/org/apache/xindice/client/xmldb/CommonConfigurable.java
===================================================================
RCS file:
/home/cvspublic/xml-xindice/java/src/org/apache/xindice/client/xmldb/CommonConfigurable.java,v
retrieving revision 1.3
diff -u -r1.3 CommonConfigurable.java
--- java/src/org/apache/xindice/client/xmldb/CommonConfigurable.java 31 Oct
2002 06:58:47 -0000 1.3
+++ java/src/org/apache/xindice/client/xmldb/CommonConfigurable.java 22 Feb
2003 19:21:27 -0000
@@ -78,6 +78,15 @@
}
/**
+ * Constructor for the CommonConfigurable object
+ * @param commonConfigurable from which the initial properties for this
+ * object are copied.
+ */
+ public CommonConfigurable(CommonConfigurable commonConfigurable) {
+ config = new Hashtable(commonConfigurable.config);
+ }
+
+ /**
* Sets a property value. If the property doesn't exist it is created, if it
* does exist it is overwritten.
*
Index: java/src/org/apache/xindice/client/xmldb/DatabaseImpl.java
===================================================================
RCS file:
/home/cvspublic/xml-xindice/java/src/org/apache/xindice/client/xmldb/DatabaseImpl.java,v
retrieving revision 1.11
diff -u -r1.11 DatabaseImpl.java
--- java/src/org/apache/xindice/client/xmldb/DatabaseImpl.java 21 Nov 2002
07:44:35 -0000 1.11
+++ java/src/org/apache/xindice/client/xmldb/DatabaseImpl.java 22 Feb 2003
19:21:28 -0000
@@ -59,6 +59,8 @@
* $Id: DatabaseImpl.java,v 1.11 2002/11/21 07:44:35 vladimir Exp $
*/
+import java.lang.reflect.Constructor;
+
import org.xmldb.api.base.Database;
import org.xmldb.api.base.ErrorCodes;
import org.xmldb.api.base.XMLDBException;
@@ -202,7 +204,19 @@
try {
if ( driver == null ) {
if (uri.startsWith(XMLRPC_URI)) {
- driver = (Database)
Class.forName("org.apache.xindice.client.xmldb.xmlrpc.DatabaseImpl").newInstance();
+ /*
+ * The only way that a particular instance of
xmlrpc.DatabaseImpl
+ * can be informed of the path to the XML-RPC service in the
+ * web server is by setting a property on the DatabaseImpl
object
+ * which is in turn passed to the CollectionImpl object. Whew!
+ * Since the user never sees the actual xmlrpc.DatabaseImpl
object,
+ * this is the only way to make sure that they can set that
property.
+ */
+ Class driverClass
+ =
Class.forName("org.apache.xindice.client.xmldb.xmlrpc.DatabaseImpl");
+ Constructor constructor = driverClass.getConstructor(
+ new Class[]{CommonConfigurable.class});
+ driver = (Database) constructor.newInstance(new
Object[]{this});
}
else if (uri.startsWith(EMBED_URI)) {
driver = (Database)
Class.forName("org.apache.xindice.client.xmldb.embed.DatabaseImpl").newInstance();
Index: java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java
===================================================================
RCS file:
/home/cvspublic/xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java,v
retrieving revision 1.20
diff -u -r1.20 CollectionImpl.java
--- java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java 30 Dec
2002 11:06:06 -0000 1.20
+++ java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java 22 Feb
2003 19:21:29 -0000
@@ -104,6 +104,12 @@
/* host and port number of server */
private String hostPort;
+
+ /* location of the XML-RPC service in the web server */
+ private String serviceLocation;
+
+ /* SAX parser the XML-RPC service will use */
+ private String xmlrpcDriver;
/* the XML-RPC client stub, connected to server */
private XmlRpcClient client = null;
@@ -115,26 +121,74 @@
*
* @param hostPort hostname and port number in <code>host:port</code>
format.
* Port no is optional, in which case HTTP default is assumed.
+ * @param serviceLocation is the path in the web server's namespace where
+ * the XML-RPC service is mounted. It is <code>null</code> unless
+ * the <code>service-location</code> property of
+ * <code>org.apache.xindice.client.xmlrpc.DatabaseImpl</code>
+ * is set.
+ * @param collPath is the name of the collection to open.
* @exception XMLDBException thrown if a connection could not be
established,
* because of URL syntax errors, or connection failure, or if no
* collection with path <code>collPath</code> could be located.
*/
- public CollectionImpl(String hostPort, String collPath) throws
XMLDBException {
+ public CollectionImpl(String hostPort, String serviceLocation,
+ String xmlrpcDriver, String collPath)
+ throws XMLDBException {
super(collPath);
this.hostPort = hostPort;
+ this.serviceLocation = serviceLocation;
+ this.xmlrpcDriver = xmlrpcDriver;
this.collPath = collPath;
- String xmlrpcURI = "http://" + hostPort + XINDICE_SERVICE_LOCATION;
+
XmlRpc.setEncoding("UTF8");
+
+ /*
+ * Determine the SAXparser the xmlrpc client will use.
+ * In priority order:
+ * DatabaseImpl xmlrpc-driver property
+ * (passed in the xmlrpcDriver parameter)
+ * System property "xindice.xmlrpc.driver"
+ * Default value "xerces"
+ */
+ if (xmlrpcDriver == null) {
+ xmlrpcDriver = System.getProperty("xindice.xmlrpc.driver");
+ }
+ if (xmlrpcDriver == null) {
+ xmlrpcDriver = "xerces";
+ }
XmlRpc.setKeepAlive(true);
try {
-
- XmlRpc.setDriver("xerces");
+ XmlRpc.setDriver(xmlrpcDriver);
} catch (Exception e) {
-
throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Xerces needed",
e);
}
-
+
+ /*
+ * Determine the path in the web server to the XML-RPC service.
+ * In priority order:
+ * DatabaseImpl service-location property
+ * (passed in the serviceLocation parameter)
+ * System property "xindice.xmlrpc.service-location"
+ * Default value "/Xindice/"
+ */
+ if (serviceLocation == null) {
+ serviceLocation = System.getProperty(
+ "xindice.xmlrpc.service-location");
+ }
+ if (serviceLocation == null) {
+ serviceLocation = XINDICE_SERVICE_LOCATION;
+ }
+
+ if (! serviceLocation.startsWith("/")) {
+ serviceLocation = "/" + serviceLocation;
+ }
+ if (! serviceLocation.endsWith("/")) {
+ serviceLocation = serviceLocation + "/";
+ }
+ System.out.println( "serviceLocation=<" + serviceLocation + ">" );
+ String xmlrpcURI = "http://" + hostPort + serviceLocation;
+
try {
client = new XmlRpcClient(xmlrpcURI);
@@ -326,7 +380,8 @@
}
try {
- return new CollectionImpl(hostPort, collPath + "/" + name);
+ return new CollectionImpl(hostPort, serviceLocation,
+ xmlrpcDriver, collPath + "/" + name);
}
catch (XMLDBException e) {
if (e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
@@ -396,8 +451,8 @@
}
try {
- return new CollectionImpl(hostPort, collPath.substring(0,
- collPath.lastIndexOf('/')));
+ return new CollectionImpl(hostPort, serviceLocation,
+ xmlrpcDriver, collPath.substring(0, collPath.lastIndexOf('/')));
}
catch (XMLDBException e) {
if (e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
Index: java/src/org/apache/xindice/client/xmldb/xmlrpc/DatabaseImpl.java
===================================================================
RCS file:
/home/cvspublic/xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/DatabaseImpl.java,v
retrieving revision 1.7
diff -u -r1.7 DatabaseImpl.java
--- java/src/org/apache/xindice/client/xmldb/xmlrpc/DatabaseImpl.java 21 Nov
2002 07:44:35 -0000 1.7
+++ java/src/org/apache/xindice/client/xmldb/xmlrpc/DatabaseImpl.java 22 Feb
2003 19:21:33 -0000
@@ -81,6 +81,30 @@
/* XML:DB conformance level of this driver */
private String CONFORMANCE_LEVEL = "0";
+ /* Property name for the xml-rpc service location. */
+ private static final String PROP_SERVICE_LOCATION = "service-location";
+
+ /* Property name for the SAX parser xml-rpc will use. */
+ private static final String PROP_XMLRPC_DRIVER = "xmlrpc-driver";
+
+ /**
+ * Create a new DatabaseImpl object.
+ */
+ public DatabaseImpl() {
+ super();
+ }
+
+ /**
+ * Create a new DatabaseImpl object with a copy of the properties
+ * from the DatabaseImpl parameter.
+ *
+ * @param commonConfigurable from which the initial parameters for this
+ * DatabaseImpl object are copied.
+ */
+ public DatabaseImpl(CommonConfigurable commonConfigurable) {
+ super(commonConfigurable);
+ }
+
/**
* Determines whether this <code>Database</code> implementation can handle
* the URI. It should return true if the Database instance knows how to
@@ -147,14 +171,15 @@
/* Absent host defaults to localhost and standard Xindice HTTP port */
if (hostPort.equals("")) {
-
hostPort = "127.0.0.1:8080";
}
try {
- return new CollectionImpl(hostPort, collPath);
- }
- catch(XMLDBException e) {
+ return new CollectionImpl(hostPort,
+ this.getProperty(PROP_SERVICE_LOCATION),
+ this.getProperty(PROP_XMLRPC_DRIVER),
+ collPath);
+ } catch(XMLDBException e) {
if(e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
// per getCollection contract, return null if not found
return null;
Index: java/src/org/apache/xindice/server/XindiceServlet.java
===================================================================
RCS file:
/home/cvspublic/xml-xindice/java/src/org/apache/xindice/server/XindiceServlet.java,v
retrieving revision 1.10
diff -u -r1.10 XindiceServlet.java
--- java/src/org/apache/xindice/server/XindiceServlet.java 13 Dec 2002
09:02:19 -0000 1.10
+++ java/src/org/apache/xindice/server/XindiceServlet.java 22 Feb 2003
19:21:33 -0000
@@ -102,12 +102,15 @@
protected XmlRpcServer xmlrpc;
protected Database db;
+
+ private String xmlRpcDriver;
+
/**
* TODO: verify that if is an error occured, the database will be closed
* propertly
*/
- public void init(ServletConfig config)
+ public void init(ServletConfig config)
throws ServletException {
/* note: there no need to call the DatabaseManager since we already
@@ -115,19 +118,20 @@
db = new Database();
/* holds the database configuration */
- Document configuration;
+ Document configurationDocument;
try {
- configuration = loadConfiguration(config);
+ configurationDocument = loadConfiguration(config);
} catch (Exception e) {
throw new ServletException("Could not load database configuration",
e);
}
+
+ Configuration configuration = new Configuration(configurationDocument,
false);
// The configuration is wrapped in a <xindice> element so we need to get
// the "root-collection" configuration.
- Configuration conf = new Configuration(configuration, false);
try {
- conf = conf.getChild("root-collection", false);
- if (conf != null) {
+ Configuration collConf = configuration.getChild("root-collection");
+ if (collConf != null) {
// 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
@@ -137,46 +141,48 @@
// 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 = conf.getAttribute(Database.DBROOT, "./db/");
+ String dbRoot = collConf.getAttribute(Database.DBROOT, "./db/");
File dbRootDir = new File(dbRoot);
if (dbRootDir.isAbsolute()) {
- db.setConfig(conf);
+ db.setConfig(collConf);
} else {
- // OK, no absolute path. We have to perform
some checks.
+ // OK, no absolute path. We have to perform some checks.
// Stupid hack but spec compliant. If getRealPath() returns
null
// the war archive has not been unpacked.
String realPath =
config.getServletContext().getRealPath("/WEB-INF");
- // Let's see if the property was specified.
- String home =
System.getProperty("xindice.db.home");
+ // Let's see if the property was specified.
+ String home = System.getProperty("xindice.db.home");
- if (home != null) {
- conf.setAttribute(Database.DBROOT, home +
System.getProperty("file.separator") + dbRoot);
- } else if (realPath != null) {
- if (log.isWarnEnabled())
- log.warn("The database root directory has been
set to "
- + realPath +
System.getProperty("file.separator") + dbRoot
- + ". Keep in mind that if a war upgrade
will take place the database"
- + " will be lost.");
- conf.setAttribute(Database.DBROOT, realPath +
System.getProperty("file.separator") + dbRoot);
- } else {
- log.fatal("The database configuration points to a
relative path, "
- + "but there was no xindice.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.db.home system
property.");
- throw new ServletException("An error
occurred initializing the database." +
- "Please see the logs for
details");
- }
-
+ if (home != null) {
+ collConf.setAttribute(Database.DBROOT,
+ home + System.getProperty("file.separator") + dbRoot);
+ } else if (realPath != null) {
+ if (log.isWarnEnabled()) {
+ log.warn("The database root directory has been set to
"
+ + realPath + System.getProperty("file.separator")
+ dbRoot
+ + ". Keep in mind that if a war upgrade will take
place the database"
+ + " will be lost.");
+ }
+ collConf.setAttribute(Database.DBROOT,
+ realPath + System.getProperty("file.separator") +
dbRoot);
+ } else {
+ log.fatal("The database configuration points to a relative
path, "
+ + "but there was no xindice.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.db.home system
property.");
+ throw new ServletException("An error occurred initializing
the database."
+ + "Please see the logs for details");
+ }
+
}
-
-
- db.setConfig(conf);
+
+ db.setConfig(collConf);
} else {
throw new ServletException("The database configuration is missing
the <root-collection> element");
@@ -185,14 +191,47 @@
throw new ServletException("Error while handling the configuration",
e);
}
- // Setup the XML-RPC impl to support UTF-8 input via Xerces.
- XmlRpc.setEncoding("UTF8");
- try {
- // TODO: This introduces a firm dependency on xerces. fix it.
- XmlRpc.setDriver("xerces");
- } catch (Exception e) {
- throw new ServletException("XML-RPC support requires Xerces", e);
- }
+ // 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 = "xerces";
+
+ Configuration xmlRpcConfiguration = configuration.getChild("xml-rpc");
+ if (xmlRpcConfiguration != null) {
+ Configuration xmlRpcDriverConfiguration =
xmlRpcConfiguration.getChild("driver");
+ if (xmlRpcDriverConfiguration != null) {
+ String name = xmlRpcConfiguration.getAttribute("name");
+ if (name != null) {
+ xmlrpcDriver = name;
+ } else {
+ throw new ServletException(
+ "The xml-rpc configuration (in '"
+ +
config.getInitParameter(Xindice.PROP_XINDICE_CONFIGURATION)
+ + "' contains a malformed 'driver' element."
+ + " The 'driver' element must have a 'name' attribute"
+ + " specifying the driver"
+ + " (XML-RPC terminology for SAX parser)"
+ + " to use." );
+ }
+ }
+ }
+
+ try {
+ XmlRpc.setDriver(xmlrpcDriver);
+ } catch (Exception e) {
+ throw new ServletException(
+ "XML-RPC error message: '"
+ + e.getMessage()
+ + "'",
+ e);
+ }
// Create the XML-RPC server and add our handler as the default.
xmlrpc = new XmlRpcServer();
@@ -239,7 +278,7 @@
throws XindiceException, IOException {
Document result;
- String path = config.getInitParameter("xindice-configuration");
+ String path =
config.getInitParameter(Xindice.PROP_XINDICE_CONFIGURATION);
if (path != null) {
if (log.isDebugEnabled()) {
log.debug("loading configuration from " + path);
@@ -397,6 +436,19 @@
output.flush();
}
+
+ /**
+ * Return the XML-RPC driver, a classname or shorthand string informing
+ * the XmlRpc package which SAX parser we wish it to use. [Created for
+ * unit-testing purposes.]
+ *
+ * @returns String containing the classname or shorthand name of the SAX
+ * parser the XmlRpc package will use.
+ */
+ public String getXmlRpcDriver() {
+ return xmlRpcDriver;
+ }
+
public static class XPathPseudoParser {
private String query;
Index: java/tests/src/org/apache/xindice/IntegrationEmbedTests.java
===================================================================
RCS file:
/home/cvspublic/xml-xindice/java/tests/src/org/apache/xindice/IntegrationEmbedTests.java,v
retrieving revision 1.3
diff -u -r1.3 IntegrationEmbedTests.java
--- java/tests/src/org/apache/xindice/IntegrationEmbedTests.java 28 Nov
2002 08:12:26 -0000 1.3
+++ java/tests/src/org/apache/xindice/IntegrationEmbedTests.java 22 Feb
2003 19:21:33 -0000
@@ -77,7 +77,9 @@
public static Test suite() throws Exception {
- return new TestSetup(new
XmlDbClientSetup(IntegrationTests.testSuite("Embed client integration tests"),
+ return new TestSetup(
+ new XmlDbClientSetup(
+ IntegrationTests.testSuite("Embed client integration tests"),
new XmlDbClient("xmldb:xindice-embed://"))) {
private Database database;
Index: java/tests/src/org/apache/xindice/IntegrationXmlRpcTests.java
===================================================================
RCS file:
/home/cvspublic/xml-xindice/java/tests/src/org/apache/xindice/IntegrationXmlRpcTests.java,v
retrieving revision 1.3
diff -u -r1.3 IntegrationXmlRpcTests.java
--- java/tests/src/org/apache/xindice/IntegrationXmlRpcTests.java 28 Nov
2002 08:12:26 -0000 1.3
+++ java/tests/src/org/apache/xindice/IntegrationXmlRpcTests.java 22 Feb
2003 19:21:33 -0000
@@ -70,16 +70,33 @@
import junitx.extensions.TestSetup;
/**
+ * Integration tests for the client code which communicates
+ * with the server by XML-RPC. The host and port may be
+ * configured with the system property <code>test.xmlrpc.hostport</code>,
+ * which is expected to be a string of the form <code>host:port</code>
+ * or <code>host</code>. The path to the XML-RPC service in the web server
+ * may be configured with the system property
+ * <code>test.xmlrpc.service-location</code>,
+ * which is expected to be a string of the form <code>/path.../</code>.
+
* @version $Revision: 1.3 $, $Date: 2002/11/28 08:12:26 $
* @author Vladimir R. Bossicard <[EMAIL PROTECTED]>
+ * @author Gary Shea <[EMAIL PROTECTED]>
*/
public class IntegrationXmlRpcTests {
public static Test suite()
throws Exception {
- return new TestSetup(new
XmlDbClientSetup(IntegrationTests.testSuite("XmlRpc client integration tests"),
- new XmlDbClient("xmldb:xindice://"))) {
+ String url = "xmldb:xindice://";
+ String hostport = System.getProperty( "test.xmlrpc.hostport");
+ if (hostport != null) {
+ url = url + hostport;
+ }
+ return new TestSetup(
+ new XmlDbClientSetup(
+ IntegrationTests.testSuite("XmlRpc client integration tests"),
+ new XmlDbClient(url))) {
private Database database;
@@ -89,6 +106,16 @@
Class cls = Class.forName(driver);
database = (Database) cls.newInstance();
+ String serviceLocation = System.getProperty(
+ "test.xmlrpc.service-location");
+ if (serviceLocation != null) {
+ database.setProperty("service-location", serviceLocation);
+ }
+ String xmlrpcDriver = System.getProperty(
+ "test.xmlrpc.driver");
+ if (xmlrpcDriver != null) {
+ database.setProperty("xmlrpc-driver", xmlrpcDriver);
+ }
DatabaseManager.registerDatabase(database);
}
Index: java/tests/src/org/apache/xindice/integration/client/XmlDbClient.java
===================================================================
RCS file:
/home/cvspublic/xml-xindice/java/tests/src/org/apache/xindice/integration/client/XmlDbClient.java,v
retrieving revision 1.3
diff -u -r1.3 XmlDbClient.java
--- java/tests/src/org/apache/xindice/integration/client/XmlDbClient.java
28 Oct 2002 08:39:20 -0000 1.3
+++ java/tests/src/org/apache/xindice/integration/client/XmlDbClient.java
22 Feb 2003 19:21:34 -0000
@@ -60,6 +60,7 @@
package org.apache.xindice.integration.client;
import org.apache.xindice.client.xmldb.services.CollectionManager;
+import org.apache.xindice.util.XindiceException;
import org.apache.xindice.xml.dom.DOMParser;
import org.xmldb.api.DatabaseManager;
@@ -82,6 +83,12 @@
public String getName(String path)
throws Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException(
+ "DatabaseManager.getCollection("
+ + driver + "/" + path
+ + ") returned null" );
+ }
return col.getName();
}
@@ -89,6 +96,12 @@
String name)
throws Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException(
+ "DatabaseManager.getCollection("
+ + driver + "/" + path
+ + ") returned null" );
+ }
CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
String collectionConfig = "<collection compressed=\"true\" name=\"" +
name + "\">" +
@@ -106,21 +119,35 @@
String name)
throws Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
- CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
-
- service.dropCollection(name);
+
+ if (col != null) {
+ CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
+ service.dropCollection(name);
+ }
}
public String[] listCollections(String path)
throws Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException(
+ "DatabaseManager.getCollection("
+ + driver + "/" + path
+ + ") returned null" );
+ }
return col.listChildCollections();
}
public int countCollections(String path)
throws Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
- return col.getChildCollectionCount();
+ if (col == null) {
+ throw new XindiceException(
+ "DatabaseManager.getCollection("
+ + driver + "/" + path
+ + ") returned null" );
+ }
+ return col.getChildCollectionCount();
}
public void createIndexer(String path,
@@ -128,6 +155,12 @@
String indexdef)
throws Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException(
+ "DatabaseManager.getCollection("
+ + driver + "/" + path
+ + ") returned null" );
+ }
CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
service.createIndexer(DOMParser.toDocument(indexdef));
@@ -136,6 +169,12 @@
public String[] listIndexes(String path)
throws Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException(
+ "DatabaseManager.getCollection("
+ + driver + "/" + path
+ + ") returned null" );
+ }
CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
return service.listIndexers();
@@ -145,6 +184,12 @@
String name)
throws Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException(
+ "DatabaseManager.getCollection("
+ + driver + "/" + path
+ + ") returned null" );
+ }
CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
service.dropIndexer(name);
@@ -155,6 +200,12 @@
String doc)
throws Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException(
+ "DatabaseManager.getCollection("
+ + driver + "/" + path
+ + ") returned null" );
+ }
XMLResource document = (XMLResource) col.createResource(name,
"XMLResource");
document.setContent(doc);
@@ -164,6 +215,12 @@
public int countDocument(String path)
throws Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException(
+ "DatabaseManager.getCollection("
+ + driver + "/" + path
+ + ") returned null" );
+ }
return col.getResourceCount();
}
@@ -172,6 +229,12 @@
String name)
throws Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException(
+ "DatabaseManager.getCollection("
+ + driver + "/" + path
+ + ") returned null" );
+ }
XMLResource document = (XMLResource) col.getResource(name);
if (document == null) {
@@ -191,6 +254,12 @@
String name)
throws Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException(
+ "DatabaseManager.getCollection("
+ + driver + "/" + path
+ + ") returned null" );
+ }
XMLResource document = (XMLResource) col.getResource(name);
col.removeResource(document);