Skip to Content.
Sympa Menu

perfsonar-dev - r1650 - trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest

Subject: perfsonar development work

List archive

r1650 - trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest


Chronological Thread 
  • From:
  • To:
  • Subject: r1650 - trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest
  • Date: Fri, 29 Sep 2006 05:51:14 -0400

Author: mac
Date: 2006-09-29 05:51:13 -0400 (Fri, 29 Sep 2006)
New Revision: 1650

Modified:

trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest/ExistDbHTTPAccess.java

trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest/ExistDbHttpXmlStorageManager.java
Log:
Changes in HTTP eXist DB XML access objects

Modified:
trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest/ExistDbHTTPAccess.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest/ExistDbHTTPAccess.java
2006-09-29 09:50:50 UTC (rev 1649)
+++
trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest/ExistDbHTTPAccess.java
2006-09-29 09:51:13 UTC (rev 1650)
@@ -2,12 +2,11 @@

import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
import java.util.ArrayList;

+import org.perfsonar.commons.util.XMLUtils;
import org.perfsonar.service.commons.storage.xmldb.XmlDbConstants;
import org.perfsonar.service.commons.storage.xmldb.XmlDbResult;

@@ -20,51 +19,14 @@
* $Id$
*
*/
-public class ExistDbHTTPAccess implements XmlDbConstants {
+public class ExistDbHTTPAccess extends HTTPAccess implements XmlDbConstants {

- // ------------------------------------------------------ Constants
-
- // -------------------------------------------------- Flags
- /**
- * Default values
- */
- public static final int DEFAULT = 0x0000;
-
- /**
- * Remove <exist:value> tags
- */
- public static final int DONT_PARSE_EXIST_VALUE_TAG = 0x0001;
-
- /**
- * Remove <exist result> tag
- */
- public static final int DONT_PARSE_EXIST_RESULT_TAG = 0x0002;
-
- /**
- * XQUERY
- */
- public static final int XQUERY = 0x0004; //also by default
-
-
- /**
- * XUPDATE
- */
- public static final int XUPDATE = 0x0008;

- /*
- * reserved for Result Types 0x0?00
- */
+ // ---------------------------------------------Instance variables

- /**
- * Enable DEBUG
- */
- public static final int DEBUG = 0x4000;
-
- /**
- * Enable DEBUG
- */
- public static final int DEBUG_MORE = 0xc000;
+ private boolean debug = false;

+
// -------------------------------------------------- other

/**
@@ -77,475 +39,249 @@
* Return all results
*/
public static final int ALL_RESULTS = 0;
+

+ // ------------------------------------------------ public methods


-
+ public int sendExistXUpdateRequest(
+ String url,
+ String updateString,
+ String username,
+ String password) throws IOException, ExistDbErrorException {

- // ---------------------------------------- Static public methods
+ HTTPResult result = sendPOSTRequest(url, updateString,username,
password);
+ return result.getResultCode();
+
+ }

-
/**
- * Sends HTTP request to eXist DB XML. Method may have several
- * modifiers which are passed as sum of flags (for instance
- * DEBUG|RETURN_FULL). If you don't know which flags should be
- * used just use 0 value or DEFAULT.
*
- * By default XQuery expression is used and encapsulated into
- * <query><text> and </text></query> tags. Use DEFAULT flag or
- * XQUERY for sure :)
- *
- * By using XUPDATE flag, expression won't be encapsulated into
- * query/text tags and will be send directly according to
- * exist DB XML REST-style communication documentation.
- * In this case, result is always empty string (but of course
- * formatted according RETURN_ flags). If RETURN_FULL, the
- * hits,
- * first
- * and count
- * values are always set to 0.
- *
- * Example of use:
- *
- * String[] s = (String[])ExistDbHTTPAccess .sendHTTPRequest(
- * "http://localhost:8080/exist/rest/db/rrdmaconfig";, //server
- * "/*:store", //XQuery expression
- * "UsErNaMe", //User name
- * "pASs-WorD", //password
- * FIRST, //start from first result
- * ALL_RESULTS, //give all results
- * DEBUG|RETURN_STRING_ARRAY|XQUERY);
- * //show debug messages and
- * //return results as
- * //String[1] array
- * //XQuery language will be used
- *
- * @param url url of eXist database
- * @param query query to database (XQuery)
- * @param username username (null or empty if no authorization)
- * @param password password (may be null or empty)
- * @param start first result to be returned
- * @param limit limit of results, ALL_RESULTS means that all results
will be returned
- * @param flags additional flags
- * @return String by default (if RETURN_STRING flag set) or String[1]
(if RETURN_STRING_ARRAY flag set) or XmlDbResult object (if RETURN_FULL flag
set)
- * @throws IOException something wrong with HTTP connection
- * @throws ExistDbErrorException database server responsed with error
(unauthorized or parse error)
+ * @param url
+ * @param content
+ * @param username
+ * @param password
+ * @param start
+ * @param limit
+ * @return
+ * @throws IOException
*/
- public static Object sendHTTPRequest(
- String url,
- String query,
+ public HTTPResult sendXQueryPOSTRequest(
+ String url,
+ String content,
String username,
- String password,
+ String password,
int start,
- int limit,
- int flags) throws IOException, ExistDbErrorException {
+ int limit) throws IOException {

- //Result string
- String result = null;
- String[] resultArray = null;
- int hits = 0;
- int count = 0;
- int first = 0;
+ //prepare XQuery
+ content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
+ "<query xmlns=\"http://exist.sourceforge.net/NS/exist\"; "+
+ "start=\""+String.valueOf(start)+"\" max=\""+
+ String.valueOf(limit)+"\"> "+
+ " <text>" +
+ "<![CDATA["+
+ content +
+ "]]>" +
+ "</text> "+
+ "</query>";

- boolean doXQuery = true;
- if ((flags&XUPDATE)>0)
- doXQuery = false;
-
- //parse <exist:value> tag ?
- boolean allowRemoveExistValue = true;
- if ((flags&DONT_PARSE_EXIST_VALUE_TAG)>0)
- allowRemoveExistValue = false;
-
- //parse <exist:result> tag ?
- boolean allowRemoveExistResult = true;
- if ((flags&DONT_PARSE_EXIST_RESULT_TAG)>0)
- allowRemoveExistResult = false;
-
- boolean debug = false;
- if ((flags&DEBUG)>0)
- debug = true;
-
- boolean debug_more = false;
- if ((flags&DEBUG_MORE)>0)
- debug_more = true;
+ return sendPOSTRequest(url, content, username, password);

- boolean full = false;
- if ((flags&RETURN_XML_DB_RESULT)>0)
- full = true;
+ }
+
+
+ public XmlDbResult sendExistXQueryRequest(
+ String url,
+ String query,
+ String username,
+ String password,
+ int start,
+ int limit) throws IOException, ExistDbErrorException {

- boolean stringarray = false;
- if ((flags&RETURN_STRING_ARRAY)>0)
- stringarray=true;
-
- if ((flags&RETURN_STRING)>0) {
- stringarray=false;
- full=false;
- }
+ /* ******************************************************** */

- //print debug
+ //send HTTP request and encapsulate query
+ HTTPResult httpResult = sendXQueryPOSTRequest(
+ url, query, username, password, start, limit);

+ /* ******************************************************** */

-
- if (debug) {
+ int resultCode = httpResult.getResultCode();
+ if (resultCode == 200) { //HTTP OK

- System.out.println("[D] Remove exist result tag: "+
- allowRemoveExistResult);
- System.out.println("[D] Remove exist value tag: "+
- allowRemoveExistValue);
+ //parse XML result returned by eXist DB XML
+ XmlDbResult xmlResult = parseExistXMLReponse(
+ httpResult.getResponse());

- if (doXQuery) {
- System.out.println("[D] Query will be encapsulated in
<query><text></text></query> tags");
- }
+ return xmlResult;

- if (full) {
- System.out.println("[D] Result XmlDbResult");
- } else if (stringarray) {
- System.out.println("[D] Result: String[1]");
- } else {
- System.out.println("[D] Result: String");
- }
-
- } //end print debug
-
-
-
- //prepare query
-
-
- if (doXQuery) {
- query = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
- "<query xmlns=\"http://exist.sourceforge.net/NS/exist\"; "+
- "start=\""+String.valueOf(start)+"\" max=\""+
- String.valueOf(limit)+"\"> "+
- " <text>" +
- "<![CDATA["+
- query +
- "]]>" +
- "</text> "+
- "</query>";
+ } else {
+ throw new ExistDbErrorException(
+ resultCode, httpResult.getResultMessage());
}

- if (debug) System.out.println("[D] query: " + query);
+ }
+
+
+
+ private XmlDbResult parseExistXMLReponse(
+ InputStream inputStream) throws IOException {

-
- //connect by HTTP with /exist/rest/db/COLLECTION
- URL _url = new URL(url);
+ int hits=-1, first=-1, count=-1;
+ String result = null;
+ String[] resultArray = null;

- //create HTTP URL Connection
- HttpURLConnection huc = (HttpURLConnection) _url.openConnection();
+ boolean allowRemoveExistValue = true;

- //set HTTP method
- huc.setRequestMethod("POST");
+ //read response

- //set content type
- huc.setRequestProperty("Content-Type",
- "application/x- www-form-urlencoded");
+ BufferedReader rd = new BufferedReader(
+ new InputStreamReader(inputStream));

- huc.setDoOutput(true);
+ //<exist:result...> parsed?
+ boolean exResult = false;

- huc.setDoInput(true);
+ //read each line
+ StringBuffer response = new StringBuffer();
+ ArrayList<String> responseList = new ArrayList<String>();

- //set content length
- huc.setRequestProperty(
- "Content-Length", String.valueOf(query.length()));
-
- //HTTP Authorization, set "Authorization: Basic " if necessary
- if (username!=null) {
+ String str;
+ while ((str = rd.readLine()) != null) {

- if (password==null) password=""; //if null make it empty String
-
- if (!("".equals(username))) {
- if (debug) System.out.println("[D] authorization Basic "+
- username+":"+password);
-
- String basicAuth = "Basic " +
- (new sun.misc.BASE64Encoder().
- encode((username+":"+password).getBytes()));

-
- huc.setRequestProperty(
- "Authorization", basicAuth);
-
+ if (debug) {
+ System.out.println("[->] read line: ["+str+"]");
}
- }
-
- //send via HTTP
- OutputStream out = huc.getOutputStream();
- out.write(query.getBytes());
- out.flush();
-
- //HTTP response available now
- int responseCode = huc.getResponseCode();
-
- if (debug) System.out.println("[D] Response code: "+ responseCode+"
("+huc.getResponseMessage()+")");
-
- //if not XQuery, what means XUpdate, return empty string
- if (!doXQuery) {
-
- //if XUpdate
- result = "";
- hits=0;
- first=0;
- count=0;

- //if XQuery, parse output is HTTP response code = 200 OK
- } else {
+ boolean doParseLine = true;

- //if XQuery
-
- //if HTTP 200 OK
- if (responseCode==200) {
+ if (!exResult) {

- //read response
- BufferedReader rd = new BufferedReader(
- new InputStreamReader(huc.getInputStream()));
-
- //<exist:result...> parsed?
- boolean exResult = false;
-
- //read each line
- StringBuffer response = new StringBuffer();
- ArrayList<String> responseList = new ArrayList<String>();
-
- String str;
- while ((str = rd.readLine()) != null) {
+ if (str.startsWith("<exist:result")) {

- if (debug_more) {
- System.out.println("[->] read line: ["+str+"]");
- }
+ if (debug) System.out.println(
+ "[HEAD] ["+str+"]");
+ doParseLine = false;
+ exResult=true;

- boolean doParseLine = true;
-
- if (allowRemoveExistResult||full) {
- if (!exResult) {
-
- if (str.startsWith("<exist:result")) {
-
- if (debug) System.out.println(
- "[HEAD] ["+str+"]");
- doParseLine = false;
- exResult=true;
-
- //if full results, parse hits/count/total as
well
- if (full) {
-
- try {
- hits=Integer.parseInt(
- extractXMLAttributeValue(
- str,"exist:hits"));
- } catch (RuntimeException e) {}
- try {
- count=Integer.parseInt(
- extractXMLAttributeValue(
- str,"exist:count"));
- } catch (RuntimeException e) {}
- try {
- first=Integer.parseInt(
- extractXMLAttributeValue(
- str,"exist:start"));
- } catch (RuntimeException e) {}
-
- if (debug) System.out.println(
- "[RESV] hits="+hits);
- if (debug) System.out.println(
- "[RESV] start="+first);
- if (debug) System.out.println(
- "[RESV] count="+count);
- } //if full
-
- //Case if exist:result in one line

- //if <exist:result>anything</exist:result>
- String content =
extractXMLTag(str,"exist:result");
- if (content!=null) {
- //take only content
- str=content;
- doParseLine=true; //this time parse
line, because
- //it may contain more data to be parsed
- if (debug) System.out.println("[D]
Results in one line, parsing content ["+str+"]...");
- }
-
- } //<exist:result>
-
- } else {
-
- if (str.startsWith("</exist:result")) {
- if (debug) System.out.println(
- "[FOOT] ["+str+"]");
- doParseLine = false;
- }
-
- } //</exist:result>
+ //if full results, parse hits/count/total as well

+ try {
+ hits=Integer.parseInt(
+ XMLUtils.extractXMLAttributeValue(
+ str,"exist:hits"));
+ } catch (RuntimeException e) {}
+ try {
+ count=Integer.parseInt(
+ XMLUtils.extractXMLAttributeValue(
+ str,"exist:count"));
+ } catch (RuntimeException e) {}
+ try {
+ first=Integer.parseInt(
+ XMLUtils.extractXMLAttributeValue(
+ str,"exist:start"));
+ } catch (RuntimeException e) {}
+
+ if (debug) System.out.println(
+ "[RESV] hits="+hits);
+ if (debug) System.out.println(
+ "[RESV] start="+first);
+ if (debug) System.out.println(
+ "[RESV] count="+count);
+
+ //Case if exist:result in one line

+ //if <exist:result>anything</exist:result>
+ String content = XMLUtils.extractXMLTag(
+ str,"exist:result");
+
+ if (content!=null) {
+ //take only content
+ str=content;
+ doParseLine=true; //this time parse line, because
+ //it may contain more data to be parsed
+ if (debug) System.out.println("[D] Results in one
line, parsing content ["+str+"]...");
}

- //parse (if inside <exist:result></exist:result>
- if (doParseLine) {
-
- if (allowRemoveExistValue) {
-
- //remove <exist:value...
- String content =
extractXMLTag(str,"exist:value");
- if (content!=null) {
- str=content;
- //add to list
- if (!("".equals(str)))
- responseList.add(str);
- if (debug) System.out.println("[D] Removed
<exist:value>");
- }
-
- }
+ } //<exist:result>
+
+ } else {
+
+ if (str.startsWith("</exist:result")) {
+ if (debug) System.out.println(
+ "[FOOT] ["+str+"]");
+ doParseLine = false;
+ }
+
+ } //</exist:result>
+
+
+
+ //parse (if inside <exist:result></exist:result>
+ if (doParseLine) {

- /*
- * ----------------------------------------------
- * at this stage, str contains string line
- * ----------------------------------------------
- */
-
- //add parsed line to response String Buffer
- response.append(str);
-
- //add Line Feed sign at the end of each line
- response.append("\n");
-
- if (debug) System.out.println("[LINE] ["+str+"]");
-
- } //parse
-
- } //read lines
+ if (allowRemoveExistValue) {
+
+ //remove <exist:value...
+ String content =
XMLUtils.extractXMLTag(str,"exist:value");
+ if (content!=null) {
+ str=content;
+ //add to list
+ if (!("".equals(str)))
+ responseList.add(str);
+ if (debug) System.out.println("[D] Removed
<exist:value>");
+ }
+
+ }

- //convert results to String
- result = response.toString();
+ /*
+ * ----------------------------------------------
+ * at this stage, str contains string line
+ * ----------------------------------------------
+ */

- //convert result list (if only exist:value) to String[]
- if (responseList.size()>0)
- resultArray = responseList.
- toArray(new String[responseList.size()]);
+ //add parsed line to response String Buffer
+ response.append(str);

-
- } //HTTP 200 OK
- else {
+ //add Line Feed sign at the end of each line
+ response.append("\n");

- throw new ExistDbErrorException(
- huc.getResponseCode(), huc.getResponseMessage());
+ if (debug) System.out.println("[LINE] ["+str+"]");

- } //any other HTTP error code
-
- } //if xquery
- //end HTTP session
- huc.disconnect();
-
- //return results as:
-
- if (full) {
-
- if (resultArray!=null)
- return new XmlDbResult(resultArray, hits, first, count);
//return XmlDbResult
- else
- return new XmlDbResult(result, hits, first, count); //return
XmlDbResult
-
-
- } else if (stringarray) {
- if (resultArray!=null) {
- return resultArray; //return String[N]
- } else {
- String[] resarr = {result}; //return String[1]
- return resarr;
- }
-
-
- } else {
-
- return result; //return String
-
- }
+ } //parse
+
+ } //read lines

- } //end
-
-
-
- protected static String extractXMLTag(String str, String tag) {
+ //convert results to String
+ result = response.toString();

- //trim from blank spaces
- str = str.trim();
+ //convert result list (if only exist:value) to String[]
+ if (responseList.size()>0)
+ resultArray = responseList.
+ toArray(new String[responseList.size()]);

- //find starting tag
- int indexStartTag1 = str.indexOf("<"+tag);
- if (indexStartTag1==-1) return null;
+ if (resultArray!=null)
+ return new XmlDbResult(resultArray, hits, first, count);
//return XmlDbResult
+ else
+ return new XmlDbResult(result, hits, first, count); //return
XmlDbResult

- //find end of starting tag
- int indexStartTag2 = str.indexOf(">", indexStartTag1);
- if (indexStartTag2==-1) return null;
-
- //find closing tag
- int indexEndTag1 = str.indexOf("</"+tag, indexStartTag2);
- if (indexEndTag1==-1) return null;
-
- String substr = str.substring(indexStartTag2+1, indexEndTag1);
- return substr;
-
}
+

- /**
- * Extracts attribute value from string
- * @param a string
- * @param attribute attribute name
- * @return
- */
- protected static String extractXMLAttributeValue(
- String str,
- String attribute) {
-
- try { //just in case of a RuntimeException
-
- int ind1 = str.indexOf(attribute);
-
- if (ind1>-1) { ind1 = str.indexOf('\"', ind1); }
- else return null; //attribute not found
-
- if (ind1>-1) {
- ind1+=1;
- int ind2 = str.indexOf('\"',ind1);
- if (ind2>-1) {
- return str.substring(ind1,ind2); //return value of
attribute
- }
- }
-
- } catch (Exception ex) {}
+ public boolean isDebug() {

- return null; //bad xml?
-
+ return debug;
+
}
-
-
- /**
- * Shorter version.
- *
- * Exist DB XML will return all results (ALL_RESULTS) beginning from 1
(FIRST)
- *
- * @param url url of eXist database
- * @param query query to database (XQuery)
- * @param username username (null or empty if no authorization)
- * @param password password (may be null or empty)
- * @param flags additional flags
- * @return String by default (if RETURN_STRING flag set) or String[1]
(if RETURN_STRING_ARRAY flag set) or XmlDbResult object (if RETURN_FULL flag
set)
- * @throws IOException something wrong with HTTP connection
- * @throws ExistDbErrorException database server responsed with error
(unauthorized or parse error)
- */
- public static Object sendHTTPRequest(
- String url,
- String query,
- String username,
- String password,
- int flags) throws IOException, ExistDbErrorException {
+
+
+ public void setDebug(boolean debug) {

- return sendHTTPRequest(
- url,
- query, username, password,
- FIRST, ALL_RESULTS, flags);
+ this.debug = debug;

- } //end
+ }
+
+

-
-
// --------------------------------------------------- test method

/**
@@ -553,10 +289,10 @@
*/
public static void main(String[] args) throws Exception {

- String query =
- "declare namespace " +
- "nmwg='http://ggf.org/ns/nmwg/base/2.0/'; " +
- "/nmwg:store/nmwg:metadata";
+// String query =
+// "declare namespace " +
+// "nmwg='http://ggf.org/ns/nmwg/base/2.0/'; " +
+// "/nmwg:store/nmwg:metadata";

// String query =
// "declare namespace " +
@@ -599,21 +335,20 @@

long t0 = System.currentTimeMillis(); //----------------time 0

- Object s = ExistDbHTTPAccess .sendHTTPRequest(
- "http://localhost:8680/exist/rest/db/ls";,
- query,
- "lookupservice",
- "sonar",
- FIRST,
- ALL_RESULTS,
- RETURN_XML_DB_RESULT|XQUERY|DEBUG_MORE);
+ String query = "data(/test/a/@id)";
+ ExistDbHTTPAccess a = new ExistDbHTTPAccess();
+ a.setDebug(true);
+ XmlDbResult result = a.sendExistXQueryRequest(
+ "http://localhost:8680/exist/rest/db/test";,
+ query,
+ "lookupservice",
+ "sonar",
+ FIRST,
+ ALL_RESULTS);
+ a.disconnectHTTPServer();

long t1 = System.currentTimeMillis(); //----------------time 1

- XmlDbResult result = (XmlDbResult)s;
-// String x = result.getResultAsString();
-// System.out.println("RESULT:
"+((x.length()<1000)?x:x.substring(1000)));
-
for (int i=0; i<result.getResultAsStringArray().length; i++) {
String x = result.getResultAsStringArray()[i];
System.out.println("RESULT["+i+"]:
"+((x.length()<1000)?x:"..."+x.substring(1000)+"..."));
@@ -626,7 +361,4 @@

}

-
-
-
} //ExistDbHTTPAccess

Modified:
trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest/ExistDbHttpXmlStorageManager.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest/ExistDbHttpXmlStorageManager.java
2006-09-29 09:50:50 UTC (rev 1649)
+++
trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest/ExistDbHttpXmlStorageManager.java
2006-09-29 09:51:13 UTC (rev 1650)
@@ -6,7 +6,9 @@
import org.perfsonar.service.commons.exceptions.RequestException;
import org.perfsonar.service.commons.exceptions.SystemException;
import org.perfsonar.service.commons.storage.DataRepository;
+import org.perfsonar.service.commons.storage.xmldb.XmlDbConstants;
import org.perfsonar.service.commons.storage.xmldb.XmlDbDataRepository;
+import org.perfsonar.service.commons.storage.xmldb.XmlDbResult;
import org.perfsonar.service.commons.storage.xmldb.XmlDbStorageManager;
import org.perfsonar.service.commons.storage.xmldb.exist.ExistDbFactory;
import
org.perfsonar.service.commons.storage.xmldb.exist.ExistDbGenericStorageManager;
@@ -21,7 +23,7 @@
*
* Results of fetch/store are
* String - if type is set to STRING_TYPE //not implemented
- * String[1] - if type is set to STRING_ARRAY_TYPE
+ * String[] - if type is set to STRING_ARRAY_TYPE
* XmlDbResult if type is set to XML_DB_RESULT_TYPE
*
* @author Roman Lapacz
@@ -40,15 +42,18 @@
* Data repository object
*/
protected XmlDbDataRepository dataRepository = null;
+
+
+ protected ExistDbHTTPAccess httpAccess = null;

// -------------------------------------- constructors



public ExistDbHttpXmlStorageManager() {
+
+ httpAccess = new ExistDbHTTPAccess();

- //do nothing
-
}


@@ -131,29 +136,31 @@
throws SystemException {

getLogger().debug("ExistDbHttpXmlStorageManager: XQuery");
- Object results = null;
-
- try {
- results = ExistDbHTTPAccess.sendHTTPRequest(
-
((XmlDbDataRepository)dataRepository).getDbUri(),
- (String)query,
-
((XmlDbDataRepository)dataRepository).getDbUsername(),
-
((XmlDbDataRepository)dataRepository).getDbPassword(),
- ExistDbHTTPAccess.FIRST,
- ExistDbHTTPAccess.ALL_RESULTS,
- getResultType()|ExistDbHTTPAccess.XQUERY);
+ XmlDbResult results = null;
+
+ try {
+ results = httpAccess.sendExistXQueryRequest(
+ ((XmlDbDataRepository)dataRepository).getDbUri(),
+ (String)query,
+ ((XmlDbDataRepository)dataRepository).getDbUsername(),
+ ((XmlDbDataRepository)dataRepository).getDbPassword(),
+ ExistDbHTTPAccess.FIRST,
+ ExistDbHTTPAccess.ALL_RESULTS);

- } catch (Exception ex) {
- throw new SystemException(
- "error.common.storage.xmldb.open",
- "XQuery by HTTP failed. "
- + "Could not connect to eXist via pure http, "
+ } catch (Exception ex) {
+ throw new SystemException(
+ "error.common.storage.xmldb.open",
+ "XQuery by HTTP failed. "
+ + "Could not connect to eXist via pure http, "
+ " nested exception was: "+
ex.getClass()+" : "+ex.getMessage());
- }
+ }

- return results; // String, String[] or XmlDbResult
- // - depends on getResultType()
+ if (getResultType()==XmlDbConstants.RETURN_STRING_ARRAY)
+ return results.getResultAsStringArray();
+
+ else return results;
+
}


@@ -162,17 +169,14 @@
throws SystemException {

getLogger().debug("ExistDbHttpXmlStorageManager: XUpdate");
- Object results = null;
+ int results;

try {
- results = ExistDbHTTPAccess.sendHTTPRequest(
+ results = httpAccess.sendExistXUpdateRequest(
((XmlDbDataRepository)dataRepository).getDbUri(),
(String)xml,
((XmlDbDataRepository)dataRepository).getDbUsername(),
- ((XmlDbDataRepository)dataRepository).getDbPassword(),
- ExistDbHTTPAccess.FIRST,
- ExistDbHTTPAccess.ALL_RESULTS,
- getResultType()|ExistDbHTTPAccess.XUPDATE);
+ ((XmlDbDataRepository)dataRepository).getDbPassword());

} catch (Exception ex) {
throw new SystemException(
@@ -187,7 +191,10 @@
// - depends on getResultType()
}

+ // ---------------------------------------------



-} //ExistDbXmlrpcXmlStorageManager
+
+
+} //ExistDbXmlStorageManager



  • r1650 - trunk/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/exist/rest, svnlog, 09/29/2006

Archive powered by MHonArc 2.6.16.

Top of Page