You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by aw...@apache.org on 2009/02/13 00:39:07 UTC

svn commit: r743928 - in /incubator/shindig/trunk/java: gadgets/src/main/java/org/apache/shindig/gadgets/spec/ gadgets/src/test/java/org/apache/shindig/gadgets/preload/ gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/ gadgets/src/test/java/org...

Author: awiner
Date: Thu Feb 12 23:39:07 2009
New Revision: 743928

URL: http://svn.apache.org/viewvc?rev=743928&view=rev
Log:
Get server-side data pipelining into compliance with expected spec changes;  specifically, added os:DataRequest as a generic Opensocial endpoint element and os:HttpRequest as the name of the makeRequest() replacement
(The previous naming wasn't compliant with the existing spec either, so we're no worse off in any case)

Modified:
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/PipelinedData.java
    incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/PipelinedDataPreloaderTest.java
    incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/PipelineDataContentRewriterTest.java
    incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/PipelinedDataTest.java
    incubator/shindig/trunk/java/server/src/test/resources/endtoend/pipeliningTest.xml

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/PipelinedData.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/PipelinedData.java?rev=743928&r1=743927&r2=743928&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/PipelinedData.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/PipelinedData.java Thu Feb 12 23:39:07 2009
@@ -40,6 +40,7 @@
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 
 import com.google.common.collect.ImmutableMap;
@@ -94,8 +95,10 @@
           socialPreloads.put(key, createPersonAppDataRequest(child));
         } else if ("ActivitiesRequest".equals(elementName)) {
           socialPreloads.put(key, createActivityRequest(child));
-        } else if ("MakeRequest".equals(elementName)) {
-          httpPreloads.put(key, createMakeRequest(child, base));
+        } else if ("DataRequest".equals(elementName)) {
+          socialPreloads.put(key, createDataRequest(child));
+        } else if ("HttpRequest".equals(elementName)) {
+          httpPreloads.put(key, createHttpRequest(child, base));
         } else {
           // TODO: This is wrong - the spec should parse, but should preload
           // notImplemented
@@ -329,21 +332,56 @@
     return expression;
   }
 
