2002/08/18 05:30:45
[org.ibex.core.git] / src / org / xwt / SOAP.java
index 4ea2d40..3c3ed7d 100644 (file)
@@ -29,7 +29,7 @@ class SOAP extends XMLRPC {
 
     /** When you get a property from an SOAP, it just returns another SOAP with the property name tacked onto methodname. */
     public Object get(String name, Scriptable start) {
-        return new SOAP(url.toString(), (methodname.equals("") ? "" : methodname + ".") + name, action, nameSpace);
+        return new SOAP(url.toString(), (methodname.equals("") ? "" : methodname + ".") + name, http, action, nameSpace);
     }
 
 
@@ -37,6 +37,7 @@ class SOAP extends XMLRPC {
 
     public void startElement(String name, String[] keys, Object[] vals, int line, int col) {
 
+        content.reset();
         if (name.equals("SOAP-ENV:Envelope")) return;
         if (name.equals("SOAP-ENV:Body")) return;
         if (name.equals("SOAP-ENV:Fault")) fault = true;
@@ -178,11 +179,11 @@ class SOAP extends XMLRPC {
 
         } else if (o instanceof ByteStream) {
             try {
-                sb.append("                <" + name + " xsi:type=\"SOAP-ENC:base64\">");
+                sb.append("                <" + name + " xsi:type=\"SOAP-ENC:base64\">\n");
                 InputStream is = ((ByteStream)o).getInputStream();
-                byte[] buf = new byte[96];
+                byte[] buf = new byte[54];
                 while(true) {
-                    int numread = is.read(buf, 0, 96);
+                    int numread = is.read(buf, 0, 54);
                     if (numread == -1) break;
                     byte[] writebuf = buf;
                     if (numread < buf.length) {
@@ -190,7 +191,7 @@ class SOAP extends XMLRPC {
                         System.arraycopy(buf, 0, writebuf, 0, numread);
                     }
                     sb.append("              ");
-                    sb.append(Base64.encode(writebuf));
+                    sb.append(new String(Base64.encode(writebuf)));
                     sb.append("\n");
                 }
                 sb.append(((Boolean)o).booleanValue() ? "1" : "0");
@@ -240,6 +241,7 @@ class SOAP extends XMLRPC {
     protected String send(Object[] args, HTTP http) throws JavaScriptException, IOException {
         // build up the request
         StringBuffer content = new StringBuffer();
+        content.append("SOAPAction: " + action + "\r\n\r\n");
         content.append("<?xml version=\"1.0\"?>\n");
         content.append("<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\n");
         content.append("                   xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\n");
@@ -257,12 +259,12 @@ class SOAP extends XMLRPC {
                 appendObject(o[i].toString(), ((Scriptable)args[0]).get(o[i].toString(), (Scriptable)args[0]), content);
         }
         content.append("    </" + methodname + "></SOAP-ENV:Body></SOAP-ENV:Envelope>");
-        http.addHeader("SOAPAction", action);
         return content.toString();
     }
 
-    SOAP(String url, String methodname, String action, String nameSpace) {
-        super(url, methodname);
+    SOAP(String url, String methodname, String action, String nameSpace) { this(url, methodname, new HTTP(url), action, nameSpace); }
+    SOAP(String url, String methodname, HTTP http, String action, String nameSpace) {
+        super(url, methodname, http);
         this.action = action;
         this.nameSpace = nameSpace;
     }