From d1d9ba0e29baed02a052dae81b049d00a1454bf8 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sun, 13 Mar 2011 19:24:02 +0000 Subject: 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 --- sca-cpp/trunk/README | 18 +++-- sca-cpp/trunk/components/Makefile.am | 2 +- sca-cpp/trunk/components/filedb/Makefile.am | 2 - sca-cpp/trunk/components/http/Makefile.am | 36 +++++++++ sca-cpp/trunk/components/http/client-test.cpp | 84 ++++++++++++++++++++ sca-cpp/trunk/components/http/http.composite | 40 ++++++++++ .../trunk/components/http/httpget.componentType | 28 +++++++ sca-cpp/trunk/components/http/httpget.cpp | 90 ++++++++++++++++++++++ sca-cpp/trunk/components/http/server-test | 39 ++++++++++ sca-cpp/trunk/components/http/url-test.scm | 23 ++++++ sca-cpp/trunk/configure.ac | 1 + .../trunk/modules/edit/apps/testget/app.composite | 65 ++++++++++++++++ sca-cpp/trunk/modules/edit/apps/testget/app.html | 20 +++++ .../modules/edit/apps/testlogic/app.composite | 12 +-- .../trunk/modules/edit/dashboards/joe@localhost | 2 +- .../modules/edit/dashboards/joe@sca-store.com | 2 +- sca-cpp/trunk/modules/edit/htdocs/main.html | 6 +- sca-cpp/trunk/modules/edit/mkapplinks | 6 ++ .../modules/edit/palettes/url/palette.composite | 14 ++-- 19 files changed, 463 insertions(+), 27 deletions(-) create mode 100644 sca-cpp/trunk/components/http/Makefile.am create mode 100644 sca-cpp/trunk/components/http/client-test.cpp create mode 100644 sca-cpp/trunk/components/http/http.composite create mode 100644 sca-cpp/trunk/components/http/httpget.componentType create mode 100644 sca-cpp/trunk/components/http/httpget.cpp create mode 100755 sca-cpp/trunk/components/http/server-test create mode 100644 sca-cpp/trunk/components/http/url-test.scm create mode 100644 sca-cpp/trunk/modules/edit/apps/testget/app.composite create mode 100644 sca-cpp/trunk/modules/edit/apps/testget/app.html diff --git a/sca-cpp/trunk/README b/sca-cpp/trunk/README index aa55d25f34..d78c41808f 100644 --- a/sca-cpp/trunk/README +++ b/sca-cpp/trunk/README @@ -12,13 +12,15 @@ implemented using OpenID and OAuth. Several useful SCA components are provided on top of the SCA runtime, which can be used to help assemble distributed SCA composite applications: -Cache: Key/value memory cache, using Memcached; +Cache: key/value memory cache, using Memcached; Chat: XMPP chat, using Apache Vysper and Libstrophe; -Log: distributed logger, using Facebook Scribe. -Nosqldb: Key/value 'NoSQL' persistent store, using TinyCDB; +Filedb: key/value 'NoSQL' persistent store, using plain files; +Http: HTTP client, using Libcurl; +Log: distributed logger, using Facebook Scribe; +Nosqldb: key/value 'NoSQL' persistent store, using TinyCDB; Queue: AMQP queuing, using Apache Qpid/C; Sqldb: SQL database, using PostgreSQL; -Webservice: Web service gateway, using Apache Axis2/C; +Webservice: Web service gateway, using Apache Axis2/C. These components present a simple ATOMPub REST interface, allowing you to send a message to a queue, a chat connection, or add an entry to a cache or a @@ -55,13 +57,15 @@ Here's a rough guide to the Tuscany SCA source tree: | |-- kernel SCA runtime kernel | | | |-- modules Modules that plug into the runtime - | | |-- atom AtomPub encoding + | | |-- atom AtomPub data encoding + | | |-- edit Composite app editor | | |-- http HTTP protocol | | |-- java Support for Java components - | | |-- json JSON-RPC encoding + | | |-- json JSON data encoding | | |-- oauth User signin using OAuth | | |-- openid User signin using OpenID | | |-- python Support for Python components + | | |-- rss RSS data encoding | | |-- scheme Support for Scheme components | | |-- server Apache HTTPD server integration | | |-- wsgi Python WSGI server integration @@ -69,6 +73,8 @@ Here's a rough guide to the Tuscany SCA source tree: | |-- components Useful SCA components | | |-- cache Memcached key/value cache | | |-- chat XMPP chat + | | |-- filedb Plain file NoSQL database + | | |-- http HTTP client | | |-- log Scribe logger | | |-- nosqldb TinyCDB NoSQL database | | |-- queue AMQP message queue 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 +#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 val = http::get(uri, cs); + assert(hasContent(val)); + assert(contains(string(car(cadr(content(val)))), "It works")); + + return true; +} + +struct getLoop { + http::CURLSession cs; + getLoop(http::CURLSession cs) : cs(cs) { + } + const bool operator()() const { + const failable val = http::get(uri, cs); + assert(hasContent(val)); + assert(contains(string(car(cadr(content(val)))), "It works")); + return true; + } +}; + +bool testGetPerf() { + http::CURLSession cs("", "", ""); + + const lambda 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 @@ + + + + + + + + + + + + + + + + + + + + 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 @@ + + + + + + + + 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 get(const lambda&)> url, http::CURLSession& ch) { + debug("httpget::get"); + const value u = url(mklist("get", list())); + debug(u, "httpget::get::url"); + return http::get(u, ch); +} + +/** + * Component implementation lambda function. + */ +class applyhttp { +public: + applyhttp(const lambda&)> url, http::CURLSession& ch) : url(url), ch(ch) { + } + + const value operator()(const list& params) const { + debug(params, "httpget::applyhttp::params"); + const value func(car(params)); + if (func == "get") + return get(url, ch); + return tuscany::mkfailure(); + } + +private: + const lambda&)> url; + http::CURLSession& ch; +}; + +/** + * Start the component. + */ +const failable start(const list& params) { + // Create a CURL session + http::CURLSession& ch = *(new (gc_new()) http::CURLSession("", "", "")); + + // Return the component implementation lambda function + return value(lambda&)>(applyhttp(car(params), ch))); +} + +} +} + +extern "C" { + +const tuscany::value apply(const tuscany::list& params) { + const tuscany::value func(car(params)); + if (func == "start") + return tuscany::httpget::start(cdr(params)); + return tuscany::mkfailure(); +} + +} 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 </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" +) + diff --git a/sca-cpp/trunk/configure.ac b/sca-cpp/trunk/configure.ac index e44bc181ec..9a64c78fb6 100644 --- a/sca-cpp/trunk/configure.ac +++ b/sca-cpp/trunk/configure.ac @@ -907,6 +907,7 @@ AC_CONFIG_FILES([Makefile components/chat/Makefile components/nosqldb/Makefile components/filedb/Makefile + components/http/Makefile components/queue/Makefile components/sqldb/Makefile components/webservice/Makefile diff --git a/sca-cpp/trunk/modules/edit/apps/testget/app.composite b/sca-cpp/trunk/modules/edit/apps/testget/app.composite new file mode 100644 index 0000000000..9f841afed6 --- /dev/null +++ b/sca-cpp/trunk/modules/edit/apps/testget/app.composite @@ -0,0 +1,65 @@ + + + + + + + + + + + + + http://www.google.com + + + + + + + + + + + + + + + + + http://www.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdXMLclient.php?whichClient=NDFDgen&lat=38.99&lon=-77.01&listLatLon=&lat1=&lon1=&lat2=&lon2=&resolutionSub=&listLat1=&listLon1=&listLat2=&listLon2=&resolutionList=&endPoint1Lat=&endPoint1Lon=&endPoint2Lat=&endPoint2Lon=&listEndPoint1Lat=&listEndPoint1Lon=&listEndPoint2Lat=&listEndPoint2Lon=&zipCodeList=&listZipCodeList=&centerPointLat=&centerPointLon=&distanceLat=&distanceLon=&resolutionSquare=&listCenterPointLat=&listCenterPointLon=&listDistanceLat=&listDistanceLon=&listResolutionSquare=&citiesLevel=&listCitiesLevel=&sector=&gmlListLatLon=&featureType=&requestedTime=&startTime=&endTime=&compType=&propertyName=&product=time-series&begin=2004-01-01T00%3A00%3A00&end=2015-03-10T00%3A00%3A00&maxt=maxt&Submit=Submit + + + + + http://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&sensor=false + + + + + + + + + + + http://feedproxy.google.com/TechCrunch + + diff --git a/sca-cpp/trunk/modules/edit/apps/testget/app.html b/sca-cpp/trunk/modules/edit/apps/testget/app.html new file mode 100644 index 0000000000..5c7c7219bb --- /dev/null +++ b/sca-cpp/trunk/modules/edit/apps/testget/app.html @@ -0,0 +1,20 @@ + + +
diff --git a/sca-cpp/trunk/modules/edit/apps/testlogic/app.composite b/sca-cpp/trunk/modules/edit/apps/testlogic/app.composite index 242a49c013..415de6a677 100644 --- a/sca-cpp/trunk/modules/edit/apps/testlogic/app.composite +++ b/sca-cpp/trunk/modules/edit/apps/testlogic/app.composite @@ -26,15 +26,10 @@ - - - - item - - + @@ -52,4 +47,9 @@ not greater than 5 + + + + 3 + diff --git a/sca-cpp/trunk/modules/edit/dashboards/joe@localhost b/sca-cpp/trunk/modules/edit/dashboards/joe@localhost index 5771c2f9de..9c40c7bd58 100644 --- a/sca-cpp/trunk/modules/edit/dashboards/joe@localhost +++ b/sca-cpp/trunk/modules/edit/dashboards/joe@localhost @@ -1 +1 @@ -((entry (title "An Empty Test App") (id "test")) (entry (title "Test Values and Lists") (id "testvalues")) (entry (title "Test Social Components") (id "testsocial")) (entry (title "Test URL Components") (id "testurl")) (entry (title "Test Logic Components") (id "testlogic")) (entry (title "Test Text Processing Components") (id "testtext")) (entry (title "An App that shows my Social Profiles") (id "me360")) (entry (title "An App that shows Friends Near Me") (id "nearme"))) +((entry (title "An Empty Test App") (id "test")) (entry (title "Test Values and Lists") (id "testvalues")) (entry (title "Test Social Components") (id "testsocial")) (entry (title "Test URL Components") (id "testurl")) (entry (title "Test Logic Components") (id "testlogic")) (entry (title "Test Text Processing Components") (id "testtext")) (entry (title "Test HTTP Get Component") (id "testget")) (entry (title "An App that shows my Social Profiles") (id "me360")) (entry (title "An App that shows Friends Near Me") (id "nearme"))) diff --git a/sca-cpp/trunk/modules/edit/dashboards/joe@sca-store.com b/sca-cpp/trunk/modules/edit/dashboards/joe@sca-store.com index 5771c2f9de..9c40c7bd58 100644 --- a/sca-cpp/trunk/modules/edit/dashboards/joe@sca-store.com +++ b/sca-cpp/trunk/modules/edit/dashboards/joe@sca-store.com @@ -1 +1 @@ -((entry (title "An Empty Test App") (id "test")) (entry (title "Test Values and Lists") (id "testvalues")) (entry (title "Test Social Components") (id "testsocial")) (entry (title "Test URL Components") (id "testurl")) (entry (title "Test Logic Components") (id "testlogic")) (entry (title "Test Text Processing Components") (id "testtext")) (entry (title "An App that shows my Social Profiles") (id "me360")) (entry (title "An App that shows Friends Near Me") (id "nearme"))) +((entry (title "An Empty Test App") (id "test")) (entry (title "Test Values and Lists") (id "testvalues")) (entry (title "Test Social Components") (id "testsocial")) (entry (title "Test URL Components") (id "testurl")) (entry (title "Test Logic Components") (id "testlogic")) (entry (title "Test Text Processing Components") (id "testtext")) (entry (title "Test HTTP Get Component") (id "testget")) (entry (title "An App that shows my Social Profiles") (id "me360")) (entry (title "An App that shows Friends Near Me") (id "nearme"))) diff --git a/sca-cpp/trunk/modules/edit/htdocs/main.html b/sca-cpp/trunk/modules/edit/htdocs/main.html index b219c27e50..ddd89b6bab 100644 --- a/sca-cpp/trunk/modules/edit/htdocs/main.html +++ b/sca-cpp/trunk/modules/edit/htdocs/main.html @@ -34,13 +34,13 @@

