You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2014/03/04 14:20:03 UTC
svn commit: r1574094 -
/wookie/trunk/wookie-features/src/main/webapp/features/widget/wookie.js
Author: scottbw
Date: Tue Mar 4 13:20:02 2014
New Revision: 1574094
URL: http://svn.apache.org/r1574094
Log:
Modified the core widget JS to first exchange the single-use token in the URL for a session token from the WOOKIE REST API (see WOOKIE-426). Also moved these various API calls into functions rather than inline within init() for better readability.
Modified:
wookie/trunk/wookie-features/src/main/webapp/features/widget/wookie.js
Modified: wookie/trunk/wookie-features/src/main/webapp/features/widget/wookie.js
URL: http://svn.apache.org/viewvc/wookie/trunk/wookie-features/src/main/webapp/features/widget/wookie.js?rev=1574094&r1=1574093&r2=1574094&view=diff
==============================================================================
--- wookie/trunk/wookie-features/src/main/webapp/features/widget/wookie.js (original)
+++ wookie/trunk/wookie-features/src/main/webapp/features/widget/wookie.js Tue Mar 4 13:20:02 2014
@@ -296,7 +296,13 @@ var Widget = {
this.proxyUrl = pairs[i].substring(pos + 1);
}
}
- }
+ }
+
+ //
+ // First, we need to refresh the security token. The initial token in the URL
+ // is only usable for a short while.
+ //
+ this.refreshToken(false);
//
// Instantiate a Widget Preferences object, and load all values
@@ -305,10 +311,39 @@ var Widget = {
//
this.preferences = WidgetPreferences;
-
//
// Load preferences using AJAX
//
+ this.loadPreferences();
+
+ //
+ // Load metadata using AJAX
+ //
+ this.loadMetadata();
+
+ },
+
+ /**
+ * Load widget metadata from Wookie API
+ */
+ loadMetadata: function(){
+ var xml_request = new XMLHttpRequest();
+ xml_request.open("GET", "/wookie/metadata?idkey="+this.instanceid_key, false);
+ xml_request.onreadystatechange = function()
+ {
+ if(xml_request.readyState == 4 && xml_request.status == 200){
+ var json = (JSON.parse(xml_request.responseText));
+ Widget.setMetadata(json);
+ }
+ }
+ xml_request.setRequestHeader("Cache-Control", "no-cache");
+ xml_request.send(null);
+ },
+
+ /**
+ * Load preferences from Wookie API
+ */
+ loadPreferences: function(){
var xml_request = new XMLHttpRequest();
xml_request.open("GET", "/wookie/preferences?idkey="+this.instanceid_key, false);
xml_request.onreadystatechange = function()
@@ -316,27 +351,28 @@ var Widget = {
if(xml_request.readyState == 4 && xml_request.status == 200){
var json = (JSON.parse(xml_request.responseText));
Widget.setPrefs(json.Preferences);
-
}
}
xml_request.setRequestHeader("Cache-Control", "no-cache");
xml_request.send(null);
-
- //
- // Load metadata using AJAX
- //
+ },
+
+ /**
+ * Refreshes the widget security token from Wookie API
+ * @param async whether to refresh the token asynchronously
+ */
+ refreshToken: function(async){
var xml_request = new XMLHttpRequest();
- xml_request.open("GET", "/wookie/metadata?idkey="+this.instanceid_key, false);
+ xml_request.open("POST", "/wookie/token?idkey="+this.instanceid_key, async);
xml_request.onreadystatechange = function()
{
- if(xml_request.readyState == 4 && xml_request.status == 200){
+ if(xml_request.readyState == 4 && xml_request.status == 201){
var json = (JSON.parse(xml_request.responseText));
- Widget.setMetadata(json);
-
+ Widget.instanceid_key = json.token;
}
}
xml_request.setRequestHeader("Cache-Control", "no-cache");
- xml_request.send(null);
+ xml_request.send(null);
},
/**