Re: Please help me run Example1
Todd Byrne <[email protected]>
| Newsgroups | gmane.text.xml.xindice.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Lisa,
I load that code up and I didn't run because I didn't have the
addressbook collection added on my computer. Once I added the collection
it ran fine.
Try pointing your browser to http://localhost:8080/xindice insuring that
the addressbook collection is there.
I have included some code that will create that collection from within
your code.
The line: System.out.println(database.acceptsURI(uri));
Doesn't seem to properly work the way I do it is to check to see if the
collection is null after calling 'DatabaseManager.getCollection(uri)'.
Here is the code to create the addressbook collection.
String uri = "xmldb:xindice://localhost:8080/db";
Collection dbCollection = DatabaseManager.getCollection(uri);
CollectionManager manager = (CollectionManager)dbCollection.getService(
"CollectionManager", "1.0");
String collectionConfig =
"<collection compressed=\"true\" name=\""
+ collectionName
+ "\">"
+
" <filer
class=\"org.apache.xindice.core.filer.BTreeFiler\" gzip=\"true\"/>"
+ "</collection>";
manager.createCollection(collectionName,
DOMParser.toDocument(collectionConfig));
Collection addressBookCollection = DatabaseManager.getCollection(uri +
"/addressbook");
Hope this helps.
I will look into why acceptsURI returns false.
Todd
Lisa McCabe wrote:
> Hi Todd, (or anyone who could help me!)
>
> Here is the source code that I have been trying to run:
>
> package org.apache.xindice.examples;
>
> import org.xmldb.api.base.*;
> import org.xmldb.api.modules.*;
> import org.xmldb.api.*;
>
> /**
> * Simple XML:DB API example to query the database.
> */
> public class Example1 {
>
> public static void main(String[] args) throws Exception {
> Collection collection = null;
> try {
>
> String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
> Class c = Class.forName(driver);
>
> Database database = (Database) c.newInstance();
>
> database.setProperty("xmlrpc-password", "...");
> database.setProperty("xmlrpc-user", "xindice");
>
> DatabaseManager.registerDatabase(database);
>
> String uri = "xmldb:xindice://localhost:8080/db/addressbook";
>
> System.out.println("*******");
> System.out.println(database.acceptsURI(uri));
> System.out.println("*******");
>
> collection = DatabaseManager.getCollection(uri);
>
> String xpath = "//person[fname='John']";
> XPathQueryService service = (XPathQueryService)
> collection.getService("XPathQueryService", "1.0");
> ResourceSet resourceSet = service.query(xpath);
> ResourceIterator resourceIterator = resourceSet.getIterator();
>
> while (resourceIterator.hasMoreResources()) {
> Resource resource = resourceIterator.nextResource();
> System.out.println((String) resource.getContent());
> }
> } catch (XMLDBException e) {
> System.err.println("XML:DB Exception occured " + e.errorCode + "
> " + e.getMessage());
> } finally {
> if (collection != null) {
> collection.close();
> }
> }
> }
> }
>
> I can't firgure out why it cannot find /db. From reading other users email,
> classpath problems seem possible. The following is my classpath. Do you see
> anything missing or out of order?
>
> c:\Sun\jwsdp-1.5\jaxp\lib;
>
> c:\junit3.8.1\junit.jar;
>
> c:\junit3.8.1\junit;
>
> c:\j2sdk1.4.2_08;
>
> c:\j2sdk1.4.2_08\bin;
>
> c:\j2sdk1.4.2_08\lib;
>
> c:\j2sdk1.4.2_08\jre;
>
> c:\j2sdk1.4.2_08\include;
>
> %XINDICE_HOME%;
>
> %XINDICE_HOME%\lib;
>
> %XINDICE_HOME%\bin;
>
> c:\XIndiceBrowser_bin\XindiceBrowser\XIndiceBrowser.jar;
>
> c:\XindiceBrowser_bin\XindiceBrowser\XIndiceBrowser_lib.jar
>
> %XINDICE_HOME%\lib\xindice-1.1b4.jar;
>
> %XINDICE_HOME%\lib\xmldb-common-20030701.jar;
>
> %XINDICE_HOME%\lib\xmldb-api-20030701.jar;
>
> %XINDICE_HOME%\lib\xmldb-api-sdk-20030701.jar;
>
> %XINDICE_HOME%\lib\xmldb-xupdate-20040205.jar;
>
> %XINDICE_HOME%\lib\xml-apis.jar;
>
> %XINDICE_HOME%\lib\xerces-2.6.0.jar;
>
> %XINDICE_HOME%\lib\xalan-2.5.2.jar;
>
> %XINDICE_HOME%\lib\commons-logging-1.0.3.jar;
>
> %XINDICE_HOME%\lib\xmlrpc-1.1.jar;
>
> %TOMCAT_HOME%\bin\common-logging-api.jar;
>
> %TOMCAT_HOME%\common\endorsed\xercesImpl.jar;
>
> %TOMCAT_HOME%\common\endorsed\xmlParserAPIs.jar;
>
> .;
>
>
>
> Thanks!
>
> Lisa McCabe
>
>
>
> ----- Original Message -----
> From: "Todd Byrne" <[email protected]>
> To: <[email protected]>
> Sent: Friday, June 24, 2005 2:36 PM
> Subject: Re: Please help me run Example1
>
>
>
>>Yeah the addressbook example is webapp.
>>
>>Once Xindice is running inside tomcat you will beable to access it from
>>simple java code but the addressbook is just a jsp example. If you have
>>the code that your having trouble getting to work post to the list and I
>>can take a look.
>>
>>Todd
>>
>>Lisa McCabe wrote:
>>
>>>Hi Todd,
>>>
>>>Thank you for your response.
>>>
>>>I forgot to say that I am running on Windows. I just downloaded the .zip
>>>file and will take a look at the example files.
>>>
>>>Are you saying that I should build a .war file then deploy it in tomcat
>
> and
>
>>>run it like a webapp? I was hoping to be able to access xindice from a
>
> java
>
>>>program. I will try what you suggest.
>>>
>>>Thanks again,
>>>Lisa
>>>
>>>PS I still think I may simply have a CLASSPATH problem.
>>>
>>>----- Original Message -----
>>>From: "Todd Byrne" <[email protected]>
>>>To: <[email protected]>
>>>Sent: Thursday, June 23, 2005 12:18 PM
>>>Subject: Re: Please help me run Example1
>>>
>>>
>>>
>>>
>>>>Hi Lisa,
>>>>
>>>>So I am assuming you downloaded
>>>>http://ftp.wayne.edu/apache/xml/xindice/xml-xindice-1.1b4-jar.tar.gz
>>>>
>>>>Un-tarred it into a dir lets say /tmp.
>>>>
>>>>cd $XINDICE_HOME/java/examples
>>>># this builds the addressbook example ant needs to be in your path
>>>>ant
>>>># this copies the war to your webapps under a tomcat directory
>>>>cp ../../dist/addressbook.war $JAKARTA_HOME/webapps #
>>>>cd $JAKARTA_HOME/bin
>>>>./shutdown.sh #shutdown tomcat
>>>>./startup.sh #restart tomecat
>>>>
>>>>Open up your favorite browser point it to:
>>>
>>>http://localhost:8080/addressbook
>>>
>>>
>>>>That should get you going. Let me know if you need any more help let me
>>>
>>>know
>>>
>>>
>>>>Todd
>>>>
>>>>PS: Lines starting with a '#' are comments.
>>>>
>>>>
>>>>Lisa McCabe wrote:
>>>>
>>>>
>>>>>Hello,
>>>>>
>>>>>I am still trying to get Example1 to run (unfortunately). I have
>
> changed
>
>>>>>the port to 8080. I have also added xmlParserAPIs.jar and
>
> xercesImpl.jar
>
>>>>>to my CLASSPATH. I still am getting the same runtime error.
>>>>>
>>>>>If my URI is "xmldb:xindice:///db/addressbook" as specified in
>
> Example1,
>
>>>>>I get
>>>>>
>>>>>XML:DB Exception occurred 1 A connection to the Database Instance 'db'
>>>>>could not be created. Error: Connection refused: connect
>>>>>
>>>>>Else if my URI is "xmldb:xindice://localhost:8080/db/addressbook"
>>>>>XML:DB Exception occurred 1 A connection to the Database Instance 'db'
>>>>>could not be created. Error: http://localhost:8080/db_bootstrap.ior
>>>>>
>>>>>Commandline xindice and "Ugly" web browser have no problems
>
> "connecting"
>
>>>>>to /db.
>>>>>
>>>>>I really need to move past this problem (and on to the next!) Hope you
>>>>>can help...
>>>>>
>>>>>Thanks,
>>>>>Lisa McCabe
>>>>>
>>>>>----- Original Message -----
>>>>>
>>>>> *From:* Lisa McCabe <mailto:[email protected]>
>>>>> *To:* [email protected]
>>>>> <mailto:[email protected]>
>>>>> *Sent:* Monday, June 20, 2005 4:48 PM
>>>>> *Subject:* Please help me run Example1
>>>>>
>>>>> Hi,
>>>>>
>>>>> I am having trouble getting Example1 to work correctly. I am using
>>>>> Xindice 1.1b4 with Tomcat V5.
>>>>>
>>>>> Example1 runs but gives me the following:
>>>>>
>>>>> XML:DB Exception occurred 1 A connection to the Database Instance
>>>>> 'db' could not be created. Error:
>>>
>>>http://localhost:8888/db_bootstrap.ior
>>>
>>>
>>>>> Xindice commandline works fine. And I can view /db through the
>
> "Ugly
>
>>>>> Browser".
>>>>>
>>>>> I also get basically the same error when I try to run
>>>
>>>XindiceBrowser.
>>>
>>>
>>>>> I have read through some old xindice-users problem emails, looking
>>>>> for similar problems. I have found one saying that db_bootstrap.ior
>>>>> indicates that I am using Xindice 1.0 client and Xindice 1.1
>
> Server.
>
>>>>> Since I downloaded Xindice binary in one .zip, I am not sure how I
>>>>> could have that problem. Another email said it could be a CLASSPATH
>>>>> problem. I think I now have every .jar file on the planet in my
>>>>> classpath but the email indicated xmlParserAPIs.jar and
>>>>> xercesImpl.jar (not xerces.jar), I could find neither of those.
>>>>>
>>>>> Is there anyone out there who could help me with this problem???!
>>>>>
>>>>> Need help,
>>>>> Lisa McCabe
>>>>>
>>>>> Thanks a bunch in advance!!