diff options
Diffstat (limited to 'sca-cpp/trunk/components/http')
-rw-r--r-- | sca-cpp/trunk/components/http/Makefile.am | 11 | ||||
-rw-r--r-- | sca-cpp/trunk/components/http/httpdelete.componentType | 28 | ||||
-rw-r--r-- | sca-cpp/trunk/components/http/httpdelete.cpp | 90 |
3 files changed, 126 insertions, 3 deletions
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 @@ +<?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/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<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, 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 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::httpdelete::start(cdr(params)); + return tuscany::mkfailure<tuscany::value>(); +} + +} |