- return call2(args);
- } catch (IOException se) {
- if (Log.on) Log.log(this, se);
- throw new JS.Exn("socket exception: " + se);
-
- } catch (JS.Exn jse) {
- if (Log.on) Log.log(this, jse.toString());
- throw jse;
- } finally {
- ThreadMessage.resumeThread();
- }
-
- }
-
- /** When you get a property from an XMLRPC, it just returns another XMLRPC with the property name tacked onto methodname. */
- public Object get(Object name) {
- return new XMLRPC(url, (methodname.equals("") ? "" : methodname + ".") + name.toString(), http);
- }
-
- public XMLRPC(String url, String methodname) {
- this(url, methodname, new HTTP(url));
- }
-
- public XMLRPC(String url, String methodname, HTTP http) {
- this.http = http;
- this.url = url;
- this.methodname = methodname;
- }
-
-
- // Helper Classes ///////////////////////////////////////////////////////////////////////////////////
-
- /** CharArrayWriter that lets us touch its buffer */
- protected static class AccessibleCharArrayWriter extends CharArrayWriter {
- public char[] getBuf() { return buf; }
- public AccessibleCharArrayWriter(int i) { super(i); }
- }
-
- /** private filter class to make sure that network transfers don't interfere with UI responsiveness */
- private static class Filter extends FilterInputStream {
- public Filter(InputStream is) { super(is); }
- public int read() throws IOException {
- java.lang.Thread.yield();
- while(Message.Q.nonThreadEventsInQueue > 0) try { java.lang.Thread.sleep(100); } catch (Exception e) { };
- return super.read();
- }
- public int read(byte[] b) throws IOException {
- java.lang.Thread.yield();
- while(Message.Q.nonThreadEventsInQueue > 0) try { java.lang.Thread.sleep(100); } catch (Exception e) { };
- return super.read(b);
- }
- public int read(byte[] b, int i, int j) throws IOException {
- java.lang.Thread.yield();
- while(Message.Q.nonThreadEventsInQueue > 0) try { java.lang.Thread.sleep(100); } catch (Exception e) { };
- return super.read(b, i, j);
+ if (Log.verbose) Log.info(this, "call to " + url + " : " + method);
+ String request = buildRequest(args);
+ if (Log.verbose) Log.info(this, "send:\n" + request);
+ InputStream is = http.POST("text/xml", request);
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));
+ if (tracker == null) tracker = new Hash();
+ if (objects == null) objects = new Vec();
+ try {
+ new Helper().parse(br);
+ final Object result = fault ? new JSExn(objects.elementAt(0)) : objects.size() == 0 ? null : objects.elementAt(0);
+ Scheduler.add(new Scheduler.Task() { public void perform() throws Exception { callback.unpause(result); }});
+ } finally {
+ tracker.clear();
+ objects.setSize(0);
+ }
+ } catch (final JSExn e) {
+ final Exception e2 = e;
+ Scheduler.add(new Scheduler.Task() { public void perform() throws Exception { callback.unpause(e2); }});
+ } catch (final IOException 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) {
+ final Exception e2 = e;
+ Scheduler.add(new Scheduler.Task() { public void perform() throws Exception { callback.unpause(new JSExn(e2)); }});