Reading an ATOM feed using Apache Abdera and Java

Post to Twitter

Today I’ll show you how to read an ATOM feed using Apache Abdera with Java. I’m going to be using Atom Hopper as the ATOMPub server and you can check out my previous articles on how to get it running.

[ad name=”Google Adsense”]

With Atom Hopper up and running and assuming the database is clean (no entries), insert the following (very simplified) ATOM XML with Poster (you can find out how to use Poster in this article):

<?xml version="1.0"?>
<entry xmlns="">
  <title>Title 1</title>
  <content>Content for entry 1</content>
  <category term="Python" />
  <category term="Java" />

Note: Make sure if your using Poster to insert this ATOM XML you use an HTTP POST with the content type set to: application/atom+xml

I used Netbeans 7 to create a new Maven Java Application project. You only need to add one dependency to the POM which is the: abdera-parser. Here is my entire POM.xml file:

<project xmlns="" xmlns:xsi=""





The code for the is as follows:

package com.giantflyingsaucer;

import java.util.List;

import org.apache.abdera.Abdera;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Category;
import org.apache.abdera.model.Link;
import org.apache.abdera.parser.Parser;

public class App {

    private static Abdera abdera = null;

    public static synchronized Abdera getInstance() {
        if (abdera == null) {
            abdera = new Abdera();
        return abdera;

    public static void main(String[] args) {
        Parser parser = getInstance().getParser();

        try {
            URL url = new URL("http://localhost:8080/namespace/feed");
            Document<Feed> doc = parser.parse(url.openStream(), url.toString());
            Feed feed = doc.getRoot();
            // Get the feed title
            System.out.println("Feed Title: " + feed.getTitle());
            // Get the entry items...
            for (Entry entry : feed.getEntries()) {
                System.out.println("Title: " + entry.getTitle());
                System.out.println("Unique Identifier: " + entry.getId().toString());
                System.out.println("Updated Date: " + entry.getUpdated().toString());
                System.out.println("Published Date: " + entry.getPublished());
                System.out.println("Content: " + entry.getContent());
                // Get the links
                for (Link link : (List<Link>) entry.getLinks()) {
                    System.out.println("Link: " + link.getHref());
                // Get the categories
                for (Category category : (List<Category>) entry.getCategories()) {
                    System.out.println("Category: " + category.getTerm());
        } catch (Exception ex) {
            System.out.println("Error: " + ex.getMessage());

Run the application and the results should be:

Feed Title: feed
Title: Title 1
Content: Content for entry 1
Unique Identifier: urn:uuid:0fb3e0ec-ea46-4f13-9dc3-20df998e9d88
Updated Date: Thu Oct 13 18:01:48 CDT 2011
Published Date: null
Category: Python
Category: Java

Post to Twitter

This entry was posted in Apache Abdera, Atom Hopper, Java, Open Source. Bookmark the permalink.