Showing posts with label abdera. Show all posts
Showing posts with label abdera. Show all posts

Tuesday, June 16, 2009

Abdera Client - Using teardown()

I was working on a program which makes several requests to Abdera back end from the client. The client was designed to use a new AbderaClient per request and teardown method was not used on AbderaClient instance after using.

This led to an exception when I run it concurrently (by using about 100 threads). AbderaClient uses HTTPClient and MultiThreadedHttpConnectionManager. Teardown method is the one who shuts down this connection manager and the best practice is to call teardown after using AbderaClient instance.
AbderaClient abderaClient = new AbderaClient(new Abdera());
// make the call
abderaClient.teardown();

Sharing a single instance of AbderaClient among all request is another option but some times it goes to a deadlock state (keeping a connection open for a long time is not recommended anyway).

Monday, September 22, 2008

Writing a Simple Atompub Client Using Apache Abdera

The atom publishing protocol (similar to RSS but with an enhanced ability) is an application level protocol for editing and publishing web resources for periodically updated web sites, using HTTP. An atom document which adheres to the Atom syndication format spec, is used as an atom feed or entry.

Apache Abdera implements this protocol and exposes a simple API to make the thing easy. The way to create an atom feed and to add an entry is shown below.
Abdera abdera = new Abdera();
Feed fd = abdera.newFeed();

fd.setId("unique feed id");
fd.setTitle("feed title");
fd.setUpdated(new Date());
fd.addAuthor("username");

//adding the entry
Entry entry = fd.addEntry();
entry.setId("unique id");
entry.setTitle("entry title");
entry.setSummary("summary");
entry.setContent("The content goes here");
entry.addSimpleExtension(new QName(namespace, "elementName"), "elementContent");//To add an extra element to the entry
entry.setUpdated(new Date());
Now let's see how to post this feed to the abdera server which contains all business logic.
AbderaClient client = new AbderaClient(abdera);
ClientResponse response = client.post("http://www.somesite.com/collection",fd);
Retrieving feeds is just a matter of calling Abdera client's get method.
ClientResponse response = client.get("http://www.somesite.com/collection/atom1.php");
Document doc = response.getDocument();
Abdera client can call put, delete methods as well. Meanwhile the server side should implement the relevant business logic for these methods.This is a good tutorial with further information to follow.


Related Posts with Thumbnails