X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FSOAP.java;h=1a279f4aa1721f900cbb7c88e62b25490848bce0;hb=ac822316ceb6f9a709901870bd1e2dc2974285e5;hp=4ea2d40392fa5450603a393055d2c13db670ed7b;hpb=3ea876879d32bb28b81d8a12f91323b636bb5199;p=org.ibex.core.git diff --git a/src/org/xwt/SOAP.java b/src/org/xwt/SOAP.java index 4ea2d40..1a279f4 100644 --- a/src/org/xwt/SOAP.java +++ b/src/org/xwt/SOAP.java @@ -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; @@ -164,25 +165,25 @@ class SOAP extends XMLRPC { if ((double)((Number)o).intValue() == ((Number)o).doubleValue()) { sb.append(" <" + name + " xsi:type=\"xsd:int\">"); sb.append(((Number)o).intValue()); - sb.append("\n"); + sb.append("\r\n"); } else { sb.append(" <" + name + " xsi:type=\"xsd:double\">"); sb.append(o); - sb.append("\n"); + sb.append("\r\n"); } } else if (o instanceof Boolean) { sb.append(" <" + name + " xsi:type=\"xsd:boolean\">"); sb.append(((Boolean)o).booleanValue() ? "true" : "false"); - sb.append("\n"); + sb.append("\r\n"); } else if (o instanceof ByteStream) { try { - sb.append(" <" + name + " xsi:type=\"SOAP-ENC:base64\">"); + sb.append(" <" + name + " xsi:type=\"SOAP-ENC:base64\">\r\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,11 +191,11 @@ class SOAP extends XMLRPC { System.arraycopy(buf, 0, writebuf, 0, numread); } sb.append(" "); - sb.append(Base64.encode(writebuf)); - sb.append("\n"); + sb.append(new String(Base64.encode(writebuf))); + sb.append("\r\n"); } sb.append(((Boolean)o).booleanValue() ? "1" : "0"); - sb.append("\n"); + sb.append("\r\n"); } catch (IOException e) { if (Log.on) Log.log(this, "caught IOException while attempting to send a ByteStream via SOAP"); if (Log.on) Log.log(this, e); @@ -218,14 +219,14 @@ class SOAP extends XMLRPC { i = oldi = i + 1; } } - sb.append("\n"); + sb.append("\r\n"); } else if (o instanceof NativeArray) { NativeArray na = (NativeArray)o; sb.append(" <" + name + " SOAP-ENC:arrayType=\"xsd:ur-type[" + na.jsGet_length() + "]\">"); for(int i=0; i\n"); + sb.append("\r\n"); } else if (o instanceof Scriptable && !(o instanceof Undefined)) { Scriptable s = (Scriptable)o; @@ -233,36 +234,37 @@ class SOAP extends XMLRPC { Object[] ids = s.getIds(); for(int i=0; i\n"); + sb.append("\r\n"); } } protected String send(Object[] args, HTTP http) throws JavaScriptException, IOException { // build up the request StringBuffer content = new StringBuffer(); - content.append("\n"); - content.append("\n"); - content.append("\n"); + content.append("SOAPAction: " + action + "\r\n\r\n"); + content.append("\r\n"); + content.append("\r\n"); + content.append("\r\n"); content.append(" <"); content.append(methodname); content.append(nameSpace != null ? " xmlns=\"" + nameSpace + "\"" : ""); - content.append(">\n"); + content.append(">\r\n"); if (args.length > 0) { Object[] o = ((Scriptable)args[0]).getIds(); for(int i=0; i"); - http.addHeader("SOAPAction", action); + content.append(" \r\n"); 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; }