Try the App Dashboard to manage your collection of apps.

Composition Editor

-

Try the Composition Editor to compose the logic of an app.

+

Try the Composition Editor to compose the logic of an app.

Page Editor

-

Try the Page Editor to draw an app page.

+

Try the Page Editor to draw an app page.

App Settings Editor

-

Try the App Settings Editor to edit the settings of app.

+

Try the App Settings Editor to edit the settings of app.

diff --git a/sca-cpp/trunk/modules/edit/mkapplinks b/sca-cpp/trunk/modules/edit/mkapplinks index 66becf1618..3a9cd67e60 100755 --- a/sca-cpp/trunk/modules/edit/mkapplinks +++ b/sca-cpp/trunk/modules/edit/mkapplinks @@ -24,6 +24,12 @@ for n in `ls apps | awk '{ printf "apps/%s/nuvem\n", $1 }'`; do fi done +for n in `ls apps | awk '{ printf "apps/%s/lib\n", $1 }'`; do + if [ ! -e "$n" ]; then + ln -s ../../../../components "$n" + fi +done + for n in `ls apps | awk '{ printf "apps/%s/htdocs\n", $1 }'`; do if [ ! -e "$n" ]; then mkdir "$n" diff --git a/sca-cpp/trunk/modules/edit/palettes/url/palette.composite b/sca-cpp/trunk/modules/edit/palettes/url/palette.composite index 3a85322e51..dc3b40e6a7 100644 --- a/sca-cpp/trunk/modules/edit/palettes/url/palette.composite +++ b/sca-cpp/trunk/modules/edit/palettes/url/palette.composite @@ -26,8 +26,8 @@ - + @@ -53,16 +53,16 @@ - - - - - - + + + + + + -- cgit v1.2.3