Using the Apache Abdera Atom model for requests and responses

Apache Abdera is an open-source project providing feed support within WebSphere® Application Server. Abdera addresses both the Atom syndication format and the Atom publishing protocol. You can implement the Apache Abdera Atom format to consume and produce Atom feeds and Atom entries in a JAX-RS application for the syndication of Web content.

About this task

The Feature Pack for Web 2.0 provides a set of libraries for Apache Abdera that you can use to represent Atom documents.

The Apache Abdera entity provider classes, which can read and write Apache Abdera Java types, are included with the main IBM® Apache Wink-based JAR file. You must register the entity provider classes in the javax.ws.rs.core.Application subclass.

You can use the following classes to represent request entities or response message bodies:
  • org.apache.abdera.model.Entry
  • org.apache.abdera.model.Feed
You can also use these classes as a resource method parameter to represent an incoming Atom request. Similarly, you can return any of these classes as a resource response.

Procedure

  1. Register the Apache Abdera provider in your javax.ws.rs.core.Application subclass.
    public class MyApplication extends javax.ws.rs.core.Application {
    
        public Set<Class<?>> getClasses() {
            Set<Class<?>> classes = new HashSet<Class<?>>();
            classes.add(org.apache.wink.providers.abdera.AbderaAtomEntryProvider.class);
            classes.add(org.apache.wink.providers.abdera.AbderaAtomFeedProvider.class);
            return classes;
        }
    }
  2. Create a new feed object in your resource method.
    @javax.ws.rs.GET
    public org.apache.abdera.model.Feed getFeed() {
         org.apache.abdera.Abdera abdera = new org.apache.abdera.Abdera();
         org.apache.abdera.model.Feed feed = abdera.newFeed();
    }
  3. Add information to the feed by setting properties and adding entries. In the following example, the title is set on the feed and a basic Atom entry is added to it:
    @javax.ws.rs.GET
    public org.apache.abdera.model.Feed getFeed() {
           org.apache.abdera.Abdera abdera = new org.apache.abdera.Abdera();
           org.apache.abdera.model.Feed feed = abdera.newFeed();
           feed.setTitle("Feed Title");
    
            org.apache.abdera.model.Entry entry = feed.addEntry();
            entry.setTitle("Entry Title");
            entry.setId("1");
            entry.addLink(“http://www.example.com");
       }
  4. Return the feed in the Java method so the feed is returned in the response. See the return feed; statement in the following example:
    @javax.ws.rs.GET
    public org.apache.abdera.model.Feed getFeed() {
            org.apache.abdera.Abdera abdera = new org.apache.abdera.Abdera();
            org.apache.abdera.model.Feed feed = abdera.newFeed();
            feed.setTitle("Feed Title");
    
            org.apache.abdera.model.Entry entry = feed.addEntry();
            entry.setTitle("Entry Title");
            entry.setId("1");
            entry.addLink(“http://www.example.com");
            return feed;
    }
  5. (optional) If an Atom feed or entry is sent in a request, you can add one of the Atom types as a parameter to the resource method.
    @javax.ws.rs.POST
    public void postFeed(org.apache.abdera.model.Feed incomingFeed) {
        // use the incomingFeed object
    }
  6. When packaging the JAX-RS application, include the Apache Abdera libraries in the classpath.

    You must include the Apache Abdera libraries in the application classpath, which is typically found in the WEB-INF/lib directory. The Apache Abdera libraries are located in the app_server_root/web2mobilefep_1.1/optionalLibraries/Feed directory.

Results

You have used the Apache Abdera Atom objects to represent request and response message bodies.




In this information ...


IBM Redbooks, demos, education, and more

(Index)

Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

Task topic Task topic    

Terms and conditions for information centers | Feedback

Last updatedLast updated: Sep 6, 2012 5:50:55 AM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=v610webmob&product=was-nd-mp&topic=twbs_jaxrs_atomcontent_abdera
File name: twbs_jaxrs_atomcontent_abdera.html