Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

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

Code Block
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());
}

2) b) Producing Atom Documents

...

- the JAX-RS

...

way

A more elegant way of producing Atom documents using Apache Wink is In order to produce an Atom document according to the JAX-RS specification using Apache Wink perform the following stepsway as described below:

  1. Open the Eclipse development environment and then create a "Dynamic Web Project".
  2. Add Apache Wink & its dependent JARs into Java Build Path and under 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).

...