diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-08 06:38:07 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-08 06:38:07 +0000 |
commit | 211c686bc6d05d8d05e5490b9a9f612619461abc (patch) | |
tree | bb8f56afb24f2b52ea92598babff7d94fd70da10 /sca-cpp/trunk/samples/store-vhost | |
parent | f6a51224cc350c7d3b42b15051a9c074cce48b5d (diff) |
More changes to get both single and mass dynamic virtual hosting working with HTTP and HTTPS.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@961589 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/samples/store-vhost')
16 files changed, 279 insertions, 153 deletions
diff --git a/sca-cpp/trunk/samples/store-vhost/Makefile.am b/sca-cpp/trunk/samples/store-vhost/Makefile.am index 61933afd35..8623f468fb 100644 --- a/sca-cpp/trunk/samples/store-vhost/Makefile.am +++ b/sca-cpp/trunk/samples/store-vhost/Makefile.am @@ -20,7 +20,7 @@ if WANT_PYTHON dist_sample_SCRIPTS = start stop ssl-start uec2-start sampledir = $(prefix)/samples/store-vhost -nobase_dist_sample_DATA = currency-converter.py fruits-catalog.py shopping-cart.py store.py store.composite htdocs/*.html htdocs/domains/joe/*.html htdocs/domains/jane/*.html +nobase_dist_sample_DATA = htdocs/*.html htdocs/domains/*/*.html domains/*/*.py domains/*/*.composite dist_noinst_SCRIPTS = server-test #TESTS = server-test diff --git a/sca-cpp/trunk/samples/store-vhost/currency-converter.py b/sca-cpp/trunk/samples/store-vhost/domains/jane/currency-converter.py index 2fded8f616..2fded8f616 100644 --- a/sca-cpp/trunk/samples/store-vhost/currency-converter.py +++ b/sca-cpp/trunk/samples/store-vhost/domains/jane/currency-converter.py diff --git a/sca-cpp/trunk/samples/store-vhost/domains/jane/fruits-catalog.py b/sca-cpp/trunk/samples/store-vhost/domains/jane/fruits-catalog.py new file mode 100644 index 0000000000..3d108f42eb --- /dev/null +++ b/sca-cpp/trunk/samples/store-vhost/domains/jane/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 getcatalog(converter, currencyCode): + code = currencyCode() + def convert(price): + return converter("convert", "USD", code, price) + symbol = converter("symbol", code) + return ( + (("'javaClass", "services.Item"), ("'name", "Passion"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))), + (("'javaClass", "services.Item"), ("'name", "Mango"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))), + (("'javaClass", "services.Item"), ("'name", "Pineapple"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(1.55))) + ) + diff --git a/sca-cpp/trunk/samples/store-vhost/shopping-cart.py b/sca-cpp/trunk/samples/store-vhost/domains/jane/shopping-cart.py index 405adb85bf..405adb85bf 100644 --- a/sca-cpp/trunk/samples/store-vhost/shopping-cart.py +++ b/sca-cpp/trunk/samples/store-vhost/domains/jane/shopping-cart.py diff --git a/sca-cpp/trunk/samples/store-vhost/store.composite b/sca-cpp/trunk/samples/store-vhost/domains/jane/store.composite index 045ebe6ec5..893b4f0ed4 100644 --- a/sca-cpp/trunk/samples/store-vhost/store.composite +++ b/sca-cpp/trunk/samples/store-vhost/domains/jane/store.composite @@ -60,7 +60,7 @@ </component> <component name="Cache"> - <implementation.cpp path="../../components/cache" library="libmemcache"/> + <implementation.cpp path="../../../../components/cache" library="libmemcache"/> <service name="Cache"> <t:binding.atom uri="cache"/> </service> diff --git a/sca-cpp/trunk/samples/store-vhost/store.py b/sca-cpp/trunk/samples/store-vhost/domains/jane/store.py index 0b4e0f72fd..0b4e0f72fd 100644 --- a/sca-cpp/trunk/samples/store-vhost/store.py +++ b/sca-cpp/trunk/samples/store-vhost/domains/jane/store.py diff --git a/sca-cpp/trunk/samples/store-vhost/domains/joe/currency-converter.py b/sca-cpp/trunk/samples/store-vhost/domains/joe/currency-converter.py new file mode 100644 index 0000000000..2fded8f616 --- /dev/null +++ b/sca-cpp/trunk/samples/store-vhost/domains/joe/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/sca-cpp/trunk/samples/store-vhost/fruits-catalog.py b/sca-cpp/trunk/samples/store-vhost/domains/joe/fruits-catalog.py index 2a6d726fdc..2a6d726fdc 100644 --- a/sca-cpp/trunk/samples/store-vhost/fruits-catalog.py +++ b/sca-cpp/trunk/samples/store-vhost/domains/joe/fruits-catalog.py diff --git a/sca-cpp/trunk/samples/store-vhost/domains/joe/shopping-cart.py b/sca-cpp/trunk/samples/store-vhost/domains/joe/shopping-cart.py new file mode 100644 index 0000000000..405adb85bf --- /dev/null +++ b/sca-cpp/trunk/samples/store-vhost/domains/joe/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 gettotal(cache): + cart = getcart(cartId, cache) + return sum(cart) + diff --git a/sca-cpp/trunk/samples/store-vhost/domains/joe/store.composite b/sca-cpp/trunk/samples/store-vhost/domains/joe/store.composite new file mode 100644 index 0000000000..893b4f0ed4 --- /dev/null +++ b/sca-cpp/trunk/samples/store-vhost/domains/joe/store.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.cpp path="../../../../components/cache" library="libmemcache"/> + <service name="Cache"> + <t:binding.atom uri="cache"/> + </service> + </component> + +</composite> diff --git a/sca-cpp/trunk/samples/store-vhost/domains/joe/store.py b/sca-cpp/trunk/samples/store-vhost/domains/joe/store.py new file mode 100644 index 0000000000..0b4e0f72fd --- /dev/null +++ b/sca-cpp/trunk/samples/store-vhost/domains/joe/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 getcatalog(catalog, shoppingCart, shoppingTotal): + return catalog("getcatalog") + +def gettotal(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/sca-cpp/trunk/samples/store-vhost/htdocs/index.html b/sca-cpp/trunk/samples/store-vhost/htdocs/index.html index c27e54f753..e0239392ff 100644 --- a/sca-cpp/trunk/samples/store-vhost/htdocs/index.html +++ b/sca-cpp/trunk/samples/store-vhost/htdocs/index.html @@ -19,139 +19,16 @@ <html>
<head>
<title>Store</title>
-
-<script type="text/javascript" src="/js/tuscany-ref.js"></script>
-
-<script type="text/javascript">
-var component = new tuscany.sca.Component("Store");
-
-//@Reference
-var catalog = new tuscany.sca.Reference("catalog");
-
-//@Reference
-var shoppingCart = new tuscany.sca.Reference("shoppingCart");
-
-//@Reference
-var shoppingTotal = new tuscany.sca.Reference("shoppingTotal");
-
-var catalogItems;
-
-function catalog_getcatalogResponse(items, exception) {
- if (exception){
- alert(exception.message);
- return;
- }
- var catalog = "";
- for (var i=0; i<items.length; i++) {
- var item = items[i].name + ' - ' + items[i].price;
- catalog += '<input name="items" type="checkbox" value="' +
- item + '">' + item + ' <br>';
- }
- document.getElementById('catalog').innerHTML=catalog;
- catalogItems = items;
-
-}
-
-function shoppingCart_getResponse(feed) {
- if (feed != null) {
- var entries = feed.getElementsByTagName("entry");
- var list = "";
- for (var i=0; i<entries.length; i++) {
- var content = entries[i].getElementsByTagName("content")[0];
- var name = content.getElementsByTagName("name")[0].firstChild.nodeValue;
- var price = content.getElementsByTagName("price")[0].firstChild.nodeValue;
- list += name + ' - ' + price + ' <br>';
- }
- document.getElementById("shoppingCart").innerHTML = list;
-
- shoppingTotal.apply("gettotal", shoppingTotal_gettotalResponse);
- }
-}
-
-function shoppingTotal_gettotalResponse(total, exception) {
- if (exception) {
- alert(exception.message);
- return;
- }
- document.getElementById('total').innerHTML = total;
-}
-
-function shoppingCart_postResponse(entry) {
- shoppingCart.get("", shoppingCart_getResponse);
-}
-
-function addToCart() {
- var items = document.catalogForm.items;
- var j = 0;
- for (var i=0; i<items.length; i++)
- if (items[i].checked) {
- var entry = '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><content type="application/xml">' +
- '<item>' +
- '<javaClass>' + catalogItems[i].javaClass + '</javaClass>' +
- '<name>' + catalogItems[i].name + '</name>' +
- '<currencyCode>' + catalogItems[i].currencyCode + '</currencyCode>' +
- '<currencySymbol>' + catalogItems[i].currencySymbol + '</currencySymbol>' +
- '<price>' + catalogItems[i].price + '</price>' +
- '</item>' +
- '</content></entry>';
- shoppingCart.post(entry, shoppingCart_postResponse);
- items[i].checked = false;
- }
-}
-function checkoutCart() {
- document.getElementById('store').innerHTML='<h2>' +
- 'Thanks for Shopping With Us!</h2>'+
- '<h2>Your Order</h2>'+
- '<form name="orderForm">'+
- document.getElementById('shoppingCart').innerHTML+
- '<br>'+
- document.getElementById('total').innerHTML+
- '<br>'+
- '<br>'+
- '<input type="submit" value="Continue Shopping">'+
- '</form>';
- shoppingCart.del("", null);
-}
-function deleteCart() {
- shoppingCart.del("", null);
- document.getElementById('shoppingCart').innerHTML = "";
- document.getElementById('total').innerHTML = "";
-}
-
-function init() {
- try {
- catalog.apply("getcatalog", catalog_getcatalogResponse);
- shoppingCart.get("", shoppingCart_getResponse);
- } catch(e){
- alert(e);
- }
-}
-</script>
-
</head>
-<body onload="init()">
+<body>
<h1>Store</h1>
-<div id="store">
-<h2>Catalog</h2>
-<form name="catalogForm">
-<div id="catalog" ></div>
-<br>
-<input type="button" onClick="addToCart()" value="Add to Cart">
-</form>
-<br>
-
-<h2>Your Shopping Cart</h2>
-<form name="shoppingCartForm">
-<div id="shoppingCart"></div>
-<br>
-<div id="total"></div>
-<br>
-<input type="button" onClick="checkoutCart()" value="Checkout">
-<input type="button" onClick="deleteCart()" value="Empty">
-<a href="shoppingCart/">(feed)</a>
-</form>
-</div>
+<p>For this sample to work, add the sample domain to your /etc/hosts as follows:<br/>
+127.0.0.1 sca-store.com jane.sca-store.com joe.sca-store.com</p>
+
+<p/>
+<p>Jane's store at <a href="http://jane.sca-store.com:8090/">jane.sca-store.com</a>
+<br/>Joe's store at <a href="http://joe.sca-store.com:8090/">joe.sca-store.com</a></p>
</body>
</html>
diff --git a/sca-cpp/trunk/samples/store-vhost/server-test b/sca-cpp/trunk/samples/store-vhost/server-test index 26efd14c0e..1ed4b55df0 100755 --- a/sca-cpp/trunk/samples/store-vhost/server-test +++ b/sca-cpp/trunk/samples/store-vhost/server-test @@ -25,11 +25,11 @@ curl_prefix=`cat $here/../../modules/http/curl.prefix` ./start sleep 2 -# For this test to work, add the following line to your etc/hosts -127.0.0.1 jane.store.com joe.store.com +# For this test to work, add the test domain to your etc/hosts as follows: +# 127.0.0.1 sca-store.com jane.sca-store.com joe.sca-store.com # Test HTTP GET -$curl_prefix/bin/curl http://jane.store.com:8090/ 2>/dev/null >tmp/jane.html +$curl_prefix/bin/curl http://jane.sca-store.com:8090/ 2>/dev/null >tmp/jane.html diff tmp/jane.html htdocs/domains/jane/index.html rc=$? diff --git a/sca-cpp/trunk/samples/store-vhost/ssl-start b/sca-cpp/trunk/samples/store-vhost/ssl-start index 1e70d6edfb..368a664674 100755 --- a/sca-cpp/trunk/samples/store-vhost/ssl-start +++ b/sca-cpp/trunk/samples/store-vhost/ssl-start @@ -17,16 +17,20 @@ # specific language governing permissions and limitations # under the License. -../../modules/http/httpd-ca-conf tmp localhost -../../modules/http/httpd-cert-conf tmp localhost -../../modules/http/httpd-conf tmp localhost 8090 htdocs -../../modules/http/httpd-ssl-conf tmp localhost 8453 htdocs +# For this sample to work, add the sample domain to your /etc/hosts as follows: +# 127.0.0.1 sca-store.com jane.sca-store.com joe.sca-store.com + +../../modules/http/ssl-ca-conf tmp sca-store.com +../../modules/http/ssl-cert-conf tmp sca-store.com server +../../modules/http/ssl-cert-conf tmp *.sca-store.com vhost +../../modules/http/httpd-conf tmp sca-store.com 8090 htdocs vhost +../../modules/http/httpd-ssl-conf tmp sca-store.com 8453 htdocs vhost ../../modules/server/server-conf tmp ../../modules/python/python-conf tmp cat >>tmp/conf/httpd.conf <<EOF -# Configure SCA Composite -SCAContribution `pwd`/ -SCAComposite store.composite +# Configure SCA Composite for mass dynamic virtual Hosting +SCAVirtualContribution `pwd`/domains/ +SCAVirtualComposite store.composite EOF diff --git a/sca-cpp/trunk/samples/store-vhost/start b/sca-cpp/trunk/samples/store-vhost/start index 6cbea136b3..01173e68b7 100755 --- a/sca-cpp/trunk/samples/store-vhost/start +++ b/sca-cpp/trunk/samples/store-vhost/start @@ -17,12 +17,12 @@ # specific language governing permissions and limitations # under the License. -../../modules/http/httpd-conf tmp localhost 8090 htdocs vhost +../../modules/http/httpd-conf tmp sca-store.com 8090 htdocs vhost ../../modules/server/server-conf tmp ../../modules/python/python-conf tmp cat >>tmp/conf/httpd.conf <<EOF -# Configure SCA Composite for mass dynamic virtual Hosting -SCAVirtualContribution `pwd`/ +# Configure SCA Composite for mass dynamic virtual hosting +SCAVirtualContribution `pwd`/domains/ SCAVirtualComposite store.composite EOF diff --git a/sca-cpp/trunk/samples/store-vhost/uec2-start b/sca-cpp/trunk/samples/store-vhost/uec2-start index 2e59815637..ddf70975ef 100755 --- a/sca-cpp/trunk/samples/store-vhost/uec2-start +++ b/sca-cpp/trunk/samples/store-vhost/uec2-start @@ -21,23 +21,25 @@ if [ "$1" != "" ]; then host=$1 else - host="localhost" + # Default to dummy test domain + host="sca-store.com" fi # Ports 80, 443, 8090, 8453 need to be open sudo ../../ubuntu/ip-redirect 80 8090 sudo ../../ubuntu/ip-redirect 443 8453 -../../modules/http/httpd-ca-conf tmp $host -../../modules/http/httpd-cert-conf tmp $host -../../modules/http/httpd-conf tmp $host 8090/80 htdocs -../../modules/http/httpd-ssl-conf tmp $host 8453/443 htdocs +../../modules/http/ssl-ca-conf tmp $host +../../modules/http/ssl-cert-conf tmp $host server +../../modules/http/ssl-cert-conf tmp "*.$host" vhost +../../modules/http/httpd-conf tmp $host 8090/80 htdocs vhost +../../modules/http/httpd-ssl-conf tmp $host 8453/443 htdocs vhost ../../modules/server/server-conf tmp ../../modules/python/python-conf tmp cat >>tmp/conf/httpd.conf <<EOF -# Configure SCA Composite -SCAContribution `pwd`/ -SCAComposite store.composite +# Configure SCA Composite for mass dynamic virtual Hosting +SCAVirtualContribution `pwd`/domains/ +SCAVirtualComposite store.composite EOF |