You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by wo...@apache.org on 2010/09/22 18:24:39 UTC
svn commit: r1000069 -
/incubator/libcloud/sandbox/java/trunk/src/simplecloud/storage/providers/nirvanix/NirvanixConnection.java
Author: woodser
Date: Wed Sep 22 16:24:39 2010
New Revision: 1000069
URL: http://svn.apache.org/viewvc?rev=1000069&view=rev
Log:
Nirvanix driver: added support to throw InvalidCredsException at initialization if invalid credentials are supplied.
Modified:
incubator/libcloud/sandbox/java/trunk/src/simplecloud/storage/providers/nirvanix/NirvanixConnection.java
Modified: incubator/libcloud/sandbox/java/trunk/src/simplecloud/storage/providers/nirvanix/NirvanixConnection.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/sandbox/java/trunk/src/simplecloud/storage/providers/nirvanix/NirvanixConnection.java?rev=1000069&r1=1000068&r2=1000069&view=diff
==============================================================================
--- incubator/libcloud/sandbox/java/trunk/src/simplecloud/storage/providers/nirvanix/NirvanixConnection.java (original)
+++ incubator/libcloud/sandbox/java/trunk/src/simplecloud/storage/providers/nirvanix/NirvanixConnection.java Wed Sep 22 16:24:39 2010
@@ -1,13 +1,21 @@
package simplecloud.storage.providers.nirvanix;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
-import org.xml.sax.InputSource;
+import libcloud.exceptions.InvalidCredsException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
import base.Driver;
import base.connection.ConnectionUserAndKey;
@@ -67,10 +75,28 @@ public class NirvanixConnection extends
// Parse response
XPath xpath = XPathFactory.newInstance().newXPath();
try {
- InputSource input = new InputSource(response.getItem().getContent());
- sessionToken = xpath.evaluate("Response/SessionToken", input);
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document doc = db.parse(response.getBodyStream());
+ Element root = doc.getDocumentElement();
+ String responseCode = xpath.evaluate("/Response/ResponseCode", root);
+ if (responseCode.equals("0")) {
+ sessionToken = xpath.evaluate("/Response/SessionToken", root);
+ } else {
+ String errorMessage = xpath.evaluate("/Response/ErrorMessage", root);
+ throw new InvalidCredsException(responseCode + ": " + errorMessage);
+ }
} catch (XPathExpressionException e) {
e.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
}
}