Revision: 4777
http://sourceforge.net/p/vexi/code/4777
Author: mkpg2
Date: 2015-03-28 23:02:52 +0000 (Sat, 28 Mar 2015)
Log Message:
-----------
Fix/Improve. Allow sending of multi reference structures via xmlrpc. Just check
whether there is a cyclical reference or not.
Modified Paths:
--------------
branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/XMLRPC.jpp
branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/rpc/xmlrpc/TestXmlRpc.java
branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/rpc/xmlrpc/serverException.js
Added Paths:
-----------
branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/rpc/xmlrpc/cyclic.js
Modified: branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/XMLRPC.jpp
===================================================================
--- branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/XMLRPC.jpp
2015-03-04 14:33:50 UTC (rev 4776)
+++ branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/XMLRPC.jpp
2015-03-28 23:02:52 UTC (rev 4777)
@@ -80,7 +80,7 @@
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
+ private IdentityHashMap 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)
@@ -310,37 +310,43 @@
sb.append("</dateTime.iso8601></value>\n");
} else if (o instanceof JSArray) {
- if (tracker.get(o) != null) {
- throw new JSExn("attempted to send multi-ref data structure
via XML-RPC");
- }
+ if (tracker.containsKey(o)) throw new JSExn("attempted to send
cyclical data structure via XML-RPC");
+
tracker.put(o, JSU.T);
- sb.append(" <value><array><data>\n");
- JSArray a = (JSArray)o;
- for (int i=0; i < a.size(); i++) {
- appendObject((JS)a.get(i), sb);
+ try{
+ sb.append(" <value><array><data>\n");
+ JSArray a = (JSArray)o;
+ for (int i=0; i < a.size(); i++) {
+ appendObject((JS)a.get(i), sb);
+ }
+ sb.append(" </data></array></value>\n");
+ }finally{
+ tracker.remove(o);
}
- sb.append(" </data></array></value>\n");
} else {
- if (tracker.get(o) != null) {
- throw new JSExn("attempted to send multi-ref data structure
via XML-RPC");
- }
+ if (tracker.containsKey(o)) throw new JSExn("attempted to send
cyclical data structure via XML-RPC");
+
tracker.put(o, JSU.T);
- JS j = (JS)o;
- sb.append(" <value><struct>\n");
- Enumeration e = null;
try{
- e = j.keys().iterator();
- }catch(JSExn ee){
- throw new JSExn("Cannot serialise: "+JSU.toString(j));
+ JS j = (JS)o;
+ sb.append(" <value><struct>\n");
+ Enumeration e = null;
+ try{
+ e = j.keys().iterator();
+ }catch(JSExn ee){
+ throw new JSExn("Cannot serialise: "+JSU.toString(j));
+ }
+ while (e.hasNext()) {
+ Object key = e.next();
+ sb.append(" <member><name>" + key +
"</name>\n");
+ appendObject(j.get((JS)key), sb);
+ sb.append(" </member>\n");
+ }
+ sb.append(" </struct></value>\n");
+ }finally{
+ tracker.remove(o);
}
- while (e.hasNext()) {
- Object key = e.next();
- sb.append(" <member><name>" + key +
"</name>\n");
- appendObject(j.get((JS)key), sb);
- sb.append(" </member>\n");
- }
- sb.append(" </struct></value>\n");
}
}
@@ -364,7 +370,7 @@
final JS doCall(final JSArray args) throws JSExn {
try{
if (logger.isDebug()) logger.debug(LOG_TYPE, "call to " + url + "
: " + method);
- if (tracker == null) tracker = new HashMap();
+ if (tracker == null) tracker = new IdentityHashMap();
if (objects == null) objects = new Basket.Array();
String request = buildRequest(args);
if (logger.isDebug()) logger.debug(LOG_TYPE, "send:\n" + request);
Modified:
branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/rpc/xmlrpc/TestXmlRpc.java
===================================================================
---
branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/rpc/xmlrpc/TestXmlRpc.java
2015-03-04 14:33:50 UTC (rev 4776)
+++
branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/rpc/xmlrpc/TestXmlRpc.java
2015-03-28 23:02:52 UTC (rev 4777)
@@ -2,6 +2,7 @@
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.List;
import java.util.Map;
import java.util.Vector;
@@ -45,7 +46,7 @@
Object r =
xmlrpc.execute("testServer.stringWithEmptyline", params);
System.out.println(r);*/
- RunJS.runJSFile(directory, "reuse.js");
+ RunJS.runJSFile(directory, "cyclic.js");
}finally{
testwebserver.shutdown();
}
@@ -106,7 +107,12 @@
////////////////////////////////////////////////////////////
static public class TestServer{
+
+ public Object identity(List o) throws XmlRpcException{
+ return o;
+ }
+
public Integer addOne(int arg) throws XmlRpcException{
return new Integer(arg + 1);
}
@@ -141,7 +147,7 @@
}
public String strangeChars(String chars){
- //Assert.assertEquals("$%\xA3",chars);
+ //Assert.assertEquals("$%�",chars);
return chars;
}
Added:
branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/rpc/xmlrpc/cyclic.js
===================================================================
---
branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/rpc/xmlrpc/cyclic.js
(rev 0)
+++
branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/rpc/xmlrpc/cyclic.js
2015-03-28 23:02:52 UTC (rev 4777)
@@ -0,0 +1,21 @@
+
+sys.import("lib");
+
+var obj = {a:"x"};
+var arr = [obj,obj];
+
+var xmlrpc = getServer();
+xmlrpc.identity(arr);
+
+
+obj["b"] = obj;
+
+var exn = true;
+try{
+ xmlrpc.identity(obj);
+ exn = false;
+}catch(e){
+ sys.log.info(e.message);
+}
+
+if(!exn) throw "Expected exn for sending cyclical data";
\ No newline at end of file
Property changes on:
branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/rpc/xmlrpc/cyclic.js
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified:
branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/rpc/xmlrpc/serverException.js
===================================================================
---
branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/rpc/xmlrpc/serverException.js
2015-03-04 14:33:50 UTC (rev 4776)
+++
branches/vexi3/org.vexi-library.js/src/test/java/test/js/exec/rpc/xmlrpc/serverException.js
2015-03-28 23:02:52 UTC (rev 4777)
@@ -2,7 +2,7 @@
try{
var xmlrpc = getServer();
- var r = xmlrpc.thowsException();
+ var r = xmlrpc.throwsException();
assert(false);
}
catch(e){
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn