Author: keith
Date: Thu Feb 7 15:37:54 2008
New Revision: 13413
Log:
Sleanin up the getXML implementation
Modified:
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/SystemHostObject.java
Modified:
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/SystemHostObject.java
==============================================================================
---
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/SystemHostObject.java
(original)
+++
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/system/SystemHostObject.java
Thu Feb 7 15:37:54 2008
@@ -750,18 +750,9 @@
InputStream in = httpCon.getInputStream();
int code = httpCon.getResponseCode();
if (code == HttpURLConnection.HTTP_OK) {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int c;
- while ((c = in.read(buffer)) != -1) {
- bos.write(buffer, 0, c);
- }
- String str = new String(bos.toByteArray());
- if (str.startsWith("<?")) {
- str = str.substring(str.indexOf("?>")+2);
- }
- Object[] objects = {str};
- httpCon.disconnect();
+ StAXOMBuilder staxOMBuilder = new StAXOMBuilder(in);
+ OMElement omElement = staxOMBuilder.getDocumentElement();
+ Object[] objects = {omElement};
return context.newObject(thisObj, "XML", objects);
} else {
httpCon.disconnect();
@@ -772,6 +763,9 @@
throw new MashupFault(e);
} catch (IOException e) {
throw new MashupFault(e);
- }
+ } catch (XMLStreamException e) {
+ throw new MashupFault("Could not get the convert the content of "
+ urlString + " to XML. You may have " +
+ "to use the scraper object to get this url and tidy it");
+ }
}
}
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev