Using Apache Abdera for working with Lotus Connections API

In the Connections API entry i blogged about how to make a REST call to the Connection server using simple Java based API, But in order to work with Connections we need two parts first is ability to make HTTP call and other is ability to parse the feed and get information from it.

The Apache Abdera project library provides infrastructure to help in both these infrastructure pieces. Both the part to make HTTP call and the part required for parsing and working with feed. I wanted to try this so i did create this HelloProfileAPI.java which is standalone Java application which makes a call to profile service and returns the result in ATOM format, once the results are returned it prints the content of feed entries on System.Out


package com.webspherenotes.connections;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import org.apache.abdera.Abdera;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.abdera.parser.Parser;

public class HelloProfileAPI {

public static void main(String[] args) {
try {
URL url = new URL(
"http://wpconnections.atech.com/profiles/atom/search.do?name=was");

// Open the URL: throws exception if not found
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
InputStream inputStream = conn.getInputStream();
Abdera abdera = new Abdera();
Parser parser = abdera.getParser();
Document feed_doc = parser.parse(inputStream);
Feed feed = feed_doc.getRoot();
List entryList = feed.getEntries();
for (Entry e : entryList) {
System.out.println(e.getContent());
}
} catch (MalformedURLException e) {
e.printStackTrace(System.out);
} catch (IOException e) {
e.printStackTrace(System.out);
}
}
}


In this case i am making call to "http://wpconnections.atech.com/profiles/atom/search.do?name=was" and then parsing the feed and then i am printing content of feed entry to System.out. In my case there is only one user with name equal to was so it returns big chunk of HTML for that user like this


<span xmlns="http://www.w3.org/1999/xhtml" class="vcard"><div><img src="http://wpconnections.atech.com/profiles/photo.do?key=c3219b57-5e65-4c50-b00a-3e722315d035&lastMod=1302886728960" class="photo"></img></div><div><a class="fn url" href="http://wpconnections.atech.com/profiles/atom/profile.do?key=c3219b57-5e65-4c50-b00a-3e722315d035">was bind</a></div><div><a class="sound url" href="http://wpconnections.atech.com/profiles/audio.do?key=c3219b57-5e65-4c50-b00a-3e722315d035&lastMod=1302886728960">Pronunciation</a></div><div class="x-groupwareMail" style="display:none"></div><div class="org"><span class="organization-unit"></span></div><div class="role"></div><div class="title"></div><div class="x-office"><span class="x-building"></span><span class="x-floor"></span><span class="x-office-number"></span></div><div class="tel"><abbr class="type" title="work">Work:</abbr><span class="value"></span></div><div class="x-manager-uid" style="display:none"></div><div class="x-is-manager" style="display:none">N</div><div class="x-profile-key">c3219b57-5e65-4c50-b00a-3e722315d035</div><div class="uid">546b0260-6273-497e-acfa-1e898f3037d4</div><div class="x-profile-uid">wasbind</div><div class="x-lconn-userid">546b0260-6273-497e-acfa-1e898f3037d4</div><div class="rev" style="display:none">2011-04-15T16:58:48.960Z</div><div class="x-profile-type" style="display:none">default</div></span></>




I tried pasting the HTML in a simple test.html to see what is getting returned and i can see the markup for person card like this

1 comment: