Java XML-RPC client for Drupal's Services module

I am trying to write a java xmlrpc client for Drupal's Services module. However, I got the "org.xml.sax.SAXParseException: Content is not allowed in prolog" error when I tried to call "system.connect()". This error occurs no matter which library I use, Redstone or Apache.

After some searching, I found this: http://www.openrdf.org/forum/mvnforum/viewthread?thread=86
Java doesn't handle BOMs on UTF-8 files properly, making the three header bytes appear as being part of the document. ...

By checking Drupal's document, it doesn't seem to be the case. I feel pretty frustrated and finally decided to look for help here. Luckily I got some response and figured out the problem is my URL ends with a slash which causes the error. This does look like site(Drupal?) specific, as in my other blog I use "http://foxrate.org/rpc/" which works fine. I further verified this using Python, which also complains about the ending slash.
Anyway, I happily provide a simple java xmlrpc client using Redstone below. A client using Apache library is very similar to this.

package org.test;
import java.net.URL;
import redstone.xmlrpc.*;
public class MyDrupal {
public static void main( String[] args ) throws Exception
{
XmlRpcClient client = new XmlRpcClient("http://speakingx.com/services/xmlrpc",true );
XmlRpcStruct session = (XmlRpcStruct)client.invoke( "system.connect", new Object[] { } );

String sessid = session.getString("sessid");
System.out.println(session);
Object[] params = new Object[] { sessid, new Integer(37), new Object[]{} };
XmlRpcStruct node = (XmlRpcStruct) client.invoke( "node.load", params );
System.out.println(node);
}
}

Technorati Tags: , , ,


Back to top