Most people today are familiar with personal and company or industry-sponsored blogs. The latter are obvious next-generation offshoots of traditional company and industry Web sites. Their content ranges from clumsily repurposed product announcements and public relations to genuinely useful and insightful explorations of topics that are germane to a company's products or the future directions of an industry.
The success of corporate and industry blogs that actually provide updated and useful information has increased interest in blogs as a communication and discussion mechanism within the enterprise. Organizations that adopt blogging should approach the task like any other enhancement to the corporate IT infrastructure. Inward-facing enterprise blogs usually contain business-sensitive discussions and information and must therefore be hosted by the organization's IT staff. Selecting the right blogging platform is the critical first step.
The selection of an open platform that supports standard blogging APIs provides significant advantages for users and administrators. For users, it means that they can add blog entries using a wide variety of popular applications ranging from browser plug-ins to platform-specific client applications. For administrators, support for public APIs can enable the use or development of management and administrative applications.
A number of standard blogging APIs are available. The most widely used and supported of these at the time of writing are:
- Blogger. The oldest of these APIs, Blogger is an XML-RPC-based interface originally created by Pyra Labs for their Blogger software. This first version was quickly adopted by many other blogging platforms because of its use of XML as a standard mechanism for data submission and exchange and because its use of the XML-RPC standard enabled its implementation in any programming language for which XML-RPC libraries were available. Google purchased Blogger in 2003, and soon after, the Blogger 2.0 API appeared—now considered one of the Google Data APIs.
- MetaWeblog. Created by software developer Dave Winer in 2002 in
response to perceived limitations in the Blogger 1.0 API, the MetaWeblog
API is an XML-RPC-based API that uses concepts from the RSS Web feed
format (most notably, the
<item>tag) to view blog posts as structured data rather than the simple strings the Blogger API supports. This integration enables developers to create, submit, manage, and query structured blog posts using a familiar model. - Atom. This XML-based API, known as the Atom Publishing Protocol,
uses Web services rather than XML-RPC as its wire-level protocol, supports
increased security by taking advantage of existing HTTP authentication
mechanisms, and supports cool features such as API discovery through the
use of an appropriate
<link>tag in Web page headers. See Resources for links to more information about this protocol.
This article focuses on MetaWeblog.
The most popular blogging packages that support the MetaWeblog API are open source and can therefore be installed and used within your inward-facing enterprise infrastructure. Popular choices include:
- BLOG:CMS. This GNU General Public License (GPL) package requires Apache Web Server, PHP, and an SQL database such as MySQL or SQLite.
- Blojsom. This Berkeley Software Distribution (BSD)-licensed package requires the Java™ language; a JavaServer Pages (JSP) application server such as JBoss, Jetty, or Apache Tomcat; and an SQL database.
- Drupal. Although primarily a content management system (CMS), Drupal is a GPL package that also supports MetaWeblog. Drupal requires an Apache or Microsoft® Internet Information Services (IIS) Web server, PHP, and either MySQL or PostgreSQL. Work on supporting Microsoft SQL server is in progress.
- Movable Type. This GPL package requires an Apache or IIS Web server, PHP, Perl, and an SQL database. A recent fork in the Movable Type development community created OpenMelody, which is young but certainly worth investigating.
- Pebble. This BSD-licensed package was written around MetaWeblog and requires the Java language and a JSP version 2.0/Servlet version 2.4 application server such as Tomcat. Content is stored on the server in XML, so no database is required.
- Roller. This Apache-licensed package from the Apache Foundation requires the Java language, a JSP 2.0/Servlet 2.4 application server such as Tomcat, and an SQL database.
- WordPress. This GPL package requires Apache Web Server, Perl, and MySQL.
Which package you decide to use initially depends on whether your Web infrastructure is oriented toward Web servers or application servers. WordPress and Movable Type will be instantly recognizable to experienced bloggers and, along with BLOG:CMS and Drupal, only require a Web server. Blojsom, Pebble, and Roller are powerful blogging packages that require an application server but differ in their relational database requirements (Pebble has none!).
The MetaWeblog API makes it possible to post, retrieve, and edit blog entries with any software package that supports it. Many people simply create blog entries online through the editor that their blog supplies, but the MetaWeblog API enables the use of much richer editing software ranging from desktop packages to browser-based packages such as ScribeFire (discussed later in this article). The MetaWeblog API also makes it easy for systems administrators to back up and archive blog entries as well as simplifying migration to other blogging packages, if necessary.
The API consists of a small number of methods, making it easy to learn. These methods are:
- editPost
boolean metaWeblog.editPost(string postid, string username, string password, struct content, boolean publish) - getCategories
struct metaWeblog.getCategories(string blogid, string username, string password) - getPost
struct metaWeblog.getPost(string postid, string username, string password) - getRecentPosts
struct metaWeblog.getRecentPosts(string postid, string username, string password, integer numberOfPosts) - newMediaObject
struct metaWeblog.newMediaObject(string blogid, string username, string password, struct content) - newPost
string Post metaWeblog.newPost(string blogid, string username, string password, struct content, boolean publish)
The parameters for these methods are:
blogid. Identifies the blog that you want to connect to.content. A structure containing the data for a blog entry.The defined members of this structure are the possible values for the
<item>type in RSS 2.0:author,category,comments,description,enclosure,guid,link,pubDate,source, andtitle. Using the these standard values provides a well-known vocabulary for blog content and metadata. RSS items such asenclosurethat have mandatory attributes are passed through structures whose members provide those values. For blog entries, the three primary members of this struct aretitle,link, anddescription.The
newMediaObjectmethod enables you to transfer a file—typically, an audio or video file—to a blog server. This method requires that the structure that you provide contain the members bits (the actual content of the file, base64-encoded), name (the file name to use on the blog server), and type (the MIME type of the file).numberOfPosts. Specifies the maximum number of posts to retrieve.password. Specifies the password that you want to use to authenticate to the blog.postid. Identifies the specific post that you want to edit or retrieve.publish. Specifies whether you want to publish the blog entry (True) or leave the new/updated entry stored as a draft (False).username. Specifies the user name that you want to use to authenticate to the blog.
The metaWeblog methods return the following:
editPost. Always returns True.getCategories. Returns a struct that identifies each available category and has three strings as members: thedescription,htmlUrl, andrssUrl.getPost. Returns a struct with the same members that can be used in the struct supplied as a parameter to thenewPostandeditPostmethods.getRecentPosts. Returns an array of structs corresponding to recent blog posts. Each struct in this array contains the same members as those returned by a call togetPost.newMediaObject. Returns a struct containing a member namedurl, which provides the URL of the file using either HTTP or FTP.newPost. Returns a string that can be used as ablogidin calls toeditPostorgetPost.
The description of an API is interesting, but nothing beats hand-on examples, especially
when the use of that API requires the use of another potentially unfamiliar
API—in this case, the XML-RPC API. The next two sections focus on
how to use the most popular MetaWeblog method, newPost,
to create a new post in various ways.
Creating a simple post using MetaWeblog
The example in Listing 1 shows an extremely simple invocation
of the metaWeblog.newPost method.
Listing 1. A simple post using MetaWeblog
import java.util.*;
import java.io.*;
import java.net.URL;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
public class DemoPost {
public static void main(String[] args) throws Exception {
// Set up XML-RPC connection to server
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://wordpress-host/wordpress/xmlrpc.php"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
// Set up parameters required by newPost method
Map<String, String> post = new HashMap<String, String>();
post.put("title", "Hello, Blog!");
post.put("link", "http://www.vonhagen.org/");
post.put("description", "This is the content of a trivial post.");
Object[] params = new Object[]{"1", "admin", "password", post, Boolean.TRUE};
// Call newPost
String result = (String) client.execute("metaWeblog.newPost", params);
System.out.println(" Created with blogid " + result);
}
}
|
The first block of code in the main method configures the XML-RPC infrastructure that MetaWeblog uses, establishing a client connection to the URL http://wordpress-host/wordpress/xmlrpc.php, which is the XML-RPC URL for my example WordPress blog server. Different blog servers use different XML-RPC URLs. Check the documentation for the blog server you chose for the specific URL you need.
The second block of code creates a hash map and populates it with name-value pairs
that provide the information required to make a blog post. After setting values
for the title, link, and
description settings, the hash map is packaged into
an array along with the other parameters that the metaWeblog.newPost
method requires.
The third block of code actually invokes the metaWeblog.newPost
method using the XML-RPC client connection created in the first block of
code. Then, this code prints the string that the method returned, which is the
blogid of the remote blog entry that was created.
Posting the contents of a file using MetaWeblog
The previous example was interesting, but the chances that you want to re-implement Twitter in blog format by posting single, short strings are pretty low. It's much more likely that you might want to create a file using your favorite text editor, then post that file to your blog with a custom title.
The example in Listing 2 builds on the previous one, showing
an invocation of the metaWeblog.newPost method
that enables you to post the contents of a file and, optionally, specify the title
of the post. These items are specified on the command line when you execute
the application.
Listing 2. Posting file contents
import java.util.*;
import java.io.*;
import java.net.URL;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
public class DemoPostFile {
private static byte[] readFromFile(String src) throws Exception {
byte data[];
File file = new File(src);
InputStream in = new FileInputStream(src);
data = new byte[(int)file.length()];
in.read(data);
in.close();
return data;
}
public static void main(String[] args) throws Exception {
String filename = null;
String title = "Sample Post From a File";
// Parse and apply command-line args
if (args.length > 1) {
filename = args[0];
title = args[1];
} else if (args.length == 1) {
filename = args[0];
title = "Posted From File: " + filename;
} else {
System.out.println("Usage: DemoPostFile filename [title] ");
return;
}
// Set up XML-RPC connection to server
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://wordpress-host/wordpress/xmlrpc.php"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
// Read post from file and set up parameters required
// by newPost method
String bits = new String(readFromFile(filename));
System.out.println(bits);
Map<String, String> post = new HashMap<String, String>();
post.put("title", title);
post.put("description", bits);
Object[] params = new Object[]{"1", "admin", "password", post, true};
// Call newPost
String result = (String) client.execute("metaWeblog.newPost", params);
System.out.println(" Created with blogid " + result);
}
}
|
The first method in this application is a readFromFile
application that is declared as static here to simplify integrating it with
the static main method's use of command-line argument parsing.
The first block of code in the main method for this application initializes the two variables that it uses for the name of the file containing the blog entry that it will post along with the title for that post. It then parses the arguments with which the application was called, determining whether a file name, title, or both are present and reacting accordingly.
The subsequent block of code initializes the XML-RPC client connection to the blog
server. This is followed by a block of code that reads the contents of the file
that you specified on the command line into a variable and sets the other
variables required to use the metaWeblog.newPost
method. The final block of code calls this method and prints the result code,
which is the blogid of the post on the blog server.
Off-the-shelf MetaWeblog utilities
Simple utilities like the one shown in the preceding section aren't for everyone: Not everyone wants to build his or her own tools, let alone execute programs from the traditional command line. Primary reasons to run blog servers that use standard APIs such as MetaWeblog are the abilities to use a variety of different applications, write in different languages, and execute within different operating systems and environments. Many blogging clients, each with its own capabilities and fan club, are available to make it easier for you to create and post blog entries.
One of the most useful MetaWeblog clients is ScribeFire (see Resources), a Mozilla Firefox add-on that provides a full-featured blog editor in Firefox that makes it easy to post to your blogs, even enabling you to drag and drop formatted text from other Web pages or documents, upload images, and much more. Figure 1 shows the use of ScribeFire (bottom portion of the Firefox window) to post to a WordPress blog (top portion of the Firefox window).
Figure 1. Posting to WordPress using ScribeFire
MetaWeblog clients typically also enable you to configure connections to multiple blogs and post the same content in different blogs. This functionality makes it extremely easy, for example, to transfer a post from an internal enterprise blog to an external corporate blog. Figure 2 shows the use of ScribeFire (bottom portion of the Firefox window) to post the same content shown in Figure 1 to a Pebble blog (top portion of the Firefox window).
Figure 2. Posting to Pebble using ScribeFire
Pebble: Basing open software on open standards
The sample utilities provided and discussed in this article are the tip of the MetaWeblog iceberg. You can use any utility that supports the MetaWeblog API to communicate with any blog server that supports that API. You can also use the MetaWeblog API as the core for implementing a blog server, as is the case with the Pebble blog server (see Resources).
The Pebble blog server is a BSD-licensed (Berkeley Software Distribution) package written around MetaWeblog. Because Pebble is open source, its code is freely downloadable and can provide many useful examples of ways in which to use the various MetaWeblog API calls. Figure 3 shows the standard Pebble interface.
Figure 3. The Pebble welcome page
A more interesting aspect of Pebble is that blog content on a Pebble server is stored as XML files rather than in a database, as most other blog servers do. Not requiring a database server makes Pebble more lightweight in terms of system resource requirements than most other blog servers, but it also simplifies tasks such as backups. Blog posts are backed up as part of the standard file system rather than requiring database dumps or checkpoints.
Enterprise blogs are not a perfect delivery mechanism for all types of corporate information, but they can become a cornerstone of modern enterprise communication and discussion. Traditional decision points when you select a corporate blog server are its cost, maintainability, and usability. As this article shows, the APIs that your blog server supports are an equally important decision point. Selecting a blog server that supports a standard API like MetaWeblog can provide significant long-term benefits in the usability of your blog, because it enables people to use many different clients to make and edit posts to that central resource. This sort of flexibility often translates into whether people use your blog.
| Description | Name | Size | Download method |
|---|---|---|---|
| Simple MetaWeblog posting application | DemoPost.java.zip | 2KB | HTTP |
| MetaWeblog application to post file content | DemoPostFile.java.zip | 2KB | HTTP |
Information about download methods
Learn
- MetaWeblog API RFC: Read the final MetaWeblog RFC post, which is the definitive resource for the MetaWeblog API.
- General MetaWeblog API: Find information about using the MetaWeblog API, including discussions and examples of MetaWeblog implementations in different programming languages.
- XML-RPC.com: Find general and detailed information about XML-RPC, APIs based on the specification, XML-RPC tools, and much more.
- Blogapps
Project: Explore this project and its great set of sample programs that show how to use various APIs to work with blogs. Though primarily focused on the Atom API, this project also includes examples that use the MetaWeblog API. These examples are used in Dave Johnson's excellent book, RSS and Atom in Action (Manning, 2006), which is a great resource for the RSS and Atom feed technologies as well as the Atom Publishing API.
- Internet Engineering Task Force (IETF) RFC 5023: Read the specification for the Atom Publishing Protocol. Its companion Atom Syndication Format, used for Web feeds, was published as an IETF proposed standard in RFC 4287.
- IBM XML certification: Find out how you can become an IBM-Certified Developer in XML and related technologies.
- XML technical library: See the developerWorks XML Zone for a wide range of technical articles and tips, tutorials, standards, and IBM Redbooks.
- developerWorks technical events and webcasts: Stay current with technology in these sessions.
- developerWorks
podcasts: Listen to interesting interviews and discussions for software developers.
Get products and technologies
- Blogger,
MetaWeblog, and Atom: Download the most popular blogging APIs at the time of writing.
- Pebble. Visit the site for detailed information and downloads for Pebble, the MetaWeblog-based blogging server.
- Apache XML-RPC: Download the latest version for your system.
- Apache XML-RPC mirror sites: Download the JAR files you need for Apache's XML-RPC implementation.
- ScribeFire: Download the latest version of the plug-in for Firefox.
- IBM product evaluation versions: Download or explore the online trials in the IBM SOA Sandbox and get your hands on application development tools and middleware products from DB2®, Lotus®, Rational®, Tivoli®, and WebSphere®.
Discuss
- XML zone discussion forums: Participate in any of several XML-related discussions.
- developerWorks blogs: Check out these blogs and get involved in the developerWorks community.
William von Hagen has been a writer and UNIX systems administrator for more than 20 years and a Linux advocate since 1993. Bill is the author or co-author of books on subjects such as Ubuntu Linux, Xen Virtualization, the GNU Compiler Collection (GCC), SUSE Linux, Mac OS X, Linux file systems, and SGML. He has also written numerous articles for Linux and Mac OS X publications and Web sites.
Comments (Undergoing maintenance)





