From dc15dc32bb3348c760ba3643c083af7e0c8e43fe Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sat, 25 Dec 2010 01:49:19 +0000 Subject: Create a sandbox branch to experiment with latest APR. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1052740 13f79535-47bb-0310-9956-ffa450edef68 --- .../cpp/apr-2/samples/store-python/Makefile.am | 28 ++++ .../samples/store-python/currency-converter.py | 29 ++++ .../apr-2/samples/store-python/fruits-catalog.py | 30 +++++ .../apr-2/samples/store-python/htdocs/index.html | 150 +++++++++++++++++++++ .../samples/store-python/htdocs/login/index.html | 40 ++++++ .../samples/store-python/htdocs/logout/index.html | 33 +++++ .../store-python/htdocs/test/items-result.txt | 1 + .../cpp/apr-2/samples/store-python/server-test | 58 ++++++++ .../apr-2/samples/store-python/shopping-cart.py | 75 +++++++++++ .../cpp/apr-2/samples/store-python/ssl-start | 36 +++++ .../sebastien/cpp/apr-2/samples/store-python/start | 31 +++++ .../sebastien/cpp/apr-2/samples/store-python/stop | 21 +++ .../cpp/apr-2/samples/store-python/store.composite | 70 ++++++++++ .../cpp/apr-2/samples/store-python/store.py | 40 ++++++ .../cpp/apr-2/samples/store-python/uec2-start | 46 +++++++ 15 files changed, 688 insertions(+) create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-python/Makefile.am create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-python/currency-converter.py create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-python/fruits-catalog.py create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/index.html create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/login/index.html create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/logout/index.html create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/test/items-result.txt create mode 100755 sandbox/sebastien/cpp/apr-2/samples/store-python/server-test create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-python/shopping-cart.py create mode 100755 sandbox/sebastien/cpp/apr-2/samples/store-python/ssl-start create mode 100755 sandbox/sebastien/cpp/apr-2/samples/store-python/start create mode 100755 sandbox/sebastien/cpp/apr-2/samples/store-python/stop create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-python/store.composite create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-python/store.py create mode 100755 sandbox/sebastien/cpp/apr-2/samples/store-python/uec2-start (limited to 'sandbox/sebastien/cpp/apr-2/samples/store-python') diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-python/Makefile.am b/sandbox/sebastien/cpp/apr-2/samples/store-python/Makefile.am new file mode 100644 index 0000000000..8db150cc0e --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-python/Makefile.am @@ -0,0 +1,28 @@ +# 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. + +if WANT_PYTHON + +dist_sample_SCRIPTS = start stop ssl-start uec2-start +sampledir = $(prefix)/samples/store-python + +nobase_dist_sample_DATA = currency-converter.py fruits-catalog.py shopping-cart.py store.py store.composite htdocs/*.html htdocs/login/*.html htdocs/logout/*.html + +dist_noinst_SCRIPTS = server-test +TESTS = server-test + +endif diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-python/currency-converter.py b/sandbox/sebastien/cpp/apr-2/samples/store-python/currency-converter.py new file mode 100644 index 0000000000..2fded8f616 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-python/currency-converter.py @@ -0,0 +1,29 @@ +# 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. + +# Currency converter implementation + +def convert(fr, to, amount): + if to == "EUR": + return amount * 0.70 + return amount + +def symbol(currency): + if currency == "EUR": + return "E" + return "$" + diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-python/fruits-catalog.py b/sandbox/sebastien/cpp/apr-2/samples/store-python/fruits-catalog.py new file mode 100644 index 0000000000..8289afcac5 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-python/fruits-catalog.py @@ -0,0 +1,30 @@ +# 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. + +# Catalog implementation + +def items(converter, currencyCode): + code = currencyCode.eval() + def convert(price): + return converter.convert("USD", code, price) + symbol = converter.symbol(code) + return ( + (("'name", "Mango"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))), + (("'name", "Passion"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))), + (("'name", "Kiwi"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(1.55))) + ) + diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/index.html b/sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/index.html new file mode 100644 index 0000000000..3945e45bb7 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/index.html @@ -0,0 +1,150 @@ + + + +Store + + + + + + + + +

Store

+
+

Catalog

+
+
+
+ +
+
+ +

Your Shopping Cart

+
+
+
+
+
+ + +(feed) +
+
+ + + diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/login/index.html b/sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/login/index.html new file mode 100644 index 0000000000..3f312e4ca4 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/login/index.html @@ -0,0 +1,40 @@ + + +

Sign in

+ + + +
+ + + + +
Username:
Password:
+ +
+ + + diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/logout/index.html b/sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/logout/index.html new file mode 100644 index 0000000000..1ac6e39a1c --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/logout/index.html @@ -0,0 +1,33 @@ + + + +

Sign out

