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/