Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

pcg4m3s on "Post a new comment using XML-RPC from java Android"

$
0
0

Hi,
for my Android application I need a way to post comment to a wordpress forum.

In my test main I do:

public static void main(String[] args) {
		// TODO Auto-generated method stub

		String xmlRpcUrl = "http://myURL/xmlrpc.php";

		try {
			XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
			config.setServerURL(new URL(xmlRpcUrl));
			XmlRpcClient client = new XmlRpcClient();
			client.setTransportFactory(new XmlRpcCommonsTransportFactory(client));
			client.setConfig(config);

			int blog_id=1;
			String username = "user";
			String password = "pass";
			int post_id=2;
			Comment comment=new Comment(0, "my comment", null, null, null);

			Object[] params = new Object[]{blog_id, username, password, post_id, comment};
			int comment_id = (int)client.execute("wp.newComment", params);
			System.out.println("COMMENT ID: "+comment_id);

		} catch (XmlRpcException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

Where Comment is my support class:

public class Comment {

	int comment_parent;
	String content;
	String author;
	String author_url;
	String author_email;

	public Comment(int comment_parent, String content, String author, String author_url, String author_email)
	{
		super();
		this.comment_parent = comment_parent;
		this.content = content;
		this.author = author;
		this.author_url = author_url;
		this.author_email = author_email;
	}
}

When I run this programa I have Exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/methods/RequestEntity
	at org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory.getTransport(XmlRpcCommonsTransportFactory.java:38)
	at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)
	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126)
	at Prova4.main(Prova4.java:36)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.methods.RequestEntity
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 6 more

Can you Help me?
Thanks!!


Viewing all articles
Browse latest Browse all 8245

Trending Articles