diff options
author | giorgio <giorgio@13f79535-47bb-0310-9956-ffa450edef68> | 2012-09-05 08:31:30 +0000 |
---|---|---|
committer | giorgio <giorgio@13f79535-47bb-0310-9956-ffa450edef68> | 2012-09-05 08:31:30 +0000 |
commit | c9bfccc35345ce58fb5774d4b0b6a9868b262c0a (patch) | |
tree | fe84dd4b90f2acd0b933550b6978094926c1d733 /sca-cpp/branches/lightweight-sca/samples | |
parent | 5ddabdaf1ff856aae79dadc045ef2aeff08c7887 (diff) |
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1381061 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/branches/lightweight-sca/samples')
159 files changed, 8937 insertions, 0 deletions
diff --git a/sca-cpp/branches/lightweight-sca/samples/Makefile.am b/sca-cpp/branches/lightweight-sca/samples/Makefile.am new file mode 100644 index 0000000000..604a963d5d --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/Makefile.am @@ -0,0 +1,22 @@ +# 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. + +SUBDIRS = store-scheme store-cpp store-python store-java store-gae store-sql store-constdb store-vhost store-cluster relay-python relay-gae + +sample_DATA = README +sampledir=$(prefix)/samples + diff --git a/sca-cpp/branches/lightweight-sca/samples/README b/sca-cpp/branches/lightweight-sca/samples/README new file mode 100644 index 0000000000..818a2faaf8 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/README @@ -0,0 +1,3 @@ +Apache Tuscany SCA Samples +========================== + diff --git a/sca-cpp/branches/lightweight-sca/samples/relay-gae/Makefile.am b/sca-cpp/branches/lightweight-sca/samples/relay-gae/Makefile.am new file mode 100644 index 0000000000..7b24ddde27 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/relay-gae/Makefile.am @@ -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. + +if WANT_PYTHON +if WANT_GAE + +dist_sample_SCRIPTS = start stop +sampledir = $(prefix)/samples/relay-gae + +BUILT_SOURCES = target.stamp +target.stamp: app.yaml *.py *.composite $(top_builddir)/modules/wsgi/*.py htdocs/*.html + mkdir -p target + cp app.yaml *.py *.composite `ls $(top_builddir)/modules/wsgi/*.py | grep -v "\-test"` target + mkdir -p target/htdocs + cp -R htdocs/* target/htdocs + touch target.stamp + +clean-local: + rm -rf target.stamp target + +nobase_sample_DATA = target/app.yaml target/*.py target/*.composite target/htdocs/*.html + +EXTRA_DIST = app.yaml *.composite *.py htdocs/*.html + +endif +endif diff --git a/sca-cpp/branches/lightweight-sca/samples/relay-gae/app.yaml b/sca-cpp/branches/lightweight-sca/samples/relay-gae/app.yaml new file mode 100644 index 0000000000..d4e78701bc --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/relay-gae/app.yaml @@ -0,0 +1,50 @@ +# 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.
+
+application: sca-relay
+version: 1
+runtime: python
+api_version: 1
+skip_files:
+- ^(.*/)?app\.yaml
+- ^(.*/)?app\.yml
+- ^(.*/)?index\.yaml
+- ^(.*/)?index\.yml
+- ^(.*/)?#.*#
+- ^(.*/)?.*~
+- ^(.*/)?.*\.py[co]
+- ^(.*/)?.*/RCS/.*
+- ^(.*/)?\..*
+- ^(.*/)?.*-test$
+- ^(.*/)?.*\.cpp$
+- ^(.*/)?.*\.o$
+- ^(.*/)?core$
+- ^(.*/)?.*\.out$
+- ^(.*/)?.*\.log$
+- ^(.*/)?Makefile.*
+- ^(.*/)?tmp/.*
+- ^(.*/)?wsgi-start
+- ^(.*/)?wsgi-stop
+
+handlers:
+- url: /(.*\.(html|png))
+ static_files: htdocs/\1
+ upload: htdocs/(.*\.(html|png))
+
+- url: /.*
+ script: composite.py
+
diff --git a/sca-cpp/branches/lightweight-sca/samples/relay-gae/domain.composite b/sca-cpp/branches/lightweight-sca/samples/relay-gae/domain.composite new file mode 100644 index 0000000000..470ac88da1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/relay-gae/domain.composite @@ -0,0 +1,74 @@ +<?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" + targetNamespace="http://relay" + name="relay"> + + <component name="JSONTwit"> + <implementation.python script="relay.py"/> + <service name="Relay"> + <binding.http uri="jsontwit"/> + </service> + <reference name="target"> + <binding.http uri="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=jsdelfino"/> + </reference> + </component> + + <component name="XMLTwit"> + <implementation.python script="relay.py"/> + <service name="Relay"> + <binding.http uri="xmltwit"/> + </service> + <reference name="target"> + <binding.http uri="http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=jsdelfino"/> + </reference> + </component> + + <component name="RSSTwit"> + <implementation.python script="relay.py"/> + <service name="Relay"> + <binding.http uri="rsstwit"/> + </service> + <reference name="target"> + <binding.http uri="http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=jsdelfino"/> + </reference> + </component> + + <component name="HTML"> + <implementation.python script="relay.py"/> + <service name="Relay"> + <binding.http uri="html"/> + </service> + <reference name="target"> + <binding.http uri="http://people.apache.org/~jsdelfino/"/> + </reference> + </component> + + <component name="JSONFB"> + <implementation.python script="relay.py"/> + <service name="Relay"> + <binding.http uri="jsonfb"/> + </service> + <reference name="target"> + <binding.http uri="https://graph.facebook.com/100001053301307"/> + </reference> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/relay-gae/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/relay-gae/htdocs/index.html new file mode 100644 index 0000000000..b8b606d3d9 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/relay-gae/htdocs/index.html @@ -0,0 +1,36 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Relay</title> +</head> +<body> + +<p><a href="/html">Sample HTML request</a></p> +<p><a href="/jsontwit">Sample Twitter JSON request</a></p> +<p><a href="/xmltwit">Sample Twitter XML request</a></p> +<p><a href="/rsstwit">Sample Twitter RSS request</a></p> +<p><a href="/jsonfb">Sample Facebook JSON request</a></p> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/relay-gae/relay.py b/sca-cpp/branches/lightweight-sca/samples/relay-gae/relay.py new file mode 100644 index 0000000000..5fe99803c1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/relay-gae/relay.py @@ -0,0 +1,21 @@ +# 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. + +# Relay implementation +def get(id, target): + return target.get(id) + diff --git a/sca-cpp/branches/lightweight-sca/samples/relay-gae/start b/sca-cpp/branches/lightweight-sca/samples/relay-gae/start new file mode 100755 index 0000000000..2e219758a8 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/relay-gae/start @@ -0,0 +1,20 @@ +#!/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/wsgi/gae-start target 8090 diff --git a/sca-cpp/branches/lightweight-sca/samples/relay-gae/stop b/sca-cpp/branches/lightweight-sca/samples/relay-gae/stop new file mode 100755 index 0000000000..3aff1d5a77 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/relay-gae/stop @@ -0,0 +1,20 @@ +#!/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/wsgi/gae-stop target 8090 diff --git a/sca-cpp/branches/lightweight-sca/samples/relay-python/Makefile.am b/sca-cpp/branches/lightweight-sca/samples/relay-python/Makefile.am new file mode 100644 index 0000000000..57938aff69 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/relay-python/Makefile.am @@ -0,0 +1,25 @@ +# 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 +sampledir = $(prefix)/samples/relay-python + +nobase_dist_sample_DATA = relay.py relay.composite htdocs/*.html + +endif diff --git a/sca-cpp/branches/lightweight-sca/samples/relay-python/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/relay-python/htdocs/index.html new file mode 100644 index 0000000000..ad5f86aa02 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/relay-python/htdocs/index.html @@ -0,0 +1,35 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Relay</title> +<body> + +<p><a href="/html">Sample HTML request</a></p> +<p><a href="/jsontwit">Sample Twitter JSON request</a></p> +<p><a href="/xmltwit">Sample Twitter XML request</a></p> +<p><a href="/rsstwit">Sample Twitter RSS request</a></p> +<p><a href="/jsonfb">Sample Facebook JSON request</a></p> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/relay-python/relay.composite b/sca-cpp/branches/lightweight-sca/samples/relay-python/relay.composite new file mode 100644 index 0000000000..470ac88da1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/relay-python/relay.composite @@ -0,0 +1,74 @@ +<?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" + targetNamespace="http://relay" + name="relay"> + + <component name="JSONTwit"> + <implementation.python script="relay.py"/> + <service name="Relay"> + <binding.http uri="jsontwit"/> + </service> + <reference name="target"> + <binding.http uri="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=jsdelfino"/> + </reference> + </component> + + <component name="XMLTwit"> + <implementation.python script="relay.py"/> + <service name="Relay"> + <binding.http uri="xmltwit"/> + </service> + <reference name="target"> + <binding.http uri="http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=jsdelfino"/> + </reference> + </component> + + <component name="RSSTwit"> + <implementation.python script="relay.py"/> + <service name="Relay"> + <binding.http uri="rsstwit"/> + </service> + <reference name="target"> + <binding.http uri="http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=jsdelfino"/> + </reference> + </component> + + <component name="HTML"> + <implementation.python script="relay.py"/> + <service name="Relay"> + <binding.http uri="html"/> + </service> + <reference name="target"> + <binding.http uri="http://people.apache.org/~jsdelfino/"/> + </reference> + </component> + + <component name="JSONFB"> + <implementation.python script="relay.py"/> + <service name="Relay"> + <binding.http uri="jsonfb"/> + </service> + <reference name="target"> + <binding.http uri="https://graph.facebook.com/100001053301307"/> + </reference> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/relay-python/relay.py b/sca-cpp/branches/lightweight-sca/samples/relay-python/relay.py new file mode 100644 index 0000000000..5fe99803c1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/relay-python/relay.py @@ -0,0 +1,21 @@ +# 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. + +# Relay implementation +def get(id, target): + return target.get(id) + diff --git a/sca-cpp/branches/lightweight-sca/samples/relay-python/start b/sca-cpp/branches/lightweight-sca/samples/relay-python/start new file mode 100755 index 0000000000..e9d9d2d51f --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/relay-python/start @@ -0,0 +1,31 @@ +#!/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/httpd-conf tmp localhost 8090 htdocs +../../modules/http/httpd-event-conf tmp +../../modules/server/server-conf tmp +../../modules/python/python-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite relay.composite + +EOF + +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/relay-python/stop b/sca-cpp/branches/lightweight-sca/samples/relay-python/stop new file mode 100755 index 0000000000..3b4f46694d --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/relay-python/stop @@ -0,0 +1,20 @@ +#!/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/httpd-stop tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/Makefile.am b/sca-cpp/branches/lightweight-sca/samples/store-cluster/Makefile.am new file mode 100644 index 0000000000..f856e63c59 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/Makefile.am @@ -0,0 +1,36 @@ +# 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 +if WANT_SQLDB +if WANT_OPENID +if WANT_LOG +if WANT_QUEUE + +dist_sample_SCRIPTS = start stop ssl-start ssl-stop proxy-conf proxy-ssl-conf server-conf server-ssl-conf tunnel-ssl-conf sqldb-master-conf sqldb-standby-conf +sampledir = $(prefix)/samples/store-cluster + +nobase_dist_sample_DATA = htdocs/*.html htdocs/*/*.html domains/*/htdocs/*.html domains/*/htdocs/*/*.html domains/*/*.py domains/*/*.composite shared/*.composite + +dist_noinst_SCRIPTS = server-test +#TESTS = server-test + +endif +endif +endif +endif +endif diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/currency-converter.py b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/currency-converter.py new file mode 100644 index 0000000000..2fded8f616 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/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/branches/lightweight-sca/samples/store-cluster/domains/jane/fruits-catalog.py b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/fruits-catalog.py new file mode 100644 index 0000000000..fb20b4ff27 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/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 items(converter, currencyCode): + code = currencyCode.eval() + def convert(price): + return converter.convert("USD", code, price) + symbol = converter.symbol(code) + return ( + (("'name", "Passion"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))), + (("'name", "Mango"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))), + (("'name", "Pineapple"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(1.55))) + ) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/htdocs/index.html new file mode 100644 index 0000000000..832c0a1472 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/htdocs/index.html @@ -0,0 +1,156 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Jane's Store</title> + +<script type="text/javascript" src="/all-min.js"></script> + +<script type="text/javascript"> +var store = sca.component("Store"); +var catalog = sca.defun(sca.reference(store, "catalog"), "items"); +var shoppingCart = sca.reference(store, "shoppingCart"); +var shoppingTotal = sca.defun(sca.reference(store, "shoppingTotal"), "total"); + +var catalogItems; + +function catalog_itemsResponse(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(doc) { + if (doc != null) { + var feed = parseXML([doc]); + 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.total(shoppingTotal_totalResponse); + } +} + +function shoppingTotal_totalResponse(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 = '<?xml version="1.0" encoding="UTF-8"?>\n' + + '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><content type="application/xml">' + + '<item>' + + '<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.items(catalog_itemsResponse); + shoppingCart.get("", shoppingCart_getResponse); + } catch(e){ + alert(e); + } +} +</script> +</head> + +<body onload="init()"> +<h1>Jane's Store</h1> +<br/> +<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> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/htdocs/login/index.html b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/htdocs/login/index.html new file mode 100644 index 0000000000..2a7be01ff1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/htdocs/login/index.html @@ -0,0 +1,212 @@ +<!-- + 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. +--> + +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<script type="text/javascript" src="/all-min.js"></script> +<title>Sign in</title> +</head> +<body> +<h1>Sign in with an OpenID or OAuth provider</h1> +<br/> + +<script type="text/javascript"> +function queryParams() { + qp = new Array(); + qs = window.location.search.substring(1).split('&'); + for (i = 0; i < qs.length; i++) { + e = qs[i].indexOf('='); + if (e > 0) + qp[qs[i].substring(0, e)] = unescape(qs[i].substring(e + 1)); + } + return qp; +} + +function openauthReferrer() { + r = queryParams()['openauth_referrer']; + if (typeof(r) == 'undefined') + return '/'; + q = r.indexOf('?'); + if (q > 0) + return r.substring(0, q); + return r; +} + +if (typeof(openauthReferrer()) == 'undefined') { + document.location = '/'; +} + +function submitOpenIDSignin(w) { + clearauthcookie(); + document.openIDSignin.openid_identifier.value = w(); + document.openIDSignin.action = openauthReferrer(); + document.openIDSignin.submit(); +} + +function withGoogle() { + return 'https://www.google.com/accounts/o8/id'; +} + +function withYahoo() { + return 'https://me.yahoo.com/'; +} + +function withMyOpenID() { + return 'http://www.myopenid.com/xrds'; +} + +function withVerisign() { + return 'https://pip.verisignlabs.com/'; +} + +function withMySpace() { + return 'https://api.myspace.com/openid'; +} + +function withGoogleApps() { + return 'https://www.google.com/accounts/o8/site-xrds?ns=2&hd=' + document.fields.domain.value; +} + +function withLivejournal() { + return 'http://' + document.fields.ljuser.value + '.livejournal.com'; +} + +function withBlogspot() { + return 'http://' + document.fields.bsuser.value + '.blogspot.com'; +} + +function withBlogger() { + return 'http://' + document.fields.bguser.value + '.blogger.com'; +} + +function withXRDSEndpoint() { + return document.fields.endpoint.value; +} + +function submitOAuth2Signin(w) { + parms = w(); + clearauthcookie(); + document.oauth2Signin.oauth2_authorize.value = parms[0]; + document.oauth2Signin.oauth2_access_token.value = parms[1]; + document.oauth2Signin.oauth2_client_id.value = parms[2]; + document.oauth2Signin.oauth2_info.value = parms[3]; + document.oauth2Signin.oauth2_scope.value = parms[4]; + document.oauth2Signin.oauth2_display.value = parms[5]; + document.oauth2Signin.openauth_referrer.value = openauthReferrer(); + document.oauth2Signin.action = '/oauth2/authorize/'; + document.oauth2Signin.submit(); +} + +function withFacebook() { + var parms = ['https://graph.facebook.com/oauth/authorize', 'https://graph.facebook.com/oauth/access_token', 'facebook.com', 'https://graph.facebook.com/me', 'email', 'page']; + return parms; +} + +function withGithub() { + var parms = ['https://github.com/login/oauth/authorize', 'https://github.com/login/oauth/access_token', 'github.com', 'https://github.com/api/v2/json/user/show', 'email', '']; + return parms; +} + +function submitOAuth1Signin(w) { + parms = w(); + clearauthcookie(); + document.oauth1Signin.oauth1_request_token.value = parms[0]; + document.oauth1Signin.oauth1_authorize.value = parms[1]; + document.oauth1Signin.oauth1_access_token.value = parms[2]; + document.oauth1Signin.oauth1_client_id.value = parms[3]; + document.oauth1Signin.oauth1_info.value = parms[4]; + document.oauth1Signin.openauth_referrer.value = openauthReferrer(); + document.oauth1Signin.action = '/oauth1/authorize/'; + document.oauth1Signin.submit(); +} + +function withLinkedin() { + var parms = ['https://api.linkedin.com/uas/oauth/requestToken', 'https://www.linkedin.com/uas/oauth/authorize', 'https://api.linkedin.com/uas/oauth/accessToken', 'linkedin.com', 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name,public-profile-url)']; + return parms; +} + +function withTwitter() { + var parms = ['https://api.twitter.com/oauth/request_token', 'https://api.twitter.com/oauth/authorize', 'https://api.twitter.com/oauth/access_token', 'twitter.com', 'https://api.twitter.com/1/statuses/user_timeline.json']; + return parms; +} +</script> + +<form name="fields"> +<p>Sign in with your Google account<br/><input type="button" onclick="submitOpenIDSignin(withGoogle)" value="Sign in"/></p> +<p>Sign in with your Yahoo account<br/><input type="button" onclick="submitOpenIDSignin(withYahoo)" value="Sign in"/></p> +<p>Sign in with your MyOpenID account<br/><input type="button" onclick="submitOpenIDSignin(withMyOpenID)" value="Sign in"/></p> +<p>Sign in with your Verisign account<br/><input type="button" onclick="submitOpenIDSignin(withVerisign)" value="Sign in"/></p> +<p>Sign in with your MySpace account<br/><input type="button" onclick="submitOpenIDSignin(withMySpace)" value="Sign in"/></p> + +<p>Sign in with a Google apps domain<br/> +<input type="text" size="20" name="domain" value="example.com"/><br/> +<input type="button" onclick="submitOpenIDSignin(withGoogleApps)" value="Sign in"/></p> + +<p>Sign in with your Livejournal account<br/> +<input type="text" size="10" name="ljuser" value=""/><br/> +<input type="button" onclick="submitOpenIDSignin(withLivejournal)" value="Sign in"/></p> + +<p>Sign in with your Blogspot account<br/> +<input type="text" size="10" name="bsuser" value=""/><br/> +<input type="button" onclick="submitOpenIDSignin(withBlogspot)" value="Sign in"/></p> + +<p>Sign in with your Blogger account<br/> +<input type="text" size="10" name="bguser" value=""/><br/> +<input type="button" onclick="submitOpenIDSignin(withBlogger)" value="Sign in"/></p> + +<p>Sign in with an OpenID endpoint<br/> +<input type="text" size="50" name="endpoint" value="https://www.google.com/accounts/o8/id"/><br/> +<input type="button" onclick="submitOpenIDSignin(withXRDSEndpoint)" value="Sign in"/></p> + +<p>Sign in with your Facebook account<br/><input type="button" onclick="submitOAuth2Signin(withFacebook)" value="Sign in"/></p> +<p>Sign in with your Github account<br/><input type="button" onclick="submitOAuth2Signin(withGithub)" value="Sign in"/></p> + +<p>Sign in with your Linkedin account<br/><input type="button" onclick="submitOAuth1Signin(withLinkedin)" value="Sign in"/></p> +<p>Sign in with your Twitter account<br/><input type="button" onclick="submitOAuth1Signin(withTwitter)" value="Sign in"/></p> +</form> + +<form name="openIDSignin" action="/" method="GET"> +<input type="hidden" name="openid_identifier" value=""/> +</form> + +<form name="oauth2Signin" action="/" method="GET"> +<input type="hidden" name="oauth2_authorize" value=""/> +<input type="hidden" name="oauth2_access_token" value=""/> +<input type="hidden" name="oauth2_client_id" value=""/> +<input type="hidden" name="oauth2_info" value=""/> +<input type="hidden" name="oauth2_scope" value=""/> +<input type="hidden" name="oauth2_display" value=""/> +<input type="hidden" name="openauth_referrer" value=""/> +</form> + +<form name="oauth1Signin" action="/" method="GET"> +<input type="hidden" name="oauth1_request_token" value=""/> +<input type="hidden" name="oauth1_authorize" value=""/> +<input type="hidden" name="oauth1_access_token" value=""/> +<input type="hidden" name="oauth1_client_id" value=""/> +<input type="hidden" name="oauth1_info" value=""/> +<input type="hidden" name="openauth_referrer" value=""/> +</form> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/htdocs/logout/index.html b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/htdocs/logout/index.html new file mode 100644 index 0000000000..50a10bdd8b --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/htdocs/logout/index.html @@ -0,0 +1,44 @@ +<!-- + 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. +--> + +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<script type="text/javascript" src="/all-min.js"></script> +<title>Sign out</title> +</head> +<body> +<h1>Sign out</h1> +<br/> + +<form name="signout" action="/login" method="GET"> +<script type="text/javascript"> +function submitSignout() { + clearauthcookie(); + document.signout.submit(); + return true; +} +</script> +<input type="button" onclick="submitSignout()" value="Sign out"/> +</form> +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/shopping-cart.py b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/shopping-cart.py new file mode 100644 index 0000000000..b3818a6727 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/shopping-cart.py @@ -0,0 +1,76 @@ +# 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 + +# Convert a particular host and user email to a cart id +def cartid(host, email): + return ("cart", host.eval(), email.eval()) + +# 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, host, email): + id = str(uuid.uuid1()) + cart = (("'entry", item[0][1], ("'id", id), item[0][3]),) + getcart(cartid(host, email), cache) + cache.put(cartid(host, email), cart) + return (id,) + + +# Find an item in the cart +def find(id, cart): + if cart == (): + return (("'entry", ("'title", "Item"), ("'id", 0)),) + elif id == cart[0][2][1]: + return (cart[0],) + else: + return find(id, cart[1:]) + +# Get items from the cart +def get(id, cache, host, email): + if id == (): + return ((("'feed", ("'title", "Your Cart"), ("'id", email.eval())) + getcart(cartid(host,email), cache)),) + return find(id[0], getcart(cartid(host, email), cache)) + +# Delete items from the cart +def delete(id, cache, host, email): + if id == (): + return cache.delete(cartid(host, email)) + return True + +# Return the price of an item +def price(item): + return float(filter(lambda x: x[0] == "'price", item[3][1][1:])[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, host, email): + return sum(getcart(cartid(host, email), cache)) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/store.composite b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/store.composite new file mode 100644 index 0000000000..c8955af24e --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/store.composite @@ -0,0 +1,63 @@ +<?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" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <implementation.python script="store.py"/> + <service name="Widget"> + <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"> + <implementation.python script="fruits-catalog.py"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <binding.jsonrpc uri="catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.python script="shopping-cart.py"/> + <property name="host">localhost</property> + <property name="email">anonymous@localhost</property> + <service name="ShoppingCart"> + <binding.atom uri="shoppingCart"/> + </service> + <service name="Total"> + <binding.jsonrpc uri="total"/> + </service> + <reference name="cache" target="Cache"/> + </component> + + <component name="CurrencyConverter"> + <implementation.python script="currency-converter.py"/> + <service name="CurrencyConverter"> + <binding.jsonrpc uri="currencyConverter"/> + </service> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/store.py b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/store.py new file mode 100644 index 0000000000..ff82f1d327 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/jane/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.total() + +def deleteall(catalog, shoppingCart, shoppingTotal): + return shoppingCart.deleteall() + +def delete(id, catalog, shoppingCart, shoppingTotal): + return shoppingCart.delete(id) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/currency-converter.py b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/currency-converter.py new file mode 100644 index 0000000000..2fded8f616 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/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/branches/lightweight-sca/samples/store-cluster/domains/joe/fruits-catalog.py b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/fruits-catalog.py new file mode 100644 index 0000000000..6644421683 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/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", "Apple"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))), + (("'name", "Orange"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))), + (("'name", "Pear"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(1.55))) + ) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/htdocs/index.html new file mode 100644 index 0000000000..0caf8b3df1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/htdocs/index.html @@ -0,0 +1,156 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Joe's Store</title> + +<script type="text/javascript" src="/all-min.js"></script> + +<script type="text/javascript"> +var store = sca.component("Store"); +var catalog = sca.defun(sca.reference(store, "catalog"), "items"); +var shoppingCart = sca.reference(store, "shoppingCart"); +var shoppingTotal = sca.defun(sca.reference(store, "shoppingTotal"), "total"); + +var catalogItems; + +function catalog_itemsResponse(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(doc) { + if (doc != null) { + var feed = parseXML([doc]); + 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.total(shoppingTotal_totalResponse); + } +} + +function shoppingTotal_totalResponse(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 = '<?xml version="1.0" encoding="UTF-8"?>\n' + + '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><content type="application/xml">' + + '<item>' + + '<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.items(catalog_itemsResponse); + shoppingCart.get("", shoppingCart_getResponse); + } catch(e){ + alert(e); + } +} +</script> +</head> + +<body onload="init()"> +<h1>Joe's Store</h1> +<br/> +<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> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/htdocs/login/index.html b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/htdocs/login/index.html new file mode 100644 index 0000000000..2a7be01ff1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/htdocs/login/index.html @@ -0,0 +1,212 @@ +<!-- + 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. +--> + +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<script type="text/javascript" src="/all-min.js"></script> +<title>Sign in</title> +</head> +<body> +<h1>Sign in with an OpenID or OAuth provider</h1> +<br/> + +<script type="text/javascript"> +function queryParams() { + qp = new Array(); + qs = window.location.search.substring(1).split('&'); + for (i = 0; i < qs.length; i++) { + e = qs[i].indexOf('='); + if (e > 0) + qp[qs[i].substring(0, e)] = unescape(qs[i].substring(e + 1)); + } + return qp; +} + +function openauthReferrer() { + r = queryParams()['openauth_referrer']; + if (typeof(r) == 'undefined') + return '/'; + q = r.indexOf('?'); + if (q > 0) + return r.substring(0, q); + return r; +} + +if (typeof(openauthReferrer()) == 'undefined') { + document.location = '/'; +} + +function submitOpenIDSignin(w) { + clearauthcookie(); + document.openIDSignin.openid_identifier.value = w(); + document.openIDSignin.action = openauthReferrer(); + document.openIDSignin.submit(); +} + +function withGoogle() { + return 'https://www.google.com/accounts/o8/id'; +} + +function withYahoo() { + return 'https://me.yahoo.com/'; +} + +function withMyOpenID() { + return 'http://www.myopenid.com/xrds'; +} + +function withVerisign() { + return 'https://pip.verisignlabs.com/'; +} + +function withMySpace() { + return 'https://api.myspace.com/openid'; +} + +function withGoogleApps() { + return 'https://www.google.com/accounts/o8/site-xrds?ns=2&hd=' + document.fields.domain.value; +} + +function withLivejournal() { + return 'http://' + document.fields.ljuser.value + '.livejournal.com'; +} + +function withBlogspot() { + return 'http://' + document.fields.bsuser.value + '.blogspot.com'; +} + +function withBlogger() { + return 'http://' + document.fields.bguser.value + '.blogger.com'; +} + +function withXRDSEndpoint() { + return document.fields.endpoint.value; +} + +function submitOAuth2Signin(w) { + parms = w(); + clearauthcookie(); + document.oauth2Signin.oauth2_authorize.value = parms[0]; + document.oauth2Signin.oauth2_access_token.value = parms[1]; + document.oauth2Signin.oauth2_client_id.value = parms[2]; + document.oauth2Signin.oauth2_info.value = parms[3]; + document.oauth2Signin.oauth2_scope.value = parms[4]; + document.oauth2Signin.oauth2_display.value = parms[5]; + document.oauth2Signin.openauth_referrer.value = openauthReferrer(); + document.oauth2Signin.action = '/oauth2/authorize/'; + document.oauth2Signin.submit(); +} + +function withFacebook() { + var parms = ['https://graph.facebook.com/oauth/authorize', 'https://graph.facebook.com/oauth/access_token', 'facebook.com', 'https://graph.facebook.com/me', 'email', 'page']; + return parms; +} + +function withGithub() { + var parms = ['https://github.com/login/oauth/authorize', 'https://github.com/login/oauth/access_token', 'github.com', 'https://github.com/api/v2/json/user/show', 'email', '']; + return parms; +} + +function submitOAuth1Signin(w) { + parms = w(); + clearauthcookie(); + document.oauth1Signin.oauth1_request_token.value = parms[0]; + document.oauth1Signin.oauth1_authorize.value = parms[1]; + document.oauth1Signin.oauth1_access_token.value = parms[2]; + document.oauth1Signin.oauth1_client_id.value = parms[3]; + document.oauth1Signin.oauth1_info.value = parms[4]; + document.oauth1Signin.openauth_referrer.value = openauthReferrer(); + document.oauth1Signin.action = '/oauth1/authorize/'; + document.oauth1Signin.submit(); +} + +function withLinkedin() { + var parms = ['https://api.linkedin.com/uas/oauth/requestToken', 'https://www.linkedin.com/uas/oauth/authorize', 'https://api.linkedin.com/uas/oauth/accessToken', 'linkedin.com', 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name,public-profile-url)']; + return parms; +} + +function withTwitter() { + var parms = ['https://api.twitter.com/oauth/request_token', 'https://api.twitter.com/oauth/authorize', 'https://api.twitter.com/oauth/access_token', 'twitter.com', 'https://api.twitter.com/1/statuses/user_timeline.json']; + return parms; +} +</script> + +<form name="fields"> +<p>Sign in with your Google account<br/><input type="button" onclick="submitOpenIDSignin(withGoogle)" value="Sign in"/></p> +<p>Sign in with your Yahoo account<br/><input type="button" onclick="submitOpenIDSignin(withYahoo)" value="Sign in"/></p> +<p>Sign in with your MyOpenID account<br/><input type="button" onclick="submitOpenIDSignin(withMyOpenID)" value="Sign in"/></p> +<p>Sign in with your Verisign account<br/><input type="button" onclick="submitOpenIDSignin(withVerisign)" value="Sign in"/></p> +<p>Sign in with your MySpace account<br/><input type="button" onclick="submitOpenIDSignin(withMySpace)" value="Sign in"/></p> + +<p>Sign in with a Google apps domain<br/> +<input type="text" size="20" name="domain" value="example.com"/><br/> +<input type="button" onclick="submitOpenIDSignin(withGoogleApps)" value="Sign in"/></p> + +<p>Sign in with your Livejournal account<br/> +<input type="text" size="10" name="ljuser" value=""/><br/> +<input type="button" onclick="submitOpenIDSignin(withLivejournal)" value="Sign in"/></p> + +<p>Sign in with your Blogspot account<br/> +<input type="text" size="10" name="bsuser" value=""/><br/> +<input type="button" onclick="submitOpenIDSignin(withBlogspot)" value="Sign in"/></p> + +<p>Sign in with your Blogger account<br/> +<input type="text" size="10" name="bguser" value=""/><br/> +<input type="button" onclick="submitOpenIDSignin(withBlogger)" value="Sign in"/></p> + +<p>Sign in with an OpenID endpoint<br/> +<input type="text" size="50" name="endpoint" value="https://www.google.com/accounts/o8/id"/><br/> +<input type="button" onclick="submitOpenIDSignin(withXRDSEndpoint)" value="Sign in"/></p> + +<p>Sign in with your Facebook account<br/><input type="button" onclick="submitOAuth2Signin(withFacebook)" value="Sign in"/></p> +<p>Sign in with your Github account<br/><input type="button" onclick="submitOAuth2Signin(withGithub)" value="Sign in"/></p> + +<p>Sign in with your Linkedin account<br/><input type="button" onclick="submitOAuth1Signin(withLinkedin)" value="Sign in"/></p> +<p>Sign in with your Twitter account<br/><input type="button" onclick="submitOAuth1Signin(withTwitter)" value="Sign in"/></p> +</form> + +<form name="openIDSignin" action="/" method="GET"> +<input type="hidden" name="openid_identifier" value=""/> +</form> + +<form name="oauth2Signin" action="/" method="GET"> +<input type="hidden" name="oauth2_authorize" value=""/> +<input type="hidden" name="oauth2_access_token" value=""/> +<input type="hidden" name="oauth2_client_id" value=""/> +<input type="hidden" name="oauth2_info" value=""/> +<input type="hidden" name="oauth2_scope" value=""/> +<input type="hidden" name="oauth2_display" value=""/> +<input type="hidden" name="openauth_referrer" value=""/> +</form> + +<form name="oauth1Signin" action="/" method="GET"> +<input type="hidden" name="oauth1_request_token" value=""/> +<input type="hidden" name="oauth1_authorize" value=""/> +<input type="hidden" name="oauth1_access_token" value=""/> +<input type="hidden" name="oauth1_client_id" value=""/> +<input type="hidden" name="oauth1_info" value=""/> +<input type="hidden" name="openauth_referrer" value=""/> +</form> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/htdocs/logout/index.html b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/htdocs/logout/index.html new file mode 100644 index 0000000000..50a10bdd8b --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/htdocs/logout/index.html @@ -0,0 +1,44 @@ +<!-- + 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. +--> + +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<script type="text/javascript" src="/all-min.js"></script> +<title>Sign out</title> +</head> +<body> +<h1>Sign out</h1> +<br/> + +<form name="signout" action="/login" method="GET"> +<script type="text/javascript"> +function submitSignout() { + clearauthcookie(); + document.signout.submit(); + return true; +} +</script> +<input type="button" onclick="submitSignout()" value="Sign out"/> +</form> +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/shopping-cart.py b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/shopping-cart.py new file mode 100644 index 0000000000..b3818a6727 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/shopping-cart.py @@ -0,0 +1,76 @@ +# 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 + +# Convert a particular host and user email to a cart id +def cartid(host, email): + return ("cart", host.eval(), email.eval()) + +# 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, host, email): + id = str(uuid.uuid1()) + cart = (("'entry", item[0][1], ("'id", id), item[0][3]),) + getcart(cartid(host, email), cache) + cache.put(cartid(host, email), cart) + return (id,) + + +# Find an item in the cart +def find(id, cart): + if cart == (): + return (("'entry", ("'title", "Item"), ("'id", 0)),) + elif id == cart[0][2][1]: + return (cart[0],) + else: + return find(id, cart[1:]) + +# Get items from the cart +def get(id, cache, host, email): + if id == (): + return ((("'feed", ("'title", "Your Cart"), ("'id", email.eval())) + getcart(cartid(host,email), cache)),) + return find(id[0], getcart(cartid(host, email), cache)) + +# Delete items from the cart +def delete(id, cache, host, email): + if id == (): + return cache.delete(cartid(host, email)) + return True + +# Return the price of an item +def price(item): + return float(filter(lambda x: x[0] == "'price", item[3][1][1:])[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, host, email): + return sum(getcart(cartid(host, email), cache)) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/store.composite b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/store.composite new file mode 100644 index 0000000000..c8955af24e --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/store.composite @@ -0,0 +1,63 @@ +<?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" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <implementation.python script="store.py"/> + <service name="Widget"> + <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"> + <implementation.python script="fruits-catalog.py"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <binding.jsonrpc uri="catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.python script="shopping-cart.py"/> + <property name="host">localhost</property> + <property name="email">anonymous@localhost</property> + <service name="ShoppingCart"> + <binding.atom uri="shoppingCart"/> + </service> + <service name="Total"> + <binding.jsonrpc uri="total"/> + </service> + <reference name="cache" target="Cache"/> + </component> + + <component name="CurrencyConverter"> + <implementation.python script="currency-converter.py"/> + <service name="CurrencyConverter"> + <binding.jsonrpc uri="currencyConverter"/> + </service> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/store.py b/sca-cpp/branches/lightweight-sca/samples/store-cluster/domains/joe/store.py new file mode 100644 index 0000000000..811b05c580 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/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 items(catalog, shoppingCart, shoppingTotal): + return catalog.items() + +def total(catalog, shoppingCart, shoppingTotal): + return shoppingCart.total() + +def deleteall(catalog, shoppingCart, shoppingTotal): + return shoppingCart.deletall() + +def delete(id, catalog, shoppingCart, shoppingTotal): + return shoppingCart.delete(id) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-cluster/htdocs/index.html new file mode 100644 index 0000000000..50c7e25ee6 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/htdocs/index.html @@ -0,0 +1,39 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Store</title> +</head> + +<body> +<h1>Store</h1> +<br/> +<p>For this sample to work, add the sample domain to your /etc/hosts as follows:<br/> +127.0.0.1 example.com jane.example.com joe.example.com</p> + +<p/> +<p>Jane's store at <a href="http://jane.example.com/">jane.example.com</a> +<br/>Joe's store at <a href="http://joe.example.com/">joe.example.com</a></p> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/htdocs/login/index.html b/sca-cpp/branches/lightweight-sca/samples/store-cluster/htdocs/login/index.html new file mode 100644 index 0000000000..2a7be01ff1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/htdocs/login/index.html @@ -0,0 +1,212 @@ +<!-- + 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. +--> + +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<script type="text/javascript" src="/all-min.js"></script> +<title>Sign in</title> +</head> +<body> +<h1>Sign in with an OpenID or OAuth provider</h1> +<br/> + +<script type="text/javascript"> +function queryParams() { + qp = new Array(); + qs = window.location.search.substring(1).split('&'); + for (i = 0; i < qs.length; i++) { + e = qs[i].indexOf('='); + if (e > 0) + qp[qs[i].substring(0, e)] = unescape(qs[i].substring(e + 1)); + } + return qp; +} + +function openauthReferrer() { + r = queryParams()['openauth_referrer']; + if (typeof(r) == 'undefined') + return '/'; + q = r.indexOf('?'); + if (q > 0) + return r.substring(0, q); + return r; +} + +if (typeof(openauthReferrer()) == 'undefined') { + document.location = '/'; +} + +function submitOpenIDSignin(w) { + clearauthcookie(); + document.openIDSignin.openid_identifier.value = w(); + document.openIDSignin.action = openauthReferrer(); + document.openIDSignin.submit(); +} + +function withGoogle() { + return 'https://www.google.com/accounts/o8/id'; +} + +function withYahoo() { + return 'https://me.yahoo.com/'; +} + +function withMyOpenID() { + return 'http://www.myopenid.com/xrds'; +} + +function withVerisign() { + return 'https://pip.verisignlabs.com/'; +} + +function withMySpace() { + return 'https://api.myspace.com/openid'; +} + +function withGoogleApps() { + return 'https://www.google.com/accounts/o8/site-xrds?ns=2&hd=' + document.fields.domain.value; +} + +function withLivejournal() { + return 'http://' + document.fields.ljuser.value + '.livejournal.com'; +} + +function withBlogspot() { + return 'http://' + document.fields.bsuser.value + '.blogspot.com'; +} + +function withBlogger() { + return 'http://' + document.fields.bguser.value + '.blogger.com'; +} + +function withXRDSEndpoint() { + return document.fields.endpoint.value; +} + +function submitOAuth2Signin(w) { + parms = w(); + clearauthcookie(); + document.oauth2Signin.oauth2_authorize.value = parms[0]; + document.oauth2Signin.oauth2_access_token.value = parms[1]; + document.oauth2Signin.oauth2_client_id.value = parms[2]; + document.oauth2Signin.oauth2_info.value = parms[3]; + document.oauth2Signin.oauth2_scope.value = parms[4]; + document.oauth2Signin.oauth2_display.value = parms[5]; + document.oauth2Signin.openauth_referrer.value = openauthReferrer(); + document.oauth2Signin.action = '/oauth2/authorize/'; + document.oauth2Signin.submit(); +} + +function withFacebook() { + var parms = ['https://graph.facebook.com/oauth/authorize', 'https://graph.facebook.com/oauth/access_token', 'facebook.com', 'https://graph.facebook.com/me', 'email', 'page']; + return parms; +} + +function withGithub() { + var parms = ['https://github.com/login/oauth/authorize', 'https://github.com/login/oauth/access_token', 'github.com', 'https://github.com/api/v2/json/user/show', 'email', '']; + return parms; +} + +function submitOAuth1Signin(w) { + parms = w(); + clearauthcookie(); + document.oauth1Signin.oauth1_request_token.value = parms[0]; + document.oauth1Signin.oauth1_authorize.value = parms[1]; + document.oauth1Signin.oauth1_access_token.value = parms[2]; + document.oauth1Signin.oauth1_client_id.value = parms[3]; + document.oauth1Signin.oauth1_info.value = parms[4]; + document.oauth1Signin.openauth_referrer.value = openauthReferrer(); + document.oauth1Signin.action = '/oauth1/authorize/'; + document.oauth1Signin.submit(); +} + +function withLinkedin() { + var parms = ['https://api.linkedin.com/uas/oauth/requestToken', 'https://www.linkedin.com/uas/oauth/authorize', 'https://api.linkedin.com/uas/oauth/accessToken', 'linkedin.com', 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name,public-profile-url)']; + return parms; +} + +function withTwitter() { + var parms = ['https://api.twitter.com/oauth/request_token', 'https://api.twitter.com/oauth/authorize', 'https://api.twitter.com/oauth/access_token', 'twitter.com', 'https://api.twitter.com/1/statuses/user_timeline.json']; + return parms; +} +</script> + +<form name="fields"> +<p>Sign in with your Google account<br/><input type="button" onclick="submitOpenIDSignin(withGoogle)" value="Sign in"/></p> +<p>Sign in with your Yahoo account<br/><input type="button" onclick="submitOpenIDSignin(withYahoo)" value="Sign in"/></p> +<p>Sign in with your MyOpenID account<br/><input type="button" onclick="submitOpenIDSignin(withMyOpenID)" value="Sign in"/></p> +<p>Sign in with your Verisign account<br/><input type="button" onclick="submitOpenIDSignin(withVerisign)" value="Sign in"/></p> +<p>Sign in with your MySpace account<br/><input type="button" onclick="submitOpenIDSignin(withMySpace)" value="Sign in"/></p> + +<p>Sign in with a Google apps domain<br/> +<input type="text" size="20" name="domain" value="example.com"/><br/> +<input type="button" onclick="submitOpenIDSignin(withGoogleApps)" value="Sign in"/></p> + +<p>Sign in with your Livejournal account<br/> +<input type="text" size="10" name="ljuser" value=""/><br/> +<input type="button" onclick="submitOpenIDSignin(withLivejournal)" value="Sign in"/></p> + +<p>Sign in with your Blogspot account<br/> +<input type="text" size="10" name="bsuser" value=""/><br/> +<input type="button" onclick="submitOpenIDSignin(withBlogspot)" value="Sign in"/></p> + +<p>Sign in with your Blogger account<br/> +<input type="text" size="10" name="bguser" value=""/><br/> +<input type="button" onclick="submitOpenIDSignin(withBlogger)" value="Sign in"/></p> + +<p>Sign in with an OpenID endpoint<br/> +<input type="text" size="50" name="endpoint" value="https://www.google.com/accounts/o8/id"/><br/> +<input type="button" onclick="submitOpenIDSignin(withXRDSEndpoint)" value="Sign in"/></p> + +<p>Sign in with your Facebook account<br/><input type="button" onclick="submitOAuth2Signin(withFacebook)" value="Sign in"/></p> +<p>Sign in with your Github account<br/><input type="button" onclick="submitOAuth2Signin(withGithub)" value="Sign in"/></p> + +<p>Sign in with your Linkedin account<br/><input type="button" onclick="submitOAuth1Signin(withLinkedin)" value="Sign in"/></p> +<p>Sign in with your Twitter account<br/><input type="button" onclick="submitOAuth1Signin(withTwitter)" value="Sign in"/></p> +</form> + +<form name="openIDSignin" action="/" method="GET"> +<input type="hidden" name="openid_identifier" value=""/> +</form> + +<form name="oauth2Signin" action="/" method="GET"> +<input type="hidden" name="oauth2_authorize" value=""/> +<input type="hidden" name="oauth2_access_token" value=""/> +<input type="hidden" name="oauth2_client_id" value=""/> +<input type="hidden" name="oauth2_info" value=""/> +<input type="hidden" name="oauth2_scope" value=""/> +<input type="hidden" name="oauth2_display" value=""/> +<input type="hidden" name="openauth_referrer" value=""/> +</form> + +<form name="oauth1Signin" action="/" method="GET"> +<input type="hidden" name="oauth1_request_token" value=""/> +<input type="hidden" name="oauth1_authorize" value=""/> +<input type="hidden" name="oauth1_access_token" value=""/> +<input type="hidden" name="oauth1_client_id" value=""/> +<input type="hidden" name="oauth1_info" value=""/> +<input type="hidden" name="openauth_referrer" value=""/> +</form> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/htdocs/logout/index.html b/sca-cpp/branches/lightweight-sca/samples/store-cluster/htdocs/logout/index.html new file mode 100644 index 0000000000..50a10bdd8b --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/htdocs/logout/index.html @@ -0,0 +1,44 @@ +<!-- + 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. +--> + +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<script type="text/javascript" src="/all-min.js"></script> +<title>Sign out</title> +</head> +<body> +<h1>Sign out</h1> +<br/> + +<form name="signout" action="/login" method="GET"> +<script type="text/javascript"> +function submitSignout() { + clearauthcookie(); + document.signout.submit(); + return true; +} +</script> +<input type="button" onclick="submitSignout()" value="Sign out"/> +</form> +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/proxy-conf b/sca-cpp/branches/lightweight-sca/samples/store-cluster/proxy-conf new file mode 100755 index 0000000000..c43feff551 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/proxy-conf @@ -0,0 +1,35 @@ +#!/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. + +root=$1 +port=$2 + +set -x + +# Configure a proxy balancer +../../modules/http/httpd-conf $root sca-store.com $port/80 $root/htdocs +../../modules/http/mass-host-conf $root $root/domains htdocs +../../modules/http/proxy-conf $root +../../modules/http/httpd-event-conf $root + +# Aggregate proxy balancer logs +category=`basename $root` +../../components/log/scribe-tail-start $category $root/logs/error_log +../../components/log/scribe-tail-start $category $root/logs/access_log + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/proxy-ssl-conf b/sca-cpp/branches/lightweight-sca/samples/store-cluster/proxy-ssl-conf new file mode 100755 index 0000000000..e4ddbb0c4b --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/proxy-ssl-conf @@ -0,0 +1,41 @@ +#!/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. + +root=$1 +port=$2 +sslport=$3 + +set -x + +# Configure an SSL-enabled proxy balancer +../../modules/http/httpd-conf $root sca-store.com $port $root/htdocs +../../modules/http/mass-host-conf $root $root/domains htdocs +../../modules/http/proxy-conf $root +../../modules/http/httpd-event-conf $root +tar -C tmp/ssl -c `../../modules/http/ssl-cert-find tmp/ssl` | tar -C $root -x +../../modules/http/httpd-ssl-conf $root $sslport +../../modules/http/httpd-tunnel-ssl-conf $root +../../modules/http/mass-host-ssl-conf $root +../../modules/http/proxy-ssl-conf $root + +# Aggregate proxy balancer logs +category=`basename $root` +../../components/log/scribe-tail-start $category $root/logs/error_log +../../components/log/scribe-tail-start $category $root/logs/access_log + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/server-conf b/sca-cpp/branches/lightweight-sca/samples/store-cluster/server-conf new file mode 100755 index 0000000000..089e1842db --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/server-conf @@ -0,0 +1,47 @@ +#!/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. + +root=$1 +port=$2 + +set -x + +# Configure an app server +../../modules/http/httpd-conf $root sca-store.com $port/80 htdocs +../../modules/http/httpd-event-conf $root +../../modules/http/mass-host-conf $root domains htdocs +../../modules/server/server-conf $root +../../modules/python/python-conf $root +cat >>$root/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/shared/ +SCAComposite shared.composite + +# Configure SCA Composite for mass dynamic virtual hosting +SCAVirtualDomain sca-store.com +SCAVirtualContribution `pwd`/domains/ +SCAVirtualComposite store.composite + +EOF + +# Aggregate app server logs +category=`basename $root` +../../components/log/scribe-tail-start $category $root/logs/error_log +../../components/log/scribe-tail-start $category $root/logs/access_log + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/server-ssl-conf b/sca-cpp/branches/lightweight-sca/samples/store-cluster/server-ssl-conf new file mode 100755 index 0000000000..4180a44056 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/server-ssl-conf @@ -0,0 +1,66 @@ +#!/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. + +root=$1 +port=$2 +sslport=$3 + +set -x + +# Configure an SSL-enabled app server +../../modules/http/httpd-conf $root sca-store.com $port htdocs +../../modules/http/httpd-event-conf $root +../../modules/http/mass-host-conf $root domains htdocs + +tar -C tmp/ssl -c `../../modules/http/ssl-cert-find tmp/ssl` | tar -C $root -x +../../modules/http/httpd-ssl-conf $root $sslport +../../modules/http/httpd-tunnel-ssl-conf $root +../../modules/http/mass-host-ssl-conf $root + +../../modules/oauth/oauth-conf $root +../../modules/oauth/oauth-memcached-conf $root localhost 11211 +../../modules/oauth/oauth-memcached-conf $root localhost 11212 +../../modules/oauth/oauth-memcached-conf $root localhost 11213 +../../modules/openid/openid-conf $root +../../modules/openid/openid-step2-conf $root +../../modules/openid/openid-memcached-conf $root localhost 11211 +../../modules/openid/openid-memcached-conf $root localhost 11212 +../../modules/openid/openid-memcached-conf $root localhost 11213 +../../modules/http/open-auth-conf $root +../../modules/http/passwd-auth-conf $root foo foo + +../../modules/server/server-conf $root +../../modules/python/python-conf $root +cat >>$root/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/shared/ +SCAComposite shared.composite + +# Configure SCA Composite for mass dynamic virtual hosting +SCAVirtualDomain sca-store.com +SCAVirtualContribution `pwd`/domains/ +SCAVirtualComposite store.composite + +EOF + +# Aggregate app server logs +category=`basename $root` +../../components/log/scribe-tail-start $category $root/logs/error_log +../../components/log/scribe-tail-start $category $root/logs/access_log + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/server-test b/sca-cpp/branches/lightweight-sca/samples/store-cluster/server-test new file mode 100755 index 0000000000..836097dcae --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/server-test @@ -0,0 +1,61 @@ +#!/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. + +# For this test to work, add the test domain to your etc/hosts as follows: +# 127.0.0.1 example.com joe.example.com joe.example.com + +echo "Testing..." +here=`echo "import os; print os.path.realpath('$0')" | python`; here=`dirname $here` +curl_prefix=`cat $here/../../modules/http/curl.prefix` + +# Setup +./start +sleep 2 + +# Test HTTP GET +$curl_prefix/bin/curl http://joe.example.com/ 2>/dev/null >tmp/index.html +diff tmp/index.html htdocs/domains/joe/index.html +rc=$? + +# Test Catalog +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl http://joe.example.com/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 ../store-cpp/htdocs/test/items-result.txt + rc=$? +fi + +# Test Shopping Cart +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl http://joe.example.com/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://joe.example.com/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 +exit $rc diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/shared/shared.composite b/sca-cpp/branches/lightweight-sca/samples/store-cluster/shared/shared.composite new file mode 100644 index 0000000000..d11d31b9ea --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/shared/shared.composite @@ -0,0 +1,63 @@ +<?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" + targetNamespace="http://shared" + name="shared"> + + <component name="Cache"> + <implementation.cpp path="../../../components/cache" library="libdatacache"/> + <service name="Cache"> + <binding.atom uri="cache"/> + </service> + <reference name="l1reader" target="Memcache"/> + <reference name="l1writer" target="Memcache"/> + <reference name="l2reader" target="Standbydb"/> + <reference name="l2writer" target="Masterdb"/> + </component> + + <component name="Memcache"> + <implementation.cpp path="../../../components/cache" library="libmemcache"/> + <service name="Memcache"> + <binding.atom uri="memcache"/> + </service> + <property name="server">localhost:11211</property> + <property name="server">localhost:11212</property> + <property name="server">localhost:11213</property> + </component> + + <component name="Masterdb"> + <implementation.cpp path="../../../components/sqldb" library="libsqldb"/> + <property name="conninfo">host=localhost port=6432 dbname=db</property> + <property name="table">store</property> + <service name="Masterdb"> + <binding.atom uri="masterdb"/> + </service> + </component> + + <component name="Standbydb"> + <implementation.cpp path="../../../components/sqldb" library="libsqldb"/> + <property name="conninfo">host=localhost port=6433 dbname=db</property> + <property name="table">store</property> + <service name="Standbydb"> + <binding.atom uri="standbydb"/> + </service> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/sqldb-master-conf b/sca-cpp/branches/lightweight-sca/samples/store-cluster/sqldb-master-conf new file mode 100755 index 0000000000..83f78be999 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/sqldb-master-conf @@ -0,0 +1,47 @@ +#!/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. + +root=$1 +port=$2 +httpport=$3 + +set -x + +# Aggregate database server logs +category=`basename $root` +../../components/log/scribe-tail-start $category "sqldb" $root/logs/postgresql +../../components/log/scribe-tail-start $category $root/logs/error_log +../../components/log/scribe-tail-start $category $root/logs/access_log + +# Configure a database backup HTTP server +../../modules/http/httpd-conf $root localhost $httpport $root/htdocs + +# Configure a database server +if [ ! -f $root/sqldb/data/postgresql.conf ]; then + create="true" +else + create="false" +fi +../../components/sqldb/pgsql-conf $root $port +if [ "$create" = "true" ]; then + ../../components/sqldb/pgsql-start $root + ../../components/sqldb/pgsql localhost $port "create table store(key text, value text);" 1>>$root/logs/postgresql 2>&1 + ../../components/sqldb/pgsql-stop $root +fi + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/sqldb-standby-conf b/sca-cpp/branches/lightweight-sca/samples/store-cluster/sqldb-standby-conf new file mode 100755 index 0000000000..4998ead4b4 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/sqldb-standby-conf @@ -0,0 +1,40 @@ +#!/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. + +root=$1 +port=$2 +httpport=$3 +mhost=$4 +mport=$5 +mhttpport=$6 + +set -x + +# Aggregate database server logs +category=`basename $root` +../../components/log/scribe-tail-start $category "sqldb" $root/logs/postgresql +../../components/log/scribe-tail-start $category $root/logs/error_log +../../components/log/scribe-tail-start $category $root/logs/access_log + +# Configure a database backup HTTP server +../../modules/http/httpd-conf $root localhost $httpport $root/htdocs + +# Configure a standby database server +../../components/sqldb/pgsql-standby-conf $root $port $mhost $mport $mhttpport + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/ssl-start b/sca-cpp/branches/lightweight-sca/samples/store-cluster/ssl-start new file mode 100755 index 0000000000..04aa267d5e --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/ssl-start @@ -0,0 +1,121 @@ +#!/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. + +set -x + +# Redirect traffic from ports 80, 443 and 444 to proxy1 +sudo ../../ubuntu/ip-redirect-all 80 8090 +sudo ../../ubuntu/ip-redirect-all 443 8091 +sudo ../../ubuntu/ip-redirect-all 444 8092 + +# Redirect traffic from ports 80, 443 and 444 to proxy2 +#sudo ../../ubuntu/ip-redirect-all 80 8093 +#sudo ../../ubuntu/ip-redirect-all 443 8094 +#sudo ../../ubuntu/ip-redirect-all 444 8095 + +# Redirect traffic from ports 119 and 563 to tunnel +sudo ../../ubuntu/ip-redirect-all 119 8119 +sudo ../../ubuntu/ip-redirect-all 563 8563 + +# Generate SSL certificates +../../modules/http/ssl-ca-conf tmp/ssl example.com +../../modules/http/ssl-cert-conf tmp/ssl localhost server +../../modules/http/ssl-cert-conf tmp/ssl *.example.com vhost +../../modules/http/ssl-cert-conf tmp/ssl example.com proxy +../../modules/http/ssl-cert-conf tmp/ssl localhost tunnel + +# Start an SSL tunnel +./tunnel-ssl-conf tmp/tunnel 8119/119 8563/563 +../../modules/http/httpd-start tmp/tunnel +sleep 1 + +# Start scribe logging +../../modules/http/tunnel-ssl-conf tmp/tunnel 1465 localhost 563 1463 +../../modules/http/httpd-restart tmp/tunnel +../../components/log/scribed-central-conf tmp/monitor +../../components/log/scribed-client-conf tmp/monitor localhost 1465 +../../components/log/scribed-central-start tmp/monitor +../../components/log/scribed-client-start tmp/monitor +sleep 1 + +# Start three memcached servers +../../modules/http/tunnel-ssl-conf tmp/tunnel 11211 localhost 563 11411 +../../components/cache/memcached-start tmp 127.0.0.1:11411 +../../modules/http/tunnel-ssl-conf tmp/tunnel 11212 localhost 563 11412 +../../components/cache/memcached-start tmp 127.0.0.1:11412 +../../modules/http/tunnel-ssl-conf tmp/tunnel 11213 localhost 563 11413 +../../components/cache/memcached-start tmp 127.0.0.1:11413 +../../modules/http/httpd-restart tmp/tunnel +sleep 1 + +# Start a master and two hot standby databases +../../modules/http/tunnel-ssl-conf tmp/tunnel 5432 localhost 563 5532 +../../modules/http/tunnel-ssl-conf tmp/tunnel 8502 localhost 563 8602 +../../modules/http/httpd-restart tmp/tunnel +./sqldb-master-conf tmp/sqldb1 127.0.0.1:5532 127.0.0.1:8602 +../../components/sqldb/pgsql-start tmp/sqldb1 +../../modules/http/httpd-start tmp/sqldb1 +sleep 1 + +../../modules/http/tunnel-ssl-conf tmp/tunnel 5433 localhost 563 5533 +../../modules/http/tunnel-ssl-conf tmp/tunnel 8503 localhost 563 8603 +../../modules/http/httpd-restart tmp/tunnel +./sqldb-standby-conf tmp/sqldb2 127.0.0.1:5533 127.0.0.1:8603 localhost 5432 8502 +../../components/sqldb/pgsql-start tmp/sqldb2 +../../modules/http/httpd-start tmp/sqldb2 + +../../modules/http/tunnel-ssl-conf tmp/tunnel 5434 localhost 563 5534 +../../modules/http/tunnel-ssl-conf tmp/tunnel 8504 localhost 563 8604 +../../modules/http/httpd-restart tmp/tunnel +./sqldb-standby-conf tmp/sqldb3 127.0.0.1:5534 127.0.0.1:8604 localhost 5432 8502 +../../components/sqldb/pgsql-start tmp/sqldb3 +../../modules/http/httpd-start tmp/sqldb3 + +# Start three app servers +./server-ssl-conf tmp/server1 8101/80 8441/443 +../../modules/http/httpd-start tmp/server1 +sleep 1 + +./server-ssl-conf tmp/server2 8102/80 8442/443 +../../modules/http/httpd-start tmp/server2 +sleep 1 + +./server-ssl-conf tmp/server3 8103/80 8443/443 +../../modules/http/httpd-start tmp/server3 +sleep 1 + +# Start two proxy balancers +./proxy-ssl-conf tmp/proxy1 8090/80 8091/443 +../../modules/http/proxy-member-conf tmp/proxy1 localhost 8101 +../../modules/http/proxy-ssl-member-conf tmp/proxy1 localhost 8441 +../../modules/http/proxy-member-conf tmp/proxy1 localhost 8102 +../../modules/http/proxy-ssl-member-conf tmp/proxy1 localhost 8442 +../../modules/http/proxy-member-conf tmp/proxy1 localhost 8103 +../../modules/http/proxy-ssl-member-conf tmp/proxy1 localhost 8443 +../../modules/http/httpd-start tmp/proxy1 + +./proxy-ssl-conf tmp/proxy2 8093/80 8094/443 +../../modules/http/proxy-member-conf tmp/proxy2 localhost 8101 +../../modules/http/proxy-ssl-member-conf tmp/proxy2 localhost 8441 +../../modules/http/proxy-member-conf tmp/proxy2 localhost 8102 +../../modules/http/proxy-ssl-member-conf tmp/proxy2 localhost 8442 +../../modules/http/proxy-member-conf tmp/proxy2 localhost 8103 +../../modules/http/proxy-ssl-member-conf tmp/proxy2 localhost 8443 +../../modules/http/httpd-start tmp/proxy2 + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/ssl-stop b/sca-cpp/branches/lightweight-sca/samples/store-cluster/ssl-stop new file mode 100755 index 0000000000..37addf8094 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/ssl-stop @@ -0,0 +1,44 @@ +#!/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. + +set -x + +../../modules/http/httpd-stop tmp/server1 +../../modules/http/httpd-stop tmp/server2 +../../modules/http/httpd-stop tmp/server3 + +../../modules/http/httpd-stop tmp/proxy1 +../../modules/http/httpd-stop tmp/proxy2 + +../../components/cache/memcached-stop tmp 127.0.0.1:11411 +../../components/cache/memcached-stop tmp 127.0.0.1:11412 +../../components/cache/memcached-stop tmp 127.0.0.1:11413 + +../../components/sqldb/pgsql-stop tmp/sqldb3 +../../modules/http/httpd-stop tmp/sqldb3 +../../components/sqldb/pgsql-stop tmp/sqldb2 +../../modules/http/httpd-stop tmp/sqldb2 +../../components/sqldb/pgsql-stop tmp/sqldb1 +../../modules/http/httpd-stop tmp/sqldb1 + +../../modules/http/httpd-stop tmp/tunnel + +../../components/log/scribed-client-stop tmp/monitor +../../components/log/scribed-central-stop tmp/monitor +../../components/log/scribe-tail-stop tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/start b/sca-cpp/branches/lightweight-sca/samples/store-cluster/start new file mode 100755 index 0000000000..dcc7e1e7a7 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/start @@ -0,0 +1,80 @@ +#!/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. + +set -x + +# Redirect traffic from port 80 to proxy1 +sudo ../../ubuntu/ip-redirect-all 80 8090 + +# Redirect traffic from port 80 to proxy2 +#sudo ../../ubuntu/ip-redirect-all 80 8091 + +# Start scribe logging +rm -rf tmp +../../components/log/scribed-central-conf tmp/monitor +../../components/log/scribed-client-conf tmp/monitor localhost +../../components/log/scribed-central-start tmp/monitor +../../components/log/scribed-client-start tmp/monitor +sleep 1 + +# Start three memcached servers +../../components/cache/memcached-start tmp 11211 +../../components/cache/memcached-start tmp 11212 +../../components/cache/memcached-start tmp 11213 + +# Start a master and two hot standby databases +./sqldb-master-conf tmp/sqldb1 5432 8502 +../../components/sqldb/pgsql-start tmp/sqldb1 +../../modules/http/httpd-start tmp/sqldb1 +sleep 1 + +./sqldb-standby-conf tmp/sqldb2 5433 8503 localhost 5432 8502 +../../components/sqldb/pgsql-start tmp/sqldb2 +../../modules/http/httpd-start tmp/sqldb2 + +./sqldb-standby-conf tmp/sqldb3 5434 8504 localhost 5432 8502 +../../components/sqldb/pgsql-start tmp/sqldb3 +../../modules/http/httpd-start tmp/sqldb3 + +# Start three app servers +./server-conf tmp/server1 8101 +../../modules/http/httpd-start tmp/server1 +sleep 1 + +./server-conf tmp/server2 8102 +../../modules/http/httpd-start tmp/server2 +sleep 1 + +./server-conf tmp/server3 8103 +../../modules/http/httpd-start tmp/server3 +sleep 1 + +# Start two proxy balancers +./proxy-conf tmp/proxy1 8090 +../../modules/http/proxy-member-conf tmp/proxy1 localhost 8101 +../../modules/http/proxy-member-conf tmp/proxy1 localhost 8102 +../../modules/http/proxy-member-conf tmp/proxy1 localhost 8103 +../../modules/http/httpd-start tmp/proxy1 + +./proxy-conf tmp/proxy2 8091 +../../modules/http/proxy-member-conf tmp/proxy2 localhost 8101 +../../modules/http/proxy-member-conf tmp/proxy2 localhost 8102 +../../modules/http/proxy-member-conf tmp/proxy2 localhost 8103 +../../modules/http/httpd-start tmp/proxy2 + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/stop b/sca-cpp/branches/lightweight-sca/samples/store-cluster/stop new file mode 100755 index 0000000000..fb6c6489fc --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/stop @@ -0,0 +1,42 @@ +#!/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. + +set -x + +../../modules/http/httpd-stop tmp/server1 +../../modules/http/httpd-stop tmp/server2 +../../modules/http/httpd-stop tmp/server3 + +../../modules/http/httpd-stop tmp/proxy1 +../../modules/http/httpd-stop tmp/proxy2 + +../../components/cache/memcached-stop tmp 11211 +../../components/cache/memcached-stop tmp 11212 +../../components/cache/memcached-stop tmp 11213 + +../../components/sqldb/pgsql-stop tmp/sqldb3 +../../modules/http/httpd-stop tmp/sqldb3 +../../components/sqldb/pgsql-stop tmp/sqldb2 +../../modules/http/httpd-stop tmp/sqldb2 +../../components/sqldb/pgsql-stop tmp/sqldb1 +../../modules/http/httpd-stop tmp/sqldb1 + +../../components/log/scribed-client-stop tmp/monitor +../../components/log/scribed-central-stop tmp/monitor +../../components/log/scribe-tail-stop tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cluster/tunnel-ssl-conf b/sca-cpp/branches/lightweight-sca/samples/store-cluster/tunnel-ssl-conf new file mode 100755 index 0000000000..f798fdab0b --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cluster/tunnel-ssl-conf @@ -0,0 +1,33 @@ +#!/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. + +root=$1 +port=$2 +sslport=$3 + +set -x + +# Configure an SSL-enabled tunnel server +../../modules/http/httpd-conf $root sca-store.com $port $root/htdocs +../../modules/http/httpd-event-conf $root +tar -C tmp/ssl -c `../../modules/http/ssl-cert-find tmp/ssl` | tar -C $root -x +../../modules/http/httpd-ssl-conf $root $sslport +../../modules/http/httpd-tunnel-ssl-conf $root +../../modules/http/cert-auth-conf $root + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/Makefile.am b/sca-cpp/branches/lightweight-sca/samples/store-constdb/Makefile.am new file mode 100644 index 0000000000..d2783f3f3b --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/Makefile.am @@ -0,0 +1,25 @@ +# 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. + +dist_sample_SCRIPTS = start stop ssl-start +sampledir = $(prefix)/samples/store-constdb + +nobase_dist_sample_DATA = currency-converter.scm fruits-catalog.scm shopping-cart.scm store.scm store.composite htdocs/*.html + +dist_noinst_SCRIPTS = server-test +TESTS = server-test + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/currency-converter.scm b/sca-cpp/branches/lightweight-sca/samples/store-constdb/currency-converter.scm new file mode 100644 index 0000000000..fc506c3d73 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/currency-converter.scm @@ -0,0 +1,27 @@ +; 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 + +(define (convert from to amount) + (if (equal? to "EUR") (* amount 0.70) amount) +) + +(define (symbol currency) + (if (equal? currency "EUR") "E" "$") +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/fruits-catalog.scm b/sca-cpp/branches/lightweight-sca/samples/store-constdb/fruits-catalog.scm new file mode 100644 index 0000000000..d55394b96a --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/fruits-catalog.scm @@ -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 + +(define (items converter currencyCode) + (define code (currencyCode)) + (define (convert price) (converter "convert" "USD" code price)) + (define symbol (converter "symbol" code)) + (list + (list (list 'name "Apple") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 2.99))) + (list (list 'name "Orange") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 3.55))) + (list (list 'name "Pear") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 1.55))) + ) +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-constdb/htdocs/index.html new file mode 100644 index 0000000000..0698a32cc5 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/htdocs/index.html @@ -0,0 +1,156 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Store</title> + +<script type="text/javascript" src="/all-min.js"></script> + +<script type="text/javascript"> +var store = sca.component("Store"); +var catalog = sca.defun(sca.reference(store, "catalog"), "items"); +var shoppingCart = sca.reference(store, "shoppingCart"); +var shoppingTotal = sca.defun(sca.reference(store, "shoppingTotal"), "total"); + +var catalogItems; + +function catalog_itemsResponse(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(doc) { + if (doc != null) { + var feed = parseXML([doc]); + 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.total(shoppingTotal_totalResponse); + } +} + +function shoppingTotal_totalResponse(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 = '<?xml version="1.0" encoding="UTF-8"?>\n' + + '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><content type="application/xml">' + + '<item>' + + '<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.items(catalog_itemsResponse); + shoppingCart.get("", shoppingCart_getResponse); + } catch(e){ + alert(e); + } +} +</script> +</head> + +<body onload="init()"> +<h1>Store</h1> +<br/> +<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> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/server-test b/sca-cpp/branches/lightweight-sca/samples/store-constdb/server-test new file mode 100755 index 0000000000..fb629a6814 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/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=`echo "import os; print os.path.realpath('$0')" | python`; 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 ../store-cpp/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 +exit $rc diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/shopping-cart.scm b/sca-cpp/branches/lightweight-sca/samples/store-constdb/shopping-cart.scm new file mode 100644 index 0000000000..e653f1e33c --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/shopping-cart.scm @@ -0,0 +1,82 @@ +; 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 + +(define cartId "1234") + +; Get the shopping cart from the cache +; Return an empty cart if not found +(define (getcart id cache) + (define cart (cache "get" (list id))) + (if (nul cart) + (list) + cart) +) + +; Post a new item to the cart, create a new cart if necessary +(define (post collection item cache) + (define id (uuid)) + (define newItem (list 'entry (cadr (car item)) (list 'id id) (cadddr (car item)))) + (define cart (cons newItem (getcart cartId cache))) + (cache "put" (list cartId) cart) + (list id) +) + +; Find an item in the cart +(define (find id cart) + (if (nul cart) + (list (list 'entry (list 'title "Item") (list 'id "0"))) + (if (= id (cadr (caddr (car cart)))) + (list (car cart)) + (find id (cdr cart)))) +) + +; Get items from the cart +(define (get id cache) + (if (nul id) + (list (append (list 'feed (list 'title "Your Cart") (list 'id cartId)) (getcart cartId cache))) + (find (car id) (getcart cartId cache)) + ) +) + +; Delete items from the cart +(define (delete id cache) + (if (nul id) + (cache "delete" (list cartId)) + true + ) +) + +; Return the price of an item +(define (price item) + (cadr (assoc 'price (cadr (cadddr item)))) +) + +; Sum the prices of a list of items +(define (sum items) + (if (nul items) + 0 + (+ (price (car items)) (sum (cdr items)))) +) + +; Return the total price of the items in the cart +(define (total cache) + (define cart (getcart cartId cache)) + (sum cart) +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/ssl-start b/sca-cpp/branches/lightweight-sca/samples/store-constdb/ssl-start new file mode 100755 index 0000000000..047ec974cb --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/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/basic-auth-conf tmp +../../modules/http/passwd-auth-conf tmp foo foo +../../modules/server/server-conf tmp +../../modules/server/scheme-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +../../components/constdb/tinycdb -c -m tmp/store.cdb </dev/null +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/start b/sca-cpp/branches/lightweight-sca/samples/store-constdb/start new file mode 100755 index 0000000000..58b15c0ec3 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/start @@ -0,0 +1,33 @@ +#!/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. + +rm -rf tmp +../../modules/http/httpd-conf tmp localhost 8090 htdocs +../../modules/http/httpd-event-conf tmp +../../modules/server/server-conf tmp +../../modules/server/scheme-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +../../components/constdb/tinycdb -c -m tmp/store.cdb </dev/null +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/stop b/sca-cpp/branches/lightweight-sca/samples/store-constdb/stop new file mode 100755 index 0000000000..3b4f46694d --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/stop @@ -0,0 +1,20 @@ +#!/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/httpd-stop tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/store.composite b/sca-cpp/branches/lightweight-sca/samples/store-constdb/store.composite new file mode 100644 index 0000000000..168be26ab6 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/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" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <implementation.scheme script="store.scm"/> + <service name="Widget"> + <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"> + <implementation.scheme script="fruits-catalog.scm"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <binding.jsonrpc uri="catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.scheme script="shopping-cart.scm"/> + <service name="Cart"> + <binding.atom uri="shoppingCart"/> + </service> + <service name="Total"> + <binding.jsonrpc uri="total"/> + </service> + <reference name="cache" target="ConstDb"/> + </component> + + <component name="CurrencyConverter"> + <implementation.scheme script="currency-converter.scm"/> + <service name="CurrencyConverter"> + <binding.jsonrpc uri="currencyConverter"/> + </service> + </component> + + <component name="ConstDb"> + <implementation.cpp path="../../components/constdb" library="libconstdb"/> + <property name="dbname">tmp/store.cdb</property> + <service name="ConstDb"> + <binding.atom uri="constdb"/> + </service> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/store.scm b/sca-cpp/branches/lightweight-sca/samples/store-constdb/store.scm new file mode 100644 index 0000000000..f54257343e --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/store.scm @@ -0,0 +1,47 @@ +; 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 + +(define (post item catalog shoppingCart shoppingTotal) + (shoppingCart "post" item) +) + +(define (getall catalog shoppingCart shoppingTotal) + (shoppingCart "getall") +) + +(define (get id catalog shoppingCart shoppingTotal) + (shoppingCart "get" id) +) + +(define (items catalog shoppingCart shoppingTotal) + (catalog "items") +) + +(define (total catalog shoppingCart shoppingTotal) + (shoppingCart "total") +) + +(define (deleteall catalog shoppingCart shoppingTotal) + (shoppingCart "deleteall") +) + +(define (delete id catalog shoppingCart shoppingTotal) + (shoppingCart "delete" id) +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cpp/Makefile.am b/sca-cpp/branches/lightweight-sca/samples/store-cpp/Makefile.am new file mode 100644 index 0000000000..3f9d8e87eb --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cpp/Makefile.am @@ -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. + + +dist_sample_SCRIPTS = start stop ssl-start +sampledir = $(prefix)/samples/store-cpp + +nobase_dist_sample_DATA = currency-converter.cpp fruits-catalog.cpp shopping-cart.cpp store.composite htdocs/*.html + +sample_LTLIBRARIES = libcurrency-converter.la libfruits-catalog.la libshopping-cart.la +noinst_DATA = libcurrency-converter${libsuffix} libfruits-catalog${libsuffix} libshopping-cart${libsuffix} + +libcurrency_converter_la_SOURCES = currency-converter.cpp +libcurrency-converter${libsuffix}: + ln -s .libs/libcurrency-converter${libsuffix} + +libfruits_catalog_la_SOURCES = fruits-catalog.cpp +libfruits-catalog${libsuffix}: + ln -s .libs/libfruits-catalog${libsuffix} + +libshopping_cart_la_SOURCES = shopping-cart.cpp +libshopping-cart${libsuffix}: + ln -s .libs/libshopping-cart${libsuffix} + +dist_noinst_SCRIPTS = server-test +TESTS = server-test diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cpp/currency-converter.cpp b/sca-cpp/branches/lightweight-sca/samples/store-cpp/currency-converter.cpp new file mode 100644 index 0000000000..5f0702490a --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cpp/currency-converter.cpp @@ -0,0 +1,67 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +/** + * Currency converter component implementation. + */ + +#include "string.hpp" +#include "function.hpp" +#include "list.hpp" +#include "value.hpp" +#include "monad.hpp" + +namespace tuscany { +namespace store { + +/** + * Convert an amount from USD to a currency. + */ +const failable<value> convert(unused const value& from, const value& to, const value& amount) { + if (to == string("EUR")) + return value(0.70 * (double)amount); + return amount; +} + +/** + * Return a currency symbol. + */ +const failable<value> symbol(const value& currency) { + if (currency == string("EUR")) + return value(string("E")); + return value(string("$")); +} + +} +} + +extern "C" { + +const tuscany::value apply(const tuscany::list<tuscany::value>& params) { + const tuscany::value func(car(params)); + if (func == "convert") + return tuscany::store::convert(cadr(params), caddr(params), cadddr(params)); + if (func == "symbol") + return tuscany::store::symbol(cadr(params)); + return tuscany::mkfailure<tuscany::value>(); +} + +} diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cpp/fruits-catalog.cpp b/sca-cpp/branches/lightweight-sca/samples/store-cpp/fruits-catalog.cpp new file mode 100644 index 0000000000..9907650316 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cpp/fruits-catalog.cpp @@ -0,0 +1,76 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +/** + * Catalog component implementation. + */ + +#include "string.hpp" +#include "function.hpp" +#include "list.hpp" +#include "value.hpp" +#include "monad.hpp" + +namespace tuscany { +namespace store { + +/** + * Returns the catalog. + */ +struct convert { + const lambda<value(const list<value>&)> converter; + const string currency; + convert(const lambda<value(const list<value>&)>& converter, const string& currency) : converter(converter), currency(currency) { + } + const value operator()(const value& price) const { + return converter(mklist<value>("convert", string("USD"), currency, price)); + } +}; + +const list<value> mkfruit(const string& name, const string& code, const string& symbol, const double price) { + return list<value>() + + mklist<value>("name", name) + mklist<value>("currencyCode", code) + mklist<value>("currencySymbol", symbol) + mklist<value>("price", price); +} + +const failable<value> items(const lambda<value(const list<value>&)>& converter, const lambda<value(const list<value>&)>& currencyCode) { + const string currency(currencyCode(list<value>())); + const string symbol(converter(mklist<value>("symbol", currency))); + const lambda<value(const value&)> conv(convert(converter, currency)); + + return value(list<value>() + + mkfruit("Apple", currency, symbol, conv(2.99)) + + mkfruit("Orange", currency, symbol, conv(3.55)) + + mkfruit("Pear", currency, symbol, conv(1.55))); +} + +} +} + +extern "C" { + +const tuscany::value apply(const tuscany::list<tuscany::value>& params) { + const tuscany::value func(car(params)); + if (func == "items") + return tuscany::store::items(cadr(params), caddr(params)); + return tuscany::mkfailure<tuscany::value>(); +} + +} diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cpp/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-cpp/htdocs/index.html new file mode 100644 index 0000000000..0698a32cc5 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cpp/htdocs/index.html @@ -0,0 +1,156 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Store</title> + +<script type="text/javascript" src="/all-min.js"></script> + +<script type="text/javascript"> +var store = sca.component("Store"); +var catalog = sca.defun(sca.reference(store, "catalog"), "items"); +var shoppingCart = sca.reference(store, "shoppingCart"); +var shoppingTotal = sca.defun(sca.reference(store, "shoppingTotal"), "total"); + +var catalogItems; + +function catalog_itemsResponse(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(doc) { + if (doc != null) { + var feed = parseXML([doc]); + 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.total(shoppingTotal_totalResponse); + } +} + +function shoppingTotal_totalResponse(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 = '<?xml version="1.0" encoding="UTF-8"?>\n' + + '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><content type="application/xml">' + + '<item>' + + '<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.items(catalog_itemsResponse); + shoppingCart.get("", shoppingCart_getResponse); + } catch(e){ + alert(e); + } +} +</script> +</head> + +<body onload="init()"> +<h1>Store</h1> +<br/> +<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> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cpp/htdocs/test/items-request.txt b/sca-cpp/branches/lightweight-sca/samples/store-cpp/htdocs/test/items-request.txt new file mode 100644 index 0000000000..09a7f8377b --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cpp/htdocs/test/items-request.txt @@ -0,0 +1,6 @@ +{ + "id": 1, + "method": "items", + "params": [ + ] +} diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cpp/htdocs/test/items-result.txt b/sca-cpp/branches/lightweight-sca/samples/store-cpp/htdocs/test/items-result.txt new file mode 100644 index 0000000000..0b456ea9d0 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cpp/htdocs/test/items-result.txt @@ -0,0 +1,23 @@ +{ + "id": 1, + "result": [ + { + "name": "Apple", + "currencyCode": "USD", + "currencySymbol": "$", + "price": 2.99 + }, + { + "name": "Orange", + "currencyCode": "USD", + "currencySymbol": "$", + "price": 3.55 + }, + { + "name": "Pear", + "currencyCode": "USD", + "currencySymbol": "$", + "price": 1.55 + } + ] +}
\ No newline at end of file diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cpp/htdocs/test/shopping-cart-entry.xml b/sca-cpp/branches/lightweight-sca/samples/store-cpp/htdocs/test/shopping-cart-entry.xml new file mode 100644 index 0000000000..0d6e5b520a --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cpp/htdocs/test/shopping-cart-entry.xml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><content type="application/xml"><item><name>Orange</name><currencyCode>USD</currencyCode><currencySymbol>$</currencySymbol><price>3.55</price></item></content></entry> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cpp/server-test b/sca-cpp/branches/lightweight-sca/samples/store-cpp/server-test new file mode 100755 index 0000000000..e621803f8d --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cpp/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=`echo "import os; print os.path.realpath('$0')" | python`; 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 @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 @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 +exit $rc diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cpp/shopping-cart.cpp b/sca-cpp/branches/lightweight-sca/samples/store-cpp/shopping-cart.cpp new file mode 100644 index 0000000000..2771d7cd9c --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cpp/shopping-cart.cpp @@ -0,0 +1,135 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +/** + * Shopping cart component implementation. + */ + +#include "string.hpp" +#include "function.hpp" +#include "list.hpp" +#include "value.hpp" +#include "monad.hpp" + +namespace tuscany { +namespace store { + +const string cartId("1234"); + +/** + * Get the shopping cart from the cache. Return an empty + * cart if not found. + */ +const list<value> getcart(const value& id, const lambda<value(const list<value>&)>& cache) { + const value cart = cache(mklist<value>("get", mklist<value>(id))); + cerr << "cart value: " << cart << "\n"; + const failable<value> fcart = cart; + cerr << "cart fvalue: " << fcart << "\n"; + cerr << "cart content: " << content(fcart) << "\n"; + cerr << "cart reason: " << reason(fcart) << "\n"; + if (isNil(cart)) + return value(list<value>()); + return (list<value>)cart; +} + +/** + * Post a new item to the cart. Create a new cart if necessary. + */ +const failable<value> post(unused const list<value>& collection, const value& item, const lambda<value(const list<value>&)>& cache) { + const value id(mkuuid()); + const list<value> newItem(mklist<value>("entry", cadr<value>(car<value>(item)), mklist<value>("id", id), cadddr<value>(car<value>(item)))); + const list<value> cart(cons<value>(newItem, getcart(cartId, cache))); + cache(mklist<value>("put", mklist<value>(cartId), cart)); + return value(mklist<value>(id)); +} + +/** + * Find an item in the cart. + */ +const value find(const value& id, const list<value>& cart) { + if (isNil(cart)) + return mklist<value>(mklist<value>("entry", mklist<value>("title", string("Item")), mklist<value>("id", "0"))); + if (id == cadr<value>(caddr<value>(car(cart)))) + return mklist<value>(car(cart)); + return find(id, cdr(cart)); +} + +/** + * Return items from the cart. + */ +const failable<value> get(const list<value>& id, const lambda<value(const list<value>&)>& cache) { + if (isNil(id)) + return value(mklist<value>(append(mklist<value>("feed", mklist<value>("title", string("Your Cart")), mklist<value>("id", cartId)), getcart(cartId, cache)))); + return find(car(id), getcart(cartId, cache)); +} + +/** + * Delete items from the cart. + */ +const failable<value> del(const list<value>& id, unused const lambda<value(const list<value>&)>& cache) { + if (isNil(id)) + return cache(mklist<value>("delete", mklist<value>(cartId))); + return value(true); +} + +/** + * Return the price of an item. + */ +const double price(const list<value>& item) { + return cadr<value>(assoc<value>("price", cdr<value>(cadr<value>(cadddr(item))))); +} + +/** + * Sum the prices of a list of items. + */ +const double sum(const list<value>& items) { + if (isNil(items)) + return 0; + return price(car(items)) + sum(cdr(items)); +} + +/** + * Return the total price of the items in the cart. + */ +const failable<value> total(const lambda<value(const list<value>&)>& cache) { + const list<value> cart(getcart(cartId, cache)); + return value(sum(cart)); +} + +} +} + +extern "C" { + +const tuscany::value apply(const tuscany::list<tuscany::value>& params) { + const tuscany::value func(car(params)); + if (func == "post") + return tuscany::store::post(cadr(params), caddr(params), cadddr(params)); + if (func == "get") + return tuscany::store::get(cadr(params), caddr(params)); + if (func == "delete") + return tuscany::store::del(cadr(params), caddr(params)); + if (func == "total") + return tuscany::store::total(cadr(params)); + return tuscany::mkfailure<tuscany::value>(); +} + +} diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cpp/ssl-start b/sca-cpp/branches/lightweight-sca/samples/store-cpp/ssl-start new file mode 100755 index 0000000000..3a96fe950c --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cpp/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/basic-auth-conf tmp +../../modules/http/passwd-auth-conf tmp foo foo +../../modules/server/server-conf tmp +../../modules/server/cpp-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +../../components/cache/memcached-start tmp +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cpp/start b/sca-cpp/branches/lightweight-sca/samples/store-cpp/start new file mode 100755 index 0000000000..4ad506f7b5 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cpp/start @@ -0,0 +1,33 @@ +#!/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. + +rm -rf tmp +../../modules/http/httpd-conf tmp localhost 8090 htdocs +../../modules/http/httpd-event-conf tmp +../../modules/server/server-conf tmp +../../modules/server/cpp-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +../../components/cache/memcached-start tmp +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cpp/stop b/sca-cpp/branches/lightweight-sca/samples/store-cpp/stop new file mode 100755 index 0000000000..3b4c74a587 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cpp/stop @@ -0,0 +1,21 @@ +#!/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/httpd-stop tmp +../../components/cache/memcached-stop tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-cpp/store.composite b/sca-cpp/branches/lightweight-sca/samples/store-cpp/store.composite new file mode 100644 index 0000000000..483fbfacc1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-cpp/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" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <implementation.widget location="store.html"/> + <service name="Widget"> + <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"> + <implementation.cpp path="." library="libfruits-catalog"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <binding.jsonrpc uri="catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.cpp path="." library="libshopping-cart"/> + <service name="ShoppingCart"> + <binding.atom uri="shoppingCart"/> + </service> + <service name="Total"> + <binding.jsonrpc uri="total"/> + </service> + <reference name="cache" target="Cache"/> + </component> + + <component name="CurrencyConverter"> + <implementation.cpp path="." library="libcurrency-converter"/> + <service name="CurrencyConverter"> + <binding.jsonrpc uri="currencyConverter"/> + </service> + </component> + + <component name="Cache"> + <implementation.cpp path="../../components/cache" library="libmemcache"/> + <service name="Cache"> + <binding.atom uri="cache"/> + </service> + <property name="server">localhost:11211</property> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/Makefile.am b/sca-cpp/branches/lightweight-sca/samples/store-gae/Makefile.am new file mode 100644 index 0000000000..09d5b516cf --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/Makefile.am @@ -0,0 +1,44 @@ +# 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 +if WANT_GAE + +dist_sample_SCRIPTS = start stop +sampledir = $(prefix)/samples/store-gae + +BUILT_SOURCES = target.stamp +target.stamp: app.yaml *.py *.composite $(top_builddir)/modules/wsgi/*.py htdocs/* $(top_builddir)/modules/js/htdocs/* + mkdir -p target + cp app.yaml *.py *.composite `ls $(top_builddir)/modules/wsgi/*.py | grep -v "\-test"` target + mkdir -p target/htdocs + cp -R htdocs/* target/htdocs + cp -R $(top_builddir)/modules/js/htdocs/* target/htdocs + touch target.stamp + +clean-local: + rm -rf target.stamp target + +nobase_sample_DATA = target/app.yaml target/*.py target/*.composite target/htdocs/*.html target/htdocs/*.js + +EXTRA_DIST = app.yaml *.composite *.py htdocs/*.html + +dist_noinst_SCRIPTS = server-test +TESTS = server-test + +endif +endif diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/app.yaml b/sca-cpp/branches/lightweight-sca/samples/store-gae/app.yaml new file mode 100644 index 0000000000..6a4e6a2fab --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/app.yaml @@ -0,0 +1,54 @@ +# 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.
+
+application: sca-store
+version: 1
+runtime: python
+api_version: 1
+skip_files:
+- ^(.*/)?app\.yaml
+- ^(.*/)?app\.yml
+- ^(.*/)?index\.yaml
+- ^(.*/)?index\.yml
+- ^(.*/)?#.*#
+- ^(.*/)?.*~
+- ^(.*/)?.*\.py[co]
+- ^(.*/)?.*/RCS/.*
+- ^(.*/)?\..*
+- ^(.*/)?.*-test$
+- ^(.*/)?.*\.cpp$
+- ^(.*/)?.*\.o$
+- ^(.*/)?core$
+- ^(.*/)?.*\.out$
+- ^(.*/)?.*\.log$
+- ^(.*/)?Makefile.*
+- ^(.*/)?tmp/.*
+- ^(.*/)?wsgi-start
+- ^(.*/)?wsgi-stop
+
+handlers:
+- url: /(.*\.(html|png))
+ static_files: htdocs/\1
+ upload: htdocs/(.*\.(html|png))
+ secure: always
+ login: required
+
+- url: /.*
+ script: composite.py
+ secure: always
+ login: required
+
diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/currency-converter.py b/sca-cpp/branches/lightweight-sca/samples/store-gae/currency-converter.py new file mode 100644 index 0000000000..2fded8f616 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/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/branches/lightweight-sca/samples/store-gae/domain-backend.composite b/sca-cpp/branches/lightweight-sca/samples/store-gae/domain-backend.composite new file mode 100644 index 0000000000..13fa8406e2 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/domain-backend.composite @@ -0,0 +1,31 @@ +<?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" + targetNamespace="http://store" + name="store-backend"> + + <component name="Cache"> + <implementation.python script="gmemcache.py"/> + <service name="Cache"> + <binding.atom uri="cache"/> + </service> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/domain-frontend.composite b/sca-cpp/branches/lightweight-sca/samples/store-gae/domain-frontend.composite new file mode 100644 index 0000000000..181e86c100 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/domain-frontend.composite @@ -0,0 +1,65 @@ +<?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" + targetNamespace="http://store" + name="store-frontend"> + + <component name="Store"> + <implementation.python script="store.py"/> + <service name="Widget"> + <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"> + <implementation.python script="fruits-catalog.py"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <binding.jsonrpc uri="catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.python script="shopping-cart.py"/> + <service name="Cart"> + <binding.atom uri="shoppingCart"/> + </service> + <service name="Total"> + <binding.jsonrpc uri="total"/> + </service> + <reference name="cache"> + <binding.http uri="https://sca-store-backend.appspot.com/cache"/> + </reference> + <property name="host">localhost</property> + <property name="email">anonymous@example.com</property> + </component> + + <component name="CurrencyConverter"> + <implementation.python script="currency-converter.py"/> + <service name="CurrencyConverter"> + <binding.jsonrpc uri="currencyConverter"/> + </service> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/domain-single.composite b/sca-cpp/branches/lightweight-sca/samples/store-gae/domain-single.composite new file mode 100644 index 0000000000..79c5aca8e1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/domain-single.composite @@ -0,0 +1,70 @@ +<?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" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <implementation.python script="store.py"/> + <service name="Widget"> + <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"> + <implementation.python script="fruits-catalog.py"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <binding.jsonrpc uri="catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.python script="shopping-cart.py"/> + <service name="Cart"> + <binding.atom uri="shoppingCart"/> + </service> + <service name="Total"> + <binding.jsonrpc uri="total"/> + </service> + <reference name="cache" target="Cache"/> + <property name="host">localhost</property> + <property name="email">anonymous@example.com</property> + </component> + + <component name="CurrencyConverter"> + <implementation.python script="currency-converter.py"/> + <service name="CurrencyConverter"> + <binding.jsonrpc uri="currencyConverter"/> + </service> + </component> + + <component name="Cache"> + <implementation.python script="gmemcache.py"/> + <service name="Cache"> + <binding.atom uri="cache"/> + </service> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/domain.composite b/sca-cpp/branches/lightweight-sca/samples/store-gae/domain.composite new file mode 100644 index 0000000000..79c5aca8e1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/domain.composite @@ -0,0 +1,70 @@ +<?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" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <implementation.python script="store.py"/> + <service name="Widget"> + <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"> + <implementation.python script="fruits-catalog.py"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <binding.jsonrpc uri="catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.python script="shopping-cart.py"/> + <service name="Cart"> + <binding.atom uri="shoppingCart"/> + </service> + <service name="Total"> + <binding.jsonrpc uri="total"/> + </service> + <reference name="cache" target="Cache"/> + <property name="host">localhost</property> + <property name="email">anonymous@example.com</property> + </component> + + <component name="CurrencyConverter"> + <implementation.python script="currency-converter.py"/> + <service name="CurrencyConverter"> + <binding.jsonrpc uri="currencyConverter"/> + </service> + </component> + + <component name="Cache"> + <implementation.python script="gmemcache.py"/> + <service name="Cache"> + <binding.atom uri="cache"/> + </service> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/fruits-catalog.py b/sca-cpp/branches/lightweight-sca/samples/store-gae/fruits-catalog.py new file mode 100644 index 0000000000..4b2baca2ff --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/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", "Platano"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))), + (("'name", "Banana"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))), + (("'name", "Guanabana"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(1.55))) + ) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/gmemcache.py b/sca-cpp/branches/lightweight-sca/samples/store-gae/gmemcache.py new file mode 100644 index 0000000000..61f1dc3486 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/gmemcache.py @@ -0,0 +1,45 @@ +# 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. + +# Google AppEngine Memcached based cache implementation +import uuid +from google.appengine.api import memcache + +# Post a new item to the cache +def post(collection, item): + id = collection + (str(uuid.uuid1()),) + r = memcache.add(repr(id), item, 600) + if r == False: + return None + return id + +# Get items from the cache +def get(id): + item = memcache.get(repr(id)) + return item + +# Update an item in the cache +def put(id, item): + return memcache.set(repr(id), item, 600) + +# Delete items from the cache +def delete(id): + r = memcache.delete(repr(id)) + if r != 2: + return False + return True + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-gae/htdocs/index.html new file mode 100644 index 0000000000..7c9a9e9d6b --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/htdocs/index.html @@ -0,0 +1,175 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Store</title> + +<script type="text/javascript" src="/all-min.js"></script> + +<script type="text/javascript"> +var store = sca.component("Store"); +var catalog = sca.defun(sca.reference(store, "catalog"), "items"); +var shoppingCart = sca.defun(sca.reference(store, "shoppingCart"), "email", "host"); +var shoppingTotal = sca.defun(sca.reference(store, "shoppingTotal"), "total"); + +var catalogItems; + +function catalog_itemsResponse(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_hostResponse(host, exception) { + if (exception) { + alert(exception.message); + return; + } + document.getElementById('host').innerHTML = host; +} + +function shoppingCart_emailResponse(email, exception) { + if (exception) { + alert(exception.message); + return; + } + document.getElementById('email').innerHTML = email; +} + +function shoppingCart_getResponse(doc) { + if (doc != null) { + var feed = parseXML([doc]); + 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.total(shoppingTotal_totalResponse); + } +} + +function shoppingTotal_totalResponse(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 = '<?xml version="1.0" encoding="UTF-8"?>\n' + + '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><content type="application/xml">' + + '<item>' + + '<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.items(catalog_itemsResponse); + shoppingCart.email(shoppingCart_emailResponse); + shoppingCart.host(shoppingCart_hostResponse); + shoppingCart.get("", shoppingCart_getResponse); + } catch(e){ + alert(e); + } +} +</script> +</head> + +<body onload="init()"> +<h1>Store</h1> +<p>Welcome to: <span id="host"></span>, you're signed in as: <span id="email"></span><br/><a href="/logout">Sign out</a></p> +<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> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/htdocs/test/items-result.txt b/sca-cpp/branches/lightweight-sca/samples/store-gae/htdocs/test/items-result.txt new file mode 100644 index 0000000000..bbc07e8917 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/htdocs/test/items-result.txt @@ -0,0 +1 @@ +{"id":1,"result":[{"price":2.9900000000000002,"currencyCode":"USD","name":"Platano","currencySymbol":"$"},{"price":3.5499999999999998,"currencyCode":"USD","name":"Banana","currencySymbol":"$"},{"price":1.55,"currencyCode":"USD","name":"Guanabana","currencySymbol":"$"}]}
\ No newline at end of file diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/htpasswd.py b/sca-cpp/branches/lightweight-sca/samples/store-gae/htpasswd.py new file mode 100644 index 0000000000..75d94f58b6 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/htpasswd.py @@ -0,0 +1,21 @@ +# 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. + +# Configure the user and password used for HTTP basic authentication +user = "foo" +passwd = "foo" + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/server-test b/sca-cpp/branches/lightweight-sca/samples/store-gae/server-test new file mode 100755 index 0000000000..2235811556 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/server-test @@ -0,0 +1,60 @@ +#!/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=`echo "import os; print os.path.realpath('$0')" | python`; here=`dirname $here` +curl_prefix=`cat $here/../../modules/http/curl.prefix` + +# Setup +./start 2>/dev/null +sleep 2 + +# Test HTTP GET (with authentication) +rm -rf tmp +mkdir -p tmp +$curl_prefix/bin/curl -L -c tmp/cookies.txt -b tmp/cookies.txt "http://localhost:8090/_ah/login?email=test@example.com&action=Login&continue=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 -b tmp/cookies.txt 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 -b tmp/cookies.txt 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 -b tmp/cookies.txt 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 +exit $rc diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/shopping-cart.py b/sca-cpp/branches/lightweight-sca/samples/store-gae/shopping-cart.py new file mode 100644 index 0000000000..11a55a552a --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/shopping-cart.py @@ -0,0 +1,82 @@ +# 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, host, email): + id = str(uuid.uuid1()) + cart = (("'entry", item[0][1], ("'id", id), item[0][3]),) + getcart(cartId, cache) + cache.put((cartId,), cart) + return (id,) + +# Find an item in the cart +def find(id, cart): + if cart == (): + return (("'entry", ("'title", "Item"), ("'id", 0)),) + elif id == cart[0][2][1]: + return (cart[0],) + else: + return find(id, cart[1:]) + +# Get items from the cart +def get(id, cache, host, email): + if id == (): + return ((("'feed", ("'title", "Your Cart"), ("'id", cartId)) + getcart(cartId, cache)),) + return find(id[0], getcart(cartId, cache)) + +# Delete items from the cart +def delete(id, cache, host, email): + 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[3][1][1:])[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, host, email): + cart = getcart(cartId, cache) + return sum(cart) + +# Return the email of the cart owner +def email(cache, host, email_): + return email_.eval() + +# Return the host that the app is running on +def host(cache, host_, email): + return host_.eval() + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/start b/sca-cpp/branches/lightweight-sca/samples/store-gae/start new file mode 100755 index 0000000000..3c9644e656 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/start @@ -0,0 +1,21 @@ +#!/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/wsgi/gae-start target 8090 + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/stop b/sca-cpp/branches/lightweight-sca/samples/store-gae/stop new file mode 100755 index 0000000000..7c8a7e5551 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/stop @@ -0,0 +1,21 @@ +#!/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/wsgi/gae-stop target 8090 + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-gae/store.py b/sca-cpp/branches/lightweight-sca/samples/store-gae/store.py new file mode 100644 index 0000000000..ff82f1d327 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-gae/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.total() + +def deleteall(catalog, shoppingCart, shoppingTotal): + return shoppingCart.deleteall() + +def delete(id, catalog, shoppingCart, shoppingTotal): + return shoppingCart.delete(id) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-java/Makefile.am b/sca-cpp/branches/lightweight-sca/samples/store-java/Makefile.am new file mode 100644 index 0000000000..f32ae72812 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-java/Makefile.am @@ -0,0 +1,34 @@ +# 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. + +JAVAROOT = ${top_builddir}/samples/store-java + +if WANT_JAVA + +dist_sample_SCRIPTS = start stop ssl-start +sampledir=$(prefix)/samples/store-java + +AM_JAVACFLAGS = -cp ${top_builddir}/modules/java/libmod-tuscany-java-${PACKAGE_VERSION}.jar:${JAVAROOT} +dist_sample_JAVA = store/*.java +CLEANFILES = *.stamp store/*.class + +nobase_dist_sample_DATA = store.composite htdocs/*.html store/*.* + +dist_noinst_SCRIPTS = server-test +TESTS = server-test + +endif diff --git a/sca-cpp/branches/lightweight-sca/samples/store-java/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-java/htdocs/index.html new file mode 100644 index 0000000000..0698a32cc5 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-java/htdocs/index.html @@ -0,0 +1,156 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Store</title> + +<script type="text/javascript" src="/all-min.js"></script> + +<script type="text/javascript"> +var store = sca.component("Store"); +var catalog = sca.defun(sca.reference(store, "catalog"), "items"); +var shoppingCart = sca.reference(store, "shoppingCart"); +var shoppingTotal = sca.defun(sca.reference(store, "shoppingTotal"), "total"); + +var catalogItems; + +function catalog_itemsResponse(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(doc) { + if (doc != null) { + var feed = parseXML([doc]); + 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.total(shoppingTotal_totalResponse); + } +} + +function shoppingTotal_totalResponse(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 = '<?xml version="1.0" encoding="UTF-8"?>\n' + + '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><content type="application/xml">' + + '<item>' + + '<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.items(catalog_itemsResponse); + shoppingCart.get("", shoppingCart_getResponse); + } catch(e){ + alert(e); + } +} +</script> +</head> + +<body onload="init()"> +<h1>Store</h1> +<br/> +<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> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-java/server-test b/sca-cpp/branches/lightweight-sca/samples/store-java/server-test new file mode 100755 index 0000000000..fb629a6814 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-java/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=`echo "import os; print os.path.realpath('$0')" | python`; 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 ../store-cpp/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 +exit $rc diff --git a/sca-cpp/branches/lightweight-sca/samples/store-java/ssl-start b/sca-cpp/branches/lightweight-sca/samples/store-java/ssl-start new file mode 100755 index 0000000000..a585f717aa --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-java/ssl-start @@ -0,0 +1,38 @@ +#!/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/basic-auth-conf tmp +../../modules/http/passwd-auth-conf tmp foo foo +../../modules/server/server-conf tmp +../../modules/java/java-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +export CLASSPATH=`pwd`/../../modules/java/libmod-tuscany-java-1.0.jar:`pwd` + +../../components/cache/memcached-start tmp +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-java/start b/sca-cpp/branches/lightweight-sca/samples/store-java/start new file mode 100755 index 0000000000..99a3f982b7 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-java/start @@ -0,0 +1,34 @@ +#!/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. + +rm -rf tmp +../../modules/http/httpd-conf tmp localhost 8090 htdocs +../../modules/server/server-conf tmp +../../modules/java/java-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +export CLASSPATH=`pwd`/../../modules/java/libmod-tuscany-java-1.0.jar:`pwd` + +../../components/cache/memcached-start tmp +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-java/stop b/sca-cpp/branches/lightweight-sca/samples/store-java/stop new file mode 100755 index 0000000000..c7a0bff857 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-java/stop @@ -0,0 +1,23 @@ +#!/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. + +export CLASSPATH=`pwd`/../../modules/java/libmod-tuscany-java-1.0.jar:`pwd` + +../../modules/http/httpd-stop tmp +../../components/cache/memcached-stop tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-java/store.composite b/sca-cpp/branches/lightweight-sca/samples/store-java/store.composite new file mode 100644 index 0000000000..2795fe1769 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-java/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" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <implementation.widget location="store.html"/> + <service name="Widget"> + <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"> + <implementation.java class="store.FruitsCatalogImpl"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <binding.jsonrpc uri="catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.java class="store.ShoppingCartImpl"/> + <service name="ShoppingCart"> + <binding.atom uri="shoppingCart"/> + </service> + <service name="Total"> + <binding.jsonrpc uri="total"/> + </service> + <reference name="cache" target="Cache"/> + </component> + + <component name="CurrencyConverter"> + <implementation.java class="store.CurrencyConverterImpl"/> + <service name="CurrencyConverter"> + <binding.jsonrpc uri="currencyConverter"/> + </service> + </component> + + <component name="Cache"> + <implementation.cpp path="../../components/cache" library="libmemcache"/> + <service name="Cache"> + <binding.atom uri="cache"/> + </service> + <property name="server">localhost:11211</property> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-java/store/CurrencyConverter.java b/sca-cpp/branches/lightweight-sca/samples/store-java/store/CurrencyConverter.java new file mode 100644 index 0000000000..1ed15a670a --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-java/store/CurrencyConverter.java @@ -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. + */ + +package store; + +public interface CurrencyConverter { + + Double convert(String from, String to, Double amount); + + String symbol(String currency); + +} diff --git a/sca-cpp/branches/lightweight-sca/samples/store-java/store/CurrencyConverterImpl.java b/sca-cpp/branches/lightweight-sca/samples/store-java/store/CurrencyConverterImpl.java new file mode 100644 index 0000000000..a6d0fd00b3 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-java/store/CurrencyConverterImpl.java @@ -0,0 +1,45 @@ +/* + * 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. + */ + +package store; + +/** + * Currency converter component implementation. + */ +public class CurrencyConverterImpl { + + /** + * Convert an amount from USD to a currency. + */ + public Double convert(String from, String to, Double amount) { + if ("EUR".equals(to)) + return amount * 0.70; + return amount; + } + + /** + * Return a currency symbol. + */ + public String symbol(String currency) { + if ("EUR".equals(currency)) + return "E"; + return "$"; + } + +} diff --git a/sca-cpp/branches/lightweight-sca/samples/store-java/store/FruitsCatalogImpl.java b/sca-cpp/branches/lightweight-sca/samples/store-java/store/FruitsCatalogImpl.java new file mode 100644 index 0000000000..8881543103 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-java/store/FruitsCatalogImpl.java @@ -0,0 +1,51 @@ +/* + * 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. + */ + +package store; + +import static org.apache.tuscany.IterableUtil.*; + +import org.apache.tuscany.Service; + +/** + * Catalog component implementation. + */ +public class FruitsCatalogImpl { + + /** + * Returns the catalog. + */ + public Iterable<?> items(final CurrencyConverter converter, final Service currencyCode) { + final String code = currencyCode.eval(); + + class Converter { + Double convert(final Double price) { + return converter.convert(code, "USD", price); + } + } + + final Converter c = new Converter(); + final String symbol = converter.symbol(code); + + return list(list(list("'name", "Apple"), list("'currencyCode", code), list("'currencySymbol", symbol), list("'price", c.convert(2.99))), + list(list("'name", "Orange"), list("'currencyCode", code), list("'currencySymbol", symbol), list("'price", c.convert(3.55))), + list(list("'name", "Pear"), list("'currencyCode", code), list("'currencySymbol", symbol), list("'price", c.convert(1.55)))); + } + +} diff --git a/sca-cpp/branches/lightweight-sca/samples/store-java/store/ShoppingCartImpl.java b/sca-cpp/branches/lightweight-sca/samples/store-java/store/ShoppingCartImpl.java new file mode 100644 index 0000000000..bd7678cce7 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-java/store/ShoppingCartImpl.java @@ -0,0 +1,113 @@ +/* + * 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. + */ + +package store; + +import static org.apache.tuscany.IterableUtil.*; +import static org.apache.tuscany.UUIDUtil.*; + +import org.apache.tuscany.Service; + +/** + * Shopping cart component implementation. + */ +public class ShoppingCartImpl { + + static String cartId = "1234"; + + /** + * Get the shopping cart from the cache. Return an empty cart if not found. + */ + public Iterable<?> getcart(final String id, final Service cache) { + final Iterable<String> iid = list(id); + final Iterable<?> cart = cache.get(iid); + if(cart == null) + return list(); + return cart; + } + + /** + * Post a new item to the cart. Create a new cart if necessary. + */ + public Iterable<String> post(final Iterable<String> collection, final Iterable<?> item, final Service cache) { + final String id = uuid(); + final Iterable<?> newItem = list("'entry", cadr(car(item)), list("'id", id), cadddr(car(item))); + final Iterable<?> cart = cons(newItem, this.getcart(cartId, cache)); + final Iterable<String> iid = list(cartId); + cache.put(iid, cart); + return list(id); + } + + /** + * Find an item in the cart. + */ + Iterable<?> find(final String id, final Iterable<?> cart) { + if(isNil(cart)) + return list(list("'entry", list("'title", "Item"), list("'id", "0"))); + if(id.equals(cadr(caddr(car(cart))))) + return list(car(cart)); + return this.find(id, cdr(cart)); + } + + /** + * Return items from the cart. + */ + public Iterable<?> get(final Iterable<String> id, final Service cache) { + if(isNil(id)) + return list(append(list("'feed", list("'title", "Your Cart"), list("'id", cartId)), this.getcart(cartId, cache))); + return this.find((String)car(id), this.getcart(cartId, cache)); + } + + /** + * Delete items from the cart. + */ + public Boolean delete(final Iterable<String> id, final Service cache) { + if(isNil(id)) { + final Iterable<String> iid = list(cartId); + return cache.delete(iid); + } + return true; + } + + /** + * Return the price of an item. + */ + Double price(final Iterable<?> item) { + System.err.println("price!! " + cadr(cadddr(item))); + return Double.valueOf((String)cadr(assoc("'price", cdr(cadr(cadddr(item)))))); + } + + /** + * Sum the prices of a list of items. + */ + Double sum(final Iterable<?> items) { + if(isNil(items)) + return 0.0; + return this.price((Iterable<?>)car(items)) + this.sum(cdr(items)); + } + + /** + * Return the total price of the items in the cart. + */ + public Double total(final Service cache) { + final Iterable<?> cart = this.getcart(cartId, cache); + return this.sum(cart); + } + +} diff --git a/sca-cpp/branches/lightweight-sca/samples/store-python/Makefile.am b/sca-cpp/branches/lightweight-sca/samples/store-python/Makefile.am new file mode 100644 index 0000000000..8db150cc0e --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/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/sca-cpp/branches/lightweight-sca/samples/store-python/currency-converter.py b/sca-cpp/branches/lightweight-sca/samples/store-python/currency-converter.py new file mode 100644 index 0000000000..2fded8f616 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/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/sca-cpp/branches/lightweight-sca/samples/store-python/fruits-catalog.py b/sca-cpp/branches/lightweight-sca/samples/store-python/fruits-catalog.py new file mode 100644 index 0000000000..8289afcac5 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/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/sca-cpp/branches/lightweight-sca/samples/store-python/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-python/htdocs/index.html new file mode 100644 index 0000000000..0698a32cc5 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-python/htdocs/index.html @@ -0,0 +1,156 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Store</title> + +<script type="text/javascript" src="/all-min.js"></script> + +<script type="text/javascript"> +var store = sca.component("Store"); +var catalog = sca.defun(sca.reference(store, "catalog"), "items"); +var shoppingCart = sca.reference(store, "shoppingCart"); +var shoppingTotal = sca.defun(sca.reference(store, "shoppingTotal"), "total"); + +var catalogItems; + +function catalog_itemsResponse(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(doc) { + if (doc != null) { + var feed = parseXML([doc]); + 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.total(shoppingTotal_totalResponse); + } +} + +function shoppingTotal_totalResponse(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 = '<?xml version="1.0" encoding="UTF-8"?>\n' + + '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><content type="application/xml">' + + '<item>' + + '<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.items(catalog_itemsResponse); + shoppingCart.get("", shoppingCart_getResponse); + } catch(e){ + alert(e); + } +} +</script> +</head> + +<body onload="init()"> +<h1>Store</h1> +<br/> +<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> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-python/htdocs/login/index.html b/sca-cpp/branches/lightweight-sca/samples/store-python/htdocs/login/index.html new file mode 100644 index 0000000000..fd3bc21889 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-python/htdocs/login/index.html @@ -0,0 +1,51 @@ +<!-- + 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. +--> + +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<script type="text/javascript" src="/all-min.js"></script> +<title>Sign in</title> +</head> +<body> +<h1>Sign in</h1> +<br/> + +<script type="text/javascript"> +function submitFormSignin() { + clearauthcookie(); + document.formSignin.httpd_location.value = '/'; + document.formSignin.submit(); +} +</script> + +<form name="formSignin" method="POST" action="/login/dologin"> +<table border="0"> +<tr><td>Username:</td><td><input type="text" name="httpd_username" value=""/></td></tr> +<tr><td>Password:</td><td><input type="password" name="httpd_password" value=""/></td></tr> +<tr><td><input type="button" onclick="submitFormSignin()" value="Sign in"/></td><td></td></tr> +</table> +<input type="hidden" name="httpd_location" value="/"/> +</form> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-python/htdocs/logout/index.html b/sca-cpp/branches/lightweight-sca/samples/store-python/htdocs/logout/index.html new file mode 100644 index 0000000000..92fd2a084b --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-python/htdocs/logout/index.html @@ -0,0 +1,43 @@ +<!-- + 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. +--> + +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<script type="text/javascript" src="/all-min.js"></script> +<title>Sign out</title> +</head> +<body> +<h1>Sign out</h1> +<br/> + +<form name="signout" action="/login" method="GET"> +<script type="text/javascript"> +function submitSignout() { + clearauthcookie(); + document.signout.submit(); + return true; +} +</script> +<input type="button" onclick="submitSignout()" value="Sign out"/> +</form> +</body></html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-python/htdocs/test/items-result.txt b/sca-cpp/branches/lightweight-sca/samples/store-python/htdocs/test/items-result.txt new file mode 100644 index 0000000000..d6aaf4d44a --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-python/htdocs/test/items-result.txt @@ -0,0 +1,23 @@ +{ + "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/sca-cpp/branches/lightweight-sca/samples/store-python/server-test b/sca-cpp/branches/lightweight-sca/samples/store-python/server-test new file mode 100755 index 0000000000..8f52543c71 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/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=`echo "import os; print os.path.realpath('$0')" | python`; 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 +exit $rc diff --git a/sca-cpp/branches/lightweight-sca/samples/store-python/shopping-cart.py b/sca-cpp/branches/lightweight-sca/samples/store-python/shopping-cart.py new file mode 100644 index 0000000000..1dac82522f --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/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 = (("'entry", item[0][1], ("'id", id), item[0][3]),) + getcart(cartId, cache) + cache.put((cartId,), cart) + return (id,) + + +# Find an item in the cart +def find(id, cart): + if cart == (): + return (("'entry", ("'title", "Item"), ("'id", 0)),) + elif id == cart[0][2][1]: + return (cart[0],) + else: + return find(id, cart[1:]) + +# Get items from the cart +def get(id, cache): + if id == (): + return ((("'feed", ("'title", "Your Cart"), ("'id", 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[3][1][1:])[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/sca-cpp/branches/lightweight-sca/samples/store-python/ssl-start b/sca-cpp/branches/lightweight-sca/samples/store-python/ssl-start new file mode 100755 index 0000000000..2a9df09c2e --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-python/ssl-start @@ -0,0 +1,37 @@ +#!/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-event-conf tmp +../../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 <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +../../components/cache/memcached-start tmp +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-python/start b/sca-cpp/branches/lightweight-sca/samples/store-python/start new file mode 100755 index 0000000000..d52a41ec13 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-python/start @@ -0,0 +1,33 @@ +#!/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. + +rm -rf tmp +../../modules/http/httpd-conf tmp localhost 8090 htdocs +../../modules/http/httpd-event-conf tmp +../../modules/server/server-conf tmp +../../modules/python/python-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +../../components/cache/memcached-start tmp +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-python/stop b/sca-cpp/branches/lightweight-sca/samples/store-python/stop new file mode 100755 index 0000000000..3b4c74a587 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-python/stop @@ -0,0 +1,21 @@ +#!/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/httpd-stop tmp +../../components/cache/memcached-stop tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-python/store.composite b/sca-cpp/branches/lightweight-sca/samples/store-python/store.composite new file mode 100644 index 0000000000..6de6f7af61 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-python/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" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <implementation.python script="store.py"/> + <service name="Widget"> + <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"> + <implementation.python script="fruits-catalog.py"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <binding.jsonrpc uri="catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.python script="shopping-cart.py"/> + <service name="ShoppingCart"> + <binding.atom uri="shoppingCart"/> + </service> + <service name="Total"> + <binding.jsonrpc uri="total"/> + </service> + <reference name="cache" target="Cache"/> + </component> + + <component name="CurrencyConverter"> + <implementation.python script="currency-converter.py"/> + <service name="CurrencyConverter"> + <binding.jsonrpc uri="currencyConverter"/> + </service> + </component> + + <component name="Cache"> + <implementation.cpp path="../../components/cache" library="libmemcache"/> + <service name="Cache"> + <binding.atom uri="cache"/> + </service> + <property name="server">localhost:11211</property> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-python/store.py b/sca-cpp/branches/lightweight-sca/samples/store-python/store.py new file mode 100644 index 0000000000..b71f505dd1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/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/sca-cpp/branches/lightweight-sca/samples/store-python/uec2-start b/sca-cpp/branches/lightweight-sca/samples/store-python/uec2-start new file mode 100755 index 0000000000..feb4ae383e --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-python/uec2-start @@ -0,0 +1,47 @@ +#!/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-event-conf tmp +../../modules/http/httpd-ssl-conf tmp 8453/443 +../../modules/server/server-conf tmp +../../modules/python/python-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +../../components/cache/memcached-start tmp +../../modules/http/httpd-start tmp + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-scheme/Makefile.am b/sca-cpp/branches/lightweight-sca/samples/store-scheme/Makefile.am new file mode 100644 index 0000000000..2330d45422 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-scheme/Makefile.am @@ -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. + +dist_sample_SCRIPTS = start stop ssl-start +sampledir = $(prefix)/samples/store-scheme + +nobase_dist_sample_DATA = currency-converter.scm fruits-catalog.scm shopping-cart.scm store.scm store.composite htdocs/*.html + +EXTRA_DIST = script-test.scm + +dist_noinst_SCRIPTS = server-test +noinst_PROGRAMS = script-test +script_test_SOURCES = script-test.cpp +script_test_LDFLAGS = -lxml2 -lmozjs + +TESTS = script-test server-test diff --git a/sca-cpp/branches/lightweight-sca/samples/store-scheme/currency-converter.scm b/sca-cpp/branches/lightweight-sca/samples/store-scheme/currency-converter.scm new file mode 100644 index 0000000000..fc506c3d73 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-scheme/currency-converter.scm @@ -0,0 +1,27 @@ +; 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 + +(define (convert from to amount) + (if (equal? to "EUR") (* amount 0.70) amount) +) + +(define (symbol currency) + (if (equal? currency "EUR") "E" "$") +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-scheme/fruits-catalog.scm b/sca-cpp/branches/lightweight-sca/samples/store-scheme/fruits-catalog.scm new file mode 100644 index 0000000000..d55394b96a --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-scheme/fruits-catalog.scm @@ -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 + +(define (items converter currencyCode) + (define code (currencyCode)) + (define (convert price) (converter "convert" "USD" code price)) + (define symbol (converter "symbol" code)) + (list + (list (list 'name "Apple") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 2.99))) + (list (list 'name "Orange") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 3.55))) + (list (list 'name "Pear") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 1.55))) + ) +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-scheme/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-scheme/htdocs/index.html new file mode 100644 index 0000000000..0698a32cc5 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-scheme/htdocs/index.html @@ -0,0 +1,156 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Store</title> + +<script type="text/javascript" src="/all-min.js"></script> + +<script type="text/javascript"> +var store = sca.component("Store"); +var catalog = sca.defun(sca.reference(store, "catalog"), "items"); +var shoppingCart = sca.reference(store, "shoppingCart"); +var shoppingTotal = sca.defun(sca.reference(store, "shoppingTotal"), "total"); + +var catalogItems; + +function catalog_itemsResponse(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(doc) { + if (doc != null) { + var feed = parseXML([doc]); + 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.total(shoppingTotal_totalResponse); + } +} + +function shoppingTotal_totalResponse(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 = '<?xml version="1.0" encoding="UTF-8"?>\n' + + '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><content type="application/xml">' + + '<item>' + + '<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.items(catalog_itemsResponse); + shoppingCart.get("", shoppingCart_getResponse); + } catch(e){ + alert(e); + } +} +</script> +</head> + +<body onload="init()"> +<h1>Store</h1> +<br/> +<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> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-scheme/script-test.cpp b/sca-cpp/branches/lightweight-sca/samples/store-scheme/script-test.cpp new file mode 100644 index 0000000000..0d5a9ccf9d --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-scheme/script-test.cpp @@ -0,0 +1,96 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +/** + * Store Test case. + */ + +#include <assert.h> +#include <regex.h> +#include "stream.hpp" +#include "string.hpp" +#include "list.hpp" +#include "xml.hpp" +#include "../../modules/scheme/driver.hpp" +#include "../../modules/json/json.hpp" + +namespace store { + +using namespace tuscany; + +bool testScript() { + gc_scoped_pool pool; + + ifstream is("script-test.scm"); + ostringstream os; + scheme::evalDriverRun(is, os); + assert(contains(str(os), "(\"Sample Feed\" \"")); + assert(contains(str(os), "\" (\"Item\" \"")); + assert(contains(str(os), "\" ((name \"Orange\") (currencyCode \"USD\") (currencySymbol \"$\") (price 3.55))) (\"Item\" \"")); + assert(contains(str(os), "\" ((name \"Apple\") (currencyCode \"USD\") (currencySymbol \"$\") (price 2.99))))")); + return true; +} + +bool testEval() { + { + gc_scoped_pool pool; + ifstream is("script-test.scm"); + ostringstream os; + scheme::setupDisplay(os); + scheme::Env globalEnv = scheme::setupEnvironment(); + const value exp(mklist<value>("storeui_service", string("items"))); + const value val = scheme::evalScript(exp, is, globalEnv); + + ostringstream vs; + vs << val; + assert(contains(str(vs), "(((name \"Apple\") (currencyCode \"USD\") (currencySymbol \"$\") (price 2.99)) ((name \"Orange\") (currencyCode \"USD\") (currencySymbol \"$\") (price 3.55)) ((name \"Pear\") (currencyCode \"USD\") (currencySymbol \"$\") (price 1.55)))")); + } + + { + gc_scoped_pool pool; + ifstream is("script-test.scm"); + ostringstream os; + scheme::setupDisplay(os); + + scheme::Env globalEnv = scheme::setupEnvironment(); + const value exp(mklist<value>("storeui_service", string("total"))); + const value res = scheme::evalScript(exp, is, globalEnv); + + ostringstream rs; + rs << res; + assert(contains(str(rs), "10")); + } + return true; +} + +} + +int main() { + + tuscany::cout << "Testing..." << tuscany::endl; + + store::testScript(); + store::testEval(); + + tuscany::cout << "OK" << tuscany::endl; + + return 0; +} diff --git a/sca-cpp/branches/lightweight-sca/samples/store-scheme/script-test.scm b/sca-cpp/branches/lightweight-sca/samples/store-scheme/script-test.scm new file mode 100644 index 0000000000..50b587b8f1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-scheme/script-test.scm @@ -0,0 +1,140 @@ +; 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 implementation + +(define (currency_convert from to amount) + (if (equal? to "EUR") (* amount 0.70) amount) +) + +(define (currency_symbol currency) + (if (equal? currency "EUR") "E" "$") +) + +(define (currency_impl op args) + (cond + ((equal? op "convert") (apply currency_convert args)) + ((equal? op "symbol") (apply currency_symbol args)) + ) +) + +; Currency composite + +(define (currency_service op . args) (currency_impl op args)) + +; Catalog implementation + +(define (catalog_get converter) + (define (convert price) (converter "convert" "USD" "USD" price)) + + (define code "USD") + (define symbol (converter "symbol" code)) + + (list + (list (list 'name "Apple") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price 2.99)) + (list (list 'name "Orange") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price 3.55)) + (list (list 'name "Pear") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price 1.55)) + ) +) + +(define (catalog_impl converter op args) + (cond + ((equal? op "items") (apply catalog_get (cons converter args))) + ) +) + +; Catalog composite + +(define (catalog_service op . args) (catalog_impl currency_service op args)) + +; Cart implementation + +(define (cart_post content item) + (cons (cons "Item" (list (uuid) item)) content) +) + +(define (cart_getall content) + (cons "Sample Feed" (cons (uuid) content)) +) + +(define (cart_getentry id) + (define entry (list (list 'name "Apple") (list 'currencyCode "USD") (list 'currencySymbol "$") (list 'price 2.99))) + (cons "Item" (list id entry)) +) + +(define (cart_total) + 10.0 +) + +(define (cart_impl op args) + (cond + ((equal? op "post") (apply cart_post args)) + ((equal? op "getall") (apply cart_getall args)) + ((equal? op "getentry") (apply cart_getentry args)) + ((equal? op "total") (apply cart_total args)) + ) +) + +; Store UI implementation + +(define (storeui_post cart content item) + (cart "post" content item) +) + +(define (storeui_getcart cart content) + (cart "getall" content) +) + +(define (storeui_getentry cart id) + (cart "getentry" id) +) + +(define (storeui_items catalog) + (catalog "items") +) + +(define (storeui_total cart) + (cart "total") +) + +(define (storeui_impl cart catalog op args) + (cond + ((equal? op "post") (apply storeui_post (cons cart args))) + ((equal? op "getall") (apply storeui_getcart (cons cart args))) + ((equal? op "getentry") (apply storeui_getentry (cons cart args))) + ((equal? op "items") (apply storeui_items (cons catalog args))) + ((equal? op "total") (apply storeui_total (cons cart args))) + ) +) + +; Store UI composite + +(define (cart_service op . args) (cart_impl op args)) + +(define (storeui_service op . args) (storeui_impl cart_service catalog_service op args)) + +; Store UI test case + +(define catalog (storeui_service "items")) +(define empty (list)) +(define apple (car catalog)) +(define orange (car (cdr catalog))) +(define added1 (storeui_service "post" empty apple)) +(define added2 (storeui_service "post" added1 orange)) +(display (storeui_service "getall" added2)) +(display (storeui_service "total")) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-scheme/server-test b/sca-cpp/branches/lightweight-sca/samples/store-scheme/server-test new file mode 100755 index 0000000000..fb629a6814 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-scheme/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=`echo "import os; print os.path.realpath('$0')" | python`; 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 ../store-cpp/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 +exit $rc diff --git a/sca-cpp/branches/lightweight-sca/samples/store-scheme/shopping-cart.scm b/sca-cpp/branches/lightweight-sca/samples/store-scheme/shopping-cart.scm new file mode 100644 index 0000000000..e653f1e33c --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-scheme/shopping-cart.scm @@ -0,0 +1,82 @@ +; 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 + +(define cartId "1234") + +; Get the shopping cart from the cache +; Return an empty cart if not found +(define (getcart id cache) + (define cart (cache "get" (list id))) + (if (nul cart) + (list) + cart) +) + +; Post a new item to the cart, create a new cart if necessary +(define (post collection item cache) + (define id (uuid)) + (define newItem (list 'entry (cadr (car item)) (list 'id id) (cadddr (car item)))) + (define cart (cons newItem (getcart cartId cache))) + (cache "put" (list cartId) cart) + (list id) +) + +; Find an item in the cart +(define (find id cart) + (if (nul cart) + (list (list 'entry (list 'title "Item") (list 'id "0"))) + (if (= id (cadr (caddr (car cart)))) + (list (car cart)) + (find id (cdr cart)))) +) + +; Get items from the cart +(define (get id cache) + (if (nul id) + (list (append (list 'feed (list 'title "Your Cart") (list 'id cartId)) (getcart cartId cache))) + (find (car id) (getcart cartId cache)) + ) +) + +; Delete items from the cart +(define (delete id cache) + (if (nul id) + (cache "delete" (list cartId)) + true + ) +) + +; Return the price of an item +(define (price item) + (cadr (assoc 'price (cadr (cadddr item)))) +) + +; Sum the prices of a list of items +(define (sum items) + (if (nul items) + 0 + (+ (price (car items)) (sum (cdr items)))) +) + +; Return the total price of the items in the cart +(define (total cache) + (define cart (getcart cartId cache)) + (sum cart) +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-scheme/ssl-start b/sca-cpp/branches/lightweight-sca/samples/store-scheme/ssl-start new file mode 100755 index 0000000000..cc0272c28f --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-scheme/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/basic-auth-conf tmp +../../modules/http/passwd-auth-conf tmp foo foo +../../modules/server/server-conf tmp +../../modules/server/scheme-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +../../components/cache/memcached-start tmp +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-scheme/start b/sca-cpp/branches/lightweight-sca/samples/store-scheme/start new file mode 100755 index 0000000000..bef6f0372b --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-scheme/start @@ -0,0 +1,33 @@ +#!/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. + +rm -rf tmp +../../modules/http/httpd-conf tmp localhost 8090 htdocs +../../modules/http/httpd-event-conf tmp +../../modules/server/server-conf tmp +../../modules/server/scheme-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +../../components/cache/memcached-start tmp +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-scheme/stop b/sca-cpp/branches/lightweight-sca/samples/store-scheme/stop new file mode 100755 index 0000000000..3b4c74a587 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-scheme/stop @@ -0,0 +1,21 @@ +#!/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/httpd-stop tmp +../../components/cache/memcached-stop tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-scheme/store.composite b/sca-cpp/branches/lightweight-sca/samples/store-scheme/store.composite new file mode 100644 index 0000000000..0711328217 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-scheme/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" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <implementation.scheme script="store.scm"/> + <service name="Widget"> + <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"> + <implementation.scheme script="fruits-catalog.scm"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <binding.jsonrpc uri="catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.scheme script="shopping-cart.scm"/> + <service name="Cart"> + <binding.atom uri="shoppingCart"/> + </service> + <service name="Total"> + <binding.jsonrpc uri="total"/> + </service> + <reference name="cache" target="Cache"/> + </component> + + <component name="CurrencyConverter"> + <implementation.scheme script="currency-converter.scm"/> + <service name="CurrencyConverter"> + <binding.jsonrpc uri="currencyConverter"/> + </service> + </component> + + <component name="Cache"> + <implementation.cpp path="../../components/cache" library="libmemcache"/> + <service name="Cache"> + <binding.atom uri="cache"/> + </service> + <property name="server">localhost:11211</property> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-scheme/store.scm b/sca-cpp/branches/lightweight-sca/samples/store-scheme/store.scm new file mode 100644 index 0000000000..f54257343e --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-scheme/store.scm @@ -0,0 +1,47 @@ +; 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 + +(define (post item catalog shoppingCart shoppingTotal) + (shoppingCart "post" item) +) + +(define (getall catalog shoppingCart shoppingTotal) + (shoppingCart "getall") +) + +(define (get id catalog shoppingCart shoppingTotal) + (shoppingCart "get" id) +) + +(define (items catalog shoppingCart shoppingTotal) + (catalog "items") +) + +(define (total catalog shoppingCart shoppingTotal) + (shoppingCart "total") +) + +(define (deleteall catalog shoppingCart shoppingTotal) + (shoppingCart "deleteall") +) + +(define (delete id catalog shoppingCart shoppingTotal) + (shoppingCart "delete" id) +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-sql/Makefile.am b/sca-cpp/branches/lightweight-sca/samples/store-sql/Makefile.am new file mode 100644 index 0000000000..3b738e3972 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-sql/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_SQLDB + +dist_sample_SCRIPTS = start stop ssl-start +sampledir = $(prefix)/samples/store-sql + +nobase_dist_sample_DATA = currency-converter.scm fruits-catalog.scm shopping-cart.scm store.scm store.composite htdocs/*.html + +dist_noinst_SCRIPTS = server-test +TESTS = server-test + +endif diff --git a/sca-cpp/branches/lightweight-sca/samples/store-sql/currency-converter.scm b/sca-cpp/branches/lightweight-sca/samples/store-sql/currency-converter.scm new file mode 100644 index 0000000000..fc506c3d73 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-sql/currency-converter.scm @@ -0,0 +1,27 @@ +; 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 + +(define (convert from to amount) + (if (equal? to "EUR") (* amount 0.70) amount) +) + +(define (symbol currency) + (if (equal? currency "EUR") "E" "$") +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-sql/fruits-catalog.scm b/sca-cpp/branches/lightweight-sca/samples/store-sql/fruits-catalog.scm new file mode 100644 index 0000000000..d55394b96a --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-sql/fruits-catalog.scm @@ -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 + +(define (items converter currencyCode) + (define code (currencyCode)) + (define (convert price) (converter "convert" "USD" code price)) + (define symbol (converter "symbol" code)) + (list + (list (list 'name "Apple") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 2.99))) + (list (list 'name "Orange") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 3.55))) + (list (list 'name "Pear") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 1.55))) + ) +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-sql/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-sql/htdocs/index.html new file mode 100644 index 0000000000..0698a32cc5 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-sql/htdocs/index.html @@ -0,0 +1,156 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Store</title> + +<script type="text/javascript" src="/all-min.js"></script> + +<script type="text/javascript"> +var store = sca.component("Store"); +var catalog = sca.defun(sca.reference(store, "catalog"), "items"); +var shoppingCart = sca.reference(store, "shoppingCart"); +var shoppingTotal = sca.defun(sca.reference(store, "shoppingTotal"), "total"); + +var catalogItems; + +function catalog_itemsResponse(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(doc) { + if (doc != null) { + var feed = parseXML([doc]); + 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.total(shoppingTotal_totalResponse); + } +} + +function shoppingTotal_totalResponse(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 = '<?xml version="1.0" encoding="UTF-8"?>\n' + + '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><content type="application/xml">' + + '<item>' + + '<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.items(catalog_itemsResponse); + shoppingCart.get("", shoppingCart_getResponse); + } catch(e){ + alert(e); + } +} +</script> +</head> + +<body onload="init()"> +<h1>Store</h1> +<br/> +<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> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-sql/server-test b/sca-cpp/branches/lightweight-sca/samples/store-sql/server-test new file mode 100755 index 0000000000..fb629a6814 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-sql/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=`echo "import os; print os.path.realpath('$0')" | python`; 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 ../store-cpp/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 +exit $rc diff --git a/sca-cpp/branches/lightweight-sca/samples/store-sql/shopping-cart.scm b/sca-cpp/branches/lightweight-sca/samples/store-sql/shopping-cart.scm new file mode 100644 index 0000000000..e653f1e33c --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-sql/shopping-cart.scm @@ -0,0 +1,82 @@ +; 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 + +(define cartId "1234") + +; Get the shopping cart from the cache +; Return an empty cart if not found +(define (getcart id cache) + (define cart (cache "get" (list id))) + (if (nul cart) + (list) + cart) +) + +; Post a new item to the cart, create a new cart if necessary +(define (post collection item cache) + (define id (uuid)) + (define newItem (list 'entry (cadr (car item)) (list 'id id) (cadddr (car item)))) + (define cart (cons newItem (getcart cartId cache))) + (cache "put" (list cartId) cart) + (list id) +) + +; Find an item in the cart +(define (find id cart) + (if (nul cart) + (list (list 'entry (list 'title "Item") (list 'id "0"))) + (if (= id (cadr (caddr (car cart)))) + (list (car cart)) + (find id (cdr cart)))) +) + +; Get items from the cart +(define (get id cache) + (if (nul id) + (list (append (list 'feed (list 'title "Your Cart") (list 'id cartId)) (getcart cartId cache))) + (find (car id) (getcart cartId cache)) + ) +) + +; Delete items from the cart +(define (delete id cache) + (if (nul id) + (cache "delete" (list cartId)) + true + ) +) + +; Return the price of an item +(define (price item) + (cadr (assoc 'price (cadr (cadddr item)))) +) + +; Sum the prices of a list of items +(define (sum items) + (if (nul items) + 0 + (+ (price (car items)) (sum (cdr items)))) +) + +; Return the total price of the items in the cart +(define (total cache) + (define cart (getcart cartId cache)) + (sum cart) +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-sql/ssl-start b/sca-cpp/branches/lightweight-sca/samples/store-sql/ssl-start new file mode 100755 index 0000000000..adfba0d761 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-sql/ssl-start @@ -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. + +../../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/basic-auth-conf tmp +../../modules/http/passwd-auth-conf tmp foo foo +../../modules/server/server-conf tmp +../../modules/server/scheme-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +../../components/cache/memcached-start tmp +../../components/sqldb/pgsql-conf tmp +../../components/sqldb/pgsql-start tmp +../../components/sqldb/pgsql "create table store(key text, value text);" 1>/dev/null 2>&1 +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-sql/start b/sca-cpp/branches/lightweight-sca/samples/store-sql/start new file mode 100755 index 0000000000..f3d5e67a33 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-sql/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. + +rm -rf tmp +../../modules/http/httpd-conf tmp localhost 8090 htdocs +../../modules/http/httpd-event-conf tmp +../../modules/server/server-conf tmp +../../modules/server/scheme-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +../../components/cache/memcached-start tmp +../../components/sqldb/pgsql-conf tmp +../../components/sqldb/pgsql-start tmp +../../components/sqldb/pgsql "create table store(key text, value text);" 1>/dev/null 2>&1 +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-sql/stop b/sca-cpp/branches/lightweight-sca/samples/store-sql/stop new file mode 100755 index 0000000000..daf271cbfa --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-sql/stop @@ -0,0 +1,22 @@ +#!/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/httpd-stop tmp +../../components/sqldb/pgsql-stop tmp +../../components/cache/memcached-stop tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-sql/store.composite b/sca-cpp/branches/lightweight-sca/samples/store-sql/store.composite new file mode 100644 index 0000000000..bb6898140f --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-sql/store.composite @@ -0,0 +1,89 @@ +<?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" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <implementation.scheme script="store.scm"/> + <service name="Widget"> + <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"> + <implementation.scheme script="fruits-catalog.scm"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <binding.jsonrpc uri="catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.scheme script="shopping-cart.scm"/> + <service name="Cart"> + <binding.atom uri="shoppingCart"/> + </service> + <service name="Total"> + <binding.jsonrpc uri="total"/> + </service> + <reference name="cache" target="Cache"/> + </component> + + <component name="CurrencyConverter"> + <implementation.scheme script="currency-converter.scm"/> + <service name="CurrencyConverter"> + <binding.jsonrpc uri="currencyConverter"/> + </service> + </component> + + <component name="Cache"> + <implementation.cpp path="../../components/cache" library="libdatacache"/> + <service name="Cache"> + <binding.atom uri="cache"/> + </service> + <reference name="l1reader" target="Memcache"/> + <reference name="l1writer" target="Memcache"/> + <reference name="l2reader" target="Sqldb"/> + <reference name="l2writer" target="Sqldb"/> + </component> + + <component name="Memcache"> + <implementation.cpp path="../../components/cache" library="libmemcache"/> + <service name="Memcache"> + <binding.atom uri="memcache"/> + </service> + <property name="server">localhost:11211</property> + </component> + + <component name="Sqldb"> + <implementation.cpp path="../../components/sqldb" library="libsqldb"/> + <property name="conninfo">host=localhost port=6432 dbname=db</property> + <property name="table">store</property> + <service name="Sqldb"> + <binding.atom uri="sqldb"/> + </service> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-sql/store.scm b/sca-cpp/branches/lightweight-sca/samples/store-sql/store.scm new file mode 100644 index 0000000000..f54257343e --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-sql/store.scm @@ -0,0 +1,47 @@ +; 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 + +(define (post item catalog shoppingCart shoppingTotal) + (shoppingCart "post" item) +) + +(define (getall catalog shoppingCart shoppingTotal) + (shoppingCart "getall") +) + +(define (get id catalog shoppingCart shoppingTotal) + (shoppingCart "get" id) +) + +(define (items catalog shoppingCart shoppingTotal) + (catalog "items") +) + +(define (total catalog shoppingCart shoppingTotal) + (shoppingCart "total") +) + +(define (deleteall catalog shoppingCart shoppingTotal) + (shoppingCart "deleteall") +) + +(define (delete id catalog shoppingCart shoppingTotal) + (shoppingCart "delete" id) +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/Makefile.am b/sca-cpp/branches/lightweight-sca/samples/store-vhost/Makefile.am new file mode 100644 index 0000000000..71dca3621d --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/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-vhost + +nobase_dist_sample_DATA = htdocs/*.html domains/*/htdocs/*.html domains/*/*.py domains/*/*.composite shared/*.composite + +dist_noinst_SCRIPTS = server-test +#TESTS = server-test + +endif diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/currency-converter.py b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/currency-converter.py new file mode 100644 index 0000000000..2fded8f616 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/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/branches/lightweight-sca/samples/store-vhost/domains/jane/fruits-catalog.py b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/fruits-catalog.py new file mode 100644 index 0000000000..fb20b4ff27 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/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 items(converter, currencyCode): + code = currencyCode.eval() + def convert(price): + return converter.convert("USD", code, price) + symbol = converter.symbol(code) + return ( + (("'name", "Passion"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))), + (("'name", "Mango"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))), + (("'name", "Pineapple"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(1.55))) + ) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/htdocs/index.html new file mode 100644 index 0000000000..832c0a1472 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/htdocs/index.html @@ -0,0 +1,156 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Jane's Store</title> + +<script type="text/javascript" src="/all-min.js"></script> + +<script type="text/javascript"> +var store = sca.component("Store"); +var catalog = sca.defun(sca.reference(store, "catalog"), "items"); +var shoppingCart = sca.reference(store, "shoppingCart"); +var shoppingTotal = sca.defun(sca.reference(store, "shoppingTotal"), "total"); + +var catalogItems; + +function catalog_itemsResponse(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(doc) { + if (doc != null) { + var feed = parseXML([doc]); + 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.total(shoppingTotal_totalResponse); + } +} + +function shoppingTotal_totalResponse(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 = '<?xml version="1.0" encoding="UTF-8"?>\n' + + '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><content type="application/xml">' + + '<item>' + + '<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.items(catalog_itemsResponse); + shoppingCart.get("", shoppingCart_getResponse); + } catch(e){ + alert(e); + } +} +</script> +</head> + +<body onload="init()"> +<h1>Jane's Store</h1> +<br/> +<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> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/shopping-cart.py b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/shopping-cart.py new file mode 100644 index 0000000000..1dac82522f --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/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 = (("'entry", item[0][1], ("'id", id), item[0][3]),) + getcart(cartId, cache) + cache.put((cartId,), cart) + return (id,) + + +# Find an item in the cart +def find(id, cart): + if cart == (): + return (("'entry", ("'title", "Item"), ("'id", 0)),) + elif id == cart[0][2][1]: + return (cart[0],) + else: + return find(id, cart[1:]) + +# Get items from the cart +def get(id, cache): + if id == (): + return ((("'feed", ("'title", "Your Cart"), ("'id", 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[3][1][1:])[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/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/store.composite b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/store.composite new file mode 100644 index 0000000000..58e5832bcf --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/store.composite @@ -0,0 +1,61 @@ +<?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" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <implementation.python script="store.py"/> + <service name="Widget"> + <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"> + <implementation.python script="fruits-catalog.py"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <binding.jsonrpc uri="catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.python script="shopping-cart.py"/> + <service name="ShoppingCart"> + <binding.atom uri="shoppingCart"/> + </service> + <service name="Total"> + <binding.jsonrpc uri="total"/> + </service> + <reference name="cache" target="Cache"/> + </component> + + <component name="CurrencyConverter"> + <implementation.python script="currency-converter.py"/> + <service name="CurrencyConverter"> + <binding.jsonrpc uri="currencyConverter"/> + </service> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/store.py b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/store.py new file mode 100644 index 0000000000..ff82f1d327 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/jane/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.total() + +def deleteall(catalog, shoppingCart, shoppingTotal): + return shoppingCart.deleteall() + +def delete(id, catalog, shoppingCart, shoppingTotal): + return shoppingCart.delete(id) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/currency-converter.py b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/currency-converter.py new file mode 100644 index 0000000000..2fded8f616 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/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/branches/lightweight-sca/samples/store-vhost/domains/joe/fruits-catalog.py b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/fruits-catalog.py new file mode 100644 index 0000000000..6644421683 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/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", "Apple"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))), + (("'name", "Orange"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))), + (("'name", "Pear"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(1.55))) + ) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/htdocs/index.html new file mode 100644 index 0000000000..0caf8b3df1 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/htdocs/index.html @@ -0,0 +1,156 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Joe's Store</title> + +<script type="text/javascript" src="/all-min.js"></script> + +<script type="text/javascript"> +var store = sca.component("Store"); +var catalog = sca.defun(sca.reference(store, "catalog"), "items"); +var shoppingCart = sca.reference(store, "shoppingCart"); +var shoppingTotal = sca.defun(sca.reference(store, "shoppingTotal"), "total"); + +var catalogItems; + +function catalog_itemsResponse(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(doc) { + if (doc != null) { + var feed = parseXML([doc]); + 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.total(shoppingTotal_totalResponse); + } +} + +function shoppingTotal_totalResponse(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 = '<?xml version="1.0" encoding="UTF-8"?>\n' + + '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><content type="application/xml">' + + '<item>' + + '<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.items(catalog_itemsResponse); + shoppingCart.get("", shoppingCart_getResponse); + } catch(e){ + alert(e); + } +} +</script> +</head> + +<body onload="init()"> +<h1>Joe's Store</h1> +<br/> +<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> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/shopping-cart.py b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/shopping-cart.py new file mode 100644 index 0000000000..1dac82522f --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/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 = (("'entry", item[0][1], ("'id", id), item[0][3]),) + getcart(cartId, cache) + cache.put((cartId,), cart) + return (id,) + + +# Find an item in the cart +def find(id, cart): + if cart == (): + return (("'entry", ("'title", "Item"), ("'id", 0)),) + elif id == cart[0][2][1]: + return (cart[0],) + else: + return find(id, cart[1:]) + +# Get items from the cart +def get(id, cache): + if id == (): + return ((("'feed", ("'title", "Your Cart"), ("'id", 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[3][1][1:])[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/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/store.composite b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/store.composite new file mode 100644 index 0000000000..58e5832bcf --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/store.composite @@ -0,0 +1,61 @@ +<?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" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <implementation.python script="store.py"/> + <service name="Widget"> + <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"> + <implementation.python script="fruits-catalog.py"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <binding.jsonrpc uri="catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.python script="shopping-cart.py"/> + <service name="ShoppingCart"> + <binding.atom uri="shoppingCart"/> + </service> + <service name="Total"> + <binding.jsonrpc uri="total"/> + </service> + <reference name="cache" target="Cache"/> + </component> + + <component name="CurrencyConverter"> + <implementation.python script="currency-converter.py"/> + <service name="CurrencyConverter"> + <binding.jsonrpc uri="currencyConverter"/> + </service> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/store.py b/sca-cpp/branches/lightweight-sca/samples/store-vhost/domains/joe/store.py new file mode 100644 index 0000000000..ff82f1d327 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/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 items(catalog, shoppingCart, shoppingTotal): + return catalog.items() + +def total(catalog, shoppingCart, shoppingTotal): + return shoppingCart.total() + +def deleteall(catalog, shoppingCart, shoppingTotal): + return shoppingCart.deleteall() + +def delete(id, catalog, shoppingCart, shoppingTotal): + return shoppingCart.delete(id) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-vhost/htdocs/index.html new file mode 100644 index 0000000000..fc377e5b61 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/htdocs/index.html @@ -0,0 +1,39 @@ +<!-- + * 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. +--> +<html> +<head> +<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/> +<meta name="apple-mobile-web-app-capable" content="yes"/> +<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/> +<link rel="stylesheet" type="text/css" href="/ui-min.css"/> +<title>Store</title> +</head> + +<body> +<h1>Store</h1> +<br/> +<p>For this sample to work, add the sample domain to your /etc/hosts as follows:<br/> +127.0.0.1 example.com jane.example.com joe.example.com</p> + +<p/> +<p>Jane's store at <a href="http://jane.example.com:8090/">jane.example.com</a> +<br/>Joe's store at <a href="http://joe.example.com:8090/">joe.example.com</a></p> + +</body> +</html> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/server-test b/sca-cpp/branches/lightweight-sca/samples/store-vhost/server-test new file mode 100755 index 0000000000..4d8c7a9129 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/server-test @@ -0,0 +1,61 @@ +#!/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=`echo "import os; print os.path.realpath('$0')" | python`; here=`dirname $here` +curl_prefix=`cat $here/../../modules/http/curl.prefix` + +# Setup +./start +sleep 2 + +# For this test to work, add the test domain to your etc/hosts as follows: +# 127.0.0.1 example.com joe.example.com joe.example.com + +# Test HTTP GET +$curl_prefix/bin/curl http://joe.example.com:8090/ 2>/dev/null >tmp/index.html +diff tmp/index.html htdocs/domains/joe/index.html +rc=$? + +# Test Catalog +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl http://joe.example.com: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 ../store-cpp/htdocs/test/items-result.txt + rc=$? +fi + +# Test Shopping Cart +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl http://joe.example.com: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://joe.example.com: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 +exit $rc diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/shared/shared.composite b/sca-cpp/branches/lightweight-sca/samples/store-vhost/shared/shared.composite new file mode 100644 index 0000000000..3183891ade --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/shared/shared.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" + targetNamespace="http://shared" + name="shared"> + + <component name="Cache"> + <implementation.cpp path="../../../components/cache" library="libmemcache"/> + <service name="Cache"> + <binding.atom uri="cache"/> + </service> + <property name="server">localhost:11211</property> + </component> + +</composite> diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/ssl-start b/sca-cpp/branches/lightweight-sca/samples/store-vhost/ssl-start new file mode 100755 index 0000000000..528c0a5e73 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/ssl-start @@ -0,0 +1,48 @@ +#!/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. + +# For this sample to work, add the sample domain to your /etc/hosts as follows: +# 127.0.0.1 example.com jane.example.com joe.example.com + +../../modules/http/ssl-ca-conf tmp example.com +../../modules/http/ssl-cert-conf tmp example.com server +../../modules/http/ssl-cert-conf tmp *.example.com vhost +../../modules/http/httpd-conf tmp example.com 8090 htdocs +../../modules/http/httpd-event-conf tmp +../../modules/http/mass-host-conf tmp domains htdocs +../../modules/http/httpd-ssl-conf tmp 8453 +../../modules/http/mass-host-ssl-conf tmp +../../modules/http/basic-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 <<EOF +# Configure SCA Composite +SCAContribution `pwd`/shared/ +SCAComposite shared.composite + +# Configure SCA Composite for mass dynamic virtual Hosting +SCAVirtualDomain example.com +SCAVirtualContribution `pwd`/domains/ +SCAVirtualComposite store.composite + +EOF + +../../components/cache/memcached-start tmp +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/start b/sca-cpp/branches/lightweight-sca/samples/store-vhost/start new file mode 100755 index 0000000000..6a20a60762 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/start @@ -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. + +rm -rf tmp +../../modules/http/httpd-conf tmp example.com 8090 htdocs +../../modules/http/httpd-event-conf tmp +../../modules/http/mass-host-conf tmp domains htdocs +../../modules/server/server-conf tmp +../../modules/python/python-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite +SCAContribution `pwd`/shared/ +SCAComposite shared.composite + +# Configure SCA Composite for mass dynamic virtual hosting +SCAVirtualDomain example.com +SCAVirtualContribution `pwd`/domains/ +SCAVirtualComposite store.composite + +EOF + +../../components/cache/memcached-start tmp +../../modules/http/httpd-start tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/stop b/sca-cpp/branches/lightweight-sca/samples/store-vhost/stop new file mode 100755 index 0000000000..3b4c74a587 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/stop @@ -0,0 +1,21 @@ +#!/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/httpd-stop tmp +../../components/cache/memcached-stop tmp diff --git a/sca-cpp/branches/lightweight-sca/samples/store-vhost/uec2-start b/sca-cpp/branches/lightweight-sca/samples/store-vhost/uec2-start new file mode 100755 index 0000000000..f86ce0f56b --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-vhost/uec2-start @@ -0,0 +1,52 @@ +#!/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 + # Default to dummy test domain + host="example.com" +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 server +../../modules/http/ssl-cert-conf tmp "*.$host" vhost +../../modules/http/httpd-conf tmp $host 8090/80 htdocs +../../modules/http/httpd-event-conf tmp +../../modules/http/mass-host-conf tmp domains htdocs +../../modules/http/httpd-ssl-conf tmp 8453/443 +../../modules/http/mass-host-ssl-conf tmp +../../modules/server/server-conf tmp +../../modules/python/python-conf tmp +cat >>tmp/conf/httpd.conf <<EOF +# Configure SCA Composite for mass dynamic virtual Hosting +SCAVirtualDomain $host +SCAVirtualContribution `pwd`/domains/ +SCAVirtualComposite store.composite + +EOF + +../../components/cache/memcached-start tmp +../../modules/http/httpd-start tmp + |