public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String encodedAddress = UriEscapers.uriEscaper().escape(user.getAddress());
if (!userContext.hasOAuthCredentials()) {
// Return an empty set of contacts; the client will show unknown avatars
// and never call PhotosHandler.
printJson(new ContactFeed(), encodedAddress, resp);
return;
}
Pair<Integer, Integer> range = getRange(req);
log.info("Fetching contacts for: " + user + ", [" + range.first + ", " + range.second + ")");
URL url = new URL(FEED_URL + encodedAddress + "/thin"
+ "?start-index=" + range.first + "&max-results=" + (range.second - range.first));
ContactFeed results;
try {
results = contacts.get().getFeed(url, ContactFeed.class);
} catch (ServiceException e) {
throw new IOException("Contact fetch failed: ", e);
}
log.info("Fetched " + results.getEntries().size() + " contacts for " + user);
// Support ?format=html for debugging.
if ("html".equals(req.getParameter("format"))) {
printHtml(results, encodedAddress, resp);
} else {