zoukankan      html  css  js  c++  java
  • 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!

  • 相关阅读:
    MYSQL分页优化查询
    13_java之final|static|包|匿名对象|代码块|内部类
    12_java之构造方法|this|super
    11_java之接口和多态
    10_java之继承和抽象类
    09_java之面向对象概述
    08_java超市管理系统
    07_java之练习题
    06_java之类概述
    05_java之方法
  • 原文地址:https://www.cnblogs.com/lexus/p/2787234.html
Copyright © 2011-2022 走看看