JAVA : Using Metaweblog API | CodingX
I was interested in this API since a long time but I didn't take time to write a post on it !
The purpose of this article is to show how to post on a blog without using the common web-interface, and build your own publish-system.
The metaweblog API is based on the xmlrpc library distributed by Apache, it's opensource and really easy to work with :)
Tanks to indiwiz/ for the topic !
public class Blog {
private String login ;
private String password ;
public boolean post(String title ,String link ,String description){
boolean retStatus = true;
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
try {
config.setServerURL(new URL("http://localhost/mw"));
} catch (MalformedURLException e) {
System.out.println("Exception catch :: server URL");
retStatus = false ;
}
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
Map m = new HashMap();
m.put("title", "Hello World ");
m.put("link", "http://www.perdu.com/");
m.put("description", "Message de test!");
Object[] params = new Object[]{"default", login, password, m, true};
try {
String ret = (String) client.execute("metaWeblog.newPost", params);
} catch (XmlRpcException e) {
System.out.println("Exception catch, unable to execute statement");
retStatus = false ;
}
return retStatus;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public void setPassword(String password) {
this.password = password;
}
}Required dependencies : (http://apache.belnet.be//ws/xmlrpc/)