summaryrefslogtreecommitdiffstats
path: root/sca-cpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-12-24 02:54:46 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-12-24 02:54:46 +0000
commitf5f34433577851deb6a5ca23b32fe275e02ac71a (patch)
tree5739c95c04ed778f142a9bfcc2a90970d8224c80 /sca-cpp
parent74aef8947b7b72eca797a2f55d39997cc7af9c25 (diff)
Add a sample showing how to relay various REST requests.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1052433 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp')
-rw-r--r--sca-cpp/trunk/configure.ac1
-rw-r--r--sca-cpp/trunk/samples/Makefile.am2
-rw-r--r--sca-cpp/trunk/samples/relay-python/Makefile.am25
-rw-r--r--sca-cpp/trunk/samples/relay-python/htdocs/index.html31
-rw-r--r--sca-cpp/trunk/samples/relay-python/htdocs/test/index.html21
-rw-r--r--sca-cpp/trunk/samples/relay-python/html.py22
-rw-r--r--sca-cpp/trunk/samples/relay-python/json.py24
-rw-r--r--sca-cpp/trunk/samples/relay-python/relay.composite75
-rw-r--r--sca-cpp/trunk/samples/relay-python/rss.py25
-rwxr-xr-xsca-cpp/trunk/samples/relay-python/start30
-rwxr-xr-xsca-cpp/trunk/samples/relay-python/stop20
-rw-r--r--sca-cpp/trunk/samples/relay-python/xml.py24
12 files changed, 299 insertions, 1 deletions
diff --git a/sca-cpp/trunk/configure.ac b/sca-cpp/trunk/configure.ac
index bd088ad908..1d53d1dacd 100644
--- a/sca-cpp/trunk/configure.ac
+++ b/sca-cpp/trunk/configure.ac
@@ -919,6 +919,7 @@ AC_CONFIG_FILES([Makefile
samples/store-nosql/Makefile
samples/store-vhost/Makefile
samples/store-cluster/Makefile
+ samples/relay-python/Makefile
doc/Makefile
doc/Doxyfile
ubuntu/Makefile
diff --git a/sca-cpp/trunk/samples/Makefile.am b/sca-cpp/trunk/samples/Makefile.am
index 7eb6c7727a..bd161fec30 100644
--- a/sca-cpp/trunk/samples/Makefile.am
+++ b/sca-cpp/trunk/samples/Makefile.am
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
-SUBDIRS = store-scheme store-cpp store-python store-java store-gae store-sql store-nosql store-vhost store-cluster
+SUBDIRS = store-scheme store-cpp store-python store-java store-gae store-sql store-nosql store-vhost store-cluster relay-python
sample_DATA = README
sampledir=$(prefix)/samples
diff --git a/sca-cpp/trunk/samples/relay-python/Makefile.am b/sca-cpp/trunk/samples/relay-python/Makefile.am
new file mode 100644
index 0000000000..4e357eb330
--- /dev/null
+++ b/sca-cpp/trunk/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 = html.py json.py xml.py rss.py relay.composite htdocs/*.html htdocs/test/*.html
+
+endif
diff --git a/sca-cpp/trunk/samples/relay-python/htdocs/index.html b/sca-cpp/trunk/samples/relay-python/htdocs/index.html
new file mode 100644
index 0000000000..2025a5851d
--- /dev/null
+++ b/sca-cpp/trunk/samples/relay-python/htdocs/index.html
@@ -0,0 +1,31 @@
+<!--
+ * 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>
+<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/trunk/samples/relay-python/htdocs/test/index.html b/sca-cpp/trunk/samples/relay-python/htdocs/test/index.html
new file mode 100644
index 0000000000..1bfb3e30c2
--- /dev/null
+++ b/sca-cpp/trunk/samples/relay-python/htdocs/test/index.html
@@ -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.
+-->
+
+<html><body><h1>It works!</h1></body></html>
+
diff --git a/sca-cpp/trunk/samples/relay-python/html.py b/sca-cpp/trunk/samples/relay-python/html.py
new file mode 100644
index 0000000000..87a94a35ba
--- /dev/null
+++ b/sca-cpp/trunk/samples/relay-python/html.py
@@ -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.
+
+# Content relay implementation
+def get(id, target):
+ #return ("text/plain", ("It works!",))
+ return target.get(id)
+
diff --git a/sca-cpp/trunk/samples/relay-python/json.py b/sca-cpp/trunk/samples/relay-python/json.py
new file mode 100644
index 0000000000..24f969d419
--- /dev/null
+++ b/sca-cpp/trunk/samples/relay-python/json.py
@@ -0,0 +1,24 @@
+# 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
+import uuid
+import sys
+
+def get(id, target):
+ return target.get(id)
+
diff --git a/sca-cpp/trunk/samples/relay-python/relay.composite b/sca-cpp/trunk/samples/relay-python/relay.composite
new file mode 100644
index 0000000000..2f5b92dee0
--- /dev/null
+++ b/sca-cpp/trunk/samples/relay-python/relay.composite
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://relay"
+ name="relay">
+
+ <component name="JSONTwit">
+ <t:implementation.python script="json.py"/>
+ <service name="Relay">
+ <t:binding.http uri="jsontwit"/>
+ </service>
+ <reference name="target">
+ <t:binding.http uri="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=jsdelfino"/>
+ </reference>
+ </component>
+
+ <component name="XMLTwit">
+ <t:implementation.python script="xml.py"/>
+ <service name="Relay">
+ <t:binding.http uri="xmltwit"/>
+ </service>
+ <reference name="target">
+ <t:binding.http uri="http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=jsdelfino"/>
+ </reference>
+ </component>
+
+ <component name="RSSTwit">
+ <t:implementation.python script="rss.py"/>
+ <service name="Relay">
+ <t:binding.http uri="rsstwit"/>
+ </service>
+ <reference name="target">
+ <t:binding.http uri="http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=jsdelfino"/>
+ </reference>
+ </component>
+
+ <component name="HTML">
+ <t:implementation.python script="html.py"/>
+ <service name="Relay">
+ <t:binding.http uri="html"/>
+ </service>
+ <reference name="target">
+ <t:binding.http uri="http://localhost:8090/test"/>
+ </reference>
+ </component>
+
+ <component name="JSONFB">
+ <t:implementation.python script="json.py"/>
+ <service name="Relay">
+ <t:binding.http uri="jsonfb"/>
+ </service>
+ <reference name="target">
+ <t:binding.http uri="https://graph.facebook.com/100001053301307"/>
+ </reference>
+ </component>
+
+</composite>
diff --git a/sca-cpp/trunk/samples/relay-python/rss.py b/sca-cpp/trunk/samples/relay-python/rss.py
new file mode 100644
index 0000000000..96e4491c1a
--- /dev/null
+++ b/sca-cpp/trunk/samples/relay-python/rss.py
@@ -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.
+
+import sys
+
+# Feed relay implementation
+def get(id, target):
+ v = target.get(id)
+ print >> sys.stderr, v
+ return v
+
diff --git a/sca-cpp/trunk/samples/relay-python/start b/sca-cpp/trunk/samples/relay-python/start
new file mode 100755
index 0000000000..c156e43a52
--- /dev/null
+++ b/sca-cpp/trunk/samples/relay-python/start
@@ -0,0 +1,30 @@
+#!/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/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/trunk/samples/relay-python/stop b/sca-cpp/trunk/samples/relay-python/stop
new file mode 100755
index 0000000000..3b4f46694d
--- /dev/null
+++ b/sca-cpp/trunk/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/trunk/samples/relay-python/xml.py b/sca-cpp/trunk/samples/relay-python/xml.py
new file mode 100644
index 0000000000..24f969d419
--- /dev/null
+++ b/sca-cpp/trunk/samples/relay-python/xml.py
@@ -0,0 +1,24 @@
+# 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
+import uuid
+import sys
+
+def get(id, target):
+ return target.get(id)
+