MetaWeblog API in Java

MetaWeblog API in Java at indiWiz.com

MetaWeblog API in Java

with one comment

Recently we were assigned with the task of writing code to remotely insert an entry to a blog. And we had to select the Blogging software. So we started with the search for a blogging software which exposed its API. To our amazement, we found XML-RPC ruling the blogging API world. And one software independent standard for it is the MetaWeblog API.

After selecting the API, we had to find a software supporting this API. This assignment was for a demo we were to show. So we wanted a minimal blogging software with no configuration. We found Pebble (we used version 2.3.1). This software is cool. Installation is breeze, just put the WAR file in an application server, and you are ready to use it!

Now came the implementation part. I assumed the existence of a Java library implementing this MetaWeblog API. But did not find any. So the next obvious step: use some XML-RPC library in Java to implement the call. I had some bad opinion about Apache’s XML-RPC library. I had used it long back ago, and I hated the way it was implemented. Since then I have been using Python to access XML-RPC services. But, this time, the job required use of Java.

So we ventured to the next step: finding an alternative OpenSource Java XML-RPC library. We found RoX. We were happy because RoX was born out of frustration of using Apache’s XML-RPC engine. We implemented it. And RoX did not work for Pebble (still not able to figure out if it was a mistake on our part, or RoX really did have a bug). So switched to Apache (version 3.1.1). The 3.x API seems to have been simplified. So finally we wrote:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
 
...
 
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL( new URL( "http://localhost:8080/pebble/xmlrpc/" ));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
 
// Params needed: blogid, username, password, struct, publish
// First create the fourth parameter, struct:
Map<string, String> m = new HashMap<string, String>();
m.put( "title" , "Hello World " + Calendar.getInstance().toString());
m.put( "link" , "http://www.indiwiz.com/" );
m.put( "description" , "This is the content of the post!" );
 
Object[] params = new Object[]{ "default" , "username" , "password" , m, true };
 
String ret = (String) client.execute( "metaWeblog.newPost" , params);
System.out.println(ret);

And then we delivered our demo!

posted on 2012-11-25 09:21  lexus 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lexus/archive/2012/11/25/2787234.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值