summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/wsgi
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-03-17 08:12:39 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-03-17 08:12:39 +0000
commit8ccd1ab0bc508fedcb72e1343396fd4c8e8aa9a6 (patch)
tree5a8a0ac7a845aa05d25753ece7212a697776ae3f /sca-cpp/trunk/modules/wsgi
parent2df2ef9c55bcd5fc17d9400799a80cc941e05a39 (diff)
Added support for HTTP references and different versions of the store-wsgi composite.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@924188 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/wsgi')
-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
7 files changed, 146 insertions, 7 deletions
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