From 84dfee258c65ba901a01da176f07eef1f61294bd Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sun, 17 Apr 2011 22:14:29 +0000 Subject: Add an XMPP message sender component that only connects to an XMPP server as needed just before sending a message to avoid unnecessary connects / disconnects in a dynamic virtual host environment. Add another component that does an HTTP delete. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1094212 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/components/http/Makefile.am | 11 ++- .../trunk/components/http/httpdelete.componentType | 28 +++++++ sca-cpp/trunk/components/http/httpdelete.cpp | 90 ++++++++++++++++++++++ 3 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 sca-cpp/trunk/components/http/httpdelete.componentType create mode 100644 sca-cpp/trunk/components/http/httpdelete.cpp (limited to 'sca-cpp/trunk/components/http') diff --git a/sca-cpp/trunk/components/http/Makefile.am b/sca-cpp/trunk/components/http/Makefile.am index 05e41bb9e1..4388ec8057 100644 --- a/sca-cpp/trunk/components/http/Makefile.am +++ b/sca-cpp/trunk/components/http/Makefile.am @@ -17,16 +17,21 @@ compdir=$(prefix)/components/http -EXTRA_DIST = http.composite httpget.componentType *.scm +EXTRA_DIST = http.composite httpget.componentType httpdelete.componentType *.scm -comp_LTLIBRARIES = libhttpget.la -noinst_DATA = libhttpget.so +comp_LTLIBRARIES = libhttpget.la libhttpdelete.la +noinst_DATA = libhttpget.so libhttpdelete.so libhttpget_la_SOURCES = httpget.cpp libhttpget_la_LDFLAGS = -lxml2 -lmozjs -curl libhttpget.so: ln -s .libs/libhttpget.so +libhttpdelete_la_SOURCES = httpdelete.cpp +libhttpdelete_la_LDFLAGS = -lxml2 -lmozjs -curl +libhttpdelete.so: + ln -s .libs/libhttpdelete.so + client_test_SOURCES = client-test.cpp client_test_LDFLAGS = -lxml2 -lcurl -lmozjs diff --git a/sca-cpp/trunk/components/http/httpdelete.componentType b/sca-cpp/trunk/components/http/httpdelete.componentType new file mode 100644 index 0000000000..620f549e21 --- /dev/null +++ b/sca-cpp/trunk/components/http/httpdelete.componentType @@ -0,0 +1,28 @@ + + + + + + + + diff --git a/sca-cpp/trunk/components/http/httpdelete.cpp b/sca-cpp/trunk/components/http/httpdelete.cpp new file mode 100644 index 0000000000..0bebfb9de2 --- /dev/null +++ b/sca-cpp/trunk/components/http/httpdelete.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 httpdelete { + +/** + * Evaluate an HTTP delete. + */ +const failable get(const lambda&)> url, http::CURLSession& ch) { + debug("httpdelete::get"); + const value u = url(mklist("get", list())); + debug(u, "httpdelete::get::url"); + return http::del(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, "httpdelete::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::httpdelete::start(cdr(params)); + return tuscany::mkfailure(); +} + +} -- cgit v1.2.3