Re: XML-RPC Java Call
Stefan Kreutter <[email protected]>
| Newsgroups | gmane.comp.cms.opengroupware.xmlrpc.devel |
|---|---|
| Message-ID | <[email protected]> |
On 18.08.2004, at 00:32, Christoph Guse wrote:
> Hello,
>
> i want to write my diploma thesis about Macromedia Flex and
> OpenGroupware. Further information can be found on
> http://guse.conquer.de .
> In order to provide Ogo Data to Macromedia Flex i want to use Java and
> XML-RPC. Today i managed to configure the Ogo server properly, so
> simple XML-RPC calls work fine. But i'm not able to execute a more
> complex call like person.fetch, because i'm not able to give over the
> complex argument. The example i found in the xml-rpc-de.pfd is for
> python.
> I found the JOGI project, but i'm probably forced to make my own
> interface. Can you guys give me a little piece of code where i can
> learn the correct give over of the complex arguments?
Using Apache's XmlRpcClient (http://ws.apache.org/xmlrpc/) it should
work like this:
public static void main(String[] args) throws IOException,
XmlRpcException {
XmlRpcClient xmlRpcClient = new
XmlRpcClient("http://myogoserver:8050/RPC2");
xmlRpcClient.setBasicAuthentication("root", "ogo");
Hashtable fetchSpec = new Hashtable();
String qualifier = "name = 'root'";
fetchSpec.put("qualifier", qualifier);
Vector sortOrdering = new Vector();
sortOrdering.add("name");
fetchSpec.put("sortOrdering", sortOrdering);
Vector params = new Vector();
params.add(fetchSpec);
Object result = xmlRpcClient.execute("person.fetch", params);
System.out.println("Result class: " + result.getClass());
System.out.println("Result: " + result);
}
The output should look like this:
Result class: class java.util.Vector
Result: [{isAccount=true, url=, name=root,
id=skyrix://myogoserver/Sx_hampton/300750, phones={02_tel={type=02_tel,
number=, info=, telephoneId=300810}, 03_tel_funk={type=03_tel_funk,
number=, info=, telephoneId=300820}, 10_fax={type=10_fax, number=,
info=, telephoneId=300840}, 15_fax_private={type=15_fax_private,
number=, info=, telephoneId=300850}, 01_tel={type=01_tel, number=,
info=, telephoneId=300800}, 05_tel_private={type=05_tel_private,
number=, info=, telephoneId=300830}}, owner={}, phoneTypes=[01_tel,
02_tel, 03_tel_funk, 05_tel_private, 10_fax, 15_fax_private],
number=SKY300750, addresses={location={type=location,
id=skyrix://myogoserver/Sx_hampton/300790}, private={type=private,
id=skyrix://myogoserver/Sx_hampton/300770}, mailing={type=mailing,
id=skyrix://myogoserver/Sx_hampton/300780}}, isPrivate=false,
extendedKeys=[email1, email2, email3, job_title, other_title1,
other_title2], login=root, extendedAttrs={}, objectVersion=2,
isComplete=true}]
Apache's XmlRpcClient wants a list of parameters encoded in a
java.util.Vector even if you only one parameter. The person.fetch
XMLRPC needs a FetchSpecification as a 'struct' which is represented in
Apache's XmlRpcClient as a java.util.Hashtable (see:
http://ws.apache.org/xmlrpc/types.html). There you have to put a
qualifier (String) and optional a sortordering.
If you use "name like 's*'" as qualifier you'll get all persons with a
name starting with s sorted by name.
Hope this helps.
-Stefan
smime.p7s
(application/pkcs7-signature, 2.1 KB) - not displayed