summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk')
-rwxr-xr-xsca-cpp/trunk/modules/http/httpd-conf2
-rw-r--r--sca-cpp/trunk/modules/wsgi/Makefile.am2
-rwxr-xr-xsca-cpp/trunk/modules/wsgi/http-test39
-rwxr-xr-xsca-cpp/trunk/modules/wsgi/http-test.py32
-rw-r--r--sca-cpp/trunk/modules/wsgi/httputil.py52
-rw-r--r--sca-cpp/trunk/modules/wsgi/jsonutil.py6
-rw-r--r--sca-cpp/trunk/modules/wsgi/scdl.py10
-rwxr-xr-xsca-cpp/trunk/modules/wsgi/util-test12
-rw-r--r--sca-cpp/trunk/test/store-wsgi/domain-backend.composite32
-rw-r--r--sca-cpp/trunk/test/store-wsgi/domain-frontend.composite62
-rw-r--r--sca-cpp/trunk/test/store-wsgi/domain-single.composite69
11 files changed, 311 insertions, 7 deletions
diff --git a/sca-cpp/trunk/modules/http/httpd-conf b/sca-cpp/trunk/modules/http/httpd-conf
index 434040803d..bc5ca25a4c 100755
--- a/sca-cpp/trunk/modules/http/httpd-conf
+++ b/sca-cpp/trunk/modules/http/httpd-conf
@@ -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
diff --git a/sca-cpp/trunk/modules/wsgi/Makefile.am b/sca-cpp/trunk/modules/wsgi/Makefile.am
index ed5c868f6b..f14087b9c4 100644
--- a/sca-cpp/trunk/modules/wsgi/Makefile.am
+++ b/sca-cpp/trunk/modules/wsgi/Makefile.am
@@ -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
diff --git a/sca-cpp/trunk/modules/wsgi/http-test b/sca-cpp/trunk/modules/wsgi/http-test
new file mode 100755
index 0000000000..844cea53fd
--- /dev/null
+++ b/sca-cpp/trunk/modules/wsgi/http-test
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# 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.
+
+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=$?
+
+# Cleanup
+./wsgi-stop 8090
+sleep 2
+return $rc
diff --git a/sca-cpp/trunk/modules/wsgi/http-test.py b/sca-cpp/trunk/modules/wsgi/http-test.py
new file mode 100755
index 0000000000..87a8780fb3
--- /dev/null
+++ b/sca-cpp/trunk/modules/wsgi/http-test.py
@@ -0,0 +1,32 @@
+#!/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 httputil import *
+
+def testClient():
+ c = mkclient("http://localhost:8090/wsgi")
+ assert c("echo", "Hey") == "Hey"
+ return True
+
+if __name__ == "__main__":
+ print "Testing..."
+ testClient()
+ print "OK"
+
diff --git a/sca-cpp/trunk/modules/wsgi/httputil.py b/sca-cpp/trunk/modules/wsgi/httputil.py
new file mode 100644
index 0000000000..e5f26db143
--- /dev/null
+++ b/sca-cpp/trunk/modules/wsgi/httputil.py
@@ -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)
+
diff --git a/sca-cpp/trunk/modules/wsgi/jsonutil.py b/sca-cpp/trunk/modules/wsgi/jsonutil.py
index ad34d785bf..ae7839df57 100644
--- a/sca-cpp/trunk/modules/wsgi/jsonutil.py
+++ b/sca-cpp/trunk/modules/wsgi/jsonutil.py
@@ -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:]
diff --git a/sca-cpp/trunk/modules/wsgi/scdl.py b/sca-cpp/trunk/modules/wsgi/scdl.py
index 2e57c77377..9687860d6e 100644
--- a/sca-cpp/trunk/modules/wsgi/scdl.py
+++ b/sca-cpp/trunk/modules/wsgi/scdl.py
@@ -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
diff --git a/sca-cpp/trunk/modules/wsgi/util-test b/sca-cpp/trunk/modules/wsgi/util-test
index d7a6a34101..a1c54e80f1 100755
--- a/sca-cpp/trunk/modules/wsgi/util-test
+++ b/sca-cpp/trunk/modules/wsgi/util-test
@@ -22,6 +22,14 @@ here=`readlink -f $0`; here=`dirname $here`
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
diff --git a/sca-cpp/trunk/test/store-wsgi/domain-backend.composite b/sca-cpp/trunk/test/store-wsgi/domain-backend.composite
new file mode 100644
index 0000000000..a543b9a6b5
--- /dev/null
+++ b/sca-cpp/trunk/test/store-wsgi/domain-backend.composite
@@ -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>
diff --git a/sca-cpp/trunk/test/store-wsgi/domain-frontend.composite b/sca-cpp/trunk/test/store-wsgi/domain-frontend.composite
new file mode 100644
index 0000000000..152b40f0b1
--- /dev/null
+++ b/sca-cpp/trunk/test/store-wsgi/domain-frontend.composite
@@ -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>
diff --git a/sca-cpp/trunk/test/store-wsgi/domain-single.composite b/sca-cpp/trunk/test/store-wsgi/domain-single.composite
new file mode 100644
index 0000000000..41ce77bedd
--- /dev/null
+++ b/sca-cpp/trunk/test/store-wsgi/domain-single.composite
@@ -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>