Manage RSS feeds with the Rome API

Get automated build reports from your continuous integration server

1 2 3 4 Page 3
Page 3 of 4

The eternal city: Integrating Rome and Continuum

You've seen how to use Rome to easily publish an RSS feed. Now let's apply it in the context of a realistic development project, such as generating an RSS feed from a continuous integration server. Some CI servers, such as Hudson, come with RSS feeds built in, but not Continuum -- at least not just yet. Continuum does come with a convenient API that allows you to access the server from an external Java application, however. You can put this API to good use to provide an RSS feed that details build results.

It is fairly easy to write a class that monitors build results and creates a new RSS entry whenever a new build is executed. In the next sections you'll go through the steps involved in creating such a class. I've simplified some of the code shown here to make reading easier, and also removed comments and error-handling code. See the source code download for full-fledged samples.

The RssPublisher class

The monitor class, called RssPublisher, is a simple POJO-style Java bean. Its only dependencies are to the Rome jars, the Continuum XML-RPC client classes, and the Jakarta Commons CLI libraries (to handle command-line options). The class uses some JavaBeans-style attributes (the getters and setters are not shown) to provide configuration details and to customize its behavior. RssPublisher is shown in Listing 7.

Listing 7. RssPublisher

public class RssPublisher implements Serializable { private String rssFeedFilename = "rss/builds.xml"; private int updateFrequency = 30; private String continuumXMLRPCUrl = "http://localhost:8080/continuum/xmlrpc"; private String rssFormat = "rss_1.0"; private String rssFeedTitle = "Company Build Results"; ... }

Read and update the RSS feed

The next step is to read and update the RSS feed whenever a project's build status changes. You do this in the updateLatestBuildResults() method, which uses a Map object to store the state of each managed project, like so:

Listing 8. updateLatestBuildResults()

private Map<String,Integer> previousState = new HashMap<String,Integer>();

public void updateLatestBuildResults() throws IOException, FeedException, XmlRpcException {

This method begins by preparing the RSS feed, creating it if necessary.

Listing 9. Preparing the RSS feed

SyndFeed feed = null;
        File feedSource = new File(getRssFeedFilename());
        if (feedSource.exists()) {
            SyndFeedInput input = new SyndFeedInput();
            feed = XmlReader(feedSource));            
        } else {
            feed = new SyndFeedImpl();
            feed.setDescription("Continuum build results");

Once you've obtained the RSS feed, you need to fetch, or create, the list of RSS entries for it.

Listing 10. Fetching or creating entries

List<SyndEntry> entries = feed.getEntries();
        if (entries == null) {
            entries = new ArrayList<SyndEntry>();

Ready, set, connect

Your next step is to obtain the list of projects being built on the Continuum server. To do this, you use the Continuum RPC library. Including this library in a Maven project is easy to do with the following dependency declaration:

Listing 11. Adding the Continuum RPC library to your dependencies


Next, you connect to the Continuum server, using the ContinuumXmlRpcClient class and the special "xmlrpc" URL.

Listing 12. ContinuumXmlRpcClient

ContinuumXmlRpcClient client 
                = new ContinuumXmlRpcClient(
                       new URL("http://localhost:8080/continuum/xmlrpc"),

You will need to provide an administrator-level username and password here. You then fetch the list of project groups and projects for each group.

Listing 13. Fetching project groups and projects

List<ProjectGroup> groups = client.getAllProjectGroups();
            for (ProjectGroup group : groups) {
            List<Project> projects = client.getProjects(group.getId());
                    for (Project project : projects) {

1 2 3 4 Page 3
Page 3 of 4
How to choose a low-code development platform