You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 25 Next »

Migration from Apache Abdera to Apache Wink

TBD

This section contains the following topics:

Consuming Atom Documents

TBD 

Apache Abdera - Click on link to Download - ConsumeAtomUsingAbdera.java

Abdera abdera = new Abdera();
Parser parser = abdera.getParser();
URL url = new URL("http://alexharden.org/blog/atom.xml");
Document<Feed> doc = parser.parse(url.openStream());
Feed feed = doc.getRoot();
System.out.println(feed.getTitle());
for (Entry entry : feed.getEntries()) {
    System.out.println("\t" + entry.getTitle());
}

TBD 

Apache Wink - Click on link to Download - ConsumeAtomUsingWink.java

RestClient client = new RestClient();
Resource resource = client.resource("http://alexharden.org/blog/atom.xml");
AtomFeed feed = resource.accept(MediaType.APPLICATION_ATOM_XML).get(AtomFeed.class);
System.out.println(feed.getTitle().getValue());
for (AtomEntry entry : feed.getEntries()) {
    System.out.println("\t" + entry.getTitle().getValue());
}

Producing Atom Documents

TBD 

Apache Abdera - Click on links to Download - ProduceAtomUsingAbdera.java ProduceAtomUsingAbdera_web.xml

protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    Abdera abdera = new Abdera();
    Feed feed = abdera.newFeed();

    feed.setId("tag:example.org,2007:/foo");
    feed.setTitle("Test Feed");
    feed.setSubtitle("Feed subtitle");
    feed.setUpdated(new Date());
    feed.addAuthor("Shiva HR");
    feed.addLink("http://example.com");
    feed.addLink("http://example.com/foo", "self");

    Entry entry = feed.addEntry();
    entry.setId("tag:example.org,2007:/foo/entries/1");
    entry.setTitle("Entry title");
    entry.setSummaryAsHtml("<p>This is the entry title</p>");
    entry.setUpdated(new Date());
    entry.setPublished(new Date());
    entry.addLink("http://example.com/foo/entries/1");

    feed.getDocument().writeTo(response.getWriter());
} 

TBD 

Apache Wink - Click on links to Download - ProduceAtomUsingWink.java ProduceAtomUsingWink_web.xml

protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    AtomFeed feed = new AtomFeed();
    feed.setId("tag:example.org,2007:/foo");
    feed.setTitle(new AtomText("Test Feed"));
    feed.setSubtitle(new AtomText("Feed subtitle"));
    feed.setUpdated(new Date());

    AtomPerson person = new AtomPerson();
    person.setName("Shiva HR");
    feed.getAuthors().add(person);

    AtomLink link1 = new AtomLink();
    link1.setHref("http://example.com");
    feed.getLinks().add(link1);

    AtomLink link2 = new AtomLink();
    link2.setHref("http://example.com/foo");
    link2.setRel("self");
    feed.getLinks().add(link2);

    AtomEntry entry = new AtomEntry();
    entry.setId("tag:example.org,2007:/foo/entries/1");
    entry.setTitle(new AtomText("Entry title"));

    AtomText summary = new AtomText();
    summary.setType(AtomTextType.html);
    summary.setValue("<p>This is the entry title</p>");
    entry.setSummary(summary);

    entry.setUpdated(new Date());
    entry.setPublished(new Date());

    AtomLink link3 = new AtomLink();
    link3.setHref("http://example.com/foo/entries/1");
    entry.getLinks().add(link3);

    feed.getEntries().add(entry);

    AtomFeed.marshal(feed, response.getOutputStream());
}

Producing Atom Documents Using Apache Wink the JAX-RS Way

