Author: chabotc Date: Sun May 10 19:42:59 2009 New Revision: 773394 URL: http://svn.apache.org/viewvc?rev=773394&view=rev Log: This patch by Pan Jie adds a cache-invalidation test case, how it works:
1. Gadget spec is invalidation.xml, your can add through http://shindig/test/misc/invalidation/invalidation.xml 2. Counter page is count.php, you can access through http://shindig/test/misc/invalidation/count.php Page looks like: Count: 6 at time: 2009-05-09 08:20:07 3. Sign page is sign.php. Gadget uses that page for signing oauth argument. Gadget usage: Accessing counter page: - Click makeRequest button. Invalidate @viewer through jsonrpc: - Click "jsonrpc invalidate button. Invalidate through restful api: - Fill invalidationKeys, oauth consumer key and oauth consumer secret. - Click "rest invalidate" button. Added: incubator/shindig/trunk/php/test/misc/invalidation/ incubator/shindig/trunk/php/test/misc/invalidation/count.php incubator/shindig/trunk/php/test/misc/invalidation/invalidation.xml incubator/shindig/trunk/php/test/misc/invalidation/sign.php Added: incubator/shindig/trunk/php/test/misc/invalidation/count.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/misc/invalidation/count.php?rev=773394&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/misc/invalidation/count.php (added) +++ incubator/shindig/trunk/php/test/misc/invalidation/count.php Sun May 10 19:42:59 2009 @@ -0,0 +1,16 @@ +<?php +...@date_default_timezone_set(@date_default_timezone_get()); + +$filename = '/tmp/shindig_test_misc_invalidation_count'; + +if (file_exists($filename)) { + $count = file_get_contents($filename); +} else { + touch($filename); + $count = 0; +} + +$count += 1; +echo "Count: $count at time: " . date('Y-m-d H:i:s'); + +file_put_contents($filename, $count); \ No newline at end of file Added: incubator/shindig/trunk/php/test/misc/invalidation/invalidation.xml URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/misc/invalidation/invalidation.xml?rev=773394&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/misc/invalidation/invalidation.xml (added) +++ incubator/shindig/trunk/php/test/misc/invalidation/invalidation.xml Sun May 10 19:42:59 2009 @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Module> + <ModulePrefs title="invalidation" author_email="[email protected]"> + <Require feature="dynamic-height"/> + </ModulePrefs> + <Content type="html"> + <![CDATA[ + <script type="text/javascript"> + + +function pre_rest() { + var content = {} + content.url = document.getElementById("restUrl").value; + content.postdata = stringify(); + content.key = document.getElementById("consumerKey").value; + content.secret = document.getElementById("consumerSecret").value; + var params = {}; + params[gadgets.io.RequestParameters.POST_DATA] = "data=" + gadgets.json.stringify(content); + params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST; + signUrl = document.getElementById("signUrl").value; + gadgets.io.makeRequest(signUrl, rest, params); +} + +function rest(obj) { + var postdata = stringify(); + var xhr = new window.XMLHttpRequest(); + var data = gadgets.json.parse(obj.data); + var url = data.url; + xhr.open("POST", url, true); + xhr.setRequestHeader("Content-type", "application/json"); + xhr.send(postdata); +} + +function jsonrpc() { + var invalidationKeys = "@viewer"; + var postdata = stringify(); + var st = shindig.auth.getSecurityToken(); + var xhr = new window.XMLHttpRequest(); + var url = [document.getElementById("rpcUrl").value]; + url.push("?st="); + url.push(encodeURIComponent(st)); + xhr.open("POST", url.join(""), true); + xhr.setRequestHeader("Content-type", "application/json"); + var jsonRpc = {} + jsonRpc.method = "cache.invalidate"; + jsonRpc.params = {} + jsonRpc.params.invalidationKeys = invalidationKeys.split("\n"); + xhr.send(gadgets.json.stringify(jsonRpc)); +} + +function stringify() { + var invalidationKeys = document.getElementById("invalidationKeys").value; + var result = {}; + result.invalidationKeys = invalidationKeys.split("\n"); + return gadgets.json.stringify(result); +} + +function makeRequest() { + var url = document.getElementById("makeRequestUrl").value; + var params = {}; + params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED; + gadgets.io.makeRequest(url, makeRequestCallback, params); +} + +function makeRequestCallback(obj) { + document.getElementById("makeRequestResult").value = obj.data; +} + +function init() { + gadgets.window.adjustHeight(); +} + +gadgets.util.registerOnLoadHandler(init); + </script> + <div> + makeRequest url:<br> + <textarea style="width:600px;" id="makeRequestUrl">http://shindig/test/misc/invalidation/count.php</textarea><br> + <input type="button" value="makeRequest" onClick="makeRequest()"><br> + makeRequest result:<br> + <textarea style="width:600px;" id="makeRequestResult"></textarea><br> + <br><br><br> + + rest url:<br> + <textarea style="width:600px;" id="restUrl">http://shindig/gadgets/api/rest/cache/invalidate</textarea><br> + rpc url:<br> + <textarea style="width:600px;" id="rpcUrl">http://shindig/gadgets/api/rpc</textarea><br> + invalidationKeys: <br> + <textarea style="width:600px;" id="invalidationKeys"></textarea><br> + sign url: <br> + <textarea style="width:600px;" id="signUrl">http://shindig/test/misc/invalidation/sign.php</textarea><br> + oauth consumer key: <br> + <textarea style="width:600px;" id="consumerKey"></textarea><br> + oauth consumer secret: <br> + <textarea style="width:600px;" id="consumerSecret"></textarea><br> + </div> + <input type="button" value="rest invalidate" onClick="pre_rest()"> + <input type="button" value="jsonrpc invalidate" onClick="jsonrpc()"> + <div id="main"> + <div id="message"></div> + <div id="logging"></div> + </div> + ]]> + </Content> +</Module> Added: incubator/shindig/trunk/php/test/misc/invalidation/sign.php URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/misc/invalidation/sign.php?rev=773394&view=auto ============================================================================== --- incubator/shindig/trunk/php/test/misc/invalidation/sign.php (added) +++ incubator/shindig/trunk/php/test/misc/invalidation/sign.php Sun May 10 19:42:59 2009 @@ -0,0 +1,18 @@ +<?php + +require_once '../../../src/gadgets/oauth/OAuth.php'; + +$data = json_decode($_POST['data']); + +$consumer = new OAuthConsumer($data->key, $data->secret); +$signature_method = new OAuthSignatureMethod_HMAC_SHA1(); +$params = array(); +$params['oauth_body_hash'] = base64_encode(sha1(stripslashes($data->postdata), true)); +$params['oauth_consumer_key'] = $data->key; +$oauth_request = OAuthRequest::from_consumer_and_token($consumer, null, 'POST', $data->url, $params); +$oauth_request->sign_request($signature_method, $consumer, null); + +$result = $oauth_request->to_url(); +header('ContentType: application/json'); +echo '{"url" : "' . $result . '"}'; +
