Revision: 3984 http://vexi.svn.sourceforge.net/vexi/?rev=3984&view=rev Author: clrg Date: 2010-12-21 13:33:27 +0000 (Tue, 21 Dec 2010)
Log Message: ----------- Add optional encoding - vexi.net.rpc.xml(server_url, encoding) where encoding defaults to UTF-8 - send requests now include encoding in the <?xml?> header - actually some of this slipped in the last commit so previous revision doesn't build (oops) Modified Paths: -------------- trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/XMLRPC.jpp Modified: trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp =================================================================== --- trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp 2010-12-21 03:55:55 UTC (rev 3983) +++ trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp 2010-12-21 13:33:27 UTC (rev 3984) @@ -738,6 +738,7 @@ case 2: //#switch(JSU.toString(method)) case "regexp": return new JSRegexp(args[0], args[1]); + case "net.rpc.xml": return new XMLRPC(Log.rpc, JSU.toString(args[0]), "", args[1]); //#end break; case 3: Modified: trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/XMLRPC.jpp =================================================================== --- trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/XMLRPC.jpp 2010-12-21 03:55:55 UTC (rev 3983) +++ trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/XMLRPC.jpp 2010-12-21 13:33:27 UTC (rev 3984) @@ -37,19 +37,26 @@ */ public class XMLRPC extends JS.Immutable implements Constants { final Logger logger; - public XMLRPC(Logger logger, String url, String encoding, String method) throws JSExn { + static final String LOG_TYPE = "- XMLRPC -"; + + public XMLRPC(Logger logger, String url, String method) throws JSExn { this(logger, url, method, "UTF-8"); } + public XMLRPC(Logger logger, String url, String method, String encoding) throws JSExn { try { this.logger = logger; this.http = HTTPFactory.create(logger,url); this.url = url; this.method = method; this.encoding = encoding; - } catch(IOException e) { + } catch (IOException e) { throw new JSExn(e.getMessage()); } } public XMLRPC(String url, String method, XMLRPC httpSource) { - this.logger = httpSource.logger; this.http = httpSource.http; this.url = url; this.method = method; + this.encoding = httpSource.encoding; + this.logger = httpSource.logger; + this.http = httpSource.http; + this.url = url; + this.method = method; } public JS get(JS name) throws JSExn { return new XMLRPC(url, (method.equals("") ? "" : method + ".") + JSU.toString(name), this); @@ -60,17 +67,16 @@ protected PublicCharArrayWriter content = new PublicCharArrayWriter(100); public static final class PublicCharArrayWriter extends CharArrayWriter { public PublicCharArrayWriter(int i) { super(i); } - public char[] getBuf(){return buf;} + public char[] getBuf() { return buf; } }; + protected String url = null; ///< the url to connect to - protected String method = null; ///< the method name to invoke on the remove server - protected String encoding = "UTF-8"; + protected String method = null; ///< the method name to invoke on the remote server + protected String encoding = null; ///< encoding of the data sent by the server protected HTTP http; ///< the HTTP connection to use private HashMap tracker; ///< used to detect multi-ref data protected boolean fault = false; ///< True iff the return value is a fault (and should be thrown as an exception) - - static final String LOG_TYPE = "- XMLRPC -"; /** @@ -122,11 +128,12 @@ case "boolean": setLast(content.getBuf()[0] == '1' ? JSU.T : JSU.F); case "string": setLast(JSU.S(new String(content.getBuf(), 0, content.size()))); case "double": setLast(JSU.N(Double.parseDouble(new String(content.getBuf(), 0, content.size())))); - case "base64": - setLast(new Fountain.ByteArray(Encode.fromBase64(new String(content.getBuf(), 0, content.size())))); + case "base64": setLast(new Fountain.ByteArray(Encode.fromBase64(new String(content.getBuf(), 0, content.size())))); case "name": objects.add(JSU.S(new String(content.getBuf(), 0, content.size()))); - case "value": if ("".equals(objects.peek())) - setLast(JSU.S(new String(content.getBuf(), 0, content.size()))); + case "value": + if ("".equals(objects.peek())) { + setLast(JSU.S(new String(content.getBuf(), 0, content.size()))); + } case "dateTime.iso8601": String s = new String(content.getBuf(), 0, content.size()); @@ -166,9 +173,7 @@ case "data": // Find last null placeholder in stack int i = objects.size() - 1; - while (objects.get(i) != ARRAY_MARKER) { - i-- - } + while (objects.get(i) != ARRAY_MARKER) i--; JSArray arr = new JSArray(); try { for (int j = objects.size()-i-2; j>=0; j--) { @@ -195,7 +200,7 @@ protected String buildRequest(JSArray args) throws JSExn, IOException { StringBuffer content = new StringBuffer(); - content.append("<?xml version=\"1.0\"?>\n"); + content.append("<?xml version=\"1.0\" encoding=\""+encoding+"\"?>\n"); content.append(" <methodCall>\n"); content.append(" <methodName>"); content.append(method); @@ -219,16 +224,15 @@ //throw new JSExn("attempted to send a null value via XML-RPC"); sb.append(" <value><nil/></value>"); } else if (o instanceof JSNumber) { - if(JSU.isInt((JS) o)){ + if (JSU.isInt((JS) o)) { sb.append(" <value><i4>"); sb.append(((JSNumber)o).toInt()); sb.append("</i4></value>\n"); - }else if(o instanceof JSNumber.B){ + } else if (o instanceof JSNumber.B) { sb.append(" <value><boolean>"); sb.append(((JSNumber)o).toBoolean() ? "1" : "0"); sb.append("</boolean></value>\n"); - } - else { + } else { sb.append(" <value><double>"); sb.append(((JSNumber)o).toDouble()); sb.append("</double></value>\n"); @@ -355,7 +359,7 @@ final Object doCall(final JSArray args) { - try{ + try { if (logger.isDebug()) logger.debug(LOG_TYPE, "call to " + url + " : " + method); if (tracker == null) tracker = new HashMap(); if (objects == null) objects = new Basket.Array(); @@ -426,7 +430,7 @@ this.logger = logger; } - private void setTagSense(int s){ + private void setTagSense(int s) { lastTagsense = tagsense; tagsense = s; } @@ -446,9 +450,9 @@ } else { if (c=='?' && lastc == '<') { setTagSense(0); - } else if(c=='/' && lastc == '<') { + } else if (c=='/' && lastc == '<') { setTagSense(-1); - } else if(c=='>') { + } else if (c=='>') { if (lastc =='/') { setTagSense(tagsense); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Lotusphere 2011 Register now for Lotusphere 2011 and learn how to connect the dots, take your collaborative environment to the next level, and enter the era of Social Business. http://p.sf.net/sfu/lotusphere-d2d _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn