String timestamp = StringUtils.trimToEmpty(req.getParameter("timestamp")).trim();
String appKey = ServletUtils.getSetting(this, xmlConfig, "dropbox_appkey", "");
if ("".equals(appKey)) return XmlResponse.buildErrorXml(-1, "Missing parameters");
WebAuthSession was = null;
WebAuthSession.WebAuthInfo info = null;
ServletContext context=getServletContext();
DropboxContext dropboxContext = null;
synchronized(this) {
@SuppressWarnings("unchecked")
//HashMap<String,DropboxContext> dropboxContextList = (HashMap<String, DropboxContext>) context.getAttribute("DropboxContext");
ArrayList<DropboxContext> dropboxContextList = (ArrayList<DropboxContext>) context.getAttribute("DropboxContext");
if (dropboxContextList == null) return XmlResponse.buildErrorXml(-1, "No Dropbox context");
dropboxContext = dropboxContextGet(dropboxContextList, 0, appKey+"-"+timestamp);
if (dropboxContext == null) return XmlResponse.buildErrorXml(-1, "No Dropbox context");
}
// Iterator<String> iterator = dropboxContextList.keySet().iterator();
//
// while(iterator.hasNext()){
// String key = (String) iterator.next();
// if (key.equals(appKey+"-"+timestamp)) {
// was = dropboxContextList.get(key).was;
// info = dropboxContextList.get(key).info;
// break;
// }
// }
was = dropboxContext.was;
info = dropboxContext.info;
if (was == null || info == null) return XmlResponse.buildErrorXml(-1, "No Dropbox context");
try {
String userId = was.retrieveWebAccessToken(info.requestTokenPair);
System.out.println("User ID: " + userId);
System.out.println("Access Key: " + was.getAccessTokenPair().key);
System.out.println("Access Secret " + was.getAccessTokenPair().secret);
//DropboxAPI<WebAuthSession> api = new DropboxAPI<WebAuthSession>(was);
//DeltaPage<Entry> deltaPage = api.delta("");
} catch (DropboxException e) {
e.printStackTrace();
return XmlResponse.buildErrorXml(-1, "Dropbox unlinked");
}
String ret = "<?xml version=\"1.0\" encoding=\"utf-8\"?><result>";
ret += "<errno>0</errno>";
ret += "<token_key>" + was.getAccessTokenPair().key + "</token_key>";
ret += "<token_secret>" + was.getAccessTokenPair().secret + "</token_secret></result>";
return ret;
}