-  /** Handle an os:MakeRequest element */
-  private HttpData createMakeRequest(Element child, Uri base) throws ELException {
-    HttpData data = new HttpData(child, base);
+  /** Handle the os:DataRequest element */
+  private SocialData createDataRequest(Element child) throws ELException, SpecParserException {
+    String method = child.getAttribute("method");
+    if (method == null) {
+      throw new SpecParserException("Missing @method attribute on os:DataRequest");
+    }
+    
+    // TODO: should we support anything that doesn't end in .get?
+    // i.e, should this be a whitelist not a blacklist? 
+    if (method.endsWith(".update")
+        || method.endsWith(".create")
+        || method.endsWith(".delete")) {
+      throw new SpecParserException("Unsupported @method attribute \"" + method + "\" on os:DataRequest");
+    }
+    
+    SocialData expression = new SocialData(child.getAttribute("key"), method);
+    NamedNodeMap nodeMap = child.getAttributes();
+    for (int i = 0; i < nodeMap.getLength(); i++) {
+      Node attrNode = nodeMap.item(i);
+      // Skip namespaced attributes
+      if (attrNode.getNamespaceURI() != null) {
+        continue;
+      }
+      
+      String name = attrNode.getLocalName();
+      // Skip the built-in names
+      if ("method".equals(name) || "key".equals(name)) {
+        continue;
+      }
+      
+      String value = attrNode.getNodeValue();
+      expression.addProperty(name, value, Object.class);
+    }
+
+    return expression;
+  }
 
-    /* TODO: check auth type, and sign-by-owner/viewer, once spec agrees
-     * to remove support for EL on @authz and @sign_*.
-    if (preload.getAuthType() != AuthType.NONE) {
-      if (preload.isSignOwner()) {
+  /** Handle an os:HttpRequest element */
+  private HttpData createHttpRequest(Element child, Uri base) throws ELException {
+    HttpData data = new HttpData(child, base);
+    // Update needsOwner and needsViewer
+    if (data.authz != AuthType.NONE) {
+      if (data.signOwner) {
         needsOwner = true;
       }
-
-      if (preload.isSignViewer()) {
+      
+      if (data.signViewer) {
         needsViewer = true;
       }
-    }*/
+    }
 
     return data;
   }
@@ -379,7 +417,7 @@
    * A single pipelined HTTP makerequest.
    */
   private static class HttpData {
-    private final String authz;
+    private final AuthType authz;
     private final Uri base;
     private final String href;
     private final boolean signOwner;
@@ -395,7 +433,8 @@
     public HttpData(Element element, Uri base) throws ELException {
       this.base = base;
 
-      this.authz = element.hasAttribute("authz") ? element.getAttribute("authz") : "none";
+      this.authz = element.hasAttribute("authz") ?
+          AuthType.parse(element.getAttribute("authz")) : AuthType.NONE;
 
       // TODO: Spec question;  should EL values be URL escaped?
       this.href = element.getAttribute("href");
@@ -438,8 +477,6 @@
      * @throws ELException if expression evaluation fails.
      */
     public RequestAuthenticationInfo evaluate(ELContext context) throws ELException {
-      final AuthType authType = AuthType.parse(authz);
-      
       Expressions expressions = Expressions.sharedInstance();
       String hrefString = String.valueOf(expressions.parse(href, String.class)
           .getValue(context));
@@ -456,7 +493,7 @@
         }
 
         public AuthType getAuthType() {
-          return authType;
+          return authz;
         }
 
         public Uri getHref() {

Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/PipelinedDataPreloaderTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/PipelinedDataPreloaderTest.java?rev=743928&r1=743927&r2=743928&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/PipelinedDataPreloaderTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/PipelinedDataPreloaderTest.java Thu Feb 12 23:39:07 2009
@@ -58,7 +58,7 @@
       + PipelinedData.OPENSOCIAL_NAMESPACE + "\">"
       + "<ModulePrefs title=\"Title\"/>"
       + "<Content href=\"http://example.org/proxied.php\" view=\"profile\">"
-      + "  <os:MakeRequest key=\"p\" href=\"" + MAKE_REQUEST_URL + "\" "
+      + "  <os:HttpRequest key=\"p\" href=\"" + MAKE_REQUEST_URL + "\" "
       + "refreshInterval=\"60\" method=\"POST\"/>" + "</Content></Module>";
 
   @Before

Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/PipelineDataContentRewriterTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/PipelineDataContentRewriterTest.java?rev=743928&r1=743927&r2=743928&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/PipelineDataContentRewriterTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/PipelineDataContentRewriterTest.java Thu Feb 12 23:39:07 2009
@@ -75,14 +75,14 @@
   private static final String CONTENT =
     "<script xmlns:os='http://ns.opensocial.org/2008/markup' type='text/os-data'>"
       + "  <os:PeopleRequest key='me' userId='canonical'/>"
-      + "  <os:MakeRequest key='json' href='test.json'/>"
+      + "  <os:HttpRequest key='json' href='test.json'/>"
       + "</script>";
 
   // Two requests, one depends on the other
   private static final String TWO_BATCH_CONTENT =
     "<script xmlns:os='http://ns.opensocial.org/2008/markup' type='text/os-data'>"
     + "  <os:PeopleRequest key='me' userId='${json.user}'/>"
-    + "  <os:MakeRequest key='json' href='${ViewParams.file}'/>"
+    + "  <os:HttpRequest key='json' href='${ViewParams.file}'/>"
     + "</script>";
 
   // One request, but it requires data that isn't present

Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/PipelinedDataTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/PipelinedDataTest.java?rev=743928&r1=743927&r2=743928&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/PipelinedDataTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/PipelinedDataTest.java Thu Feb 12 23:39:07 2009
@@ -33,10 +33,13 @@
 
 import javax.el.ELResolver;
 
+import org.json.JSONArray;
 import org.json.JSONObject;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
 public class PipelinedDataTest {
@@ -53,6 +56,38 @@
   }
   
   @Test
+  public void testDataRequest() throws Exception {
+    String xml = "<Content><DataRequest xmlns=\"" + PipelinedData.OPENSOCIAL_NAMESPACE + "\" "
+        + " key=\"key\""
+        + " method=\"people.get\""
+        + " groupId=\"${params.groupId}\""
+        + " userId=\"${userIds}\""
+        + " startIndex=\"${startIndex}\""
+        + " fields=\"${fields}\""
+        + "/></Content>";
+
+    elValues.put("startIndex", 10);
+    // Test a param that evaluates to null
+    elValues.put("params", ImmutableMap.of());
+    elValues.put("userIds", Lists.newArrayList("first", "second"));    
+    elValues.put("fields", new JSONArray("['name','id']"));
+    PipelinedData socialData = new PipelinedData(XmlUtil.parse(xml), null);
+    assertFalse(socialData.needsOwner());
+    assertFalse(socialData.needsViewer());
+
+    JSONObject expected = new JSONObject("{method: 'people.get', id: 'key', params:"
+        + "{userId: ['first','second'],"
+        + "startIndex: 10,"
+        + "fields: ['name','id']"
+        + "}}");
+
+    PipelinedData.Batch batch = socialData.getBatch(elResolver);
+    assertTrue(batch.getHttpPreloads().isEmpty());
+    assertEquals(1, batch.getSocialPreloads().size());
+    assertEquals(expected.toString(), batch.getSocialPreloads().get("key").toString());
+  }
+
+  @Test
   public void testPeopleRequest() throws Exception {
     String xml = "<Content><PeopleRequest xmlns=\"" + PipelinedData.OPENSOCIAL_NAMESPACE + "\" "
         + " key=\"key\""
@@ -231,7 +266,7 @@
   public void testBatching() throws Exception {
     String xml = "<Content xmlns=\"" + PipelinedData.OPENSOCIAL_NAMESPACE + "\">"
     		+ "<PeopleRequest key=\"key\" userId=\"${userId}\"/>"
-            + "<MakeRequest key=\"key2\" href=\"${key}\"/>"
+            + "<HttpRequest key=\"key2\" href=\"${key}\"/>"
         + "</Content>";
 
     PipelinedData socialData = new PipelinedData(XmlUtil.parse(xml), GADGET_URI);
@@ -255,14 +290,16 @@
 
 
  @Test
-  public void makeRequestDefaults() throws Exception {
-    String xml = "<Content><MakeRequest xmlns=\"" + PipelinedData.OPENSOCIAL_NAMESPACE + "\" "
+  public void httpRequestDefaults() throws Exception {
+    String xml = "<Content><HttpRequest xmlns=\"" + PipelinedData.OPENSOCIAL_NAMESPACE + "\" "
         + " key=\"key\""
         + " href=\"/example.html\""
         + "/></Content>";
 
     PipelinedData pipelinedData = new PipelinedData(XmlUtil.parse(xml), GADGET_URI);
     PipelinedData.Batch batch = pipelinedData.getBatch(elResolver);
+    assertFalse(pipelinedData.needsViewer());
+    assertFalse(pipelinedData.needsOwner());
     
     assertEquals(1, batch.getHttpPreloads().size());
     RequestAuthenticationInfo preload = batch.getHttpPreloads().get("key");
@@ -272,8 +309,8 @@
   }
 
   @Test
-  public void makeRequestDefaultsSigned() throws Exception {
-    String xml = "<Content><MakeRequest xmlns=\"" + PipelinedData.OPENSOCIAL_NAMESPACE + "\" "
+  public void httpRequestDefaultsSigned() throws Exception {
+    String xml = "<Content><HttpRequest xmlns=\"" + PipelinedData.OPENSOCIAL_NAMESPACE + "\" "
         + " key=\"key\""
         + " href=\"/example.html\""
         + " authz=\"signed\""
@@ -282,6 +319,8 @@
 
     PipelinedData pipelinedData = new PipelinedData(XmlUtil.parse(xml), GADGET_URI);
     PipelinedData.Batch batch = pipelinedData.getBatch(elResolver);
+    assertTrue(pipelinedData.needsViewer());
+    assertFalse(pipelinedData.needsOwner());
     
     assertEquals(1, batch.getHttpPreloads().size());
     RequestAuthenticationInfo preload = batch.getHttpPreloads().get("key");

Modified: incubator/shindig/trunk/java/server/src/test/resources/endtoend/pipeliningTest.xml
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/pipeliningTest.xml?rev=743928&r1=743927&r2=743928&view=diff
==============================================================================
--- incubator/shindig/trunk/java/server/src/test/resources/endtoend/pipeliningTest.xml (original)
+++ incubator/shindig/trunk/java/server/src/test/resources/endtoend/pipeliningTest.xml Thu Feb 12 23:39:07 2009
@@ -28,6 +28,6 @@
     <!--  Load the canonical user -->
     <os:PeopleRequest key="me" userId="canonical"/>
     <!--  Load a JSON file -->
-    <os:MakeRequest key="json" href="test.json"/>
+    <os:HttpRequest key="json" href="test.json"/>
   </Content>
 </Module>