Author: keith
Date: Tue Sep  2 07:01:14 2008
New Revision: 21345
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=21345

Log:
Fixing Mashup-1102. The issue was that we had used responceXML.toString() but 
with JSON you need to use toStringWithConsume() instead


Modified:
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java?rev=21345&r1=21344&r2=21345&view=diff
==============================================================================
--- 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java
      (original)
+++ 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java
      Tue Sep  2 07:01:14 2008
@@ -18,6 +18,7 @@
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axis2.AxisFault;
@@ -849,9 +850,24 @@
      * Getter for the responseText property. The raw text representing the XML 
(or non-XML) response.
      * If the responseXML property is empty, you can check the responseText 
property to see if a non-XML response was received.
      */
-    public String jsGet_responseText() {
+    public String jsGet_responseText() throws MashupFault {
         if (responseText == null && responseXML != null) {
-            responseText = responseXML.toString();
+
+            // If the response is something like JSON calling toString on it 
wont work. We need to
+            // call toStringWithConsume instead, the following checks are 
checking for this
+            // condition.
+            if (responseXML instanceof OMSourcedElementImpl) {
+                OMSourcedElementImpl sourcedElement = (OMSourcedElementImpl) 
responseXML;
+                if (sourcedElement.getDataSource() != null) {
+                    try {
+                        responseText = sourcedElement.toStringWithConsume();
+                    } catch (XMLStreamException e) {
+                        throw new MashupFault(e);
+                    }
+                }
+            } else {
+                responseText = responseXML.toString();
+            }
         }
         return responseText;
     }
@@ -860,7 +876,11 @@
      * Getter for the responseE4X property.
      * The parsed E4X XML message representing the response from the service.
      */
-    public Scriptable jsGet_responseE4X() {
+    public Scriptable jsGet_responseE4X() throws MashupFault {
+        if (responseXML instanceof OMSourcedElementImpl) {
+            throw new MashupFault("The response is not in an XML format. 
Please try using " +
+                    "responseText instead");
+        }
         if (responseXML != null) {
             Object[] objects = { responseXML };
             return context.newObject(this, "XML", objects);
@@ -873,7 +893,11 @@
      * The parsed XML message representing the response from the service.
      * Currently we return an E4X object. But ideally this needs to be a DOM.
      */
-    public Scriptable jsGet_responseXML() {
+    public Scriptable jsGet_responseXML() throws MashupFault {
+        if (responseXML instanceof OMSourcedElementImpl) {
+            throw new MashupFault("The response is not in an XML format. 
Please try using " +
+                    "responseText instead");
+        }
         if (responseXML != null) {
             Object[] objects = { responseXML };
             return context.newObject(this, "XML", objects);

_______________________________________________
Mashup-dev mailing list
[email protected]
http://mailman.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to