In order to produce an Atom document according to the JAX-RS specification using Apache Wink perform the following steps:

  1. Open the Eclipse development environment and then create a "Dynamic Web Project".
  2. Add Wink & its dependent JARs into Java Build Path and Java EE Module Dependencies.
  3. Create a POJO class and a method that creates Atom feed document. Annotate the class & its methods with the required JAX-RS annotations as below:
    ProduceAtom.java
  4. Add org.apache.wink.server.internal.servlet.RestServlet into web.xml and specify the path of above Resource class in it's init-param.
    See ProduceAtomWinkElegant_web.xml and application
  5. Deploy the web-application and access it using the url http://localhost:8080/ProduceAtom_Wink_Elegant/rest/getAtom
  6. Final WAR -> ProduceAtom_Wink_Elegant.zip (add Wink & its dependent JARs under ProduceAtom_Wink_Elegant\WEB-INF\lib and re-zip it as WAR).

Consuming RSS Documents

TBD 

Apache Abdera - Click on link to Download - ConsumeRssUsingAbdera.java

public static void main(String[] args) throws ParseException, IOException {
    System.out.println("Consuming RSS Documents using Abdera...\n");
    Abdera abdera = new Abdera();
    Parser parser = abdera.getParser();
    URL url = new URL("http://www.rssboard.org/files/sample-rss-2.xml");
    Document<RssFeed> doc = parser.parse(url.openStream());
    RssFeed rssFeed = doc.getRoot();
    System.out.println("Title: " + rssFeed.getTitle());
    System.out.println("Description: " + rssFeed.getSubtitle() + "\n");
    int itemCount = 0;
    for (Entry entry : rssFeed.getEntries()) {
        System.out.println("Item " + ++itemCount + ":");
        System.out.println("\tTitle: " + entry.getTitle());
        System.out.println("\tPublish Date: " + entry.getPublished());
        System.out.println("\tDescription: " + entry.getContent());
    }
} 

TBD 

Apache Wink - Click on link to Download - ConsumeRssUsingWink.java

public static void main(String[] args) {
    System.out.println("Consuming RSS Documents using Apache Wink...\n");
    RestClient client = new RestClient();
    String url = "http://www.rssboard.org/files/sample-rss-2.xml";
    Resource resource = client.resource(url);
    RssFeed rss = resource.accept(MediaType.APPLICATION_XML).get(RssFeed.class);
    RssChannel channel = rss.getChannel();
    System.out.println("Title: " + channel.getTitle());
    System.out.println("Description: " + channel.getDescription() + "\n");
    int itemCount = 0;
    for (RssItem item : channel.getItems()) {
        System.out.println("Item " + ++itemCount + ":");
        System.out.println("\tTitle: " + item.getTitle());
        System.out.println("\tPublish Date: " + item.getPubDate());
        System.out.println("\tDescription: " + item.getDescription());
    }
}

Creating RSS Documents

TBD

Apache Abdera

As of v0.4 Abdera has no support for RSS write. TBD

Apache Wink

Same as in 2)a) or 2)b). The resource method now returns an RssFeed object instead of AtomFeed object. 

Apache Wink - Click on link to Download - ProduceRss_Wink_Elegant.zip

public static void main(String[] args) {
    System.out.println("Consuming RSS Documents using Apache Wink...\n");
    RestClient client = new RestClient();
    String url = "http://www.rssboard.org/files/sample-rss-2.xml";
    Resource resource = client.resource(url);
    RssFeed rss = resource.accept(MediaType.APPLICATION_XML).get(RssFeed.class);
    RssChannel channel = rss.getChannel();
    System.out.println("Title: " + channel.getTitle());
    System.out.println("Description: " + channel.getDescription() + "\n");
    int itemCount = 0;
    for (RssItem item : channel.getItems()) {
        System.out.println("Item " + ++itemCount + ":");
        System.out.println("\tTitle: " + item.getTitle());
        System.out.println("\tPublish Date: " + item.getPubDate());
        System.out.println("\tDescription: " + item.getDescription());
    }
}

Writing Atom Publishing Protocol (APP) Server

TBD

Writing Atom Publishing Protocol (APP) Client

TBD

Object Models Comparison for Atom Syndication Format (ASF)

TBD

Object Models Comparison for Atom Publishing Protocol (APP)

TBD

Object Models Comparison for RSS (Really Simple Syndication)

TBD

  • No labels