Talking XMLRPC to a Wordpress instance
This is a short example demonstration how to use the Apache XMLRPC library to talk to a running Wordpress instance.
Wordpress 1.5 supports various XMLRPC operations by default ( MT & Blogger APIs for example ) however the two shown below are "demo" operations that all Wordpress installations should support and require no authentication.
To run this example you will need to include the dependencies - Apache XMLRPC & Jakarta COMMONS Codec - however if you are lazy, here is my "xmlrpc-2.0-dep.jar" JAR containing both.
Code
import java.util.Vector;
import org.apache.xmlrpc.XmlRpcClient;
public class XMLRPCTest {
/**
* @param args
*/
public static void main(String[] args) {
try {
Object result;
/* You can specify an alternative target URL here */
XmlRpcClient xmlrpc = new XmlRpcClient ("http://blog.lobstertechnology.com/xmlrpc");
/*
* demo.sayHello operation, returns a java.lang.String
*
*/
result = xmlrpc.execute( "demo.sayHello", new Vector() );
System.out.println( "demo.sayHello: " + result +
" (" + result.getClass().getName() + ")" );
/*
* demo.addTwoNumbers operation, returns a java.lang.Integer
*
*/
Vector params = new Vector ();
params.addElement ("5");
params.addElement ("8");
result = xmlrpc.execute( "demo.addTwoNumbers", params );
System.out.println( "demo.addTwoNumbers: " + result +
" (" + result.getClass().getName() + ")" );
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
Example
demo.sayHello: Hello! (java.lang.String)
demo.addTwoNumbers: 13 (java.lang.Integer)
Related Links
XMLRPCTest.java - Java Source Code
xmlrpc-2.0-dep.jar - Dependencies
Apache XMLRPC - http://ws.apache.org/xmlrpc/
Jakarta COMMONS Codec - http://jakarta.apache.org/commons/codec/
About this entry
You’re currently reading “Talking XMLRPC to a Wordpress instance,” an entry on Weblog of Michael Cutler
- Published:
- 14th November 2005 / 2:11pm
Related Entries
- Upgrading to Wordpress 2.0
20th December 2005 - More thoughts on SpamKit…
16th December 2005 - Changes in Wordpress 1.5.2
15th August 2005 - Wordpress Hack » Inserting rel nofollow on links in all categories…
1st December 2005 - Wordpress Hack » Reading MySQL username & password from wp-config.php
24th January 2006
No comments
Jump to comment form | comments rss [?] | trackback uri [?]