+ +
+ + +
+ diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/test/items-result.txt b/sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/test/items-result.txt new file mode 100644 index 0000000000..788b7cdf89 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-python/htdocs/test/items-result.txt @@ -0,0 +1 @@ +{"id":1,"result":[{"name":"Mango","currencyCode":"USD","currencySymbol":"$","price":2.99},{"name":"Passion","currencyCode":"USD","currencySymbol":"$","price":3.55},{"name":"Kiwi","currencyCode":"USD","currencySymbol":"$","price":1.55}]} \ No newline at end of file diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-python/server-test b/sandbox/sebastien/cpp/apr-2/samples/store-python/server-test new file mode 100755 index 0000000000..27490c580b --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-python/server-test @@ -0,0 +1,58 @@ +#!/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. + +echo "Testing..." +here=`readlink -f $0`; here=`dirname $here` +curl_prefix=`cat $here/../../modules/http/curl.prefix` + +# Setup +./start +sleep 2 + +# Test HTTP GET +$curl_prefix/bin/curl http://localhost:8090/ 2>/dev/null >tmp/index.html +diff tmp/index.html htdocs/index.html +rc=$? + +# Test Catalog +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl http://localhost:8090/references/Store/catalog -X POST -H "Content-type: application/json-rpc" --data @../store-cpp/htdocs/test/items-request.txt >tmp/items-result.txt 2>/dev/null + diff tmp/items-result.txt htdocs/test/items-result.txt + rc=$? +fi + +# Test Shopping Cart +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl http://localhost:8090/references/Store/shoppingCart -X POST -H "Content-type: application/atom+xml" --data @../store-cpp/htdocs/test/shopping-cart-entry.xml 2>/dev/null + rc=$? +fi +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl http://localhost:8090/references/Store/shoppingCart >tmp/shopping-cart-feed.xml 2>/dev/null + grep "3.55" tmp/shopping-cart-feed.xml >/dev/null + rc=$? +fi + +# Cleanup +./stop +sleep 2 + +if [ "$rc" = "0" ]; then + echo "OK" +fi +return $rc diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-python/shopping-cart.py b/sandbox/sebastien/cpp/apr-2/samples/store-python/shopping-cart.py new file mode 100644 index 0000000000..feb7398ed9 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-python/shopping-cart.py @@ -0,0 +1,75 @@ +# 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. + +# Shopping cart implementation +import uuid +import sys + +cartId = "1234" + +# Get the shopping cart from the cache +# Return an empty cart if not found +def getcart(id, cache): + cart = cache.get((id,)) + if cart is None: + return () + return cart + +# Post a new item to the cart, create a new cart if necessary +def post(collection, item, cache): + id = str(uuid.uuid1()) + cart = ((item[0], id, item[2]),) + getcart(cartId, cache) + cache.put((cartId,), cart) + return (id,) + + +# Find an item in the cart +def find(id, cart): + if cart == (): + return ("Item", "0", ()) + elif id == cart[0][1]: + return cart[0] + else: + return find(id, cart[1:]) + +# Get items from the cart +def get(id, cache): + 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): + if id == (): + return cache.delete((cartId,)) + return True + +# Return the price of an item +def price(item): + return float(filter(lambda x: x[0] == "'price", item[2])[0][1]) + +# Sum the prices of a list of items +def sum(items): + if items == (): + return 0 + return price(items[0]) + sum(items[1:]) + +# Return the total price of the items in the cart +def total(cache): + cart = getcart(cartId, cache) + return sum(cart) + diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-python/ssl-start b/sandbox/sebastien/cpp/apr-2/samples/store-python/ssl-start new file mode 100755 index 0000000000..60b9bb5ace --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-python/ssl-start @@ -0,0 +1,36 @@ +#!/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. + +../../modules/http/ssl-ca-conf tmp localhost +../../modules/http/ssl-cert-conf tmp localhost +../../modules/http/httpd-conf tmp localhost 8090 htdocs +../../modules/http/httpd-ssl-conf tmp 8453 +../../modules/http/open-auth-conf tmp +../../modules/http/passwd-auth-conf tmp foo foo +../../modules/server/server-conf tmp +../../modules/python/python-conf tmp +cat >>tmp/conf/httpd.conf <>tmp/conf/httpd.conf < + + + + + + + + + + + + + + + + USD + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost:11211 + + + diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-python/store.py b/sandbox/sebastien/cpp/apr-2/samples/store-python/store.py new file mode 100644 index 0000000000..b71f505dd1 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-python/store.py @@ -0,0 +1,40 @@ +# 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. + +# Store implementation + +def post(item, catalog, shoppingCart, shoppingTotal): + return shoppingCart.post(item) + +def getall(catalog, shoppingCart, shoppingTotal): + return shoppingCart.getall() + +def get(id, catalog, shoppingCart, shoppingTotal): + return shoppingCart.get(id) + +def items(catalog, shoppingCart, shoppingTotal): + return catalog.items() + +def total(catalog, shoppingCart, shoppingTotal): + return shoppingCart.gettotal() + +def deleteall(catalog, shoppingCart, shoppingTotal): + return shoppingCart.deleteall() + +def delete(id, catalog, shoppingCart, shoppingTotal): + return shoppingCart.delete(id) + diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-python/uec2-start b/sandbox/sebastien/cpp/apr-2/samples/store-python/uec2-start new file mode 100755 index 0000000000..84c170e596 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-python/uec2-start @@ -0,0 +1,46 @@ +#!/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. + +# Pass your EC2 public host name +if [ "$1" != "" ]; then + host=$1 +else + host="localhost" +fi + +# Ports 80, 443, 444, 8090, 8453, 8454 need to be open +sudo ../../ubuntu/ip-redirect-all 80 8090 +sudo ../../ubuntu/ip-redirect-all 443 8453 + +../../modules/http/ssl-ca-conf tmp $host +../../modules/http/ssl-cert-conf tmp $host +../../modules/http/httpd-conf tmp $host 8090/80 htdocs +../../modules/http/httpd-ssl-conf tmp 8453/443 +../../modules/server/server-conf tmp +../../modules/python/python-conf tmp +cat >>tmp/conf/httpd.conf <