Web services are all the rage today so I figured that I would try to figure some of that stuff out since they're very popular around here in Northern Virginia. So I got to playing around with some XML-RPC stuff today. I figured that since my blog software already exports some functions, that I would take advantage of that for testing some stuff out.
Note to other Movable Type users, your XML-RPC script, mt-xmlrpc.cgi, uses a different password than your account's password. It's automatically generated. To find it, and/or change it, go to the Authors page in the admin console, click on your username and scroll down to the bottom where it says something about a web services password.
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.xmlrpc.*;
import org.apache.xmlrpc.client.*;
public class MovableTypeTest
{
public static void main(String[] args)
{
try
{
XmlRpcClient client = new XmlRpcClient();
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://www.testing.com/mt/mt-xmlrpc.cgi"));
client.setConfig(config);
Vector parameters = new Vector();
parameters.add("0123456789ABCDEF");
parameters.add("USERNAME");
parameters.add("PASSWORD");
Object[] response = (Object[])client.execute("blogger.getUsersBlogs", parameters);
System.out.println("Blogs:");
for (Object o: response)
{
HashMap map = (HashMap)o;
Iterator it = map.keySet().iterator();
while (it.hasNext())
{
String key = (String)it.next();
System.out.println("\t" + key + " = " + map.get(key));
}
}
} catch (Exception ex) { ex.printStackTrace(); }
}
}
Leave a comment