File name: twbs_jaxrs_atomcontent_abdera.html
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
- 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;
}
}
- 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();
}
- 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");
}
- 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;
}
- (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
}
- 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/web2fep/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)
Most of the following links will take you to information that is not part of the formal product documentation and is provided "as is." Some of these links go to non-IBM Web sites and are provided for your convenience only and do not in any manner serve as an endorsement by IBM of those Web sites, the material thereon, or the owner thereof.
|
|
