Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

client program using apache xmlrpc libraries  RSS feed

 
Prasath Nadarajah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i,m developing an weblog client application using java and apache xmlrpc libraries.
I wrote a simple program i used to communicate with WordPress.
but it throws the following exception:

Exception: Failed to parse server's response: Expected methodResponse element, got html

I cannot figure out what's wrong with the code
can anyone help me on this??

Program

import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import java.net.URL;
import java.util.Vector;

public class SimpleXmlrpc {

public SimpleXmlrpc() {
}

public static void main(String[] args) {

XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();

try{

config.setServerURL(new URL("http://localhost/wordsite"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);

Object[] params = new Object[]{ new String("usrername"),
new String("password")
};

String result = (String)client.execute("sayHello", params); .
System.out.println("Results" + result);
}
catch(Exception e)
{
System.out.println("Exception: " + e.getMessage());
}
}
}



http://codex.wordpress.org/XML-RPC_wp
 
Prasath Nadarajah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The sayHello method is a test method that returns a string "hello". it does,nt requires an authentication.
 
Prasath Nadarajah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also i,m glad if someone will provide some guidelines how i can commicate blog's xmlrpc
any alternative other than using apache xml-rpc libraries...
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception: Failed to parse server's response: Expected methodResponse element, got html


Your client code was expecting XML formatted response but got HTML. Probably because the server sent a plain HTML error message.

A utility like TCPMON or SOAPui will let you see exactly what is being sent and what is being received.

Bill
 
Prasath Nadarajah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks bill
the actual error i made was i must insert the URL of the xml-rpc file (not the site URL)

config.setServerURL(new URL("http://localhost/wordsite")) // wrong

config.setServerURL(new URL(""http://localhost/wordsite/xmlrpc.php"")) // correct
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!