You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by ch...@apache.org on 2009/04/29 14:00:22 UTC

svn commit: r769765 - in /incubator/shindig/trunk/php: index.php src/social/service/InvalidateHandler.php src/social/service/RestRequestItem.php src/social/servlet/ApiServlet.php src/social/servlet/DataServiceServlet.php

Author: chabotc
Date: Wed Apr 29 12:00:21 2009
New Revision: 769765

URL: http://svn.apache.org/viewvc?rev=769765&view=rev
Log:
Patch from Pan Jie:

0.9 Spec changes invalidation entry from "/invalidation" to "/cache/invalidation".

I did 3 things in this patch:
1. add entries "/gadgets/rpc" and "/gadgets/api/rest"
2. change invalidation service path
3. do not allow delete/put method for invalidation handler



Modified:
    incubator/shindig/trunk/php/index.php
    incubator/shindig/trunk/php/src/social/service/InvalidateHandler.php
    incubator/shindig/trunk/php/src/social/service/RestRequestItem.php
    incubator/shindig/trunk/php/src/social/servlet/ApiServlet.php
    incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php

Modified: incubator/shindig/trunk/php/index.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/index.php?rev=769765&r1=769764&r2=769765&view=diff
==============================================================================
--- incubator/shindig/trunk/php/index.php (original)
+++ incubator/shindig/trunk/php/index.php Wed Apr 29 12:00:21 2009
@@ -85,6 +85,8 @@
     Config::get('web_prefix') . '/gadgets/ifr' => 'GadgetRenderingServlet',
     Config::get('web_prefix') . '/gadgets/metadata' => 'MetadataServlet',
     Config::get('web_prefix') . '/gadgets/oauthcallback' => 'OAuthCallbackServlet',
+    Config::get('web_prefix') . '/gadgets/rpc' => 'JsonRpcServlet',
+    Config::get('web_prefix') . '/gadgets/api/rest' => 'DataServiceServlet',
     Config::get('web_prefix') . '/social/rest' => 'DataServiceServlet',
     Config::get('web_prefix') . '/social/rpc' => 'JsonRpcServlet',
     Config::get('web_prefix') . '/public.crt' => 'CertServlet',

Modified: incubator/shindig/trunk/php/src/social/service/InvalidateHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/InvalidateHandler.php?rev=769765&r1=769764&r2=769765&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/InvalidateHandler.php (original)
+++ incubator/shindig/trunk/php/src/social/service/InvalidateHandler.php Wed Apr 29 12:00:21 2009
@@ -25,7 +25,7 @@
    */
   private $invalidateService;
   
-  private static $INVALIDATE_PATH = "/invalidate";
+  private static $INVALIDATE_PATH = "/cache/invalidate";
   
   private static $KEYS_PARAM = "invalidationKeys";
 
@@ -35,25 +35,41 @@
     $this->invalidateService = new $service($cache);
   }
 
+  public function handleItem(RequestItem $requestItem) {
+    try {
+      $method = strtolower($requestItem->getMethod());
+      $method = 'handle' . ucfirst($method);
+      $response = $this->$method($requestItem);
+    } catch (SocialSpiException $e) {
+      $response = new ResponseItem($e->getCode(), $e->getMessage());
+    } catch (Exception $e) {
+      $response = new ResponseItem(ResponseError::$INTERNAL_ERROR, "Internal error: " . $e->getMessage());
+    }
+    return $response;
+  }
   public function handleDelete(RequestItem $request) {
-    $this->handleGet($request);
+    throw new SocialSpiException("Http delete not allowed for invalidation service", ResponseError::$BAD_REQUEST);
   }
 
   public function handlePut(RequestItem $request) {
-    $this->handleGet($request);
+    throw new SocialSpiException("Http put not allowed for invalidation service", ResponseError::$BAD_REQUEST);
   }
 
   public function handlePost(RequestItem $request) {
-    $this->handleGet($request);
+    $this->handleInvalidate($request);
   }
-
+  
   public function handleGet(RequestItem $request) {
+    $this->handleInvalidate($request);
+  }
+
+  public function handleInvalidate(RequestItem $request) {
     if (!$request->getToken()->getAppId() && !$request->getToken()->getAppUrl()) {
       throw new SocialSpiException("Can't invalidate content without specifying application", ResponseError::$BAD_REQUEST);
     }
     
     $isBackendInvalidation = AuthenticationMode::$OAUTH_CONSUMER_REQUEST == $request->getToken()->getAuthenticationMode();
-    $invalidationKeys = $request->getListParameter('invalidationKey');
+    $invalidationKeys = $request->getListParameter('invalidationKeys');
     $resources = array();
     $userIds = array();
     if ($request->getToken()->getViewerId()) {

Modified: incubator/shindig/trunk/php/src/social/service/RestRequestItem.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/RestRequestItem.php?rev=769765&r1=769764&r2=769765&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/RestRequestItem.php (original)
+++ incubator/shindig/trunk/php/src/social/service/RestRequestItem.php Wed Apr 29 12:00:21 2009
@@ -24,7 +24,15 @@
 class RestRequestItem extends RequestItem {
   private $url;
   private $params;
+  
+  /**
+   * @var InputConverter
+   */
   private $inputConverter;
+  
+  /**
+   * @var OutputConverter
+   */
   private $outputConverter;
   private $postData;
 
@@ -73,6 +81,9 @@
         $data = $this->inputConverter->convertMessages($this->postData);
         $this->params['message'] = $data;
         break;
+      case DataServiceServlet::$INVALIDATE_ROUTE:
+        $this->params = json_decode($this->postData, true);
+        break;
       default:
         throw new Exception("Invalid or unknown service endpoint: $service");
         break;

Modified: incubator/shindig/trunk/php/src/social/servlet/ApiServlet.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/servlet/ApiServlet.php?rev=769765&r1=769764&r2=769765&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/servlet/ApiServlet.php (original)
+++ incubator/shindig/trunk/php/src/social/servlet/ApiServlet.php Wed Apr 29 12:00:21 2009
@@ -63,7 +63,7 @@
   public static $ACTIVITY_ROUTE = "activities";
   public static $APPDATA_ROUTE = "appdata";
   public static $MESSAGE_ROUTE = "messages";
-  public static $INVALIDATE_ROUTE = "invalidate";
+  public static $INVALIDATE_ROUTE = "cache";
 
   public function __construct() {
     parent::__construct();

Modified: incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php?rev=769765&r1=769764&r2=769765&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php (original)
+++ incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php Wed Apr 29 12:00:21 2009
@@ -29,7 +29,7 @@
   public static $ACTIVITY_ROUTE = "activities";
   public static $APPDATA_ROUTE = "appdata";
   public static $MESSAGE_ROUTE = "messages";
-  public static $INVALIDATE_ROUTE = "invalidate";
+  public static $INVALIDATE_ROUTE = "cache";
 
   public function doGet() {
     $this->doPost();
@@ -107,8 +107,9 @@
    * Handler for non-batch requests (REST only has non-batch requests)
    */
   private function handleSingleRequest(SecurityToken $token, $inputConverter, $outputConverter) {
+    //uri example: /social/rest/people/@self   /gadgets/api/rest/cache/invalidate
     $servletRequest = array(
-        'url' => substr($_SERVER["REQUEST_URI"], strlen(Config::get('web_prefix') . '/social/rest')));
+        'url' => substr($_SERVER["REQUEST_URI"], strpos($_SERVER["REQUEST_URI"], '/rest') + 5));
     if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
       $servletRequest['postData'] = $GLOBALS['HTTP_RAW_POST_DATA'];
       if (get_magic_quotes_gpc()) {