Author: jsdelfino
Date: Wed Mar 17 08:12:39 2010
New Revision: 924188

URL: http://svn.apache.org/viewvc?rev=924188&view=rev
Log:
Added support for HTTP references and different versions of the store-wsgi 
composite.

Added:
    tuscany/sca-cpp/trunk/modules/wsgi/http-test
      - copied, changed from r923071, 
tuscany/sca-cpp/trunk/modules/wsgi/util-test
    tuscany/sca-cpp/trunk/modules/wsgi/http-test.py
      - copied, changed from r923071, 
tuscany/sca-cpp/trunk/modules/wsgi/util-test
    tuscany/sca-cpp/trunk/modules/wsgi/httputil.py
    tuscany/sca-cpp/trunk/test/store-wsgi/domain-backend.composite
    tuscany/sca-cpp/trunk/test/store-wsgi/domain-frontend.composite
    tuscany/sca-cpp/trunk/test/store-wsgi/domain-single.composite
Modified:
    tuscany/sca-cpp/trunk/modules/http/httpd-conf
    tuscany/sca-cpp/trunk/modules/wsgi/Makefile.am
    tuscany/sca-cpp/trunk/modules/wsgi/jsonutil.py
    tuscany/sca-cpp/trunk/modules/wsgi/scdl.py
    tuscany/sca-cpp/trunk/modules/wsgi/util-test

Modified: tuscany/sca-cpp/trunk/modules/http/httpd-conf
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/httpd-conf?rev=924188&r1=924187&r2=924188&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/httpd-conf (original)
+++ tuscany/sca-cpp/trunk/modules/http/httpd-conf Wed Mar 17 08:12:39 2010
@@ -28,6 +28,8 @@ mkdir -p $root/logs
 mkdir -p $root/conf
 cat >$root/conf/httpd.conf <<EOF
 ErrorLog $root/logs/error_log
+LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" 
combined
+CustomLog $root/logs/access_log combined
 ServerName http://127.0.0.1:$port
 Listen $port
 DocumentRoot $htdocs

Modified: tuscany/sca-cpp/trunk/modules/wsgi/Makefile.am
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/wsgi/Makefile.am?rev=924188&r1=924187&r2=924188&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/wsgi/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/modules/wsgi/Makefile.am Wed Mar 17 08:12:39 2010
@@ -37,6 +37,6 @@ client_test_SOURCES = client-test.cpp
 client_test_LDFLAGS = -lxml2 -lcurl -lmozjs
 
 noinst_PROGRAMS = client-test
-TESTS = util-test wsgi-test wiring-test server-test
+TESTS = util-test wsgi-test wiring-test http-test server-test
 
 endif

Copied: tuscany/sca-cpp/trunk/modules/wsgi/http-test (from r923071, 
tuscany/sca-cpp/trunk/modules/wsgi/util-test)
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/wsgi/http-test?p2=tuscany/sca-cpp/trunk/modules/wsgi/http-test&p1=tuscany/sca-cpp/trunk/modules/wsgi/util-test&r1=923071&r2=924188&rev=924188&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/wsgi/util-test (original)
+++ tuscany/sca-cpp/trunk/modules/wsgi/http-test Wed Mar 17 08:12:39 2010
@@ -17,11 +17,23 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-# Run Python util test cases
+uri=$1
+if [ "$uri" = "" ]; then
+    uri="http://localhost:8090";
+fi
+
+# Setup
+mkdir -p tmp
+./wsgi-start 8090 2>/dev/null
+sleep 2
+
+# Test JSON-RPC
 here=`readlink -f $0`; here=`dirname $here`
 python_prefix=`cat $here/../python/python.prefix`
+$python_prefix/bin/python http-test.py
+rc=$?
 
-$python_prefix/bin/python xml-test.py
-$python_prefix/bin/python atom-test.py
-$python_prefix/bin/python json-test.py
-
+# Cleanup
+./wsgi-stop 8090
+sleep 2
+return $rc

Copied: tuscany/sca-cpp/trunk/modules/wsgi/http-test.py (from r923071, 
tuscany/sca-cpp/trunk/modules/wsgi/util-test)
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/wsgi/http-test.py?p2=tuscany/sca-cpp/trunk/modules/wsgi/http-test.py&p1=tuscany/sca-cpp/trunk/modules/wsgi/util-test&r1=923071&r2=924188&rev=924188&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/wsgi/util-test (original)
+++ tuscany/sca-cpp/trunk/modules/wsgi/http-test.py Wed Mar 17 08:12:39 2010
@@ -1,5 +1,4 @@
-#!/bin/sh
-
+#!/usr/bin/python
 #  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
@@ -17,11 +16,17 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-# Run Python util test cases
-here=`readlink -f $0`; here=`dirname $here`
-python_prefix=`cat $here/../python/python.prefix`
+# HTTP client proxy functions
+
+from httputil import *
+
+def testClient():
+    c = mkclient("http://localhost:8090/wsgi";)
+    assert c("echo", "Hey") == "Hey"
+    return True
 
-$python_prefix/bin/python xml-test.py
-$python_prefix/bin/python atom-test.py
-$python_prefix/bin/python json-test.py
+if __name__ == "__main__":
+    print "Testing..."
+    testClient()
+    print "OK"
 

Added: tuscany/sca-cpp/trunk/modules/wsgi/httputil.py
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/wsgi/httputil.py?rev=924188&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/modules/wsgi/httputil.py (added)
+++ tuscany/sca-cpp/trunk/modules/wsgi/httputil.py Wed Mar 17 08:12:39 2010
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+#  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.
+
+# HTTP client proxy functions
+
+from httplib import HTTPConnection
+from urlparse import urlparse
+from StringIO import StringIO
+from util import *
+from atomutil import *
+from jsonutil import *
+
+id = 1
+
+# Make a callable HTTP client
+class client:
+    def __init__(self, uri):
+        self.uri = urlparse(uri)
+
+    def __call__(self, func, *args):
+        global id
+        req = StringIO()
+        writeStrings(jsonRequest(id, func, args), req)
+        id = id + 1
+        c = HTTPConnection(self.uri.hostname, 80 if self.uri.port == None else 
self.uri.port)
+        c.request("POST", self.uri.path, req.getvalue(), {"Content-type": 
"application/json-rpc"})
+        res = c.getresponse()
+        if res.status != 200:
+            return None
+        return jsonResultValue((res.read(),))
+
+    def __repr__(self):
+        return repr((self.uri,))
+
+def mkclient(uri):
+    return client(uri)
+

Modified: tuscany/sca-cpp/trunk/modules/wsgi/jsonutil.py
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/wsgi/jsonutil.py?rev=924188&r1=924187&r2=924188&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/wsgi/jsonutil.py (original)
+++ tuscany/sca-cpp/trunk/modules/wsgi/jsonutil.py Wed Mar 17 08:12:39 2010
@@ -124,13 +124,13 @@ def jsonResult(id, val):
 # Convert a JSON-RPC result to a value
 def jsonResultValue(s):
     jsres = readJSON(s)
-    rval = cadr(elementsToValues(jsres))
-    val = cadr(rval)
+    res = elementsToValues(jsres)
+    val = cadr(assoc("'result", res))
     if isList(val) and not isJSArray(val):
         return (val,)
     return val
 
-# Return a portalbe function name from a JSON-RPC function name
+# Return a portable function name from a JSON-RPC function name
 def funcName(f):
     if len(f) > 7 and f.find("system.") == 0:
         return f[7:]

Modified: tuscany/sca-cpp/trunk/modules/wsgi/scdl.py
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/wsgi/scdl.py?rev=924188&r1=924187&r2=924188&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/wsgi/scdl.py (original)
+++ tuscany/sca-cpp/trunk/modules/wsgi/scdl.py Wed Mar 17 08:12:39 2010
@@ -19,6 +19,7 @@
 
 from xml.etree.cElementTree import iterparse
 from util import *
+from httputil import *
 
 # Element tree utility functions, used to parse SCDL documents
 def parse(file):
@@ -142,6 +143,13 @@ def uriToComponent(u, comps):
         return (m, car(comps))
     return uriToComponent(u, cdr(comps))
 
+# Evaluate a reference, return a proxy to the resolved component or an
+# HTTP client configured with the reference target uri
+def evalReference(r, comps):
+    if not r.startswith("http://";):
+        return nameToComponent(r, comps)
+    return mkclient(r)
+
 # Evaluate a component, resolve its implementation and references
 def evalComponent(comp, comps):
     comp.mod = __import__(comp.impl)
@@ -149,7 +157,7 @@ def evalComponent(comp, comps):
     # Make a list of proxy lambda functions for the component references and 
properties
     # A reference proxy is the callable lambda function of the component wired 
to the reference
     # A property proxy is a lambda function that returns the value of the 
property
-    comp.proxies = tuple(map(lambda r: nameToComponent(r, comps), comp.refs)) 
+ tuple(map(lambda v: lambda: v, comp.props))
+    comp.proxies = tuple(map(lambda r: evalReference(r, comps), comp.refs)) + 
tuple(map(lambda v: lambda: v, comp.props))
 
     return comp
 

