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
This commit is contained in:
parent
2df2ef9c55
commit
8ccd1ab0bc
11 changed files with 311 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
39
sca-cpp/trunk/modules/wsgi/http-test
Executable file
39
sca-cpp/trunk/modules/wsgi/http-test
Executable file
|
|
@ -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
|
||||
32
sca-cpp/trunk/modules/wsgi/http-test.py
Executable file
32
sca-cpp/trunk/modules/wsgi/http-test.py
Executable file
|
|
@ -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"
|
||||
|
||||
52
sca-cpp/trunk/modules/wsgi/httputil.py
Normal file
52
sca-cpp/trunk/modules/wsgi/httputil.py
Normal file
|
|
@ -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)
|
||||
|
||||
|
|
@ -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:]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
32
sca-cpp/trunk/test/store-wsgi/domain-backend.composite
Normal file
32
sca-cpp/trunk/test/store-wsgi/domain-backend.composite
Normal file
|
|
@ -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>
|
||||
62
sca-cpp/trunk/test/store-wsgi/domain-frontend.composite
Normal file
62
sca-cpp/trunk/test/store-wsgi/domain-frontend.composite
Normal file
|
|
@ -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>
|
||||
69
sca-cpp/trunk/test/store-wsgi/domain-single.composite
Normal file
69
sca-cpp/trunk/test/store-wsgi/domain-single.composite
Normal file
|
|
@ -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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue