perfsonar-dev - perfsonar: r3256 - in trunk/perfsonar_base/src/main/java/org/perfsonar: base/util client/testHarness
Subject: perfsonar development work
List archive
perfsonar: r3256 - in trunk/perfsonar_base/src/main/java/org/perfsonar: base/util client/testHarness
Chronological Thread
- From:
- To:
- Subject: perfsonar: r3256 - in trunk/perfsonar_base/src/main/java/org/perfsonar: base/util client/testHarness
- Date: Sat, 19 Jan 2008 18:31:06 -0500
Author: fernandes
Date: 2008-01-19 18:31:06 -0500 (Sat, 19 Jan 2008)
New Revision: 3256
Modified:
trunk/perfsonar_base/src/main/java/org/perfsonar/base/util/XMLUtils.java
trunk/perfsonar_base/src/main/java/org/perfsonar/client/testHarness/SOAPClient.java
Log:
CL-MP modifications for new functionalities
Modified:
trunk/perfsonar_base/src/main/java/org/perfsonar/base/util/XMLUtils.java
===================================================================
--- trunk/perfsonar_base/src/main/java/org/perfsonar/base/util/XMLUtils.java
2008-01-19 23:22:53 UTC (rev 3255)
+++ trunk/perfsonar_base/src/main/java/org/perfsonar/base/util/XMLUtils.java
2008-01-19 23:31:06 UTC (rev 3256)
@@ -9,8 +9,10 @@
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
@@ -19,14 +21,12 @@
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
-
import org.ggf.ns.nmwg.base.v2_0.Element;
import org.ggf.ns.nmwg.base.v2_0.Handler;
import org.ggf.ns.nmwg.base.v2_0.Message;
-
import org.perfsonar.base.exceptions.PerfSONARException;
-
import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -208,7 +208,7 @@
parser.setFeature(NAMESPACES_FEATURE_ID, namespaces);
parser.setFeature(NAMESPACE_PREFIXES_FEATURE_ID,
namespacePrefixes);
-
+// bad xml?
parser.setContentHandler(handler);
InputSource ipSrc = new InputSource(
@@ -404,9 +404,84 @@
}
+ // ---------------------------------------------------------- XML Files
parsing
+ /**
+ * Converts XML File into DOM Document
+ * @param file xml file in system
+ * @return Document
+ * @throws PerfSONARException if something goes wrong
+ */
+ public static Document convertXMLFileToDom(String file) throws
PerfSONARException{
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ Document dom = null;
+ try {
+
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ dom = db.parse(file);
+
+ }catch (IOException e) {
+ throw new PerfSONARException("error.common.parse_error",
+ "IO exception: "
+ + "encountered while reading xml file "
+ + e.getMessage());
+ } catch (SAXException e) {
+ throw new
PerfSONARException("error.common.parse_error",
+ "SAX Exception: "
+ + e.getMessage());
+ } catch (ParserConfigurationException e) {
+ throw new
PerfSONARException("error.common.parse_error", "Parser Configuration "
+ + "Exception " + e.getMessage());
+ }
+
+ return dom;
+ }
+ /**
+ * Gets the internal elements of nodes with a specific tag
+ * @param dom The document to get the elements from
+ * @param node The tag for the nodes
+ * @param elements A list of internal elements to get from the node
+ * @return Document
+ */
+ public static List<Map<String,String>> getNodeElementsFromDom(
+ Document dom, String node, List<String> elements) {
+
+ List<Map<String,String>> elementsMapList = new
ArrayList<Map<String,String>>();
+ org.w3c.dom.Element root = dom.getDocumentElement();
+ NodeList nl = root.getElementsByTagName(node);
+ if(nl != null && nl.getLength() > 0) {
+ for(int i = 0 ; i < nl.getLength();i++) {
+ org.w3c.dom.Element el =
(org.w3c.dom.Element)nl.item(i);
+ HashMap<String,String> elementsMap = new
HashMap<String,String>();
+ for(String e : elements)
+ elementsMap.put(e,
getElementValue(el,e));
+ elementsMapList.add(elementsMap);
+ }
+ }
+
+ return elementsMapList;
+ }
+
+ /**
+ * Auxiliar private method to get a text value from an Element
+ * @param element The element to get the value from
+ * @param node The tag of the node which value is wanted
+ * @return Document
+ */
+ private static String getElementValue(org.w3c.dom.Element element,
String node) {
+ NodeList nl = element.getElementsByTagName(node);
+ String value = null;
+ if(nl != null && nl.getLength() > 0) {
+ org.w3c.dom.Element el =
(org.w3c.dom.Element)nl.item(0);
+ value = el.getFirstChild().getNodeValue();
+ }
+
+ return value;
+ }
+
// ---------------------------------------------------------- Inner class
Modified:
trunk/perfsonar_base/src/main/java/org/perfsonar/client/testHarness/SOAPClient.java
===================================================================
---
trunk/perfsonar_base/src/main/java/org/perfsonar/client/testHarness/SOAPClient.java
2008-01-19 23:22:53 UTC (rev 3255)
+++
trunk/perfsonar_base/src/main/java/org/perfsonar/client/testHarness/SOAPClient.java
2008-01-19 23:31:06 UTC (rev 3256)
@@ -19,10 +19,11 @@
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPBodyElement;
-
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
-
+import org.ggf.ns.nmwg.base.v2_0.Message;
+import org.perfsonar.base.exceptions.PerfSONARException;
+import org.perfsonar.base.util.XMLUtils;
import org.w3c.dom.Document;
@@ -149,8 +150,58 @@
System.out.println("Client exiting");
}
+ public Document makeRequest(String endPoint, Message request) throws
PerfSONARException{
+ Document result = null;
+ try {
+ // prepare to call - set service elements
+ Service service = new Service();
+ Call call = (Call) service.createCall();
+ call.setTargetEndpointAddress(new URL(endPoint));
+ call
+ .setOperationName(new
QName("http://soapinterop.org/",
+ "submit"));
+ Document requestDocument =
XMLUtils.convertMessageToDOM(request);
+
+ // build a SOAPBodyElement from the document
+ SOAPBodyElement requestMessage = new SOAPBodyElement(
+ requestDocument.getDocumentElement());
+
+ // call on the end point
+ Object resultObject = call.invoke(new Object[] {
requestMessage });
+
+ // result object is a vector - strange!!! But this is
how the world
+ // works :-D
+ // we will now extract the result from the vector
+ SOAPBodyElement resultSBE;
+
+ try {
+
+ resultSBE = (SOAPBodyElement) ((Vector)
resultObject).get(0);
+
+ // change it to document - here is where
validity
+ // can be checked..
+ result = resultSBE.getAsDocument();
+
+ } catch (ClassCastException e) {
+ e.printStackTrace();
+ System.out
+
.println("SOAPClient.makeRequest: We didn't get a Vector of
SOAPBodyElements!");
+ } catch (Exception e) {
+ System.out
+
.println("SOAPClient.makeRequest: General exception while retrieving report");
+ e.printStackTrace();
+ }
+
+ } catch (Exception e) {
+ System.err
+ .println("SOAPClient.makeRequest:
General exception encountered by client");
+ e.printStackTrace();
+ }
+ return result;
+ }
+
public static void main(String[] args) {
SOAPClient doclitClient = new SOAPClient();
- perfsonar: r3256 - in trunk/perfsonar_base/src/main/java/org/perfsonar: base/util client/testHarness, svnlog, 01/19/2008
Archive powered by MHonArc 2.6.16.