Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

atom-archive-traverser

This is a java client for processing an atom feed as described in this article or the awesome Rest In Practice book. It uses Abdera and Jersey Client (Though it is trivial to create FeedReaders for other REST/Http clients).

The idea is that it loads an atom feed and then examines each entry in turn until it finds the first entry we wish for it to process. If it reaches the end of the feed, then it will follow "prev-archive" links to traverse through all the archive feeds that have ever been published. When it reaches the entry we are looking for (or the first ever published event), it will then process each event in publication order, following "next-archive" links until it reaches the last published feed.

This is available in the central maven repository:

 <dependency>
    <groupId>uk.co.optimisticpanda</groupId>
    <artifactId>atom-archive-traverser</artifactId>
    <version>0.0.2</version>
 </dependency>

Creating a new feed traverser is trivial:

import org.apache.abdera.model.Entry;
import com.sun.jersey.api.client.Client;
import static uk.co.optimisticpanda.atom.EntryFunctions.*;

public class TestDependencies {

    public static void main(String[] args) {
        // Obtain a jersey client
        Client client = new Client();

        // Create Feed Traverser
        FeedTraverser traverser = FeedTraverserBuilder.createFeedTraverser(client)//
                
                // Start processing entries that occured after the entry with an id of 0
                .foundLastProcessedEntryWhen(idEquals("0")) //
                
                // Filter the feed to only process entries that have the CREATE category
                .processEntriesWhich(haveACategoryOf("CREATE")) //
                
                // Print out each matching entry
                .whenFound(printEntryDetails) //
                
                .build();
        
        // Traverse Feed
        traverser.traverse("http://localhost:8080/service/notifications/");
    }

    // EntryVisitor that just prints out the details of each visited entry.  
    private static EntryVisitor printEntryDetails = new EntryVisitor() {
        public void visit(Entry entry) {
            System.out.printf("\t%s\t:\t%s\n", entry.getId(), entry.getTitle());
        }
    };
}

About

A client for processing atom events. Based on the algorithm described in Rest In Practice

Resources

License

Packages

No packages published

Languages

You can’t perform that action at this time.