Over a million developers have joined DZone.

Building a simple AtomPub client with NetBeans IDE 7, Maven, Java and Apache Abdera

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

In my last article I showed you how to create and run a simple AtomPub server using Apache Abdera. Today we will create a client (using modified code provided in this guide as well as the Apache Abdera examples) to put some data into the AtomPub server.

At this point I assume you already have Java and NetBeans IDE 7 running, if not you can go here to get them both. I also assume you have some NetBeans IDE and Java knowledge.

Start NetBeans IDE 7 and create a new Maven Java project named: ATOMPubClient

Right-click on the Dependencies and select: Add Dependency… When the dialog opens up put in the Query textbox the following: abdera-client

In the App.java class (already created) modify it so the code looks like this:

 * Original code created by the Apache Abdera team
 * http://abdera.apache.org/
package com.giantflyingsaucer.atompubclient;
import java.util.Date;
import org.apache.abdera.Abdera;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.abdera.protocol.Response.ResponseType;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
public class App {
    public static void main(String[] args) throws Exception {
        Abdera abdera = new Abdera();
        AbderaClient abderaClient = new AbderaClient(abdera);
        Factory factory = abdera.getFactory();
        Entry entry = factory.newEntry();
        entry.setTitle("This is the title");
        entry.setUpdated(new Date());
        entry.setContent("Hello World");
        report("The Entry to Post", entry.toString());
        Document<Entry> doc = abderaClient.post("http://localhost:9002/employee", entry).getDocument();
        report("The Created Entry", doc.getRoot().toString());
        ClientResponse resp = abderaClient.get("http://localhost:9002/employee");
        if (resp.getType() == ResponseType.SUCCESS) {
            Document<Feed> docFeed = resp.getDocument();
            report("The Returned Feed", docFeed.getRoot().toString());
        } else {
          // Error
    private static void report(String title, String message) {
        System.out.println("== " + title + " ==");
        if (message != null)

This is very simple, an entry is created and the feed is returned – nothing more. I’ve ignored the capability of editing and deleting. This code can be improved in several ways but my purpose was just to make it a bit easier for developers to get started with Apache Abdera and to supplement the existing documents.

The full source code is available here.

From http://www.giantflyingsaucer.com/blog/?p=2961

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}