2004/01/13 10:27:47
[org.ibex.core.git] / src / org / xwt / XMLRPC.java
index a5ef850..2bb107c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
+// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
 package org.xwt;
 
 import java.io.*;
@@ -39,9 +39,9 @@ class XMLRPC extends JS {
 
     /** this holds character content as we read it in -- since there is only one per instance, we don't support mixed content */
     protected AccessibleCharArrayWriter content = new AccessibleCharArrayWriter(100);
-    protected String url = null;       ///< the url to connect to
-    protected String method = null;    ///< the method name to invoke on the remove server
-    protected HTTP http = null;        ///< the HTTP connection to use
+    protected String url = null;         ///< the url to connect to
+    protected String method = null;      ///< the method name to invoke on the remove server
+    protected HTTP http = null;          ///< the HTTP connection to use
     private Hash tracker;                ///< used to detect multi-ref data
     protected boolean fault = false;     ///< True iff the return value is a fault (and should be thrown as an exception)
 
@@ -92,8 +92,9 @@ class XMLRPC extends JS {
             case "boolean": objects.setElementAt(content.getBuf()[0] == '1' ? Boolean.TRUE : Boolean.FALSE, objects.size() - 1);
             case "string": objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1);
             case "double": objects.setElementAt(new Double(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
-            case "base64": objects.setElementAt(new Res.ByteArray(Base64.decode(new String(content.getBuf(), 0, content.size())),
-                                                                  null), objects.size() - 1);
+            case "base64":
+                objects.setElementAt(new Stream.ByteArray(Base64.decode(new String(content.getBuf(), 0, content.size())),
+                                                          null), objects.size() - 1);
             case "name": objects.addElement(new String(content.getBuf(), 0, content.size()));
             case "value": if ("".equals(objects.lastElement()))
                 objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1);
@@ -108,19 +109,19 @@ class XMLRPC extends JS {
                 try {
                     JSDate nd = new JSDate();
                     double date = JSDate.date_msecFromDate(Double.valueOf(s.substring(0, 4)).doubleValue(),
-                                                                    Double.valueOf(s.substring(4, 6)).doubleValue() - 1,
-                                                                    Double.valueOf(s.substring(6, 8)).doubleValue(),
-                                                                    Double.valueOf(s.substring(9, 11)).doubleValue(),
-                                                                    Double.valueOf(s.substring(12, 14)).doubleValue(),
-                                                                    Double.valueOf(s.substring(15, 17)).doubleValue(),
-                                                                    (double)0
-                                                                    );
+                                                           Double.valueOf(s.substring(4, 6)).doubleValue() - 1,
+                                                           Double.valueOf(s.substring(6, 8)).doubleValue(),
+                                                           Double.valueOf(s.substring(9, 11)).doubleValue(),
+                                                           Double.valueOf(s.substring(12, 14)).doubleValue(),
+                                                           Double.valueOf(s.substring(15, 17)).doubleValue(),
+                                                           (double)0
+                                                           );
                     nd.setTime(JSDate.internalUTC(date));
                     objects.setElementAt(nd, objects.size() - 1);
                     
                 } catch (Exception e) {
-                    if (Log.on) Log.log(this, "error parsing date : " + s);
-                    if (Log.on) Log.log(this, e);
+                    throw new RuntimeException("xwt.net.rpc.xml.recieve.malformedDateTag" +
+                                    "the server sent a <dateTime.iso8601> tag which was malformed: " + s);
                 }
             case "member":
                 Object memberValue = objects.elementAt(objects.size() - 1);
@@ -150,8 +151,8 @@ class XMLRPC extends JS {
         public void characters(char[] ch, int start, int length) {
             try { content.write(ch, start, length); }
             catch (Exception e) { 
-                if (Log.on) Log.log(this, "Exception in XMLRPC.content() -- this should never happen");
-                if (Log.on) Log.log(this, e);
+                if (Log.on) Log.info(this, "Exception in XMLRPC.content() -- this should never happen");
+                if (Log.on) Log.info(this, e);
             }
         }
         
@@ -201,10 +202,10 @@ class XMLRPC extends JS {
             sb.append(((Boolean)o).booleanValue() ? "1" : "0");
             sb.append("</boolean></value>\n");
 
-        } else if (o instanceof Res) {
+        } else if (o instanceof Stream) {
             try {
                 sb.append("                <value><base64>\n");
-                InputStream is = ((Res)o).getInputStream();
+                InputStream is = ((Stream)o).getInputStream();
                 byte[] buf = new byte[54];
                 while(true) {
                     int numread = is.read(buf, 0, 54);
@@ -220,8 +221,8 @@ class XMLRPC extends JS {
                 }
                 sb.append("\n              </base64></value>\n");
             } catch (IOException e) {
-                if (Log.on) Log.log(this, "caught IOException while attempting to send a ByteStream via XML-RPC");
-                if (Log.on) Log.log(this, e);
+                if (Log.on) Log.info(this, "caught IOException while attempting to send a ByteStream via XML-RPC");
+                if (Log.on) Log.info(this, e);
                 throw new JSExn("caught IOException while attempting to send a ByteStream via XML-RPC");
             }
 
@@ -313,12 +314,11 @@ class XMLRPC extends JS {
 
     final void call(final JS.UnpauseCallback callback, final JSArray args) {
         try {
-            if (Log.verbose) Log.log(this, "call to " + url + " : " + method);
+            if (Log.verbose) Log.info(this, "call to " + url + " : " + method);
             String request = buildRequest(args);
-            if (Log.verbose) Log.log(this, "send:\n" + request);
+            if (Log.verbose) Log.info(this, "send:\n" + request);
             InputStream is = http.POST("text/xml", request);
             BufferedReader br = new BufferedReader(new InputStreamReader(is));
-            if (Log.verbose) br = Log.loggedReader(br);
             if (tracker == null) tracker = new Hash();
             if (objects == null) objects = new Vec();
             try {
@@ -330,11 +330,14 @@ class XMLRPC extends JS {
                 objects.setSize(0);
             }
         } catch (final JSExn e) {
-            Scheduler.add(new Scheduler.Task() { public void perform() throws Exception { callback.unpause(e); }});
+            final Exception e2 = e;
+            Scheduler.add(new Scheduler.Task() { public void perform() throws Exception { callback.unpause(e2); }});
         } catch (final IOException e) {
-            Scheduler.add(new Scheduler.Task() { public void perform() throws Exception { callback.unpause(new JSExn(e)); }});
+            final Exception e2 = e;
+            Scheduler.add(new Scheduler.Task() { public void perform() throws Exception { callback.unpause(new JSExn(e2)); }});
         } catch (final XML.Exn e) {
-            Scheduler.add(new Scheduler.Task() { public void perform() throws Exception { callback.unpause(new JSExn(e)); }});
+            final Exception e2 = e;
+            Scheduler.add(new Scheduler.Task() { public void perform() throws Exception { callback.unpause(new JSExn(e2)); }});
         }
     }
 }