DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Building a simple AtomPub client with NetBeans IDE 7, Maven, Java and Apache Abdera

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

Chad Lung user avatar by
Chad Lung
·
Oct. 21, 11 · Java Zone · Interview
Like (0)
Save
Tweet
8.47K Views

Join the DZone community and get the full member experience.

Join For Free

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.setId("tag:example.org,2011:foo");
        entry.setTitle("This is the title");
        entry.setUpdated(new Date());
        entry.addAuthor("Chad");
        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)
            System.out.println(message);
        System.out.println();
    }
}

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

Integrated development environment Apache Abdera NetBeans Java (programming language) Apache Maven

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Everything I Needed to Know About Observability, I Learned from ‘Bewitched’
  • Exporting and Importing Projects in Eclipse
  • Use Lambda Function URL To Write a Serverless App Backed by DynamoDB
  • What SREs Can Learn From the Atlassian Nightmare Outage of 2022

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo