Testopia:Documentation:XMLRPC:Java XMLRPC Struct Passing

From MozillaWiki
Jump to navigation Jump to search

xmlrpc2 doesn't want to mess about with any of the new-fangled Java Collections stuff (i.e. HashMap, TreeMap), but rather sticks with the older Hashtable and Vector classes. If you try to pass in newer collection classes to XmlRpcClient.execute(), you will get an XmlRpcException about failure to write request and/or unsupported class type. here's a simple code snippet showing how to pass in mapped values, and then extract them:

Hashtable<String,Object> query = new Hashtable<String,Object>();
Vector<Object> params = new Vector<Object>();

query.put("plan_id", plan_id);
query.put("planidtype", "equals");
query.put("case_status_id", case_status);
query.put("isautomated", is_automated);

params.add(query);
		
Vector<Hashtable<String,Object>> xmlrpc_result;
xmlrpc_result = (Vector)(client.execute("TestCase.list", params));

for (Hashtable<String,Object> testcase : xmlrpc_result)
{
    System.out.println("case_id", (Integer)testcase.get("case_id"));
    ...
}

Generally speaking, it seems to be the case that you are always passing in a Vector, which either contains Integers or a Hashmap of key/value pairs. And the response from the server seems to follow the same pattern.