Author: chabotc
Date: Thu Jul 16 13:46:43 2009
New Revision: 794672
URL: http://svn.apache.org/viewvc?rev=794672&view=rev
Log:
Add native support for the system.listMethods RPC call. Since most people won't
configure the osapi.services key when their first trying out shindig, i've
added a including-all-functions default if container.js->osapi.services is
still the default value
Added:
incubator/shindig/trunk/php/src/social/service/SystemHandler.php
Modified:
incubator/shindig/trunk/php/src/gadgets/render/GadgetBaseRenderer.php
incubator/shindig/trunk/php/src/social/service/InvalidateHandler.php
incubator/shindig/trunk/php/src/social/servlet/ApiServlet.php
incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php
Modified: incubator/shindig/trunk/php/src/gadgets/render/GadgetBaseRenderer.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/render/GadgetBaseRenderer.php?rev=794672&r1=794671&r2=794672&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/render/GadgetBaseRenderer.php
(original)
+++ incubator/shindig/trunk/php/src/gadgets/render/GadgetBaseRenderer.php Thu
Jul 16 13:46:43 2009
@@ -379,13 +379,24 @@
if (isset($gadgetConfig['osml'])) {
unset($gadgetConfig['osml']);
}
- if (!isset($gadgetConfig['osapi.services']) ||
count($gadgetConfig['osapi.services']) == 1) {
+ if (! isset($gadgetConfig['osapi.services']) ||
count($gadgetConfig['osapi.services']) == 1) {
// this should really be set in config/container.js, but if not, we
build a complete default set so at least most of it works out-of-the-box
$gadgetConfig['osapi.services'] = array(
- 'gadgets.rpc' => array('container.listMethods'),
- 'http://%host%/social/rpc' =>
array("messages.update","albums.update","activities.delete","activities.update","activities.supportedFields","albums.get","activities.get","mediaitems.update","messages.get","appdata.get","system.listMethods","people.supportedFields","messages.create","mediaitems.delete","mediaitems.create","people.get","people.create","albums.delete","messages.delete","appdata.update","activities.create","mediaitems.get","albums.create","appdata.delete","people.update","appdata.create"),
- 'http://%host%/gadgets/api/rpc' => array('cache.invalidate',
'system.listMethods')
- );
+ 'gadgets.rpc' => array('container.listMethods'),
+ 'http://%host%/social/rpc' => array("messages.update",
"albums.update",
+ "activities.delete", "activities.update",
+ "activities.supportedFields", "albums.get",
+ "activities.get", "mediaitems.update",
+ "messages.get", "appdata.get",
+ "system.listMethods", "people.supportedFields",
+ "messages.create", "mediaitems.delete",
+ "mediaitems.create", "people.get", "people.create",
+ "albums.delete", "messages.delete",
+ "appdata.update", "activities.create",
+ "mediaitems.get", "albums.create",
+ "appdata.delete", "people.update",
+ "appdata.create"),
+ 'http://%host%/gadgets/api/rpc' => array('cache.invalidate'));
}
return "gadgets.config.init(" . json_encode($gadgetConfig) . ");\n";
}
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=794672&r1=794671&r2=794672&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/InvalidateHandler.php
(original)
+++ incubator/shindig/trunk/php/src/social/service/InvalidateHandler.php Thu
Jul 16 13:46:43 2009
@@ -19,9 +19,9 @@
*/
class InvalidateHandler extends DataRequestHandler {
-
+
private static $INVALIDATE_PATH = "/cache/invalidate";
-
+
private static $KEYS_PARAM = "invalidationKeys";
public function __construct() {
@@ -41,7 +41,7 @@
try {
$method = strtolower($requestItem->getMethod());
$method = 'handle' . ucfirst($method);
- $response = $this->$method($requestItem);
+ $this->$method($requestItem);
} catch (SocialSpiException $e) {
$response = new ResponseItem($e->getCode(), $e->getMessage());
} catch (Exception $e) {
@@ -49,6 +49,7 @@
}
return $response;
}
+
public function handleDelete(RequestItem $request) {
throw new SocialSpiException("Http delete not allowed for invalidation
service", ResponseError::$BAD_REQUEST);
}
@@ -60,7 +61,7 @@
public function handlePost(RequestItem $request) {
$this->handleInvalidate($request);
}
-
+
public function handleGet(RequestItem $request) {
$this->handleInvalidate($request);
}
@@ -70,7 +71,7 @@
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('invalidationKeys');
$resources = array();
@@ -81,7 +82,7 @@
foreach($invalidationKeys as $key) {
if (strpos($key, 'http') !== false) {
if (!$isBackendInvalidation) {
- throw new SocialSpiException('Cannot flush application resources
from a gadget. Must use OAuth consumer request');
+ throw new SocialSpiException('Cannot flush application resources
from a gadget. Must use OAuth consumer request');
}
$resources[] = $key;
} else {
Added: incubator/shindig/trunk/php/src/social/service/SystemHandler.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/SystemHandler.php?rev=794672&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/SystemHandler.php (added)
+++ incubator/shindig/trunk/php/src/social/service/SystemHandler.php Thu Jul 16
13:46:43 2009
@@ -0,0 +1,82 @@
+<?php
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+require_once 'src/gadgets/ContainerConfig.php';
+
+class SystemHandler extends DataRequestHandler {
+
+ public function __construct() { // do nothing, listMethods doesn't have a
service implementation since it depends on the container.js configuration
+ }
+
+ 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) {
+ throw new SocialSpiException("Http delete not allowed for invalidation
service", ResponseError::$BAD_REQUEST);
+ }
+
+ public function handlePut(RequestItem $request) {
+ throw new SocialSpiException("Http put not allowed for invalidation
service", ResponseError::$BAD_REQUEST);
+ }
+
+ public function handlePost(RequestItem $request) {
+ throw new SocialSpiException("Http put not allowed for invalidation
service", ResponseError::$BAD_REQUEST);
+ }
+
+ public function handleGet(RequestItem $request) {
+ return $this->handleListMethods($request);
+ }
+
+ public function handleListMethods(RequestItem $request) {
+ $containerConfig = new ContainerConfig(Config::get('container_path'));
+ $gadgetConfig = $containerConfig->getConfig('default',
'gadgets.features');
+ if (! isset($gadgetConfig['osapi.services']) ||
count($gadgetConfig['osapi.services']) == 1) {
+ // this should really be set in config/container.js, but if not, we
build a complete default set so at least most of it works out-of-the-box
+ $gadgetConfig['osapi.services'] = array(
+ 'gadgets.rpc' => array('container.listMethods'),
+ 'http://%host%/social/rpc' => array("messages.update",
"albums.update",
+ "activities.delete", "activities.update",
+ "activities.supportedFields", "albums.get",
+ "activities.get", "mediaitems.update",
+ "messages.get", "appdata.get",
+ "system.listMethods", "people.supportedFields",
+ "messages.create", "mediaitems.delete",
+ "mediaitems.create", "people.get", "people.create",
+ "albums.delete", "messages.delete",
+ "appdata.update", "activities.create",
+ "mediaitems.get", "albums.create",
+ "appdata.delete", "people.update",
+ "appdata.create"),
+ 'http://%host%/gadgets/api/rpc' => array('cache.invalidate'));
+ }
+ return $gadgetConfig['osapi.services'];
+ }
+}
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=794672&r1=794671&r2=794672&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/servlet/ApiServlet.php (original)
+++ incubator/shindig/trunk/php/src/social/servlet/ApiServlet.php Thu Jul 16
13:46:43 2009
@@ -19,14 +19,6 @@
*/
require 'src/social/service/DataRequestHandler.php';
-require 'src/social/service/PersonHandler.php';
-require 'src/social/spi/ActivityService.php';
-require 'src/social/spi/PersonService.php';
-require 'src/social/spi/AppDataService.php';
-require 'src/social/spi/MessagesService.php';
-require 'src/social/service/ActivityHandler.php';
-require 'src/social/service/AppDataHandler.php';
-require 'src/social/service/MessagesHandler.php';
require 'src/common/SecurityToken.php';
require 'src/common/BlobCrypter.php';
require 'src/social/converters/InputConverter.php';
@@ -55,7 +47,7 @@
* Common base class for API servlets.
*/
abstract class ApiServlet extends HttpServlet {
- protected $handlers = array();
+ public $handlers = array();
protected static $DEFAULT_ENCODING = "UTF-8";
@@ -64,19 +56,13 @@
public static $APPDATA_ROUTE = "appdata";
public static $MESSAGE_ROUTE = "messages";
public static $INVALIDATE_ROUTE = "cache";
+ public static $SYSTEM_ROUTE = "system";
public static $ALBUM_ROUTE = "albums";
public static $MEDIA_ITEM_ROUTE = "mediaitems";
public function __construct() {
parent::__construct();
$this->setNoCache(true);
- $this->handlers[self::$PEOPLE_ROUTE] = new PersonHandler();
- $this->handlers[self::$ACTIVITY_ROUTE] = new ActivityHandler();
- $this->handlers[self::$APPDATA_ROUTE] = new AppDataHandler();
- $this->handlers[self::$MESSAGE_ROUTE] = new MessagesHandler();
- $this->handlers[self::$INVALIDATE_ROUTE] = new InvalidateHandler();
- $this->handlers[self::$ALBUM_ROUTE] = new AlbumHandler();
- $this->handlers[self::$MEDIA_ITEM_ROUTE] = new MediaItemHandler();
if (isset($_SERVER['CONTENT_TYPE']) &&
(strtolower($_SERVER['CONTENT_TYPE']) != $_SERVER['CONTENT_TYPE'])) {
// make sure the content type is in all lower case since that's what
we'll check for in the handlers
$_SERVER['CONTENT_TYPE'] = strtolower($_SERVER['CONTENT_TYPE']);
@@ -155,8 +141,52 @@
* Delivers a request item to the appropriate DataRequestHandler.
*/
protected function handleRequestItem(RequestItem $requestItem) {
+ // lazy initialization of the service handlers, no need to instance them
all for each request
if (! isset($this->handlers[$requestItem->getService()])) {
- throw new SocialSpiException("The service " . $requestItem->getService()
. " is not implemented", ResponseError::$NOT_IMPLEMENTED);
+ switch ($requestItem->getService()) {
+ case self::$PEOPLE_ROUTE:
+ require_once 'src/social/spi/PersonService.php';
+ require_once 'src/social/service/PersonHandler.php';
+ $this->handlers[self::$PEOPLE_ROUTE] = new PersonHandler();
+ break;
+ case self::$ACTIVITY_ROUTE:
+ require_once 'src/social/spi/ActivityService.php';
+ require_once 'src/social/service/ActivityHandler.php';
+ $this->handlers[self::$ACTIVITY_ROUTE] = new ActivityHandler();
+ break;
+ case self::$APPDATA_ROUTE:
+ require_once 'src/social/spi/AppDataService.php';
+ require_once 'src/social/service/AppDataHandler.php';
+ $this->handlers[self::$APPDATA_ROUTE] = new AppDataHandler();
+ break;
+ case self::$MESSAGE_ROUTE:
+ require_once 'src/social/spi/MessagesService.php';
+ require_once 'src/social/service/MessagesHandler.php';
+ $this->handlers[self::$MESSAGE_ROUTE] = new MessagesHandler();
+ break;
+ case self::$INVALIDATE_ROUTE:
+ require_once 'src/social/spi/InvalidateService.php';
+ require_once 'src/social/service/InvalidateHandler.php';
+ $this->handlers[self::$INVALIDATE_ROUTE] = new InvalidateHandler();
+ break;
+ case self::$SYSTEM_ROUTE:
+ require_once 'src/social/service/SystemHandler.php';
+ $this->handlers[self::$SYSTEM_ROUTE] = new SystemHandler();
+ break;
+ case self::$ALBUM_ROUTE:
+ require_once 'src/social/spi/AlbumService.php';
+ require_once 'src/social/service/AlbumHandler.php';
+ $this->handlers[self::$ALBUM_ROUTE] = new AlbumHandler();
+ break;
+ case self::$MEDIA_ITEM_ROUTE:
+ require_once 'src/social/spi/MediaItemService.php';
+ require_once 'src/social/service/MediaItemHandler.php';
+ $this->handlers[self::$MEDIA_ITEM_ROUTE] = new MediaItemHandler();
+ break;
+ default:
+ throw new SocialSpiException("The service " .
$requestItem->getService() . " is not implemented",
ResponseError::$NOT_IMPLEMENTED);
+ break;
+ }
}
$handler = $this->handlers[$requestItem->getService()];
return $handler->handleItem($requestItem);
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=794672&r1=794671&r2=794672&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php
(original)
+++ incubator/shindig/trunk/php/src/social/servlet/DataServiceServlet.php Thu
Jul 16 13:46:43 2009
@@ -30,9 +30,10 @@
public static $APPDATA_ROUTE = "appdata";
public static $MESSAGE_ROUTE = "messages";
public static $INVALIDATE_ROUTE = "cache";
+ public static $SYSTEM_ROUTE = "system";
public static $ALBUM_ROUTE = "albums";
public static $MEDIA_ITEM_ROUTE = "mediaitems";
-
+
public function doGet() {
$this->doPost();