Modified: tuscany/sca-cpp/trunk/modules/wsgi/util-test
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/wsgi/util-test?rev=924188&r1=924187&r2=924188&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/wsgi/util-test (original)
+++ tuscany/sca-cpp/trunk/modules/wsgi/util-test Wed Mar 17 08:12:39 2010
@@ -22,6 +22,14 @@ here=`readlink -f $0`; here=`dirname $he
 python_prefix=`cat $here/../python/python.prefix`
 
 $python_prefix/bin/python xml-test.py
-$python_prefix/bin/python atom-test.py
-$python_prefix/bin/python json-test.py
+rc=$?
+if [ "$rc" = "0" ]; then
+    $python_prefix/bin/python atom-test.py
+    rc=$?
+fi
+if [ "$rc" = "0" ]; then
+    $python_prefix/bin/python json-test.py
+    rc=$?
+fi
 
+return $rc

Added: tuscany/sca-cpp/trunk/test/store-wsgi/domain-backend.composite
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/test/store-wsgi/domain-backend.composite?rev=924188&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/test/store-wsgi/domain-backend.composite (added)
+++ tuscany/sca-cpp/trunk/test/store-wsgi/domain-backend.composite Wed Mar 17 
08:12:39 2010
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912";
+  xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1";
+  targetNamespace="http://store";
+  name="store-backend">
+        
+    <component name="Cache">
+        <implementation.python script="gmemcache.py"/>
+        <service name="Cache">
+            <t:binding.atom uri="cache"/>
+        </service>
+    </component>     
+
+</composite>

Added: tuscany/sca-cpp/trunk/test/store-wsgi/domain-frontend.composite
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/test/store-wsgi/domain-frontend.composite?rev=924188&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/test/store-wsgi/domain-frontend.composite (added)
+++ tuscany/sca-cpp/trunk/test/store-wsgi/domain-frontend.composite Wed Mar 17 
08:12:39 2010
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912";
+  xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1";
+  targetNamespace="http://store";
+  name="store-frontend">
+        
+    <component name="Store">
+        <t:implementation.python script="store.py"/>
+        <service name="Widget">
+            <t:binding.http uri="store"/>
+        </service>
+        <reference name="catalog" target="http://sca-store-backend/catalog"/>
+        <reference name="shoppingCart" 
target="http://sca-store-backend/shoppingCart"/>
+        <reference name="shoppingTotal" 
target="http://sca-store-backend/shoppingCart"/>
+    </component>
+    
+    <component name="Catalog">
+        <t:implementation.python script="fruits-catalog.py"/> 
+        <property name="currencyCode">USD</property>
+        <service name="Catalog">
+            <t:binding.jsonrpc uri="catalog"/>
+        </service>
+        <reference name="currencyConverter" target="CurrencyConverter"/>
+    </component> 
+     
+    <component name="ShoppingCart">
+        <t:implementation.python script="shopping-cart.py"/>
+        <service name="ShoppingCart">
+            <t:binding.atom uri="shoppingCart"/>
+        </service>        
+        <service name="Total">
+            <t:binding.jsonrpc uri="total"/>
+        </service>        
+        <reference name="cache" 
target="http://sca-store-backend.appspot.com/cache"/>
+    </component>
+    
+    <component name="CurrencyConverter">
+        <t:implementation.python script="currency-converter.py"/>
+        <service name="CurrencyConverter">
+            <t:binding.jsonrpc uri="currencyConverter"/>
+        </service>        
+    </component>     
+
+</composite>

Added: tuscany/sca-cpp/trunk/test/store-wsgi/domain-single.composite
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/test/store-wsgi/domain-single.composite?rev=924188&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/test/store-wsgi/domain-single.composite (added)
+++ tuscany/sca-cpp/trunk/test/store-wsgi/domain-single.composite Wed Mar 17 
08:12:39 2010
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912";
+  xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1";
+  targetNamespace="http://store";
+  name="store">
+        
+    <component name="Store">
+        <t:implementation.python script="store.py"/>
+        <service name="Widget">
+            <t:binding.http uri="store"/>
+        </service>
+        <reference name="catalog" target="Catalog"/>
+        <reference name="shoppingCart" target="ShoppingCart/Cart"/>
+        <reference name="shoppingTotal" target="ShoppingCart/Total"/>
+    </component>
+    
+    <component name="Catalog">
+        <t:implementation.python script="fruits-catalog.py"/> 
+        <property name="currencyCode">USD</property>
+        <service name="Catalog">
+            <t:binding.jsonrpc uri="catalog"/>
+        </service>
+        <reference name="currencyConverter" target="CurrencyConverter"/>
+    </component> 
+     
+    <component name="ShoppingCart">
+        <t:implementation.python script="shopping-cart.py"/>
+        <service name="ShoppingCart">
+            <t:binding.atom uri="shoppingCart"/>
+        </service>        
+        <service name="Total">
+            <t:binding.jsonrpc uri="total"/>
+        </service>        
+        <reference name="cache" target="Cache"/>
+    </component>
+    
+    <component name="CurrencyConverter">
+        <t:implementation.python script="currency-converter.py"/>
+        <service name="CurrencyConverter">
+            <t:binding.jsonrpc uri="currencyConverter"/>
+        </service>        
+    </component>     
+
+    <component name="Cache">
+        <implementation.python script="gmemcache.py"/>
+        <service name="Cache">
+            <t:binding.atom uri="cache"/>
+        </service>
+    </component>     
+
+</composite>


Reply via email to