Author: chabotc
Date: Mon Jun 22 10:57:32 2009
New Revision: 787196

URL: http://svn.apache.org/viewvc?rev=787196&view=rev
Log:
Patch by Jinhui Du to enable both 0.8 and 0.9 style message handling through 
the same interface:

1. Uses HTTP put method to update and the post method to create. It only affects
MessageHandler. Since all the other handlers(ActivityHandler, InvalidateHandler,
PersonHandler, AppDataHandler) either treat the post and the put method as the
same or don't support the put method.

2. Adds the logic to support old message creation.


Modified:
    incubator/shindig/trunk/php/src/social/service/DataRequestHandler.php
    incubator/shindig/trunk/php/src/social/service/MessagesHandler.php

Modified: incubator/shindig/trunk/php/src/social/service/DataRequestHandler.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/DataRequestHandler.php?rev=787196&r1=787195&r2=787196&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/DataRequestHandler.php 
(original)
+++ incubator/shindig/trunk/php/src/social/service/DataRequestHandler.php Mon 
Jun 22 10:57:32 2009
@@ -40,11 +40,11 @@
           $response = $this->handleGet($requestItem);
         }
       } elseif (in_array($method, self::$UPDATE_SYNONYMS)) {
-        $response = $this->handlePost($requestItem);
+        $response = $this->handlePut($requestItem);
       } elseif (in_array($method, self::$DELETE_SYNONYMS)) {
         $response = $this->handleDelete($requestItem);
       } elseif (in_array($method, self::$CREATE_SYNONYMS)) {
-        $response = $this->handlePut($requestItem);
+        $response = $this->handlePost($requestItem);
       } else {
         throw new SocialSpiException("Unserviced Http method type", 
ResponseError::$BAD_REQUEST);
       }

Modified: incubator/shindig/trunk/php/src/social/service/MessagesHandler.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/MessagesHandler.php?rev=787196&r1=787195&r2=787196&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/MessagesHandler.php 
(original)
+++ incubator/shindig/trunk/php/src/social/service/MessagesHandler.php Mon Jun 
22 10:57:32 2009
@@ -37,7 +37,7 @@
     $userIds = $requestItem->getUsers();
     HandlerPreconditions::requireSingular($userIds, "UserId can only be 
singular.");
     $msgCollId = $requestItem->getParameter("msgCollId");
-    HandlerPreconditions::requireNotEmpty($msgCollId, "A message collection is 
required");
+    HandlerPreconditions::requireNotEmpty($msgCollId, "A message collection id 
is required");
 
     $token = $requestItem->getToken();
     $messageIds = $requestItem->getListParameter("messageId");
@@ -90,10 +90,18 @@
     HandlerPreconditions::requireSingular($userIds, "UserId is not singular.");
 
     $msgCollId = $requestItem->getParameter("msgCollId");
+    $entity = $requestItem->getParameter("entity");
+    
+    // If the parameters contain 'message' the request is from the old api(< 
0.9).
+    if ($requestItem->getParameter("message")) {
+      $entity = $requestItem->getParameter("message");
+      $msgCollId = "@outbox";
+    }
+
     if (empty($msgCollId)) {
       // Creates a message collection.
-      $messageCollection = $requestItem->getParameter("entity");
-      HandlerPreconditions::requireNotEmpty($messageCollection, "Can't parse 
message collection.");
+      $messageCollection = $entity;
+      HandlerPreconditions::requireNotEmpty($messageCollection, "Filed entity 
not specified.");
       $title = isset($messageCollection['title']) ? 
trim($messageCollection['title']) : '';
       HandlerPreconditions::requireCondition(strlen($title) > 0, "Title must 
be specified.");
       return $this->service->createMessageCollection($userIds[0], 
$messageCollection, $requestItem->getToken());
@@ -101,8 +109,8 @@
       // Creates a message.
       $messageIds = $requestItem->getListParameter("messageId");
       HandlerPreconditions::requireEmpty($messageIds, "messageId cannot be 
specified in create method.");
-      $message = $requestItem->getParameter("entity");
-      HandlerPreconditions::requireNotEmpty($message, "Can't parse message.");
+      $message = $entity;
+      HandlerPreconditions::requireNotEmpty($message, "Filed entity not 
specified.");
       HandlerPreconditions::requireEmpty($messageIds, "messageId cannot be 
specified in create method.");
 
       // Message fields validation.


Reply via email to