summaryrefslogtreecommitdiffstats
path: root/sca-cpp/branches/lightweight-sca/components/http
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/branches/lightweight-sca/components/http')
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/Makefile.am56
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/client-test.cpp111
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/content-test.scm23
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/http.composite93
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/httpdelete.componentType29
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/httpdelete.cpp106
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/httpget.componentType29
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/httpget.cpp108
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/httppatch.componentType30
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/httppatch.cpp110
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/httppost.componentType30
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/httppost.cpp110
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/httpput.componentType30
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/httpput.cpp110
-rwxr-xr-xsca-cpp/branches/lightweight-sca/components/http/server-test40
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/server-test.scm44
-rw-r--r--sca-cpp/branches/lightweight-sca/components/http/url-test.scm23
17 files changed, 1082 insertions, 0 deletions
diff --git a/sca-cpp/branches/lightweight-sca/components/http/Makefile.am b/sca-cpp/branches/lightweight-sca/components/http/Makefile.am
new file mode 100644
index 0000000000..623be12298
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/Makefile.am
@@ -0,0 +1,56 @@
+# 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.
+
+compdir=$(prefix)/components/http
+
+EXTRA_DIST = http.composite httpget.componentType httppost.componentType httpput.componentType httppatch.componentType httpdelete.componentType *.scm
+
+comp_LTLIBRARIES = libhttpget.la libhttpdelete.la libhttppost.la libhttpput.la libhttppatch.la
+noinst_DATA = libhttpget${libsuffix} libhttpdelete${libsuffix} libhttppost${libsuffix} libhttpput${libsuffix} libhttppatch${libsuffix}
+
+libhttpget_la_SOURCES = httpget.cpp
+libhttpget_la_LDFLAGS = -lxml2 -lmozjs -curl
+libhttpget${libsuffix}:
+ ln -s .libs/libhttpget${libsuffix}
+
+libhttpdelete_la_SOURCES = httpdelete.cpp
+libhttpdelete_la_LDFLAGS = -lxml2 -lmozjs -curl
+libhttpdelete${libsuffix}:
+ ln -s .libs/libhttpdelete${libsuffix}
+
+libhttppost_la_SOURCES = httppost.cpp
+libhttppost_la_LDFLAGS = -lxml2 -lmozjs -curl
+libhttppost${libsuffix}:
+ ln -s .libs/libhttppost${libsuffix}
+
+libhttpput_la_SOURCES = httpput.cpp
+libhttpput_la_LDFLAGS = -lxml2 -lmozjs -curl
+libhttpput${libsuffix}:
+ ln -s .libs/libhttpput${libsuffix}
+
+libhttppatch_la_SOURCES = httppatch.cpp
+libhttppatch_la_LDFLAGS = -lxml2 -lmozjs -curl
+libhttppatch${libsuffix}:
+ ln -s .libs/libhttppatch${libsuffix}
+
+client_test_SOURCES = client-test.cpp
+client_test_LDFLAGS = -lxml2 -lcurl -lmozjs
+
+dist_noinst_SCRIPTS = server-test
+noinst_PROGRAMS = client-test
+TESTS = server-test
+
diff --git a/sca-cpp/branches/lightweight-sca/components/http/client-test.cpp b/sca-cpp/branches/lightweight-sca/components/http/client-test.cpp
new file mode 100644
index 0000000000..bb1918f1f8
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/client-test.cpp
@@ -0,0 +1,111 @@
+/*
+ * 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$ */
+
+/**
+ * Test HTTP components.
+ */
+
+#include <assert.h>
+#include "stream.hpp"
+#include "string.hpp"
+
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+#include "perf.hpp"
+#include "../../modules/http/http.hpp"
+
+namespace tuscany {
+namespace http {
+
+const string getURI("http://localhost:8090/httpget");
+const string postURI("http://localhost:8090/httppost");
+const string putURI("http://localhost:8090/httpput");
+const string deleteURI("http://localhost:8090/httpdelete");
+
+bool testGet() {
+ http::CURLSession cs("", "", "", "", 0);
+
+ const failable<value> val = http::get(getURI, cs);
+ assert(hasContent(val));
+ return true;
+}
+
+struct getLoop {
+ http::CURLSession& cs;
+ getLoop(http::CURLSession& cs) : cs(cs) {
+ }
+ const bool operator()() const {
+ const failable<value> val = http::get(getURI, cs);
+ assert(hasContent(val));
+ return true;
+ }
+};
+
+bool testGetPerf() {
+ http::CURLSession cs("", "", "", "", 0);
+
+ const lambda<bool()> gl = getLoop(cs);
+ cout << "HTTP get test " << time(gl, 5, 200) << " ms" << endl;
+
+ return true;
+}
+
+bool testPost() {
+ http::CURLSession cs("", "", "", "", 0);
+
+ const failable<value> val = http::get(postURI, cs);
+ assert(hasContent(val));
+ return true;
+}
+
+bool testPut() {
+ http::CURLSession cs("", "", "", "", 0);
+
+ const failable<value> val = http::get(putURI, cs);
+ assert(hasContent(val));
+ return true;
+}
+
+bool testDelete() {
+ http::CURLSession cs("", "", "", "", 0);
+
+ const failable<value> val = http::get(deleteURI, cs);
+ assert(hasContent(val));
+ return true;
+}
+
+}
+}
+
+int main() {
+ tuscany::cout << "Testing..." << tuscany::endl;
+
+ tuscany::http::testGet();
+ tuscany::http::testGetPerf();
+ tuscany::http::testPost();
+ tuscany::http::testPut();
+ tuscany::http::testDelete();
+
+ tuscany::cout << "OK" << tuscany::endl;
+
+ return 0;
+}
diff --git a/sca-cpp/branches/lightweight-sca/components/http/content-test.scm b/sca-cpp/branches/lightweight-sca/components/http/content-test.scm
new file mode 100644
index 0000000000..f381546190
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/content-test.scm
@@ -0,0 +1,23 @@
+; 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 test case
+
+(define (get id)
+ (list (list 'entry '(title "Item") '(id "111") '(content (item (name "Apple") (currencyCode "USD") (currencySymbol "$") (price 2.99)))))
+)
+
diff --git a/sca-cpp/branches/lightweight-sca/components/http/http.composite b/sca-cpp/branches/lightweight-sca/components/http/http.composite
new file mode 100644
index 0000000000..32c0da62c0
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/http.composite
@@ -0,0 +1,93 @@
+<?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://tuscany.apache.org/xmlns/sca/components"
+ name="http">
+
+ <component name="httpget">
+ <implementation.cpp path="." library="libhttpget"/>
+ <property name="timeout">0</property>
+ <service name="httpget">
+ <binding.http uri="httpget"/>
+ </service>
+ <reference name="url" target="url-test"/>
+ </component>
+
+ <component name="httppost">
+ <implementation.cpp path="." library="libhttppost"/>
+ <property name="timeout">0</property>
+ <service name="httppost">
+ <binding.http uri="httppost"/>
+ </service>
+ <reference name="url" target="url-test"/>
+ <reference name="content" target="content-test"/>
+ </component>
+
+ <component name="httpput">
+ <implementation.cpp path="." library="libhttpput"/>
+ <property name="timeout">0</property>
+ <service name="httpput">
+ <binding.http uri="httpput"/>
+ </service>
+ <reference name="url" target="url-test"/>
+ <reference name="content" target="content-test"/>
+ </component>
+
+ <component name="httppatch">
+ <implementation.cpp path="." library="libhttppatch"/>
+ <property name="timeout">0</property>
+ <service name="httppatch">
+ <binding.http uri="httppatch"/>
+ </service>
+ <reference name="url" target="url-test"/>
+ <reference name="content" target="content-test"/>
+ </component>
+
+ <component name="httpdelete">
+ <implementation.cpp path="." library="libhttpdelete"/>
+ <property name="timeout">0</property>
+ <service name="httpdelete">
+ <binding.http uri="httpdelete"/>
+ </service>
+ <reference name="url" target="url-test"/>
+ </component>
+
+ <component name="url-test">
+ <implementation.scheme script="url-test.scm"/>
+ <service name="url-test">
+ <binding.http uri="url-test"/>
+ </service>
+ </component>
+
+ <component name="content-test">
+ <implementation.scheme script="content-test.scm"/>
+ <service name="content-test">
+ <binding.http uri="content-test"/>
+ </service>
+ </component>
+
+ <component name="scheme-test">
+ <implementation.scheme script="server-test.scm"/>
+ <service name="scheme">
+ <binding.http uri="scheme"/>
+ </service>
+ </component>
+
+</composite>
diff --git a/sca-cpp/branches/lightweight-sca/components/http/httpdelete.componentType b/sca-cpp/branches/lightweight-sca/components/http/httpdelete.componentType
new file mode 100644
index 0000000000..c2d728a538
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/httpdelete.componentType
@@ -0,0 +1,29 @@
+<?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.
+-->
+<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/components">
+
+ <property name="timeout"/>
+ <service name="httpdelete"/>
+ <reference name="url"/>
+
+</componentType>
diff --git a/sca-cpp/branches/lightweight-sca/components/http/httpdelete.cpp b/sca-cpp/branches/lightweight-sca/components/http/httpdelete.cpp
new file mode 100644
index 0000000000..c725461ec2
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/httpdelete.cpp
@@ -0,0 +1,106 @@
+/*
+ * 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$ */
+
+/**
+ * HTTP client component implementation.
+ */
+
+#define WANT_HTTPD_LOG 1
+#include "string.hpp"
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+#include "../../modules/http/http.hpp"
+
+namespace tuscany {
+namespace httpdelete {
+
+/**
+ * Evaluate an HTTP delete.
+ */
+const failable<value> get(const lambda<value(const list<value>&)>& url, http::CURLSession& ch) {
+ debug("httpdelete::get");
+ const value u = url(mklist<value>("get", list<value>()));
+ debug(u, "httpdelete::get::url");
+ return http::del(u, ch);
+}
+
+/**
+ * Component implementation lambda function.
+ */
+class applyhttp {
+public:
+ applyhttp(const lambda<value(const list<value>&)>& url, const perthread_ptr<http::CURLSession>& ch) : url(url), ch(ch) {
+ }
+
+ const value operator()(const list<value>& params) const {
+ debug(params, "httpdelete::applyhttp::params");
+ const value func(car(params));
+ if (func == "get")
+ return get(url, *ch);
+ return mkfailure<value>();
+ }
+
+private:
+ const lambda<value(const list<value>&)> url;
+ perthread_ptr<http::CURLSession> ch;
+};
+
+/**
+ * Create a new CURL session.
+ */
+class newsession {
+public:
+ newsession(const lambda<value(const list<value>&)>& timeout) : timeout(timeout) {
+ }
+ const gc_ptr<http::CURLSession> operator()() const {
+ const int t = atoi(c_str((string)timeout(list<value>())));
+ return new (gc_new<http::CURLSession>()) http::CURLSession("", "", "", "", t);
+ }
+private:
+ const lambda<value(const list<value>&)> timeout;
+};
+
+/**
+ * Start the component.
+ */
+const failable<value> start(const list<value>& params) {
+ // Create a CURL session
+ const perthread_ptr<http::CURLSession> ch = perthread_ptr<http::CURLSession>(lambda<gc_ptr<http::CURLSession>()>(newsession(cadr(params))));
+
+ // Return the component implementation lambda function
+ return value(lambda<value(const list<value>&)>(applyhttp(car(params), ch)));
+}
+
+}
+}
+
+extern "C" {
+
+const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
+ const tuscany::value func(car(params));
+ if (func == "start")
+ return tuscany::httpdelete::start(cdr(params));
+ return tuscany::mkfailure<tuscany::value>();
+}
+
+}
diff --git a/sca-cpp/branches/lightweight-sca/components/http/httpget.componentType b/sca-cpp/branches/lightweight-sca/components/http/httpget.componentType
new file mode 100644
index 0000000000..c6c24fbed8
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/httpget.componentType
@@ -0,0 +1,29 @@
+<?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.
+-->
+<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/components">
+
+ <property name="timeout"/>
+ <service name="httpget"/>
+ <reference name="url"/>
+
+</componentType>
diff --git a/sca-cpp/branches/lightweight-sca/components/http/httpget.cpp b/sca-cpp/branches/lightweight-sca/components/http/httpget.cpp
new file mode 100644
index 0000000000..884dc1a6ff
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/httpget.cpp
@@ -0,0 +1,108 @@
+/*
+ * 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$ */
+
+/**
+ * HTTP client component implementation.
+ */
+
+#define WANT_HTTPD_LOG 1
+#include "string.hpp"
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+#include "parallel.hpp"
+#include "../../modules/http/http.hpp"
+
+namespace tuscany {
+namespace httpget {
+
+/**
+ * Evaluate an HTTP get.
+ */
+const failable<value> get(const lambda<value(const list<value>&)>& url, http::CURLSession& ch) {
+ debug("httpget::get");
+ const value u = url(mklist<value>("get", list<value>()));
+ debug(u, "httpget::get::url");
+ return http::get(u, ch);
+}
+
+/**
+ * Component implementation lambda function.
+ */
+class applyhttp {
+public:
+ applyhttp(const lambda<value(const list<value>&)>& url, const perthread_ptr<http::CURLSession>& ch) : url(url), ch(ch) {
+ }
+
+ const value operator()(const list<value>& params) const {
+ debug(params, "httpget::applyhttp::params");
+ const value func(car(params));
+ if (func == "get")
+ return get(url, *ch);
+ return mkfailure<value>();
+ }
+
+private:
+ const lambda<value(const list<value>&)> url;
+ perthread_ptr<http::CURLSession> ch;
+};
+
+
+/**
+ * Create a new CURL session.
+ */
+class newsession {
+public:
+ newsession(const lambda<value(const list<value>&)>& timeout) : timeout(timeout) {
+ }
+ const gc_ptr<http::CURLSession> operator()() const {
+ const int t = atoi(c_str((string)timeout(list<value>())));
+ return new (gc_new<http::CURLSession>()) http::CURLSession("", "", "", "", t);
+ }
+private:
+ const lambda<value(const list<value>&)> timeout;
+};
+
+/**
+ * Start the component.
+ */
+const failable<value> start(const list<value>& params) {
+ // Create a CURL session
+ const perthread_ptr<http::CURLSession> ch = perthread_ptr<http::CURLSession>(lambda<gc_ptr<http::CURLSession>()>(newsession(cadr(params))));
+
+ // Return the component implementation lambda function
+ return value(lambda<value(const list<value>&)>(applyhttp(car(params), ch)));
+}
+
+}
+}
+
+extern "C" {
+
+const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
+ const tuscany::value func(car(params));
+ if (func == "start")
+ return tuscany::httpget::start(cdr(params));
+ return tuscany::mkfailure<tuscany::value>();
+}
+
+}
diff --git a/sca-cpp/branches/lightweight-sca/components/http/httppatch.componentType b/sca-cpp/branches/lightweight-sca/components/http/httppatch.componentType
new file mode 100644
index 0000000000..eb3a96078b
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/httppatch.componentType
@@ -0,0 +1,30 @@
+<?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.
+-->
+<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/components">
+
+ <property name="timeout"/>
+ <service name="httppatch"/>
+ <reference name="url"/>
+ <reference name="content"/>
+
+</componentType>
diff --git a/sca-cpp/branches/lightweight-sca/components/http/httppatch.cpp b/sca-cpp/branches/lightweight-sca/components/http/httppatch.cpp
new file mode 100644
index 0000000000..051b1e09ac
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/httppatch.cpp
@@ -0,0 +1,110 @@
+/*
+ * 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$ */
+
+/**
+ * HTTP client component implementation.
+ */
+
+#define WANT_HTTPD_LOG 1
+#include "string.hpp"
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+#include "parallel.hpp"
+#include "../../modules/http/http.hpp"
+
+namespace tuscany {
+namespace httppatch {
+
+/**
+ * Evaluate an HTTP patch.
+ */
+const failable<value> get(const lambda<value(const list<value>&)>& url, const lambda<value(const list<value>&)>& val, http::CURLSession& ch) {
+ debug("httppatch::get");
+ const value u = url(mklist<value>("get", list<value>()));
+ const value v = val(mklist<value>("get", list<value>()));
+ debug(u, "httppatch::get::url");
+ debug(v, "httppatch::get::val");
+ return http::patch(v, u, ch);
+}
+
+/**
+ * Component implementation lambda function.
+ */
+class applyhttp {
+public:
+ applyhttp(const lambda<value(const list<value>&)>& url, const lambda<value(const list<value>&)>& val, const perthread_ptr<http::CURLSession>& ch) : url(url), val(val), ch(ch) {
+ }
+
+ const value operator()(const list<value>& params) const {
+ debug(params, "httppatch::applyhttp::params");
+ const value func(car(params));
+ if (func == "get")
+ return get(url, val, *ch);
+ return mkfailure<value>();
+ }
+
+private:
+ const lambda<value(const list<value>&)> url;
+ const lambda<value(const list<value>&)> val;
+ perthread_ptr<http::CURLSession> ch;
+};
+
+/**
+ * Create a new CURL session.
+ */
+class newsession {
+public:
+ newsession(const lambda<value(const list<value>&)>& timeout) : timeout(timeout) {
+ }
+ const gc_ptr<http::CURLSession> operator()() const {
+ const int t = atoi(c_str((string)timeout(list<value>())));
+ return new (gc_new<http::CURLSession>()) http::CURLSession("", "", "", "", t);
+ }
+private:
+ const lambda<value(const list<value>&)> timeout;
+};
+
+/**
+ * Start the component.
+ */
+const failable<value> start(const list<value>& params) {
+ // Create a CURL session
+ const perthread_ptr<http::CURLSession> ch = perthread_ptr<http::CURLSession>(lambda<gc_ptr<http::CURLSession>()>(newsession(caddr(params))));
+
+ // Return the component implementation lambda function
+ return value(lambda<value(const list<value>&)>(applyhttp(car(params), cadr(params), ch)));
+}
+
+}
+}
+
+extern "C" {
+
+const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
+ const tuscany::value func(car(params));
+ if (func == "start")
+ return tuscany::httppatch::start(cdr(params));
+ return tuscany::mkfailure<tuscany::value>();
+}
+
+}
diff --git a/sca-cpp/branches/lightweight-sca/components/http/httppost.componentType b/sca-cpp/branches/lightweight-sca/components/http/httppost.componentType
new file mode 100644
index 0000000000..42b0096446
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/httppost.componentType
@@ -0,0 +1,30 @@
+<?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.
+-->
+<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/components">
+
+ <property name="timeout"/>
+ <service name="httppost"/>
+ <reference name="url"/>
+ <reference name="content"/>
+
+</componentType>
diff --git a/sca-cpp/branches/lightweight-sca/components/http/httppost.cpp b/sca-cpp/branches/lightweight-sca/components/http/httppost.cpp
new file mode 100644
index 0000000000..84fd984e19
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/httppost.cpp
@@ -0,0 +1,110 @@
+/*
+ * 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$ */
+
+/**
+ * HTTP client component implementation.
+ */
+
+#define WANT_HTTPD_LOG 1
+#include "string.hpp"
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+#include "parallel.hpp"
+#include "../../modules/http/http.hpp"
+
+namespace tuscany {
+namespace httppost {
+
+/**
+ * Evaluate an HTTP post.
+ */
+const failable<value> get(const lambda<value(const list<value>&)>& url, const lambda<value(const list<value>&)>& val, http::CURLSession& ch) {
+ debug("httppost::get");
+ const value u = url(mklist<value>("get", list<value>()));
+ const value v = val(mklist<value>("get", list<value>()));
+ debug(u, "httppost::get::url");
+ debug(v, "httppost::get::val");
+ return http::post(v, u, ch);
+}
+
+/**
+ * Component implementation lambda function.
+ */
+class applyhttp {
+public:
+ applyhttp(const lambda<value(const list<value>&)>& url, const lambda<value(const list<value>&)>& val, const perthread_ptr<http::CURLSession>& ch) : url(url), val(val), ch(ch) {
+ }
+
+ const value operator()(const list<value>& params) const {
+ debug(params, "httppost::applyhttp::params");
+ const value func(car(params));
+ if (func == "get")
+ return get(url, val, *ch);
+ return mkfailure<value>();
+ }
+
+private:
+ const lambda<value(const list<value>&)> url;
+ const lambda<value(const list<value>&)> val;
+ perthread_ptr<http::CURLSession> ch;
+};
+
+/**
+ * Create a new CURL session.
+ */
+class newsession {
+public:
+ newsession(const lambda<value(const list<value>&)>& timeout) : timeout(timeout) {
+ }
+ const gc_ptr<http::CURLSession> operator()() const {
+ const int t = atoi(c_str((string)timeout(list<value>())));
+ return new (gc_new<http::CURLSession>()) http::CURLSession("", "", "", "", t);
+ }
+private:
+ const lambda<const value(const list<value>&)> timeout;
+};
+
+/**
+ * Start the component.
+ */
+const failable<value> start(const list<value>& params) {
+ // Create a CURL session
+ const perthread_ptr<http::CURLSession> ch = perthread_ptr<http::CURLSession>(lambda<gc_ptr<http::CURLSession>()>(newsession(caddr(params))));
+
+ // Return the component implementation lambda function
+ return value(lambda<value(const list<value>&)>(applyhttp(car(params), cadr(params), ch)));
+}
+
+}
+}
+
+extern "C" {
+
+const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
+ const tuscany::value func(car(params));
+ if (func == "start")
+ return tuscany::httppost::start(cdr(params));
+ return tuscany::mkfailure<tuscany::value>();
+}
+
+}
diff --git a/sca-cpp/branches/lightweight-sca/components/http/httpput.componentType b/sca-cpp/branches/lightweight-sca/components/http/httpput.componentType
new file mode 100644
index 0000000000..791a7faa8a
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/httpput.componentType
@@ -0,0 +1,30 @@
+<?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.
+-->
+<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/components">
+
+ <property name="timeout"/>
+ <service name="httpput"/>
+ <reference name="url"/>
+ <reference name="content"/>
+
+</componentType>
diff --git a/sca-cpp/branches/lightweight-sca/components/http/httpput.cpp b/sca-cpp/branches/lightweight-sca/components/http/httpput.cpp
new file mode 100644
index 0000000000..2ae5da396e
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/httpput.cpp
@@ -0,0 +1,110 @@
+/*
+ * 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$ */
+
+/**
+ * HTTP client component implementation.
+ */
+
+#define WANT_HTTPD_LOG 1
+#include "string.hpp"
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+#include "parallel.hpp"
+#include "../../modules/http/http.hpp"
+
+namespace tuscany {
+namespace httpput {
+
+/**
+ * Evaluate an HTTP put.
+ */
+const failable<value> get(const lambda<value(const list<value>&)>& url, const lambda<value(const list<value>&)>& val, http::CURLSession& ch) {
+ debug("httpput::get");
+ const value u = url(mklist<value>("get", list<value>()));
+ const value v = val(mklist<value>("get", list<value>()));
+ debug(u, "httpput::get::url");
+ debug(v, "httpput::get::val");
+ return http::put(v, u, ch);
+}
+
+/**
+ * Component implementation lambda function.
+ */
+class applyhttp {
+public:
+ applyhttp(const lambda<value(const list<value>&)>& url, const lambda<value(const list<value>&)>& val, const perthread_ptr<http::CURLSession>& ch) : url(url), val(val), ch(ch) {
+ }
+
+ const value operator()(const list<value>& params) const {
+ debug(params, "httpput::applyhttp::params");
+ const value func(car(params));
+ if (func == "get")
+ return get(url, val, *ch);
+ return mkfailure<value>();
+ }
+
+private:
+ const lambda<value(const list<value>&)> url;
+ const lambda<value(const list<value>&)> val;
+ perthread_ptr<http::CURLSession> ch;
+};
+
+/**
+ * Create a new CURL session.
+ */
+class newsession {
+public:
+ newsession(const lambda<value(const list<value>&)>& timeout) : timeout(timeout) {
+ }
+ const gc_ptr<http::CURLSession> operator()() const {
+ const int t = atoi(c_str((string)timeout(list<value>())));
+ return new (gc_new<http::CURLSession>()) http::CURLSession("", "", "", "", t);
+ }
+private:
+ const lambda<value(const list<value>&)> timeout;
+};
+
+/**
+ * Start the component.
+ */
+const failable<value> start(const list<value>& params) {
+ // Create a CURL session
+ const perthread_ptr<http::CURLSession> ch = perthread_ptr<http::CURLSession>(lambda<gc_ptr<http::CURLSession>()>(newsession(caddr(params))));
+
+ // Return the component implementation lambda function
+ return value(lambda<value(const list<value>&)>(applyhttp(car(params), cadr(params), ch)));
+}
+
+}
+}
+
+extern "C" {
+
+const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
+ const tuscany::value func(car(params));
+ if (func == "start")
+ return tuscany::httpput::start(cdr(params));
+ return tuscany::mkfailure<tuscany::value>();
+}
+
+}
diff --git a/sca-cpp/branches/lightweight-sca/components/http/server-test b/sca-cpp/branches/lightweight-sca/components/http/server-test
new file mode 100755
index 0000000000..7e3116c59d
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/server-test
@@ -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.
+
+# Setup
+rm -rf tmp
+../../modules/http/httpd-conf tmp localhost 8090 ../../modules/http/htdocs
+../../modules/server/server-conf tmp
+../../modules/server/scheme-conf tmp
+cat >>tmp/conf/httpd.conf <<EOF
+SCAContribution `pwd`/
+SCAComposite http.composite
+EOF
+
+../../modules/http/httpd-start tmp
+sleep 2
+
+# Test
+./client-test 2>/dev/null
+rc=$?
+
+# Cleanup
+../../modules/http/httpd-stop tmp
+sleep 2
+exit $rc
diff --git a/sca-cpp/branches/lightweight-sca/components/http/server-test.scm b/sca-cpp/branches/lightweight-sca/components/http/server-test.scm
new file mode 100644
index 0000000000..4bbff6e5c2
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/server-test.scm
@@ -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.
+
+; JSON-RPC test case
+
+(define (echo x) x)
+
+; ATOMPub test case
+
+(define (get id)
+ (if (nul id)
+ '((feed (title "Sample Feed") (id "123456789") (entry
+ (((title "Item") (id "111") (content (item (name "Apple") (currencyCode "USD") (currencySymbol "$") (price 2.99))))
+ ((title "Item") (id "222") (content (item (name "Orange") (currencyCode "USD") (currencySymbol "$") (price 3.55))))
+ ((title "Item") (id "333") (content (item (name "Pear") (currencyCode "USD") (currencySymbol "$") (price 1.55))))))))
+
+ (list (list 'entry '(title "Item") (list 'id (car id)) '(content (item (name "Apple") (currencyCode "USD") (currencySymbol "$") (price 2.99))))))
+)
+
+(define (post collection item)
+ '("123456789")
+)
+
+(define (put id item)
+ true
+)
+
+(define (delete id)
+ true
+)
diff --git a/sca-cpp/branches/lightweight-sca/components/http/url-test.scm b/sca-cpp/branches/lightweight-sca/components/http/url-test.scm
new file mode 100644
index 0000000000..dd92720c32
--- /dev/null
+++ b/sca-cpp/branches/lightweight-sca/components/http/url-test.scm
@@ -0,0 +1,23 @@
+; 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.
+
+; URL test case
+
+(define (get id)
+ "http://localhost:8090/scheme"
+)
+