- final String content = send(args, http);
- if (Log.verbose) {
- String s;
- BufferedReader br2 = new BufferedReader(new StringReader(content));
- while ((s = br2.readLine()) != null) Log.log(this, "send: " + s);
- }
-
- InputStream is = http.POST("text/xml", content);
- try {
- BufferedReader br = !Log.verbose ?
- new BufferedReader(new InputStreamReader(is)) :
- new BufferedReader(new FilterReader(new InputStreamReader(is)) {
- public int read() throws IOException {
- int i = super.read();
- if (Log.on) Log.log(this, "recv: " + ((char)i));
- return i;
- }
- public int read(char[] c, int off, int len) throws IOException {
- int ret = super.read(c, off, len);
- if (ret == -1) return ret;
- String s;
- BufferedReader br2 = new BufferedReader(new StringReader(new String(c, off, ret)));
- while ((s = br2.readLine()) != null) Log.log(this, "recv: " + s);
- return ret;
- }
- });
- return null;
- } finally {
- is.close();
- }
- }
-
- protected String send(JSArray args, HTTP http) throws JSExn, IOException {
- StringBuffer content = new StringBuffer();
- content.append("\r\n");
- content.append("<?xml version=\"1.0\"?>\n");
- content.append(" <methodCall>\n");
- content.append(" <methodName>");
- content.append(methodname);
- content.append("</methodName>\n");
- content.append(" <params>\n");
- for(int i=0; i<args.length(); i++) {
- content.append(" <param>\n");
- appendObject(args.elementAt(i), content);
- content.append(" </param>\n");
- }
- content.append(" </params>\n");
- content.append(" </methodCall>");
- return content.toString();
- }
-
- protected Object recieve(BufferedReader br) throws JSExn, IOException {
- // parse XML reply
- try {
- new Helper().parse(br);
- } catch (XML.XMLException e) {
- if (Log.on) Log.log(this, "reply from server was not well-formed XML: " + e);
- throw new JSExn("reply from server was not well-formed XML: " + e);
- }
-
- if (fault) throw new JSExn(objects.elementAt(0));
- if (objects.size() == 0) return null;
- return objects.elementAt(0);
- }