} else if (me instanceof byte[]) {
objects.removeElementAt(objects.size() - 1);
- objects.addElement(new String(Base64.decode(new String(content.getBuf(), 0, content.size()))));
+ objects.addElement(new ByteStream(Base64.decode(new String(content.getBuf(), 0, content.size()))));
content.reset();
} else if (me instanceof Integer) {
}
/** Appends the SOAP representation of <code>o</code> to <code>sb</code> */
- void appendObject(String name, Object o, StringBuffer sb) {
+ void appendObject(String name, Object o, StringBuffer sb) throws JavaScriptException {
if (o instanceof Number) {
if ((double)((Number)o).intValue() == ((Number)o).doubleValue()) {
sb.append(" <" + name + " xsi:type=\"xsd:int\">");
sb.append(((Boolean)o).booleanValue() ? "true" : "false");
sb.append("</" + name + ">\n");
+ } else if (o instanceof ByteStream) {
+ try {
+ sb.append(" <" + name + " xsi:type=\"SOAP-ENC:base64\">\n");
+ InputStream is = ((ByteStream)o).getInputStream();
+ byte[] buf = new byte[54];
+ while(true) {
+ int numread = is.read(buf, 0, 54);
+ if (numread == -1) break;
+ byte[] writebuf = buf;
+ if (numread < buf.length) {
+ writebuf = new byte[numread];
+ System.arraycopy(buf, 0, writebuf, 0, numread);
+ }
+ sb.append(" ");
+ sb.append(new String(Base64.encode(writebuf)));
+ sb.append("\n");
+ }
+ sb.append(((Boolean)o).booleanValue() ? "1" : "0");
+ sb.append("</" + name + ">\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);
+ throw new JavaScriptException("caught IOException while attempting to send a ByteStream via SOAP");
+ }
+
} else if (o instanceof String) {
sb.append(" <" + name + " xsi:type=\"xsd:string\">");
String s = (String)o;
}
}
- protected String send(Object[] args, HTTP http) throws JavaScriptException {
+ protected String send(Object[] args, HTTP http) throws JavaScriptException, IOException {
// build up the request
StringBuffer content = new StringBuffer();
content.append("<?xml version=\"1.0\"?>\n");