Using Connection API

There could be situations when you would want to use the Connections API for interacting with Connections from outside the Web interface provided by Connection. Ex, you want to create a custom web application or portlet that will let you search for user in the Connection profile repository or want to pull users blog entries and display them outside, if thats the case you should use the REST API provided by Connections, basic idea is you make a HTTP call from your application to Connection, and it will return ATOM based response, you can then parse the feed,.. If you want to post data to connections you will have to create ATOM feed and send it to Connection using HTTP using either HTTP POST or PUT methods or you can delete a record by calling HTTP DELETE method.

I wanted to try this feature so i did create a simple standalone Java application which makes use of plain java to make a HTTP call with name of the user as argument to profiles feature in Connections and the Connections server will return list of all the users with matching name and i will print the output to Standard output



package com.webspherenotes.ssl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class HelloSSL {

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();
BufferedReader reader =
new BufferedReader(new InputStreamReader(inputStream));
String line = null;
while((line = reader.readLine()) != null){
System.out.println(line);
}
} catch (MalformedURLException e) {
e.printStackTrace(System.out);
} catch (IOException e) {
e.printStackTrace(System.out);
}
}
}


In my case the profiles application is available at http://wpconnections.atech.com/profiles and i am calling the Search API with one parameter name=was, which is my search criteria. Similarly you can search for all the users from say Fremont city by passing city=fremont as argument.

Connection will return a search result in ATOM feed format, i am reading that response and printing it to System.out.Take a look at Lotus Connections API document for more information what API meets your requirement and what are the inputs and outputs of the API call.

1 comment: