summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/components
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-03-13 19:24:02 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-03-13 19:24:02 +0000
commitd1d9ba0e29baed02a052dae81b049d00a1454bf8 (patch)
tree722f36446ddb5acc51b4f3a3047f64b988fa99a4 /sca-cpp/trunk/components
parent6ecf9ca142893fe27ae9a2e269f7dff73fb6d7c6 (diff)
Add a reusable component that returns the contents of a configured url.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1081203 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/components')
-rw-r--r--sca-cpp/trunk/components/Makefile.am2
-rw-r--r--sca-cpp/trunk/components/filedb/Makefile.am2
-rw-r--r--sca-cpp/trunk/components/http/Makefile.am36
-rw-r--r--sca-cpp/trunk/components/http/client-test.cpp84
-rw-r--r--sca-cpp/trunk/components/http/http.composite40
-rw-r--r--sca-cpp/trunk/components/http/httpget.componentType28
-rw-r--r--sca-cpp/trunk/components/http/httpget.cpp90
-rwxr-xr-xsca-cpp/trunk/components/http/server-test39
-rw-r--r--sca-cpp/trunk/components/http/url-test.scm23
9 files changed, 341 insertions, 3 deletions
diff --git a/sca-cpp/trunk/components/Makefile.am b/sca-cpp/trunk/components/Makefile.am
index 55f14a4ea8..f3116a9c45 100644
--- a/sca-cpp/trunk/components/Makefile.am
+++ b/sca-cpp/trunk/components/Makefile.am
@@ -15,5 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-SUBDIRS = cache chat log nosqldb filedb queue sqldb webservice
+SUBDIRS = cache chat http log nosqldb filedb queue sqldb webservice
diff --git a/sca-cpp/trunk/components/filedb/Makefile.am b/sca-cpp/trunk/components/filedb/Makefile.am
index 90c8b4207d..359ad68a2f 100644
--- a/sca-cpp/trunk/components/filedb/Makefile.am
+++ b/sca-cpp/trunk/components/filedb/Makefile.am
@@ -15,8 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-INCLUDES = -I${TINYCDB_INCLUDE}
-
incl_HEADERS = *.hpp
incldir = $(prefix)/include/components/filedb
diff --git a/sca-cpp/trunk/components/http/Makefile.am b/sca-cpp/trunk/components/http/Makefile.am
new file mode 100644
index 0000000000..05e41bb9e1
--- /dev/null
+++ b/sca-cpp/trunk/components/http/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.
+
+compdir=$(prefix)/components/http
+
+EXTRA_DIST = http.composite httpget.componentType *.scm
+
+comp_LTLIBRARIES = libhttpget.la
+noinst_DATA = libhttpget.so
+
+libhttpget_la_SOURCES = httpget.cpp
+libhttpget_la_LDFLAGS = -lxml2 -lmozjs -curl
+libhttpget.so:
+ ln -s .libs/libhttpget.so
+
+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/trunk/components/http/client-test.cpp b/sca-cpp/trunk/components/http/client-test.cpp
new file mode 100644
index 0000000000..eb8162b834
--- /dev/null
+++ b/sca-cpp/trunk/components/http/client-test.cpp
@@ -0,0 +1,84 @@
+/*
+ * 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 file database component.
+ */
+
+#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 uri("http://localhost:8090/httpget");
+
+bool testGet() {
+ http::CURLSession cs("", "", "");
+
+ const failable<value> val = http::get(uri, cs);
+ assert(hasContent(val));
+ assert(contains(string(car<value>(cadr<value>(content(val)))), "It works"));
+
+ return true;
+}
+
+struct getLoop {
+ http::CURLSession cs;
+ getLoop(http::CURLSession cs) : cs(cs) {
+ }
+ const bool operator()() const {
+ const failable<value> val = http::get(uri, cs);
+ assert(hasContent(val));
+ assert(contains(string(car<value>(cadr<value>(content(val)))), "It works"));
+ return true;
+ }
+};
+
+bool testGetPerf() {
+ http::CURLSession cs("", "", "");
+
+ const lambda<bool()> gl = getLoop(cs);
+ cout << "HTTP get test " << time(gl, 5, 200) << " ms" << endl;
+
+ return true;
+}
+
+}
+}
+
+int main() {
+ tuscany::cout << "Testing..." << tuscany::endl;
+
+ tuscany::http::testGet();
+ tuscany::http::testGetPerf();
+
+ tuscany::cout << "OK" << tuscany::endl;
+
+ return 0;
+}
diff --git a/sca-cpp/trunk/components/http/http.composite b/sca-cpp/trunk/components/http/http.composite
new file mode 100644
index 0000000000..53f574a0e0
--- /dev/null
+++ b/sca-cpp/trunk/components/http/http.composite
@@ -0,0 +1,40 @@
+<?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://tuscany.apache.org/xmlns/sca/components"
+ name="http">
+
+ <component name="httpget">
+ <implementation.cpp path="." library="libhttpget"/>
+ <service name="httpget">
+ <t:binding.http uri="httpget"/>
+ </service>
+ <reference name="url" target="url-test"/>
+ </component>
+
+ <component name="url-test">
+ <t:implementation.scheme script="url-test.scm"/>
+ <service name="url-test">
+ <t:binding.http uri="url-test"/>
+ </service>
+ </component>
+
+</composite>
diff --git a/sca-cpp/trunk/components/http/httpget.componentType b/sca-cpp/trunk/components/http/httpget.componentType
new file mode 100644
index 0000000000..620f549e21
--- /dev/null
+++ b/sca-cpp/trunk/components/http/httpget.componentType
@@ -0,0 +1,28 @@
+<?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">
+
+ <service name="http"/>
+ <reference name="url"/>
+
+</composite>
diff --git a/sca-cpp/trunk/components/http/httpget.cpp b/sca-cpp/trunk/components/http/httpget.cpp
new file mode 100644
index 0000000000..e64761714c
--- /dev/null
+++ b/sca-cpp/trunk/components/http/httpget.cpp
@@ -0,0 +1,90 @@
+/*
+ * 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.
+ */
+
+#include "string.hpp"
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.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, 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 tuscany::mkfailure<tuscany::value>();
+ }
+
+private:
+ const lambda<value(const list<value>&)> url;
+ http::CURLSession& ch;
+};
+
+/**
+ * Start the component.
+ */
+const failable<value> start(const list<value>& params) {
+ // Create a CURL session
+ http::CURLSession& ch = *(new (gc_new<http::CURLSession>()) http::CURLSession("", "", ""));
+
+ // 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/trunk/components/http/server-test b/sca-cpp/trunk/components/http/server-test
new file mode 100755
index 0000000000..edfeb5d189
--- /dev/null
+++ b/sca-cpp/trunk/components/http/server-test
@@ -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.
+
+# Setup
+../../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
+return $rc
diff --git a/sca-cpp/trunk/components/http/url-test.scm b/sca-cpp/trunk/components/http/url-test.scm
new file mode 100644
index 0000000000..29e6629aa5
--- /dev/null
+++ b/sca-cpp/trunk/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/index.html"
+)
+