Author: jsdelfino
Date: Sat Jul 17 22:44:52 2010
New Revision: 965145

URL: http://svn.apache.org/viewvc?rev=965145&view=rev
Log:
Support the host property and a /logout URL on WSGI servers.

Modified:
    tuscany/sca-cpp/trunk/modules/wsgi/composite.py
    tuscany/sca-cpp/trunk/modules/wsgi/jsonutil.py
    tuscany/sca-cpp/trunk/modules/wsgi/scdl.py
    tuscany/sca-cpp/trunk/samples/store-gae/domain-frontend.composite
    tuscany/sca-cpp/trunk/samples/store-gae/domain-single.composite
    tuscany/sca-cpp/trunk/samples/store-gae/domain.composite
    tuscany/sca-cpp/trunk/samples/store-gae/htdocs/index.html
    tuscany/sca-cpp/trunk/samples/store-gae/shopping-cart.py

Modified: tuscany/sca-cpp/trunk/modules/wsgi/composite.py
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/wsgi/composite.py?rev=965145&r1=965144&r2=965145&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/wsgi/composite.py (original)
+++ tuscany/sca-cpp/trunk/modules/wsgi/composite.py Sat Jul 17 22:44:52 2010
@@ -86,6 +86,9 @@ def result(e, r, st, h = (), b = None):
         r("200 OK", list(h + (("Etag", md), ("Expires", "Tue, 01 Jan 1980 
00:00:00 GMT"))))
         return b
 
+    if st == 301:
+        r("301 Moved Permanently", list(h))
+
     return failure(e, r, 500)
 
 # Return an HTTP failure result
@@ -115,6 +118,14 @@ def postArgs(a):
     l = car(a);
     return cons(l, postArgs(cdr(a)))
 
+# Return the URL of the logout page
+def logout(ruri):
+    try:
+        from google.appengine.api import users
+        return users.create_logout_url(ruri)
+    except:
+        return None
+
 # WSGI application function
 def application(e, r):
     m = requestMethod(e)
@@ -132,6 +143,14 @@ def application(e, r):
             return fileresult(e, r, "application/x-javascript", fpath)
         if fpath.endswith(".png"):
             return fileresult(e, r, "image/png", fpath)
+        if fpath == "/":
+            return result(e, r, 301, (("Location", "/index.html"),))
+
+    # Logout
+    if fpath == "/logout":
+        redir = logout("/")
+        if redir:
+            return result(e, r, 301, (("Location", redir),))
 
     # Find the requested component
     path = tokens(fpath)

Modified: tuscany/sca-cpp/trunk/modules/wsgi/jsonutil.py
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/wsgi/jsonutil.py?rev=965145&r1=965144&r2=965145&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/wsgi/jsonutil.py (original)
+++ tuscany/sca-cpp/trunk/modules/wsgi/jsonutil.py Sat Jul 17 22:44:52 2010
@@ -132,9 +132,11 @@ def jsonResultValue(s):
 
 # Return a portable function name from a JSON-RPC function name
 def funcName(f):
-    if len(f) > 7 and f.find("system.") == 0:
+    if f.startswith("."):
+        return f[1:]
+    if f.startswith("system."):
         return f[7:]
-    if len(f) > 8 and f.find("Service.") == 0:
+    if f.startswith("Service."):
         return f[8:]
     return f
 

Modified: tuscany/sca-cpp/trunk/modules/wsgi/scdl.py
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/wsgi/scdl.py?rev=965145&r1=965144&r2=965145&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/wsgi/scdl.py (original)
+++ tuscany/sca-cpp/trunk/modules/wsgi/scdl.py Sat Jul 17 22:44:52 2010
@@ -19,6 +19,7 @@
 
 from xml.etree.cElementTree import iterparse
 from sys import stderr
+from os import environ
 from util import *
 from httputil import *
 
@@ -186,9 +187,11 @@ def evalReference(r, comps):
     return nameToComponent(t, comps)
 
 # Evaluate a property, return a lambda function returning the property
-# value. The user and email properties are configured with the values
-# from the HTTP request, if any
+# value. The host, user and email properties are configured with the
+# values from the HTTP request, if any
 def evalProperty(p):
+    if car(p) == "host":
+        return lambda: hostProperty(cadr(p), environ)
     if car(p) == "user":
         return lambda: userProperty(cadr(p))
     if car(p) == "email":
@@ -206,6 +209,9 @@ def userProperty(v):
     user = currentUser()
     return user.user_id() if user else v
 
+def hostProperty(v, e):
+    return e.get("HTTP_HOST", e.get("SERVER_NAME", v)).split(":")[0]
+
 def emailProperty(v):
     user = currentUser()
     return user.email() if user else v

Modified: tuscany/sca-cpp/trunk/samples/store-gae/domain-frontend.composite
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-gae/domain-frontend.composite?rev=965145&r1=965144&r2=965145&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-gae/domain-frontend.composite (original)
+++ tuscany/sca-cpp/trunk/samples/store-gae/domain-frontend.composite Sat Jul 
17 22:44:52 2010
@@ -52,6 +52,7 @@
         <reference name="cache">
             <t:binding.http uri="https://sca-store-backend.appspot.com/cache"/>
         </reference>
+        <property name="host">localhost</property>
         <property name="email">[email protected]</property>
     </component>
     

Modified: tuscany/sca-cpp/trunk/samples/store-gae/domain-single.composite
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-gae/domain-single.composite?rev=965145&r1=965144&r2=965145&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-gae/domain-single.composite (original)
+++ tuscany/sca-cpp/trunk/samples/store-gae/domain-single.composite Sat Jul 17 
22:44:52 2010
@@ -50,6 +50,7 @@
             <t:binding.jsonrpc uri="total"/>
         </service>        
         <reference name="cache" target="Cache"/>
+        <property name="host">localhost</property>
         <property name="email">[email protected]</property>
     </component>
     

Modified: tuscany/sca-cpp/trunk/samples/store-gae/domain.composite
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-gae/domain.composite?rev=965145&r1=965144&r2=965145&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-gae/domain.composite (original)
+++ tuscany/sca-cpp/trunk/samples/store-gae/domain.composite Sat Jul 17 
22:44:52 2010
@@ -50,6 +50,7 @@
             <t:binding.jsonrpc uri="total"/>
         </service>        
         <reference name="cache" target="Cache"/>
+        <property name="host">localhost</property>
         <property name="email">[email protected]</property>
     </component>
     

Modified: tuscany/sca-cpp/trunk/samples/store-gae/htdocs/index.html
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-gae/htdocs/index.html?rev=965145&r1=965144&r2=965145&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-gae/htdocs/index.html (original)
+++ tuscany/sca-cpp/trunk/samples/store-gae/htdocs/index.html Sat Jul 17 
22:44:52 2010
@@ -51,6 +51,14 @@ function catalog_getcatalogResponse(item
     catalogItems = items;
 }
 
+function shoppingCart_gethostResponse(host, exception) {
+    if (exception) { 
+        alert(exception.message); 
+        return;
+    }
+    document.getElementById('host').innerHTML = host;
+}
+
 function shoppingCart_getemailResponse(email, exception) {
     if (exception) { 
         alert(exception.message); 
@@ -131,6 +139,7 @@ function init() {
     try {
         catalog.apply("getcatalog", catalog_getcatalogResponse);
         shoppingCart.apply("getemail", shoppingCart_getemailResponse);
+        shoppingCart.apply("gethost", shoppingCart_gethostResponse);
         shoppingCart.get("", shoppingCart_getResponse);
     } catch(e){
         alert(e);
@@ -141,7 +150,7 @@ function init() {
 
 <body onload="init()">
 <h1>Store</h1>
-<p>You're signed in as: <span id="email"></span><br/><a 
href="/_ah/login?continue=/store.html&action=Logout">Sign out</a></p>
+<p>Welcome to: <span id="host"></span>, you're signed in as: <span 
id="email"></span><br/><a href="/logout">Sign out</a></p>
 <div id="store">
 <h2>Catalog</h2>
 <form name="catalogForm">

Modified: tuscany/sca-cpp/trunk/samples/store-gae/shopping-cart.py
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-gae/shopping-cart.py?rev=965145&r1=965144&r2=965145&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-gae/shopping-cart.py (original)
+++ tuscany/sca-cpp/trunk/samples/store-gae/shopping-cart.py Sat Jul 17 
22:44:52 2010
@@ -30,7 +30,7 @@ def getcart(id, cache):
     return cart
 
 # Post a new item to the cart, create a new cart if necessary
-def post(collection, item, cache, email):
+def post(collection, item, cache, host, email):
     id = str(uuid.uuid1())
     cart = ((item[0], id, item[2]),) + getcart(cartId, cache)
     cache("put", (cartId,), cart)
@@ -46,13 +46,13 @@ def find(id, cart):
         return find(id, cart[1:])
 
 # Get items from the cart
-def get(id, cache, email):
+def get(id, cache, host, email):
     if id == ():
         return ("Your Cart", cartId) + getcart(cartId, cache)
     return find(id[0], getcart(cartId, cache))
 
 # Delete items from the  cart
-def delete(id, cache, email):
+def delete(id, cache, host, email):
     if id == ():
         return cache("delete", (cartId,))
     return True
@@ -68,11 +68,15 @@ def sum(items):
     return price(items[0]) + sum(items[1:])
 
 # Return the total price of the items in the cart
-def gettotal(cache, email):
+def gettotal(cache, host, email):
     cart = getcart(cartId, cache)
     return sum(cart)
 
 # Return the email of the cart owner
-def getemail(cache, email):
+def getemail(cache, host, email):
     return email()
 
+# Return the host that the app is running on
+def gethost(cache, host, email):
+    return host()
+


Reply via email to